aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-08-20 14:48:12 (EDT)
committerAlexander Kurtakov2013-08-28 04:53:50 (EDT)
commit25b44117fffac7ec121daae6b2c0c438f4f1545e (patch)
tree2dfd541fdee894dfaa72b9c894acaa6d3ea7509a
parent6f43418e245d509302e7c6b0a02004ac1fce3084 (diff)
downloadorg.eclipse.linuxtools-25b44117fffac7ec121daae6b2c0c438f4f1545e.zip
org.eclipse.linuxtools-25b44117fffac7ec121daae6b2c0c438f4f1545e.tar.gz
org.eclipse.linuxtools-25b44117fffac7ec121daae6b2c0c438f4f1545e.tar.bz2
RPM: working set option for RPM Project B#413732refs/changes/57/15857/4
Allow user to select a working set(s) to put the new RPM Project into. Also allow right-clicking on an existing working set on the explorer to add the newly created RPM to that working set(s). Similar functionality to eclipse-fedorapackager. Change-Id: I70da873d340ed3dbe3a7dfae22809a79b58b583e Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/15857 Tested-by: Hudson CI Reviewed-by: Alexander Kurtakov <akurtako@redhat.com> IP-Clean: Alexander Kurtakov <akurtako@redhat.com> Tested-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui/META-INF/MANIFEST.MF1
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/Activator.java55
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/NewProjectCreationPage.java130
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RPMNewProject.java15
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/rpm_strings.properties6
5 files changed, 198 insertions, 9 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui/META-INF/MANIFEST.MF b/rpm/org.eclipse.linuxtools.rpm.ui/META-INF/MANIFEST.MF
index db0e089..3f5fad2 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui/META-INF/MANIFEST.MF
+++ b/rpm/org.eclipse.linuxtools.rpm.ui/META-INF/MANIFEST.MF
@@ -15,3 +15,4 @@ Require-Bundle: org.eclipse.ui.ide,
org.eclipse.debug.ui;bundle-version="3.6.0"
Export-Package:
org.eclipse.linuxtools.rpm.ui
+Bundle-Activator: org.eclipse.linuxtools.internal.rpm.ui.Activator
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/Activator.java b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/Activator.java
new file mode 100644
index 0000000..0fbc7c4
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/Activator.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpm.ui;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ /** The symbolic ID of the plugin */
+ public static final String PLUGIN_ID = "org.eclipse.linuxtools.rpm.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/NewProjectCreationPage.java b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/NewProjectCreationPage.java
index 8dbceeb..43cb577 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/NewProjectCreationPage.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/NewProjectCreationPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
+ * Copyright (c) 2011, 2013 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,15 +10,25 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.rpm.ui;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.TreePath;
import org.eclipse.linuxtools.rpm.core.RPMProjectLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
+import org.eclipse.ui.dialogs.WorkingSetConfigurationBlock;
/**
* Standard page for project creation adding some rpm specific controls.
@@ -27,6 +37,9 @@ import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
public class NewProjectCreationPage extends WizardNewProjectCreationPage {
private ComboViewer typeCombo;
+ private final WorkingSetGroup workingSetGroup;
+
+ private static final IWorkingSet[] EMPTY_WORKING_SET_ARRAY = new IWorkingSet[0];
/**
* Instantiate the page.
@@ -34,6 +47,18 @@ public class NewProjectCreationPage extends WizardNewProjectCreationPage {
*/
public NewProjectCreationPage(String pageName) {
super(pageName);
+ workingSetGroup = new WorkingSetGroup();
+ setWorkingSets(EMPTY_WORKING_SET_ARRAY);
+ }
+
+ /**
+ * The wizard owning this page can call this method to initialise fields using the
+ * current selection.
+ *
+ * @param selection the current object selection
+ */
+ public void init(IStructuredSelection selection) {
+ setWorkingSets(getSelectedWorkingSet(selection));
}
@Override
@@ -54,12 +79,14 @@ public class NewProjectCreationPage extends WizardNewProjectCreationPage {
typeCombo.setContentProvider(ArrayContentProvider.getInstance());
typeCombo.setInput(RPMProjectLayout.values());
typeCombo.getCombo().select(0);
-
+ // Working set controls
+ Control workingSetControl = workingSetGroup.createControl(control);
+ workingSetControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
/**
* Returns the selected layout if any or the default one - RPMBUILD.
- *
+ *
* @return The selected project layout.
*/
public RPMProjectLayout getSelectedLayout() {
@@ -68,4 +95,101 @@ public class NewProjectCreationPage extends WizardNewProjectCreationPage {
}
+ /**
+ * Returns the working sets to which the new project should be added.
+ *
+ * @return the selected working sets to which the new project should be added
+ */
+ public IWorkingSet[] getWorkingSets() {
+ return workingSetGroup.getSelectedWorkingSets();
+ }
+
+ /**
+ * Sets the working sets to which the new project should be added.
+ *
+ * @param workingSets the initial selected working sets
+ */
+ public void setWorkingSets(IWorkingSet[] workingSets) {
+ if (workingSets == null) {
+ workingSetGroup.setWorkingSets(EMPTY_WORKING_SET_ARRAY);
+ }
+ workingSetGroup.setWorkingSets(workingSets);
+ }
+
+ /**
+ * Try our best to set the working sets field to something sensible based on the
+ * current selection.
+ */
+ private IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection) {
+ if (!(selection instanceof ITreeSelection))
+ return EMPTY_WORKING_SET_ARRAY;
+
+ ITreeSelection treeSelection = (ITreeSelection) selection;
+ if (treeSelection.isEmpty())
+ return EMPTY_WORKING_SET_ARRAY;
+
+ List<?> elements= treeSelection.toList();
+ if (elements.size() == 1) {
+ Object element = elements.get(0);
+ TreePath[] paths = treeSelection.getPathsFor(element);
+ if (paths.length != 1 || paths[0].getSegmentCount() == 0)
+ return EMPTY_WORKING_SET_ARRAY;
+
+ Object candidate = paths[0].getSegment(0);
+ if (!(candidate instanceof IWorkingSet))
+ return EMPTY_WORKING_SET_ARRAY;
+
+ IWorkingSet workingSetCandidate = (IWorkingSet) candidate;
+ if (!workingSetCandidate.isAggregateWorkingSet())
+ return new IWorkingSet[] { workingSetCandidate };
+
+ return EMPTY_WORKING_SET_ARRAY;
+ }
+
+ ArrayList<IWorkingSet> result = new ArrayList<IWorkingSet>();
+ for (Object element : elements) {
+ if (element instanceof IWorkingSet && !((IWorkingSet) element).isAggregateWorkingSet()) {
+ result.add((IWorkingSet)element);
+ }
+ }
+
+ if (!result.isEmpty()) {
+ return result.toArray(new IWorkingSet[result.size()]);
+ } else {
+ return EMPTY_WORKING_SET_ARRAY;
+ }
+ }
+
+ /**
+ * Little class to encapsulate the working set group of controls.
+ */
+ private final class WorkingSetGroup {
+
+ private WorkingSetConfigurationBlock workingSetBlock;
+
+ public WorkingSetGroup() {
+ String[] workingSetIds = new String[] { "org.eclipse.ui.resourceWorkingSetPage" }; //$NON-NLS-1$
+ workingSetBlock = new WorkingSetConfigurationBlock(workingSetIds,
+ Activator.getDefault().getDialogSettings());
+ }
+
+ public Control createControl(Composite composite) {
+ Group workingSetGroup = new Group(composite, SWT.NONE);
+ workingSetGroup.setFont(composite.getFont());
+ workingSetGroup.setText(Messages.getString("NewProjectCreationPage.0")); //$NON-NLS-1$
+ workingSetGroup.setLayout(new GridLayout(1, false));
+
+ workingSetBlock.createContent(workingSetGroup);
+
+ return workingSetGroup;
+ }
+
+ public void setWorkingSets(IWorkingSet[] workingSets) {
+ workingSetBlock.setWorkingSets(workingSets);
+ }
+
+ public IWorkingSet[] getSelectedWorkingSets() {
+ return workingSetBlock.getSelectedWorkingSets();
+ }
+ }
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RPMNewProject.java b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RPMNewProject.java
index b65ae41..6b66e8b 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RPMNewProject.java
+++ b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/RPMNewProject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Red Hat, Inc.
+ * Copyright (c) 2009, 2013 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,6 +12,7 @@ package org.eclipse.linuxtools.internal.rpm.ui;
import java.lang.reflect.InvocationTargetException;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -21,6 +22,8 @@ import org.eclipse.jface.wizard.Wizard;
import org.eclipse.linuxtools.rpm.core.RPMProjectCreator;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
/**
@@ -47,7 +50,6 @@ public class RPMNewProject extends Wizard implements INewWizard {
return false;
}
return true;
-
}
public void init(IWorkbench workbench, IStructuredSelection selection) {
@@ -59,11 +61,16 @@ public class RPMNewProject extends Wizard implements INewWizard {
namePage.setImageDescriptor(ImageDescriptor.createFromFile(getClass(),
"/icons/rpm.gif")); //$NON-NLS-1$
addPage(namePage);
+ namePage.init(selection);
}
protected void createProject(IProgressMonitor monitor) throws CoreException {
RPMProjectCreator rpmProjectCreator = new RPMProjectCreator(namePage.getSelectedLayout());
- rpmProjectCreator.create(namePage.getProjectName(), namePage.getLocationPath(), monitor);
+ IProject project = rpmProjectCreator.create(namePage.getProjectName(), namePage.getLocationPath(), monitor);
+ // Add new project to working sets, if requested
+ IWorkingSet[] workingSets = namePage.getWorkingSets();
+ if (workingSets.length > 0) {
+ PlatformUI.getWorkbench().getWorkingSetManager().addToWorkingSets(project, workingSets);
+ }
}
-
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/rpm_strings.properties b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/rpm_strings.properties
index b67c223..090a15b 100644
--- a/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/rpm_strings.properties
+++ b/rpm/org.eclipse.linuxtools.rpm.ui/src/org/eclipse/linuxtools/internal/rpm/ui/rpm_strings.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2004, 2009 Red Hat, Inc.
+# Copyright (c) 2004, 2013 Red Hat, Inc.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -177,4 +177,6 @@ ErrorDialog.title=Error
RPMNewProject.0=New RPM Project
RPMNewProject.1=Create a new RPM project
-RPMNewProject.2=Created project will have a standard rpmbuild structure. \ No newline at end of file
+RPMNewProject.2=Created project will have a standard rpmbuild structure.
+
+NewProjectCreationPage.0=Working sets \ No newline at end of file