aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2011-02-14 09:02:27 -0800
committerAndroid Code Review <code-review@android.com>2011-02-14 09:02:27 -0800
commitb8d178edb4c159ce4dbd5fe522d584d34ad2c042 (patch)
tree7d2bbd749ee7e3fab3a1c63654e319059c90d0d9 /eclipse
parent99f15759c9fc900577710102cc07f566ce593ddf (diff)
parent7e6f7f3fcd78883086a08f0efb647044b883889b (diff)
downloadsdk-b8d178edb4c159ce4dbd5fe522d584d34ad2c042.zip
sdk-b8d178edb4c159ce4dbd5fe522d584d34ad2c042.tar.gz
sdk-b8d178edb4c159ce4dbd5fe522d584d34ad2c042.tar.bz2
Merge "Refactor WorkingSet function."
Diffstat (limited to 'eclipse')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreationPage.java20
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java113
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewTestProjectCreationPage.java30
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/WorkingSetGroup.java66
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/WorkingSetHelper.java130
5 files changed, 214 insertions, 145 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreationPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreationPage.java
index 295c49e..027b94e 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreationPage.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreationPage.java
@@ -31,8 +31,8 @@ import com.android.ide.eclipse.adt.internal.wizards.newproject.NewTestProjectCre
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.SdkConstants;
import com.android.sdklib.internal.project.ProjectProperties;
-import com.android.sdklib.internal.project.ProjectProperties.PropertyType;
import com.android.sdklib.internal.project.ProjectPropertiesWorkingCopy;
+import com.android.sdklib.internal.project.ProjectProperties.PropertyType;
import com.android.sdklib.xml.AndroidManifest;
import com.android.sdklib.xml.ManifestData;
import com.android.sdklib.xml.ManifestData.Activity;
@@ -48,11 +48,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.JavaConventions;
-import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
-import org.eclipse.jdt.internal.ui.workingsets.IWorkingSetIDs;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeSelection;
-import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.osgi.util.TextProcessor;
import org.eclipse.swt.SWT;
@@ -68,7 +64,6 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
@@ -82,8 +77,6 @@ import java.io.File;
import java.io.FileFilter;
import java.net.URI;
import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
import java.util.regex.Pattern;
/**
@@ -185,7 +178,7 @@ public class NewProjectCreationPage extends WizardPage {
}
public void init(IStructuredSelection selection, IWorkbenchPart activePart) {
- setWorkingSets(NewProjectWizard.getSelectedWorkingSet(selection, activePart));
+ setWorkingSets(WorkingSetHelper.getSelectedWorkingSet(selection, activePart));
}
// --- Getters used by NewProjectWizard ---
@@ -378,6 +371,7 @@ public class NewProjectCreationPage extends WizardPage {
createLocationGroup(composite);
createTargetGroup(composite);
createPropertiesGroup(composite);
+ createWorkingSetGroup(composite);
// Update state the first time
enableLocationWidgets();
@@ -397,9 +391,6 @@ public class NewProjectCreationPage extends WizardPage {
setMessage(null);
setControl(scrolledComposite);
- Control workingSetControl = mWorkingSetGroup.createControl(composite);;
- workingSetControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
// Validate. This will complain about the first empty field.
validatePageComplete();
}
@@ -710,6 +701,11 @@ public class NewProjectCreationPage extends WizardPage {
});
}
+ private void createWorkingSetGroup(final Composite composite) {
+ Composite group = mWorkingSetGroup.createControl(composite);
+ group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ }
+
//--- Internal getters & setters ------------------
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java
index d12830c..6e2a677 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectWizard.java
@@ -51,20 +51,15 @@ import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
-import org.eclipse.jdt.internal.ui.workingsets.IWorkingSetIDs;
import org.eclipse.jdt.ui.actions.OpenJavaPerspectiveAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeSelection;
-import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
@@ -77,13 +72,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
+import java.util.Map.Entry;
/**
* A "New Android Project" Wizard.
@@ -91,8 +83,8 @@ import java.util.Set;
* Note: this class is public so that it can be accessed from unit tests.
* It is however an internal class. Its API may change without notice.
* It should semantically be considered as a private final class.
+ * <p/>
* Do not derive from this class.
-
*/
public class NewProjectWizard extends Wizard implements INewWizard {
@@ -1086,7 +1078,7 @@ public class NewProjectWizard extends Wizard implements INewWizard {
* Adds the given folder to the project's class path.
*
* @param javaProject The Java Project to update.
- * @param sourceFolder Template Parameters.
+ * @param sourceFolders Template Parameters.
* @param monitor An existing monitor.
* @throws JavaModelException if the classpath could not be set.
*/
@@ -1210,103 +1202,4 @@ public class NewProjectWizard extends Wizard implements INewWizard {
return str;
}
-
- /*
- * Copied from org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageOne
- */
-
- private static final IWorkingSet[] EMPTY_WORKING_SET_ARRAY = new IWorkingSet[0];
-
- public static IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection,
- IWorkbenchPart activePart) {
- IWorkingSet[] selected= getSelectedWorkingSet(selection);
- if (selected != null && selected.length > 0) {
- for (int i= 0; i < selected.length; i++) {
- if (!isValidWorkingSet(selected[i]))
- return EMPTY_WORKING_SET_ARRAY;
- }
- return selected;
- }
-
- if (!(activePart instanceof PackageExplorerPart))
- return EMPTY_WORKING_SET_ARRAY;
-
- PackageExplorerPart explorerPart= (PackageExplorerPart) activePart;
- if (explorerPart.getRootMode() == PackageExplorerPart.PROJECTS_AS_ROOTS) {
- //Get active filter
- IWorkingSet filterWorkingSet= explorerPart.getFilterWorkingSet();
- if (filterWorkingSet == null)
- return EMPTY_WORKING_SET_ARRAY;
-
- if (!isValidWorkingSet(filterWorkingSet))
- return EMPTY_WORKING_SET_ARRAY;
-
- return new IWorkingSet[] {filterWorkingSet};
- } else {
- //If we have been gone into a working set return the working set
- Object input= explorerPart.getViewPartInput();
- if (!(input instanceof IWorkingSet))
- return EMPTY_WORKING_SET_ARRAY;
-
- IWorkingSet workingSet= (IWorkingSet)input;
- if (!isValidWorkingSet(workingSet))
- return EMPTY_WORKING_SET_ARRAY;
-
- return new IWorkingSet[] {workingSet};
- }
- }
-
- public static 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)
- return EMPTY_WORKING_SET_ARRAY;
-
- TreePath path= paths[0];
- if (path.getSegmentCount() == 0)
- return EMPTY_WORKING_SET_ARRAY;
-
- Object candidate= path.getSegment(0);
- if (!(candidate instanceof IWorkingSet))
- return EMPTY_WORKING_SET_ARRAY;
-
- IWorkingSet workingSetCandidate= (IWorkingSet) candidate;
- if (isValidWorkingSet(workingSetCandidate))
- return new IWorkingSet[] { workingSetCandidate };
-
- return EMPTY_WORKING_SET_ARRAY;
- }
-
- ArrayList result= new ArrayList();
- for (Iterator iterator= elements.iterator(); iterator.hasNext();) {
- Object element= iterator.next();
- if (element instanceof IWorkingSet && isValidWorkingSet((IWorkingSet) element)) {
- result.add(element);
- }
- }
- return (IWorkingSet[]) result.toArray(new IWorkingSet[result.size()]);
- }
-
-
- private static boolean isValidWorkingSet(IWorkingSet workingSet) {
- String id= workingSet.getId();
- if (!IWorkingSetIDs.JAVA.equals(id) && !IWorkingSetIDs.RESOURCE.equals(id))
- return false;
-
- if (workingSet.isAggregateWorkingSet())
- return false;
-
- return true;
- }
-
-
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewTestProjectCreationPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewTestProjectCreationPage.java
index d7c4048..dfdd72e 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewTestProjectCreationPage.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewTestProjectCreationPage.java
@@ -89,6 +89,7 @@ import java.util.regex.Pattern;
* Note: this class is public so that it can be accessed from unit tests.
* It is however an internal class. Its API may change without notice.
* It should semantically be considered as a private final class.
+ * <p/>
* Do not derive from this class.
*/
public class NewTestProjectCreationPage extends WizardPage {
@@ -174,7 +175,7 @@ public class NewTestProjectCreationPage extends WizardPage {
}
public void init(IStructuredSelection selection, IWorkbenchPart activePart) {
- setWorkingSets(NewProjectWizard.getSelectedWorkingSet(selection, activePart));
+ setWorkingSets(WorkingSetHelper.getSelectedWorkingSet(selection, activePart));
}
// --- Getters used by NewProjectWizard ---
@@ -308,6 +309,7 @@ public class NewTestProjectCreationPage extends WizardPage {
createTestTargetGroup(composite);
createTargetGroup(composite);
createPropertiesGroup(composite);
+ createWorkingSetGroup(composite);
// Update state the first time
enableLocationWidgets();
@@ -325,9 +327,6 @@ public class NewTestProjectCreationPage extends WizardPage {
setMessage(null);
setControl(scrolledComposite);
- Control workingSetControl = mWorkingSetGroup.createControl(composite);
- workingSetControl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
// Validate. This will complain about the first empty field.
validatePageComplete();
}
@@ -706,6 +705,12 @@ public class NewTestProjectCreationPage extends WizardPage {
});
}
+ private void createWorkingSetGroup(final Composite composite) {
+ Composite group = mWorkingSetGroup.createControl(composite);
+ group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ mToggleComposites.add(group);
+ }
//--- Internal getters & setters ------------------
@@ -759,10 +764,8 @@ public class NewTestProjectCreationPage extends WizardPage {
*/
private void useMainProjectInformation() {
if (mInfo.isTestingMain() && mMainInfo != null) {
- IWorkingSet[] workingSets = mMainInfo.getSelectedWorkingSets();
- if (workingSets != null && workingSets.length > 0) {
- mWorkingSetGroup.setWorkingSets(workingSets);
- }
+ useMainWorkingSets();
+
String projName = String.format("%1$sTest", mMainInfo.getProjectName());
String appName = String.format("%1$sTest", mMainInfo.getApplicationName());
@@ -806,6 +809,17 @@ public class NewTestProjectCreationPage extends WizardPage {
}
}
+ private void useMainWorkingSets() {
+ IWorkingSet[] workingSets = mMainInfo.getSelectedWorkingSets();
+ if (workingSets != null) {
+ // getSelectedWorkingSets returns an empty list if the working set feature is disabled.
+ if (workingSets.length > 0) {
+ mWorkingSetGroup.setChecked(true);
+ }
+ mWorkingSetGroup.setWorkingSets(workingSets);
+ }
+ }
+
/**
* Callback invoked when the user edits the project text field.
*/
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/WorkingSetGroup.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/WorkingSetGroup.java
index 33ed218..8192361 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/WorkingSetGroup.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/WorkingSetGroup.java
@@ -1,18 +1,13 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 IBM Corporation 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
*
- * Licensed under the Eclipse Public License, Version 1.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.eclipse.org/org/documents/epl-v10.php
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
package com.android.ide.eclipse.adt.internal.wizards.newproject;
@@ -21,6 +16,7 @@ import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
import org.eclipse.jdt.internal.ui.workingsets.IWorkingSetIDs;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
@@ -34,9 +30,11 @@ import org.eclipse.ui.dialogs.WorkingSetConfigurationBlock;
* Creates the working set group with controls that allow
* the selection of working sets
*/
+@SuppressWarnings("restriction")
public class WorkingSetGroup {
private WorkingSetConfigurationBlock fWorkingSetBlock;
+ private Button mEnableButton;
public WorkingSetGroup() {
String[] workingSetIds = new String[] {
@@ -46,7 +44,7 @@ public class WorkingSetGroup {
.getDialogSettings());
}
- public Control createControl(Composite composite) {
+ public Composite createControl(Composite composite) {
Group workingSetGroup = new Group(composite, SWT.NONE);
workingSetGroup.setFont(composite.getFont());
workingSetGroup.setText(NewWizardMessages.NewJavaProjectWizardPageOne_WorkingSets_group);
@@ -54,6 +52,15 @@ public class WorkingSetGroup {
fWorkingSetBlock.createContent(workingSetGroup);
+ // WorkingSetGroup is implemented in such a way that the checkbox it contains
+ // can only be programmatically set if there's an existing working set associated
+ // *before* we construct the control. However the control is created when the
+ // wizard is opened, not when the page is first shown.
+ //
+ // One choice is to duplicate the class in our project.
+ // Or find the checkbox we want and trigger it manually.
+ mEnableButton = findCheckbox(workingSetGroup);
+
return workingSetGroup;
}
@@ -64,4 +71,33 @@ public class WorkingSetGroup {
public IWorkingSet[] getSelectedWorkingSets() {
return fWorkingSetBlock.getSelectedWorkingSets();
}
+
+ public boolean isChecked() {
+ return mEnableButton == null ? false : mEnableButton.getSelection();
+ }
+
+ public void setChecked(boolean state) {
+ if (mEnableButton != null) {
+ mEnableButton.setSelection(state);
+ }
+ }
+
+ /**
+ * Finds the first button of style Checkbox in the given parent composite.
+ * Returns null if not found.
+ */
+ private Button findCheckbox(Composite parent) {
+ for (Control control : parent.getChildren()) {
+ if (control instanceof Button && (control.getStyle() & SWT.CHECK) == SWT.CHECK) {
+ return (Button) control;
+ } else if (control instanceof Composite) {
+ Button found = findCheckbox((Composite) control);
+ if (found != null) {
+ return found;
+ }
+ }
+ }
+
+ return null;
+ }
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/WorkingSetHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/WorkingSetHelper.java
new file mode 100755
index 0000000..428bfd3
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/WorkingSetHelper.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package com.android.ide.eclipse.adt.internal.wizards.newproject;
+
+import org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart;
+import org.eclipse.jdt.internal.ui.workingsets.IWorkingSetIDs;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkingSet;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * This class contains a helper method to deal with working sets.
+ * <p/>
+ * Copied from org.eclipse.jdt.ui.wizards.NewJavaProjectWizardPageOne
+ */
+@SuppressWarnings("restriction")
+public final class WorkingSetHelper {
+
+ private static final IWorkingSet[] EMPTY_WORKING_SET_ARRAY = new IWorkingSet[0];
+
+ /** This class is never instantiated. */
+ private WorkingSetHelper() {
+ }
+
+ public static IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection,
+ IWorkbenchPart activePart) {
+ IWorkingSet[] selected= getSelectedWorkingSet(selection);
+ if (selected != null && selected.length > 0) {
+ for (int i= 0; i < selected.length; i++) {
+ if (!isValidWorkingSet(selected[i]))
+ return EMPTY_WORKING_SET_ARRAY;
+ }
+ return selected;
+ }
+
+ if (!(activePart instanceof PackageExplorerPart))
+ return EMPTY_WORKING_SET_ARRAY;
+
+ PackageExplorerPart explorerPart= (PackageExplorerPart) activePart;
+ if (explorerPart.getRootMode() == PackageExplorerPart.PROJECTS_AS_ROOTS) {
+ //Get active filter
+ IWorkingSet filterWorkingSet= explorerPart.getFilterWorkingSet();
+ if (filterWorkingSet == null)
+ return EMPTY_WORKING_SET_ARRAY;
+
+ if (!isValidWorkingSet(filterWorkingSet))
+ return EMPTY_WORKING_SET_ARRAY;
+
+ return new IWorkingSet[] {filterWorkingSet};
+ } else {
+ //If we have been gone into a working set return the working set
+ Object input= explorerPart.getViewPartInput();
+ if (!(input instanceof IWorkingSet))
+ return EMPTY_WORKING_SET_ARRAY;
+
+ IWorkingSet workingSet= (IWorkingSet)input;
+ if (!isValidWorkingSet(workingSet))
+ return EMPTY_WORKING_SET_ARRAY;
+
+ return new IWorkingSet[] {workingSet};
+ }
+ }
+
+ private static 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)
+ return EMPTY_WORKING_SET_ARRAY;
+
+ TreePath path= paths[0];
+ if (path.getSegmentCount() == 0)
+ return EMPTY_WORKING_SET_ARRAY;
+
+ Object candidate= path.getSegment(0);
+ if (!(candidate instanceof IWorkingSet))
+ return EMPTY_WORKING_SET_ARRAY;
+
+ IWorkingSet workingSetCandidate= (IWorkingSet) candidate;
+ if (isValidWorkingSet(workingSetCandidate))
+ return new IWorkingSet[] { workingSetCandidate };
+
+ return EMPTY_WORKING_SET_ARRAY;
+ }
+
+ ArrayList<Object> result = new ArrayList<Object>();
+ for (Iterator<?> iterator = elements.iterator(); iterator.hasNext();) {
+ Object element= iterator.next();
+ if (element instanceof IWorkingSet && isValidWorkingSet((IWorkingSet) element)) {
+ result.add(element);
+ }
+ }
+ return result.toArray(new IWorkingSet[result.size()]);
+ }
+
+
+ private static boolean isValidWorkingSet(IWorkingSet workingSet) {
+ String id= workingSet.getId();
+ if (!IWorkingSetIDs.JAVA.equals(id) && !IWorkingSetIDs.RESOURCE.equals(id))
+ return false;
+
+ if (workingSet.isAggregateWorkingSet())
+ return false;
+
+ return true;
+ }
+}