Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael ADAM2016-08-25 09:58:59 +0000
committerGerrit Code Review @ Eclipse.org2016-09-27 08:02:02 +0000
commitad65ff8c3f11fd8651c42be6eff13abbb1d3b279 (patch)
tree96920ac8874dce44d109342dda08af4e1e09814f /plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf
parent21f7c5441e48e341c79ccd90cc78227b39c6e6d7 (diff)
downloadorg.eclipse.papyrus-ad65ff8c3f11fd8651c42be6eff13abbb1d3b279.tar.gz
org.eclipse.papyrus-ad65ff8c3f11fd8651c42be6eff13abbb1d3b279.tar.xz
org.eclipse.papyrus-ad65ff8c3f11fd8651c42be6eff13abbb1d3b279.zip
Bug 500219 - [Model Explorer] Papyrus Should provide an other way to
customize uml label Change-Id: Ic3213ed9aefb636f4e581df7996378dfd96d8937 Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
Diffstat (limited to 'plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf')
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/ICustomizedLabelProvider.java26
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedLabelProvider.java94
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/DecoratingCustomizedLabelProvider.java22
-rw-r--r--plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/ResolvingCustomizedLabelProvider.java30
4 files changed, 140 insertions, 32 deletions
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/ICustomizedLabelProvider.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/ICustomizedLabelProvider.java
index dc309d9c2f8..e2ce6216ce7 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/ICustomizedLabelProvider.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/ICustomizedLabelProvider.java
@@ -11,13 +11,16 @@
* Gregoire Dupe (Mia-Software) - Bug 369987 - [Restructuring][Table] Switch to the new customization and facet framework
* Vincent Lorenzo (CEA-LIST) - Bug 372644 - Create Customizable tooltips for the TreeViewer using a CustomizableLabelProvider
* Gregoire Dupe (Mia-Software) - Bug 373078 - API Cleaning
+ * Mickael ADAM (ALL4TEC) - mickael.adam@all4tec.net - Bug 500219 - implementation of IStyledLabelProvider
*/
package org.eclipse.papyrus.emf.facet.custom.ui;
import org.eclipse.emf.ecore.ETypedElement;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.IFontProvider;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.StyledString;
import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManager;
import org.eclipse.swt.graphics.Image;
@@ -30,7 +33,7 @@ import org.eclipse.swt.graphics.Image;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICustomizedLabelProvider extends ILabelProvider,
- IColorProvider, IFontProvider, ICustomizedToolTipLabelProvider {
+ IColorProvider, IFontProvider, ICustomizedToolTipLabelProvider, IStyledLabelProvider {
/**
* This method returns the customization manager used by the label provider. The
* customization stack updates have to be done using this {@link ICustomizationManager}.
@@ -64,4 +67,25 @@ public interface ICustomizedLabelProvider extends ILabelProvider,
*/
ICustomizedLabelProvider cloneLabelProvider();
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
+ *
+ * @since 1.3
+ */
+ @Override
+ default StyledString getStyledText(final Object element) {
+ return new StyledString(getText(element));
+ }
+
+ /**
+ * Returns the styled text label for the given element.
+ *
+ * @since 1.3
+ */
+ default StyledString getStyledText(final Object element, final ETypedElement eTypedElement) {
+ return new StyledString(getText(element, eTypedElement));
+ }
+
}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedLabelProvider.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedLabelProvider.java
index dbd3499764f..aa319689a6c 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedLabelProvider.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/CustomizedLabelProvider.java
@@ -16,13 +16,14 @@
* Gregoire Dupe (Mia-Software) - Bug 374941 - To be able to customize overlay icons on EClass
* Gregoire Dupe (Mia-Software) - Bug 364325 - [Restructuring] The user must be able to navigate into a model using the Facet.
* Vincent Lorenzo (CEA-LIST) - Bug 352603 - [Table] A tooltip which displays the full label of a String cell editor
- * Grégoire Dupé(Mia-Software) - Bug 352603 - [Table] A tooltip which displays the full label of a String cell editor
+ * Gr�goire Dup�(Mia-Software) - Bug 352603 - [Table] A tooltip which displays the full label of a String cell editor
* David Couvrand (Soft-Maint) - Bug 402725 - Need a query to get an image from an URI
* Nicolas Rault (Soft-Maint) - Bug 402725 - Need a query to get an image from an URI
* David Couvrand (Soft-Maint) - Bug 418418 - [Customization] Overlay icons not implemented
* David Couvrand (Soft-Maint) - Bug 422058 - Implementation of strikethrough and underline in the CustomizedLabelProvider
- * Grégoire Dupé (Mia-Software) - Bug 424122 - [Table] Images, fonts and colors are not shared between the instances of table
+ * Gr�goire Dup� (Mia-Software) - Bug 424122 - [Table] Images, fonts and colors are not shared between the instances of table
* Thomas Cicognani (Soft-Maint) - Bug 424414 - ImageManager doesn't cache images
+ * Mickael ADAM (ALL4TEC) - mickael.adam@all4tec.net - Bug 500219 - implementation of IStyledLabelProvider
*/
package org.eclipse.papyrus.emf.facet.custom.ui.internal;
@@ -105,8 +106,8 @@ public class CustomizedLabelProvider extends CellLabelProvider implements
public String getText(final Object element) {
String result;
if (element instanceof EObject) {
- result = getPropertyValue(element,
- this.propertiesHandler.getLabelProperty(), null, String.class);
+ result = getPropertyValue(element, this.propertiesHandler.getLabelProperty(), null, String.class);
+
} else if (element == null) {
result = Messages.CustomizedLabelProvider_null;
} else if (element instanceof List<?>) {
@@ -139,6 +140,27 @@ public class CustomizedLabelProvider extends CellLabelProvider implements
return result;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.emf.facet.custom.ui.ICustomizedLabelProvider#getStyledText(java.lang.Object)
+ */
+ @Override
+ public StyledString getStyledText(final Object element) {
+ Object result = null;
+ if (element instanceof EObject) {
+ result = getPropertyValue(element,
+ this.propertiesHandler.getLabelProperty(), null, StyledString.class);
+ if (result instanceof String) {
+ result = new StyledString((String) result);
+ }
+ } else {
+ result = new StyledString(getText(element));
+ }
+
+ return (StyledString) result;
+ }
+
private static ICustomOverride getICustomOverride() {
final Bundle bundle = Activator.getDefault().getBundle();
final BundleContext bundleContext = bundle.getBundleContext();
@@ -150,17 +172,22 @@ public class CustomizedLabelProvider extends CellLabelProvider implements
}
public String getText(final Object object, final ETypedElement eTypedElement) {
- String result;
+ String result = null;
if (object == null) {
result = Messages.CustomizedLabelProvider_null;
} else {
if (object instanceof EObject) {
final EObject eObject = (EObject) object;
try {
- result = this.customManager.getCustomValueOf(eObject,
+ Object objectResult = this.customManager.getCustomValueOf(eObject,
eTypedElement,
this.propertiesHandler.getLabelProperty(),
- String.class);
+ Object.class);
+ if (objectResult instanceof StyledString) {
+ result = objectResult.toString();
+ } else if (objectResult instanceof String) {
+ result = (String) objectResult;
+ }
} catch (CustomizationException e) {
Logger.logError(e, Activator.getDefault());
result = "!!! Error, cf log !!!";
@@ -171,27 +198,36 @@ public class CustomizedLabelProvider extends CellLabelProvider implements
}
return result;
+ }
- // TODO Remove before to commit
- // if (structuralFeature.getUpperBound() == 1) {
- // final Object object = this.customManager.getFacetManager().get(eObject,
- // structuralFeature, Object.class);
- // result = getText(object);
- // } else {
- // final StringBuffer stringBuffer = new StringBuffer();
- // final List<Object> objects = this.customManager.getFacetManager()
- // .getMultiValued(eObject, structuralFeature, Object.class);
- // final Iterator<Object> objectsIter = objects.iterator();
- // while (objectsIter.hasNext()) {
- // final Object object = objectsIter.next();
- // stringBuffer.append(this.getText(object));
- // if (objectsIter.hasNext()) {
- // stringBuffer.append(", ");
- // }
- // }
- // result = stringBuffer.toString();
- // }
- // TODO (end)
+ @Override
+ public StyledString getStyledText(final Object object, final ETypedElement eTypedElement) {
+ StyledString result = null;
+ if (object == null) {
+ result = new StyledString(Messages.CustomizedLabelProvider_null);
+ } else {
+ if (object instanceof EObject) {
+ final EObject eObject = (EObject) object;
+ try {
+ Object objectResult = this.customManager.getCustomValueOf(eObject,
+ eTypedElement,
+ this.propertiesHandler.getLabelProperty(),
+ Object.class);
+ if (objectResult instanceof StyledString) {
+ result = (StyledString) objectResult;
+ } else if (objectResult instanceof String) {
+ result = new StyledString((String) objectResult);
+ }
+ } catch (CustomizationException e) {
+ Logger.logError(e, Activator.getDefault());
+ result = new StyledString("!!! Error, cf log !!!");
+ }
+ } else {
+ result = new StyledString(object.toString());
+ }
+
+ }
+ return result;
}
@Override
@@ -587,8 +623,4 @@ public class CustomizedLabelProvider extends CellLabelProvider implements
return new CustomizedLabelProvider(this.customManager);
}
- public StyledString getStyledText(final Object element) {
- return new StyledString(getText(element));
- }
-
}
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/DecoratingCustomizedLabelProvider.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/DecoratingCustomizedLabelProvider.java
index c339a77c462..b16b59b9798 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/DecoratingCustomizedLabelProvider.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/DecoratingCustomizedLabelProvider.java
@@ -7,6 +7,7 @@
*
* Contributors:
* David Couvrand (Soft-Maint) - Bug 418418 - [Customization] Overlay icons not implemented
+ * Mickael ADAM (ALL4TEC) - mickael.adam@all4tec.net - Bug 500219 - implementation of getStyledText
*******************************************************************************/
package org.eclipse.papyrus.emf.facet.custom.ui.internal;
@@ -14,6 +15,7 @@ import org.eclipse.emf.ecore.ETypedElement;
import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider;
import org.eclipse.jface.viewers.IDecorationContext;
import org.eclipse.jface.viewers.ILabelDecorator;
+import org.eclipse.jface.viewers.StyledString;
import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManager;
import org.eclipse.papyrus.emf.facet.custom.ui.ICustomizedLabelProvider;
import org.eclipse.swt.graphics.Color;
@@ -32,6 +34,26 @@ public class DecoratingCustomizedLabelProvider extends
super(labelProvider, decorator, decorationContext);
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider#getStyledText(java.lang.Object)
+ */
+ @Override
+ public StyledString getStyledText(final Object element) {
+ return this.lblProvider.getStyledText(element);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.emf.facet.custom.ui.ICustomizedLabelProvider#getStyledText(java.lang.Object, org.eclipse.emf.ecore.ETypedElement)
+ */
+ @Override
+ public StyledString getStyledText(final Object element, final ETypedElement eTypedElement) {
+ return this.lblProvider.getStyledText(element, eTypedElement);
+ }
+
public DecoratingCustomizedLabelProvider(
final ICustomizationManager customizationMgr) {
this(new CustomizedLabelProvider(customizationMgr),
diff --git a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/ResolvingCustomizedLabelProvider.java b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/ResolvingCustomizedLabelProvider.java
index a4ad09bdbd9..759b7670c68 100644
--- a/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/ResolvingCustomizedLabelProvider.java
+++ b/plugins/facet/org.eclipse.papyrus.emf.facet.custom.ui/src/org/eclipse/papyrus/emf/facet/custom/ui/internal/ResolvingCustomizedLabelProvider.java
@@ -7,11 +7,14 @@
*
* Contributors:
* Nicolas Bros (Mia-Software) - Bug 379683 - customizable Tree content provider
+ * Mickael ADAM (ALL4TEC) - mickael.adam@all4tec.net - Bug 500219 - implementation of getStyledText
+ *
*******************************************************************************/
package org.eclipse.papyrus.emf.facet.custom.ui.internal;
import org.eclipse.emf.ecore.ETypedElement;
import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.papyrus.emf.facet.custom.core.ICustomizationManager;
import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EAttributeTreeElement;
@@ -66,6 +69,32 @@ public class ResolvingCustomizedLabelProvider implements ICustomizedLabelProvide
return result;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.emf.facet.custom.ui.ICustomizedLabelProvider#getStyledText(java.lang.Object)
+ */
+ @Override
+ public StyledString getStyledText(final Object element) {
+ StyledString result;
+ if (delegate instanceof ICustomizedLabelProvider) {
+ if (element instanceof EReferenceTreeElement) {
+ final EReferenceTreeElement treeElement = (EReferenceTreeElement) element;
+ final EObjectTreeElement parent = treeElement.getParent();
+ result = this.delegate.getStyledText(parent.getEObject(), treeElement.getEReference());
+ } else if (element instanceof EAttributeTreeElement) {
+ final EAttributeTreeElement treeElement = (EAttributeTreeElement) element;
+ final EObjectTreeElement parent = (EObjectTreeElement) treeElement.getParent();
+ result = this.delegate.getStyledText(parent.getEObject(), treeElement.getEAttribute());
+ } else {
+ result = this.delegate.getStyledText(CustomizedContentProviderUtils.resolve(element));
+ }
+ } else {
+ result = new StyledString(getText(element));
+ }
+ return result;
+ }
+
public void addListener(final ILabelProviderListener listener) {
this.delegate.addListener(listener);
}
@@ -489,4 +518,5 @@ public class ResolvingCustomizedLabelProvider implements ICustomizedLabelProvide
public ICustomizedLabelProvider cloneLabelProvider() {
return new ResolvingCustomizedLabelProvider(this.delegate.cloneLabelProvider());
}
+
}

Back to the top