Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-01-20 13:33:54 +0000
committercletavernie2012-01-20 13:33:54 +0000
commit4419c6a7b502912ce78e6022eb1c57f6e07b67df (patch)
tree65d49e790d27d2984c1ad0b4db9126c84b9d2d1d /plugins
parent0cc12e79115034e5e22892d9d18620e8bab0f0c2 (diff)
downloadorg.eclipse.papyrus-4419c6a7b502912ce78e6022eb1c57f6e07b67df.tar.gz
org.eclipse.papyrus-4419c6a7b502912ce78e6022eb1c57f6e07b67df.tar.xz
org.eclipse.papyrus-4419c6a7b502912ce78e6022eb1c57f6e07b67df.zip
359794: [UML - Tools] Content/Label providers
https://bugs.eclipse.org/bugs/show_bug.cgi?id=359794
Diffstat (limited to 'plugins')
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/PropertyEditorTypeContentProvider.java12
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/ExtensibleLabelProvider.java108
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IFilteredLabelProvider.java (renamed from plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/IFilteredLabelProvider.java)5
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/providers/UMLFilteredLabelProvider.java13
-rw-r--r--plugins/views/properties/org.eclipse.papyrus.views.properties/schema/labelprovider.exsd2
-rw-r--r--plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/EMFFilteredLabelProvider.java7
-rw-r--r--plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/SelectionLabelProvider.java44
7 files changed, 139 insertions, 52 deletions
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/PropertyEditorTypeContentProvider.java b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/PropertyEditorTypeContentProvider.java
index 5e0e2b024cb..a9b1a16cd7b 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/PropertyEditorTypeContentProvider.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/PropertyEditorTypeContentProvider.java
@@ -77,12 +77,20 @@ public class PropertyEditorTypeContentProvider extends EMFGraphicalContentProvid
if(source.getProperty() == null) {
return true;
}
- return editorType.getType() == source.getProperty().getType();
+ return editorType.getType() == source.getProperty().getType() && isMultiplicityEquivalent(editorType.getMultiplicity(), source.getProperty().getMultiplicity());
}
return false;
}
+ private boolean isMultiplicityEquivalent(int multiplicity, int multiplicity2) {
+ if(multiplicity < 0 || multiplicity > 1) {
+ return multiplicity2 < 0 || multiplicity2 > 1;
+ }
+
+ return multiplicity == 1 && multiplicity2 == 1;
+ }
+
public boolean getFilter() {
return filter;
}
@@ -91,7 +99,5 @@ public class PropertyEditorTypeContentProvider extends EMFGraphicalContentProvid
this.filter = filter;
clearCache();
}
-
}
-
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/ExtensibleLabelProvider.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/ExtensibleLabelProvider.java
new file mode 100644
index 00000000000..3627341de77
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/ExtensibleLabelProvider.java
@@ -0,0 +1,108 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.providers;
+
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
+import org.eclipse.swt.graphics.Image;
+
+
+public class ExtensibleLabelProvider implements ILabelProvider, ILabelProviderListener {
+
+ private final Set<ILabelProviderListener> listeners;
+
+ private final SortedMap<Integer, List<IFilteredLabelProvider>> providers;
+
+ private final ILabelProvider defaultProvider;
+
+ public ExtensibleLabelProvider() {
+ listeners = new LinkedHashSet<ILabelProviderListener>();
+ providers = new TreeMap<Integer, List<IFilteredLabelProvider>>();
+
+ defaultProvider = new LabelProvider();
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ listeners.add(listener);
+ }
+
+ public void dispose() {
+ listeners.clear();
+ for(List<IFilteredLabelProvider> filteredProviders : providers.values()) {
+ for(IFilteredLabelProvider provider : filteredProviders) {
+ provider.dispose();
+ }
+ }
+ providers.clear();
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ listeners.remove(listener);
+ }
+
+ public void registerProvider(int priority, IFilteredLabelProvider provider) {
+ getProviders(priority).add(provider);
+ provider.addListener(this);
+ }
+
+ public Image getImage(Object element) {
+ return getProvider(element).getImage(element);
+ }
+
+ public String getText(Object element) {
+ return getProvider(element).getText(element);
+ }
+
+ protected final ILabelProvider getProvider(Object element) {
+ for(List<IFilteredLabelProvider> filteredProviders : providers.values()) {
+ for(IFilteredLabelProvider provider : filteredProviders) {
+ if(provider.accept(element)) {
+ return provider;
+ }
+ }
+ }
+
+ return defaultProvider;
+ }
+
+ protected final List<IFilteredLabelProvider> getProviders(int priority) {
+ if(!providers.containsKey(priority)) {
+ providers.put(priority, new LinkedList<IFilteredLabelProvider>());
+ }
+
+ return providers.get(priority);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards the event to each listener
+ */
+ public void labelProviderChanged(LabelProviderChangedEvent event) {
+ for(ILabelProviderListener listener : listeners) {
+ listener.labelProviderChanged(event);
+ }
+ }
+}
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/IFilteredLabelProvider.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IFilteredLabelProvider.java
index 028c92a2d28..1d7dfb56763 100644
--- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/IFilteredLabelProvider.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IFilteredLabelProvider.java
@@ -9,10 +9,9 @@
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
*****************************************************************************/
-package org.eclipse.papyrus.views.properties.providers;
+package org.eclipse.papyrus.infra.widgets.providers;
import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
/**
* A LabelProvider which only accepts a specific set of objects
@@ -21,5 +20,5 @@ import org.eclipse.jface.viewers.IStructuredSelection;
*/
public interface IFilteredLabelProvider extends ILabelProvider {
- public boolean accept(IStructuredSelection selection);
+ public boolean accept(Object element);
}
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/providers/UMLFilteredLabelProvider.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/providers/UMLFilteredLabelProvider.java
index 0aa4a4eb116..b3a1f314be5 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/providers/UMLFilteredLabelProvider.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/providers/UMLFilteredLabelProvider.java
@@ -17,8 +17,8 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.widgets.providers.IFilteredLabelProvider;
import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.papyrus.views.properties.providers.IFilteredLabelProvider;
import org.eclipse.uml2.uml.Element;
/**
@@ -32,9 +32,6 @@ import org.eclipse.uml2.uml.Element;
*/
public class UMLFilteredLabelProvider extends UMLLabelProvider implements IFilteredLabelProvider {
- /**
- * {@inheritDoc}
- */
public boolean accept(IStructuredSelection selection) {
if(selection.isEmpty()) {
return false;
@@ -51,7 +48,11 @@ public class UMLFilteredLabelProvider extends UMLLabelProvider implements IFilte
return true;
}
- protected boolean accept(Object element) {
+ public boolean accept(Object element) {
+ if(element instanceof IStructuredSelection) {
+ return accept((IStructuredSelection)element);
+ }
+
//The element is a UML Element or can be adapted to an EObject
EObject eObject = EMFHelper.getEObject(element);
if(eObject == null) {
@@ -60,10 +61,12 @@ public class UMLFilteredLabelProvider extends UMLLabelProvider implements IFilte
if(eObject instanceof Element) {
return true;
}
+
//TODO : is this really this provider's role to accept GMF Diagrams ?
if(eObject instanceof Diagram) {
return true;
}
+
return false;
}
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/schema/labelprovider.exsd b/plugins/views/properties/org.eclipse.papyrus.views.properties/schema/labelprovider.exsd
index 41b20e6ac87..4230f16eacf 100644
--- a/plugins/views/properties/org.eclipse.papyrus.views.properties/schema/labelprovider.exsd
+++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/schema/labelprovider.exsd
@@ -55,7 +55,7 @@
</documentation>
<appInfo>
- <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.views.properties.providers.IFilteredLabelProvider"/>
+ <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.infra.widgets.providers.IFilteredLabelProvider"/>
</appInfo>
</annotation>
</attribute>
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/EMFFilteredLabelProvider.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/EMFFilteredLabelProvider.java
index 76b7dab5b91..db1e17b400e 100644
--- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/EMFFilteredLabelProvider.java
+++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/EMFFilteredLabelProvider.java
@@ -16,6 +16,7 @@ import java.util.Iterator;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.widgets.providers.IFilteredLabelProvider;
/**
* A LabelProvider which only accepts EMF Objects (EObject, or objects which can be adapted to EObjects)
@@ -41,7 +42,11 @@ public class EMFFilteredLabelProvider extends EMFLabelProvider implements IFilte
return true;
}
- protected boolean accept(Object element) {
+ public boolean accept(Object element) {
+ if(element instanceof IStructuredSelection) {
+ return accept((IStructuredSelection)element);
+ }
+
//The element is an EObject or can be adapted to an EObject
return EMFHelper.getEObject(element) != null;
}
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/SelectionLabelProvider.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/SelectionLabelProvider.java
index 9f7d0add7b5..7c18f34fd71 100644
--- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/SelectionLabelProvider.java
+++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/providers/SelectionLabelProvider.java
@@ -12,16 +12,13 @@
package org.eclipse.papyrus.views.properties.providers;
import java.util.Collection;
-import java.util.LinkedList;
import java.util.TreeMap;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.papyrus.infra.widgets.providers.ExtensibleLabelProvider;
+import org.eclipse.papyrus.infra.widgets.providers.IFilteredLabelProvider;
import org.eclipse.papyrus.views.properties.Activator;
-import org.eclipse.swt.graphics.Image;
/**
* A class for providing labels for a selected element.
@@ -31,7 +28,7 @@ import org.eclipse.swt.graphics.Image;
* @author Camille Letavernier
*
*/
-public class SelectionLabelProvider extends LabelProvider {
+public class SelectionLabelProvider extends ExtensibleLabelProvider {
public static final String EXTENSION_ID = "org.eclipse.papyrus.views.properties.labelprovider"; //$NON-NLS-1$
@@ -42,6 +39,7 @@ public class SelectionLabelProvider extends LabelProvider {
protected final TreeMap<Integer, Collection<IFilteredLabelProvider>> labelProviders = new TreeMap<Integer, Collection<IFilteredLabelProvider>>();
public SelectionLabelProvider() {
+ super();
readExtensionPoint();
}
@@ -52,42 +50,10 @@ public class SelectionLabelProvider extends LabelProvider {
try {
final IFilteredLabelProvider provider = (IFilteredLabelProvider)e.createExecutableExtension(LABEL_PROVIDER_PROPERTY);
final int priority = Integer.parseInt(e.getAttribute(PRIORITY_PROPERTY));
- getLabelProviders(priority).add(provider);
+ registerProvider(priority, provider);
} catch (Exception ex) {
Activator.log.error("Cannot load the label provider : " + e.getAttribute(LABEL_PROVIDER_PROPERTY), ex);
}
}
}
-
- protected Collection<IFilteredLabelProvider> getLabelProviders(int priority) {
- if(!labelProviders.containsKey(priority)) {
- labelProviders.put(priority, new LinkedList<IFilteredLabelProvider>());
- }
- return labelProviders.get(priority);
- }
-
- @Override
- public String getText(Object element) {
- return getLabelProvider(element).getText(element);
- }
-
- @Override
- public Image getImage(Object element) {
- return getLabelProvider(element).getImage(element);
- }
-
- protected ILabelProvider getLabelProvider(Object element) {
- if(element instanceof IStructuredSelection) {
- IStructuredSelection selection = (IStructuredSelection)element;
- for(Collection<IFilteredLabelProvider> providers : labelProviders.values()) {
- for(IFilteredLabelProvider labelProvider : providers) {
- if(labelProvider.accept(selection)) {
- return labelProvider;
- }
- }
- }
- }
-
- return new LabelProvider(); //Default
- }
}

Back to the top