aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Besedin2011-10-06 15:38:29 (EDT)
committerOleg Besedin2011-10-06 15:38:29 (EDT)
commit7af46d79c3d52dc5c98651172e058b57ca851acd (patch)
tree866d4ae7c65204d941352855b66953a90e650c76
parent335fae2a02aaa221174f640bedefbfe83f2a2ad5 (diff)
downloadeclipse.platform.ui-7af46d79c3d52dc5c98651172e058b57ca851acd.zip
eclipse.platform.ui-7af46d79c3d52dc5c98651172e058b57ca851acd.tar.gz
eclipse.platform.ui-7af46d79c3d52dc5c98651172e058b57ca851acd.tar.bz2
Bug 294628 - [PropertiesDialog] Properties Dialog : need support for
showing properties on multiple selection
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPropertyPage.java7
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/PropertyDialogAction.java25
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/PropertyPage.java10
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyDialog.java34
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageContributorManager.java58
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageNode.java6
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/RegistryPageContributor.java167
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/PropertyPagesRegistryReader.java17
8 files changed, 243 insertions, 81 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPropertyPage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPropertyPage.java
index 0cdf088..fbda04e 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPropertyPage.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPropertyPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -31,6 +31,11 @@ import org.eclipse.ui.dialogs.PropertyDialogAction;
* </extension>
* </pre>
* </p>
+ * <p>
+ * Property pages that support multiple selected objects should
+ * implement {@link IWorkbenchPropertyPageMulti} instead.
+ * </p>
+ * @see IWorkbenchPropertyPageMulti
*/
public interface IWorkbenchPropertyPage extends IPreferencePage {
/**
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/PropertyDialogAction.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/PropertyDialogAction.java
index 3374289..f584e01 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/PropertyDialogAction.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/PropertyDialogAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * James Blackburn (Broadcom Corp.) - Bug 294628 multiple selection
*******************************************************************************/
package org.eclipse.ui.dialogs;
@@ -94,13 +95,13 @@ public class PropertyDialogAction extends SelectionProviderAction {
}
/**
- * Returns whether the provided object has pages registered in the property
+ * Returns whether the provided selection has pages registered in the property
* page manager.
*
* @param object
* @return boolean
*/
- private boolean hasPropertyPagesFor(Object object) {
+ private boolean hasPropertyPagesFor(IStructuredSelection object) {
return PropertyPageContributorManager.getManager().getApplicableContributors(object).size() != 0;
}
@@ -115,7 +116,7 @@ public class PropertyDialogAction extends SelectionProviderAction {
* state of the action on each selection change.
* </p>
*
- * @return <code>true</code> if the selection is of size 1 and there are
+ * @return <code>true</code> if the selection is not empty and there are
* property pages for the selected element, and <code>false</code>
* otherwise
*/
@@ -128,7 +129,7 @@ public class PropertyDialogAction extends SelectionProviderAction {
/**
* Returns whether this action is applicable to the current selection. This
- * checks that the selection is of size 1, and checks with the workbench's
+ * checks that the selection is not empty, and checks with the workbench's
* property page manager to see if there are any property pages registered
* for the selected element's type.
* <p>
@@ -138,12 +139,12 @@ public class PropertyDialogAction extends SelectionProviderAction {
*
* @param selection
* The selection to test
- * @return <code>true</code> if the selection is of size 1 and there are
+ * @return <code>true</code> if the selection is of not empty and there are
* property pages for the selected element, and <code>false</code>
* otherwise
*/
public boolean isApplicableForSelection(IStructuredSelection selection) {
- return selection.size() == 1 && hasPropertyPagesFor(selection.getFirstElement());
+ return !selection.isEmpty() && hasPropertyPagesFor(selection);
}
@@ -167,13 +168,11 @@ public class PropertyDialogAction extends SelectionProviderAction {
* @since 3.1
*/
public PreferenceDialog createDialog() {
-
- Object element = getStructuredSelection().getFirstElement();
- if (element == null) {
+ if (getStructuredSelection().isEmpty())
return null;
- }
+
return PropertyDialog
- .createDialogOn(shellProvider.getShell(), initialPageId, element);
+ .createDialogOn(shellProvider.getShell(), initialPageId, getStructuredSelection());
}
@@ -181,6 +180,6 @@ public class PropertyDialogAction extends SelectionProviderAction {
* @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
*/
public void selectionChanged(IStructuredSelection selection) {
- setEnabled(selection.size() == 1 && selection.getFirstElement() != null);
+ setEnabled(!selection.isEmpty());
}
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/PropertyPage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/PropertyPage.java
index a4bf64d..1d6667d 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/PropertyPage.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/dialogs/PropertyPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -13,12 +13,16 @@ package org.eclipse.ui.dialogs;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.ui.IWorkbenchPropertyPage;
+import org.eclipse.ui.IWorkbenchPropertyPageMulti;
/**
* Abstract base implementation of a workbench property page (
* <code>IWorkbenchPropertyPage</code>). The implementation is a JFace
* preference page with an adaptable element.
* <p>
+ * Property pages that support multiple selected objects should
+ * implement {@link IWorkbenchPropertyPageMulti} instead.
+ * <p>
* Subclasses must implement the <code>createContents</code> framework method to
* supply the property page's main control.
* </p>
@@ -38,9 +42,9 @@ import org.eclipse.ui.IWorkbenchPropertyPage;
* </p>
*
* @see IWorkbenchPropertyPage
+ * @see IWorkbenchPropertyPageMulti
*/
-public abstract class PropertyPage extends PreferencePage implements
- IWorkbenchPropertyPage {
+public abstract class PropertyPage extends PreferencePage implements IWorkbenchPropertyPage {
/**
* The element.
*/
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyDialog.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyDialog.java
index f4760e3..a2b2dda 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyDialog.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyDialog.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -7,14 +7,15 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * James Blackburn (Broadcom Corp.) - Bug 294628 multiple selection
*******************************************************************************/
package org.eclipse.ui.internal.dialogs;
import java.util.Iterator;
-
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.PreferenceManager;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
@@ -91,18 +92,35 @@ public class PropertyDialog extends FilteredPreferenceDialog {
}
/**
- * Returns the name of the given element.
+ * Returns the name of the given element(s). Prints at most 3 names.
*
* @param element
- * the element
+ * the element / IStructuredSelection
* @return the name of the element
*/
private static String getName(Object element) {
- IWorkbenchAdapter adapter = (IWorkbenchAdapter)Util.getAdapter(element, IWorkbenchAdapter.class);
- if (adapter != null) {
- return adapter.getLabel(element);
+ Object[] elements;
+ if (element instanceof IStructuredSelection)
+ elements = ((IStructuredSelection) element).toArray();
+ else
+ elements = new Object[] { element };
+ StringBuffer sb = new StringBuffer();
+ // Print at most 3 entries...
+ for (int i = 0; i < elements.length; i++) {
+ element = elements[i];
+ if (i > 2) {
+ sb.append(" ..."); //$NON-NLS-1$
+ break;
+ }
+ IWorkbenchAdapter adapter = (IWorkbenchAdapter) Util.getAdapter(element,
+ IWorkbenchAdapter.class);
+ if (adapter != null) {
+ if (sb.length() > 0)
+ sb.append(", "); //$NON-NLS-1$
+ sb.append(adapter.getLabel(element));
+ }
}
- return "";//$NON-NLS-1$
+ return sb.toString();
}
/**
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageContributorManager.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageContributorManager.java
index 2ef7574..cb25119 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageContributorManager.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageContributorManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Oakland Software (Francis Upton) <francisu@ieee.org> - bug 219273
+ * James Blackburn (Broadcom Corp.) - Bug 294628 multiple selection
*******************************************************************************/
package org.eclipse.ui.internal.dialogs;
@@ -16,14 +17,15 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
-
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
import org.eclipse.jface.preference.PreferenceNode;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.internal.ObjectContributorManager;
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
import org.eclipse.ui.internal.registry.PropertyPagesRegistryReader;
@@ -66,13 +68,28 @@ public class PropertyPageContributorManager extends ObjectContributorManager {
* contributors and sequentially invoke them to contribute to the property
* page manager. Matching algorithm will also check subclasses and
* implemented interfaces.
+ *
+ * If object is an IStructuredSelection then attempt to match all the
+ * contained objects.
+ *
* @param manager
* @param object
* @return true if contribution took place, false otherwise.
*/
public boolean contribute(PropertyPageManager manager, Object object) {
- List result = getContributors(object);
+ Collection result = null;
+ if (object instanceof IStructuredSelection) {
+ Object[] objs = ((IStructuredSelection) object).toArray();
+ for (int i = 0; i < objs.length; i++) {
+ List contribs = getContributors(objs[i]);
+ if (result == null)
+ result = new LinkedHashSet(contribs);
+ else
+ result.retainAll(contribs);
+ }
+ } else
+ result = getContributors(object);
if (result == null || result.size() == 0) {
return false;
@@ -129,7 +146,7 @@ public class PropertyPageContributorManager extends ObjectContributorManager {
* @param nodes
* @return List of CategorizedPageNode
*/
- private List buildNodeList(List nodes) {
+ private List buildNodeList(Collection nodes) {
Hashtable mapping = new Hashtable();
Iterator nodesIterator = nodes.iterator();
@@ -192,6 +209,8 @@ public class PropertyPageContributorManager extends ObjectContributorManager {
* @return Collection of PropertyPageContribution
*/
public Collection getApplicableContributors(Object element) {
+ if (element instanceof IStructuredSelection)
+ return getApplicableContributors((IStructuredSelection) element);
Collection contributors = getContributors(element);
Collection result = new ArrayList();
for (Iterator iter = contributors.iterator(); iter.hasNext();) {
@@ -203,6 +222,37 @@ public class PropertyPageContributorManager extends ObjectContributorManager {
return result;
}
+ /**
+ * Get applicable contributors for multiple selection
+ *
+ * @param selection
+ * @return Collection of applicable property page contributors
+ * @since 3.7
+ */
+ public Collection getApplicableContributors(IStructuredSelection selection) {
+ Iterator it = selection.iterator();
+ Collection result = null;
+ while (it.hasNext()) {
+ Object element = it.next();
+ Collection collection = getApplicableContributors(element);
+ if (result == null)
+ result = new LinkedHashSet(collection);
+ else
+ result.retainAll(collection);
+ }
+ if (result != null && !result.isEmpty() && selection.size() > 1) {
+ // only add contributors which can handle multi selection
+ it = result.iterator();
+ while (it.hasNext()) {
+ RegistryPageContributor contrib = (RegistryPageContributor) it
+ .next();
+ if (!contrib.supportsMultipleSelection())
+ it.remove();
+ }
+ }
+ return result;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ui.internal.ObjectContributorManager#getExtensionPointFilter()
*/
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageNode.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageNode.java
index b22bc77..4606bda 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageNode.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/PropertyPageNode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -12,9 +12,9 @@ package org.eclipse.ui.internal.dialogs;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.preference.IPreferencePage;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.IWorkbenchPropertyPage;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.internal.misc.StatusUtil;
import org.eclipse.ui.internal.preferences.WorkbenchPreferenceExtensionNode;
@@ -28,7 +28,7 @@ import org.eclipse.ui.statushandlers.StatusManager;
public class PropertyPageNode extends WorkbenchPreferenceExtensionNode {
private RegistryPageContributor contributor;
- private IWorkbenchPropertyPage page;
+ private IPreferencePage page;
private Image icon;
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/RegistryPageContributor.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/RegistryPageContributor.java
index e69760c..da32597 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/RegistryPageContributor.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/RegistryPageContributor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -9,16 +9,17 @@
* IBM Corporation - initial API and implementation
* Jan-Hendrik Diederich, Bredex GmbH - bug 201052
* Oakland Software (Francis Upton) <francisu@ieee.org> - bug 223808
+ * James Blackburn (Broadcom Corp.) - Bug 294628 multiple selection
*******************************************************************************/
package org.eclipse.ui.internal.dialogs;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-
import org.eclipse.core.expressions.EvaluationContext;
import org.eclipse.core.expressions.EvaluationResult;
import org.eclipse.core.expressions.Expression;
@@ -28,11 +29,14 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.preference.IPreferencePage;
import org.eclipse.jface.preference.PreferenceNode;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionFilter;
import org.eclipse.ui.IPluginContribution;
import org.eclipse.ui.IWorkbenchPropertyPage;
+import org.eclipse.ui.IWorkbenchPropertyPageMulti;
import org.eclipse.ui.SelectionEnabler;
import org.eclipse.ui.internal.IWorkbenchConstants;
import org.eclipse.ui.internal.LegacyResourceSupport;
@@ -66,6 +70,11 @@ public class RegistryPageContributor implements IPropertyPageContributor,
private boolean adaptable = false;
+ /**
+ * Flag which indicates if this property page supports multiple selection
+ */
+ private final boolean supportsMultiSelect;
+
private IConfigurationElement pageElement;
private SoftReference filterProperties;
@@ -88,6 +97,8 @@ public class RegistryPageContributor implements IPropertyPageContributor,
pageElement
.getAttribute(PropertyPagesRegistryReader.ATT_ADAPTABLE))
.booleanValue();
+ supportsMultiSelect = PropertyPagesRegistryReader.ATT_SELECTION_FILTER_MULTI
+ .equals(pageElement.getAttribute(PropertyPagesRegistryReader.ATT_SELECTION_FILTER));
initializeEnablement(element);
}
@@ -114,29 +125,45 @@ public class RegistryPageContributor implements IPropertyPageContributor,
* @throws CoreException
* thrown if there is a problem creating the apge
*/
- public IWorkbenchPropertyPage createPage(Object element)
+ public IPreferencePage createPage(Object element)
throws CoreException {
- IWorkbenchPropertyPage ppage = null;
- ppage = (IWorkbenchPropertyPage) WorkbenchPlugin.createExtension(
+ IPreferencePage ppage = null;
+ ppage = (IPreferencePage) WorkbenchPlugin.createExtension(
pageElement, IWorkbenchRegistryConstants.ATT_CLASS);
ppage.setTitle(getPageName());
- Object adapted = element;
- if (adaptable) {
- adapted = getAdaptedElement(element);
- if (adapted == null) {
- String message = "Error adapting selection to Property page " + pageId + " is being ignored"; //$NON-NLS-1$ //$NON-NLS-2$
- throw new CoreException(new Status(IStatus.ERROR,
- WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR, message,
- null));
+ Object[] elements = getObjects(element);
+ IAdaptable[] adapt = new IAdaptable[elements.length];
+
+ for (int i = 0; i < elements.length; i++) {
+ Object adapted = elements[i];
+ if (adaptable) {
+ adapted = getAdaptedElement(adapted);
+ if (adapted == null) {
+ String message = "Error adapting selection to Property page " + pageId + " is being ignored"; //$NON-NLS-1$ //$NON-NLS-2$
+ throw new CoreException(new Status(IStatus.ERROR,
+ WorkbenchPlugin.PI_WORKBENCH, IStatus.ERROR,
+ message, null));
+ }
}
+ adapt[i] = (IAdaptable) ((adapted instanceof IAdaptable) ? adapted
+ : new AdaptableForwarder(adapted));
}
- if (adapted instanceof IAdaptable)
- ppage.setElement((IAdaptable) adapted);
- else
- ppage.setElement(new AdaptableForwarder(adapted));
+ if (supportsMultiSelect) {
+ if ((ppage instanceof IWorkbenchPropertyPageMulti))
+ ((IWorkbenchPropertyPageMulti) ppage).setElements(adapt);
+ else
+ throw new CoreException(
+ new Status(
+ IStatus.ERROR,
+ WorkbenchPlugin.PI_WORKBENCH,
+ IStatus.ERROR,
+ "Property page must implement IWorkbenchPropertyPageMulti: " + getPageName(), //$NON-NLS-1$
+ null));
+ } else
+ ((IWorkbenchPropertyPage) ppage).setElement(adapt[0]);
return ppage;
}
@@ -201,60 +228,84 @@ public class RegistryPageContributor implements IPropertyPageContributor,
}
/**
- * Return true if name filter is not defined in the registry for this page,
- * or if name of the selected object matches the name filter.
+ * Calculate whether the Property page is applicable to the current
+ * selection. Checks:
+ * <ul>
+ * <li>multiSelect</li>
+ * <li>enabledWhen enablement expression/li>
+ * <li>nameFilter</li>
+ * <li>custom Filter</li>
+ * <li>checks legacy resource support</li>
+ * </ul>
+ * <p>
+ * For multipleSelection pages, considers all elements in the selection for
+ * enablement.
*/
public boolean isApplicableTo(Object object) {
+ Object[] objs = getObjects(object);
+
+ // If not a multi-select page not applicable to multiple selection
+ if (objs.length > 1 && !supportsMultiSelect)
+ return false;
- if (failsEnablement(object))
+ if (failsEnablement(objs))
return false;
// Test name filter
String nameFilter = pageElement
.getAttribute(PropertyPagesRegistryReader.ATT_NAME_FILTER);
- if (nameFilter != null) {
- String objectName = object.toString();
- IWorkbenchAdapter adapter = (IWorkbenchAdapter) Util.getAdapter(object,
- IWorkbenchAdapter.class);
- if (adapter != null) {
- String elementName = adapter.getLabel(object);
- if (elementName != null) {
- objectName = elementName;
+
+ for (int i = 0; i < objs.length; i++) {
+ object = objs[i];
+ // Name filter
+ if (nameFilter != null) {
+ String objectName = object.toString();
+ IWorkbenchAdapter adapter = (IWorkbenchAdapter) Util
+ .getAdapter(object, IWorkbenchAdapter.class);
+ if (adapter != null) {
+ String elementName = adapter.getLabel(object);
+ if (elementName != null) {
+ objectName = elementName;
+ }
}
+ if (!SelectionEnabler.verifyNameMatch(objectName, nameFilter))
+ return false;
}
- if (!SelectionEnabler.verifyNameMatch(objectName, nameFilter))
- return false;
- }
- // Test custom filter
- if (getFilterProperties() == null)
- return true;
- IActionFilter filter = null;
+ // Test custom filter
+ if (getFilterProperties() == null)
+ return true;
+ IActionFilter filter = null;
- // Do the free IResource adapting
- Object adaptedObject = LegacyResourceSupport.getAdaptedResource(object);
- if (adaptedObject != null) {
- object = adaptedObject;
- }
+ // Do the free IResource adapting
+ Object adaptedObject = LegacyResourceSupport
+ .getAdaptedResource(object);
+ if (adaptedObject != null) {
+ object = adaptedObject;
+ }
- filter = (IActionFilter)Util.getAdapter(object, IActionFilter.class);
+ filter = (IActionFilter) Util.getAdapter(object,
+ IActionFilter.class);
- if (filter != null)
- return testCustom(object, filter);
+ if (filter != null && !testCustom(object, filter))
+ return false;
+ }
return true;
}
/**
- * Return whether or not object fails the enablement criterea.
- *
- * @param object
+ * Return whether or not object fails the enabledWhen enablement criterea.
+ * For multi-select pages, evaluate the enabledWhen expression using the
+ * structured selection as a Collection (which should be iterated over).
* @return boolean <code>true</code> if it fails the enablement test
*/
- private boolean failsEnablement(Object object) {
+ private boolean failsEnablement(Object[] objs) {
if (enablementExpression == null)
return false;
try {
+ // If multi-select property page, always pass a collection for iteration
+ Object object = (supportsMultiSelect) ? Arrays.asList(objs) : objs[0];
EvaluationContext context = new EvaluationContext(null, object);
context.setAllowPluginActivation(true);
return enablementExpression.evaluate(
@@ -267,6 +318,20 @@ public class RegistryPageContributor implements IPropertyPageContributor,
}
/**
+ * Returns an object array for the passed in object. If the object is an
+ * IStructuredSelection, then return its array otherwise return a 1 element
+ * Object[] containing the passed in object
+ *
+ * @param obj
+ * @return an object array representing the passed in object
+ */
+ private Object[] getObjects(Object obj) {
+ if (obj instanceof IStructuredSelection)
+ return ((IStructuredSelection) obj).toArray();
+ return new Object[] { obj };
+ }
+
+ /**
* Initialize the enablement expression for this decorator
*/
protected void initializeEnablement(IConfigurationElement definingElement) {
@@ -404,6 +469,14 @@ public class RegistryPageContributor implements IPropertyPageContributor,
}
/**
+ * @return boolean indicating if this page supports multiple selection
+ * @since 3.7
+ */
+ boolean supportsMultipleSelection() {
+ return supportsMultiSelect;
+ }
+
+ /**
* @return the configuration element
* @since 3.1
*/
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/PropertyPagesRegistryReader.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/PropertyPagesRegistryReader.java
index eccaed8..c347567 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/PropertyPagesRegistryReader.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/PropertyPagesRegistryReader.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * James Blackburn (Broadcom Corp.) - Bug 294628 multiple selection
*******************************************************************************/
package org.eclipse.ui.internal.registry;
@@ -14,7 +15,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.ui.PlatformUI;
@@ -41,6 +41,19 @@ public class PropertyPagesRegistryReader extends CategorizedPageRegistryReader {
*/
public static final String ATT_FILTER_VALUE = "value";//$NON-NLS-1$
+ /**
+ * Value "<code>selectionFilter</code>". Is an enum allowing propertyPages to
+ * support multiple selection when enum value is <code>ATT_SELECTION_FILTER_MULTI</code>
+ * @since 3.7
+ */
+ public static final String ATT_SELECTION_FILTER = "selectionFilter";//$NON-NLS-1$
+
+ /**
+ * Selection filter attribute value indicating support for multiple selection.
+ * @since 3.7
+ */
+ public static final String ATT_SELECTION_FILTER_MULTI = "multi";//$NON-NLS-1$
+
private static final String TAG_PAGE = "page";//$NON-NLS-1$
/**