Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-08-23 09:30:18 -0400
committervlorenzo2012-08-23 09:30:18 -0400
commit34935ca27036414137da5efd8addbe2b92f8f232 (patch)
tree6afe978839cf1ed7fb4f835bc844a0f6c2b102dd /plugins/infra
parent3aefe99e61689c91c0222194337a9c14febb3a2f (diff)
downloadorg.eclipse.papyrus-34935ca27036414137da5efd8addbe2b92f8f232.tar.gz
org.eclipse.papyrus-34935ca27036414137da5efd8addbe2b92f8f232.tar.xz
org.eclipse.papyrus-34935ca27036414137da5efd8addbe2b92f8f232.zip
387883: [Property View] the property view header doesn't support multi-selection
https://bugs.eclipse.org/bugs/show_bug.cgi?id=387883
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF3
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFLabelProvider.java96
2 files changed, 91 insertions, 8 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
index 3670db69dad..1103e73de19 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
@@ -26,7 +26,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.emf.transaction;bundle-version="1.4.0",
org.eclipse.emf.ecore.xmi,
org.eclipse.emf.facet.custom.metamodel;bundle-version="0.2.0",
- org.eclipse.emf.facet.custom.ui;bundle-version="0.2.0"
+ org.eclipse.emf.facet.custom.ui;bundle-version="0.2.0",
+ org.eclipse.emf.facet.util.emf.core
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.papyrus.infra.emf,
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFLabelProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFLabelProvider.java
index a294de4b6ba..58dc70e8afd 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFLabelProvider.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFLabelProvider.java
@@ -11,6 +11,11 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.emf.providers;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.facet.infra.browser.uicore.CustomizableModelLabelProvider;
@@ -21,7 +26,6 @@ import org.eclipse.papyrus.infra.emf.Activator;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.widgets.providers.IDetailLabelProvider;
import org.eclipse.swt.graphics.Image;
-
/**
* This class handles labels for EMF Objects
* The class can handle the following cases :
@@ -76,9 +80,22 @@ public class EMFLabelProvider extends CustomizableModelLabelProvider implements
return ""; //$NON-NLS-1$
}
- //TODO : Implement a multi-selection label, instead of just the first element's label
- Object element = selection.getFirstElement();
- return getText(element);
+ if(selection.size() == 1) {
+ return getText(selection.getFirstElement());
+ } else {
+ final List<Object> selectionAsList = selection.toList();
+ String str = "";
+ for(int i = 0; i < selectionAsList.size(); i++) {
+ final String txt = getText(selectionAsList.get(i));
+ if(txt != null) {
+ str += txt;
+ }
+ if(i < selectionAsList.size() - 1) {
+ str += ", ";
+ }
+ }
+ return str;
+ }
}
/**
@@ -109,11 +126,76 @@ public class EMFLabelProvider extends CustomizableModelLabelProvider implements
protected Image getImage(IStructuredSelection selection) {
if(selection.isEmpty()) {
return null;
+ } else if(selection.size() == 1) {
+ return getImage(selection.getFirstElement());
+ }
+
+ final List<?> selectionAsList = selection.toList();
+ final Set<EObject> selectedEObject = new HashSet<EObject>();
+ boolean isEObjectSelection = true;
+ for(final Object current : selectionAsList) {
+ final EObject obj = EMFHelper.getEObject(current);
+ if(obj != null) {
+ selectedEObject.add(obj);
+ } else {
+ isEObjectSelection = false;
+ }
}
- //TODO : Implement a multi-selection label, instead of just the first element's label
- Object element = selection.getFirstElement();
- return getImage(element);
+ if(isEObjectSelection) {//all selected elements are EObject
+ if(selectedEObject.size() == 1 || hasCommonImage(selectedEObject)) {
+ return getImage(selectedEObject.toArray()[0]);
+ } else {
+ final EClass common = org.eclipse.emf.facet.util.emf.core.internal.EMFUtils.computeLeastCommonSupertype(getEClasses(selectedEObject));
+ if(!common.isAbstract()) {
+ //FIXME : the label provider service should manage this case
+ final Object instance = common.getEPackage().getEFactoryInstance().create(common);
+ return getImage(instance);
+ }
+ }
+ } else if(selectedEObject.size() == 0) {
+ //the multiple selection contains any EObject
+ } else {
+ //the selection contains EObject and others elements
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param objects
+ * a collection of objects
+ * @return
+ * <code>true</code> if the image found for each object is the same <code>false</code> of if the collection is empty or the image returned
+ * for each object is not the same
+ */
+ private boolean hasCommonImage(final Collection<?> objects) {
+ if(!objects.isEmpty()) {
+ final Image lastImage = getImage(objects.toArray()[0]);
+ for(final Object current : objects) {
+ if(lastImage != getImage(current)) {
+ return false;
+ }
+ }
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ *
+ * @param objects
+ * a collection of eobject
+ * @return
+ * the set of eclasses for the parameter objects
+ */
+ private Set<EClass> getEClasses(final Collection<EObject> objects) {
+ final Set<EClass> eclasses = new HashSet<EClass>();
+ for(final EObject current : objects) {
+ eclasses.add(current.eClass());
+ }
+ return eclasses;
}
public String getDetail(Object object) {

Back to the top