diff options
author | Arthur Daussy | 2014-06-25 13:04:09 +0000 |
---|---|---|
committer | Mikael Barbero | 2014-07-07 09:11:20 +0000 |
commit | 705a95454617872c1199ef6f488b1718437c5cf7 (patch) | |
tree | 7c02611913b19905f838d93c651ce8eb65810e66 | |
parent | be415bef27196a7313db1039d0e178f4c1de900e (diff) | |
download | org.eclipse.emf.compare-705a95454617872c1199ef6f488b1718437c5cf7.tar.gz org.eclipse.emf.compare-705a95454617872c1199ef6f488b1718437c5cf7.tar.xz org.eclipse.emf.compare-705a95454617872c1199ef6f488b1718437c5cf7.zip |
Cutomization of the way stereotyped elements are displayed.
Adds a UML item provider adapter decorator to customize the way the
streotyped element are displayed (custom label and custom icon)
Removes the now useless StereotypedElementChangeCustomItemProvider.
Change-Id: Ie3a50308ce96cf20d41427646ec5618875e7ea40
Signed-off-by: Arthur Daussy <arthur.daussy@obeo.fr>
7 files changed, 421 insertions, 118 deletions
diff --git a/plugins/org.eclipse.emf.compare.uml2.edit/plugin.properties b/plugins/org.eclipse.emf.compare.uml2.edit/plugin.properties index cfcc810e8..0347d0c70 100644 --- a/plugins/org.eclipse.emf.compare.uml2.edit/plugin.properties +++ b/plugins/org.eclipse.emf.compare.uml2.edit/plugin.properties @@ -164,3 +164,6 @@ _UI_DirectedRelationshipChange_type = Directed Relationship Change _UI_StereotypeAttributeChange_type = Stereotype Attribute Change _UI_StereotypedElementChange_type = Stereotyped Element Change _UI_StereotypedElementChange_stereotypeApplications_feature = Stereotype Applications + +#Error messaged +Unable_To_Retreive_Icon_Error_Message = "Unable to retrieve the icon at location {0} diff --git a/plugins/org.eclipse.emf.compare.uml2.edit/plugin.xml b/plugins/org.eclipse.emf.compare.uml2.edit/plugin.xml index a435d39f2..656866b5c 100644 --- a/plugins/org.eclipse.emf.compare.uml2.edit/plugin.xml +++ b/plugins/org.eclipse.emf.compare.uml2.edit/plugin.xml @@ -36,4 +36,21 @@ Contributors: "org.eclipse.emf.compare.provider.IItemStyledLabelProvider org.eclipse.emf.compare.provider.IItemDescriptionProvider"/> </extension> + + <extension + point="org.eclipse.emf.compare.edit.adapterFactory"> + <factory + class="org.eclipse.emf.compare.uml2.internal.provider.decorator.UMLProfileItemProviderAdapterFactoryDecorator" + supportedTypes= + "org.eclipse.emf.edit.provider.IEditingDomainItemProvider + org.eclipse.emf.edit.provider.IStructuredItemContentProvider + org.eclipse.emf.edit.provider.ITreeItemContentProvider + org.eclipse.emf.edit.provider.IItemLabelProvider + org.eclipse.emf.edit.provider.IItemPropertySource + org.eclipse.emf.compare.provider.IItemStyledLabelProvider + org.eclipse.emf.compare.provider.IItemDescriptionProvider" + ranking="60" + uri="http://www.eclipse.org/uml2/5.0.0/UML"> + </factory> + </extension> </plugin> diff --git a/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/custom/StereotypedElementChangeCustomItemProvider.java b/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/custom/StereotypedElementChangeCustomItemProvider.java deleted file mode 100644 index c47cf902e..000000000 --- a/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/custom/StereotypedElementChangeCustomItemProvider.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Copyright (c) 2014 Obeo. - * 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: - * Obeo - initial API and implementation - */ -package org.eclipse.emf.compare.uml2.internal.provider.custom; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.collect.Iterables; - -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.compare.DifferenceKind; -import org.eclipse.emf.compare.provider.ExtendedAdapterFactoryItemDelegator; -import org.eclipse.emf.compare.provider.utils.ComposedStyledString; -import org.eclipse.emf.compare.provider.utils.IStyledString; -import org.eclipse.emf.compare.provider.utils.IStyledString.Style; -import org.eclipse.emf.compare.uml2.internal.StereotypedElementChange; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.NamedElement; -import org.eclipse.uml2.uml.Stereotype; - -/* - * TODO: Improve label and Implement getImage. - */ -/** - * Custom item provider for {@link StereotypedElementChange}. - * - * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a> - */ - -public class StereotypedElementChangeCustomItemProvider extends UMLDiffCustomItemProvider { - - /** - * Transform a {@link Stereotype} into its name. - */ - private static final Function<Stereotype, String> TO_STEREOTYPE_NAME = new Function<Stereotype, String>() { - - public String apply(Stereotype input) { - return input.getName(); - } - }; - - /** - * Item delegator. - */ - private final ExtendedAdapterFactoryItemDelegator itemDelegator; - - /** - * Constructor. - * - * @param adapterFactory - * the adapter factory to use. - */ - public StereotypedElementChangeCustomItemProvider(AdapterFactory adapterFactory) { - super(adapterFactory); - itemDelegator = new ExtendedAdapterFactoryItemDelegator(getRootAdapterFactory()); - } - - @Override - public IStyledString.IComposedStyledString getStyledText(Object object) { - final StereotypedElementChange stereotypedElementChange = (StereotypedElementChange)object; - - EObject base = stereotypedElementChange.getDiscriminant(); - if (!(base instanceof Element)) { - throw new RuntimeException("The discrimant of a StereotypedElementChange should be a uml Element"); //$NON-NLS-1$ - } - final String sterotypesNames = Joiner.on(", ").join(//$NON-NLS-1$ - Iterables.transform(((Element)base).getAppliedStereotypes(), TO_STEREOTYPE_NAME)); - final ComposedStyledString stereotypeText = new ComposedStyledString(); - stereotypeText.append("<").append(sterotypesNames).append("> "); //$NON-NLS-1$ //$NON-NLS-2$ - - if (base instanceof NamedElement) { - stereotypeText.append(((NamedElement)base).getName()); - } else { - // Can't really do more - stereotypeText.append(itemDelegator.getText(base)); - } - - final String action; - switch (stereotypedElementChange.getKind()) { - case ADD: - action = "add"; //$NON-NLS-1$ - break; - case DELETE: - action = "remove"; //$NON-NLS-1$ - break; - default: - throw new IllegalStateException("Unsupported " + DifferenceKind.class.getSimpleName() //$NON-NLS-1$ - + " value: " + stereotypedElementChange.getKind()); //$NON-NLS-1$ - } - - return stereotypeText.append(" [" + action + "]", //$NON-NLS-1$ //$NON-NLS-2$ - Style.DECORATIONS_STYLER); - } - -} diff --git a/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/custom/UMLCompareCustomItemProviderAdapterFactory.java b/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/custom/UMLCompareCustomItemProviderAdapterFactory.java index 30672cbbd..2eca6148b 100644 --- a/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/custom/UMLCompareCustomItemProviderAdapterFactory.java +++ b/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/custom/UMLCompareCustomItemProviderAdapterFactory.java @@ -75,12 +75,6 @@ public class UMLCompareCustomItemProviderAdapterFactory extends UMLCompareAdapte private UMLDiffCustomItemProvider umlDiffExtendedItemProvider; /** - * This keeps track of the one adapter used for all - * {@link org.eclipse.emf.compare.uml2.internal.StereotypedElementChange} instances. - */ - private StereotypedElementChangeCustomItemProvider stereotypedElementChangeExtendedItemProvider; - - /** * This constructs an instance. */ public UMLCompareCustomItemProviderAdapterFactory() { @@ -103,15 +97,6 @@ public class UMLCompareCustomItemProviderAdapterFactory extends UMLCompareAdapte return stereotypeApplicationChangeExtendedItemProvider; } - @Override - public Adapter createStereotypedElementChangeAdapter() { - if (stereotypedElementChangeExtendedItemProvider == null) { - stereotypedElementChangeExtendedItemProvider = new StereotypedElementChangeCustomItemProvider( - this); - } - return stereotypedElementChangeExtendedItemProvider; - } - /** * {@inheritDoc} * diff --git a/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/decorator/ForwardingItemProviderAdapterDecorator.java b/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/decorator/ForwardingItemProviderAdapterDecorator.java new file mode 100644 index 000000000..79d8fe39d --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/decorator/ForwardingItemProviderAdapterDecorator.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2014 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.emf.compare.uml2.internal.provider.decorator; + +import org.eclipse.emf.compare.provider.ExtendedItemProviderDecorator; +import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; +import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; +import org.eclipse.emf.edit.provider.IItemLabelProvider; +import org.eclipse.emf.edit.provider.IItemPropertySource; +import org.eclipse.emf.edit.provider.ITreeItemContentProvider; + +/** + * Item provider adapter decorator that forwards all requests to the decorated adapter factory. + * + * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a> + */ +public class ForwardingItemProviderAdapterDecorator extends ExtendedItemProviderDecorator implements IEditingDomainItemProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource { + + /** + * Constructor. + * + * @param adapterFactory + * {@link ComposeableAdapterFactory} + */ + public ForwardingItemProviderAdapterDecorator(ComposeableAdapterFactory adapterFactory) { + super(adapterFactory); + } + +} diff --git a/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/decorator/StereotypedElementItemProviderDecorator.java b/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/decorator/StereotypedElementItemProviderDecorator.java new file mode 100644 index 000000000..475caa3ca --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/decorator/StereotypedElementItemProviderDecorator.java @@ -0,0 +1,279 @@ +/******************************************************************************* + * Copyright (c) 2014 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.emf.compare.uml2.internal.provider.decorator; + +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.collect.Iterables; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.ResourceLocator; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.compare.provider.ExtendedItemProviderDecorator; +import org.eclipse.emf.compare.uml2.internal.provider.UMLCompareEditPlugin; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.URIConverter; +import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; +import org.eclipse.emf.edit.provider.ComposedImage; +import org.eclipse.emf.edit.provider.IChangeNotifier; +import org.eclipse.emf.edit.provider.IChildCreationExtender; +import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; +import org.eclipse.emf.edit.provider.IItemColorProvider; +import org.eclipse.emf.edit.provider.IItemFontProvider; +import org.eclipse.emf.edit.provider.IItemLabelProvider; +import org.eclipse.emf.edit.provider.IItemPropertySource; +import org.eclipse.emf.edit.provider.IItemProviderDecorator; +import org.eclipse.emf.edit.provider.ITreeItemContentProvider; +import org.eclipse.emf.edit.provider.ReflectiveItemProvider; +import org.eclipse.uml2.common.util.UML2Util; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Stereotype; + +/** + * Item provider decorator for stereotyped {@link Element}s. + * + * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a> + */ +public class StereotypedElementItemProviderDecorator extends ExtendedItemProviderDecorator implements IEditingDomainItemProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource, IItemColorProvider, IItemFontProvider { + + /** + * Constructor. + * + * @param adapterFactory + * {@link ComposeableAdapterFactory}. + */ + public StereotypedElementItemProviderDecorator(ComposeableAdapterFactory adapterFactory) { + super(adapterFactory); + } + + @Override + public String getText(Object object) { + if (object instanceof Element) { + Element elem = (Element)object; + EList<Stereotype> appliedStereotypes = elem.getAppliedStereotypes(); + if (!appliedStereotypes.isEmpty()) { + return getStereotypedElementLabel((Element)object, appliedStereotypes); + } + } + return super.getText(object); + } + + /** + * Gets a label for a stereotyped {@link Element}. + * + * @param element + * stereotyped {@link Element}. + * @param appliedStereotypes + * List of stereotypes to display. + * @return the label of the stereotyped element. + */ + private String getStereotypedElementLabel(Element element, EList<Stereotype> appliedStereotypes) { + StringBuilder labelBuilder = new StringBuilder(); + String stereotypes = Joiner.on(',').join( + Iterables.transform(appliedStereotypes, new Function<Stereotype, String>() { + + public String apply(Stereotype input) { + return input.getName(); + } + })); + + labelBuilder.append('<').append(stereotypes).append("> "); //$NON-NLS-1$ + if (element instanceof NamedElement) { + NamedElement namedElement = (NamedElement)element; + labelBuilder.append(namedElement.getName()); + } + return labelBuilder.toString(); + } + + @Override + public Object getImage(Object object) { + if (object instanceof Element && !((Element)object).getAppliedStereotypes().isEmpty()) { + return new ComposedImage(getStereotypeIcons((Element)object, super.getImage(object))); + } + return super.getImage(object); + } + + /** + * Gets all icons from the stereotypes applied on the element. + * <p> + * The icons for a stereotype are computed this way: + * </p> + * <ol> + * <li>IF:There is {@link org.eclipse.uml2.uml.Image} in the profile model then computes the icon from its + * location. (warning: currently the feature "content" of a {@link org.eclipse.uml2.uml.Image} is not used + * to get a icon)</li> + * <li>ELSEIF: There is ItemProvider registered into the platform for the stereotype application use it.</li> + * <li>ELSE: Uses the base element icon.</li> + * </ol> + * <p> + * This method has been inspired from the implementation of + * {@link org.eclipse.uml2.uml.edit.providers.ElementItemProvider#overlayImage(Object object, Object image)} + * </p> + * + * @param element + * base {@link Element}. + * @param baseElementIcon + * Base element icon. + * @return List of icon to use + */ + protected List<Object> getStereotypeIcons(Element element, Object baseElementIcon) { + List<Object> images = null; + Iterator<Stereotype> stereotypeIterator = element.getAppliedStereotypes().iterator(); + while (stereotypeIterator.hasNext() && images == null) { + Stereotype appliedStereotype = stereotypeIterator.next(); + if (!appliedStereotype.getIcons().isEmpty()) { + images = getStereotypeIconsFromProfile(appliedStereotype); + } else { + Object img = getStereotypeIconFromItemProvider(appliedStereotype, element); + if (img != null) { + images = Collections.singletonList(img); + } + } + } + if (images == null) { + // If there is no icon for any stereotypes then uses the base element icon. + images = Collections.singletonList(baseElementIcon); + } + + return images; + } + + /** + * Get the icon of a stereotype using registered item providers. + * + * @param appliedStereotype + * Applied stereotype from which you want to retrieve an icon. + * @param element + * Base UML element. + * @return The icon of the stereotype or <code>null</code> if none. + */ + private Object getStereotypeIconFromItemProvider(Stereotype appliedStereotype, Element element) { + EObject steretotypeApplication = element.getStereotypeApplication(appliedStereotype); + return getStereotypeIconFromItemProvider(steretotypeApplication); + } + + /** + * Gets the icons for a stereotype using the UML profile model. + * + * @param appliedStereotype + * Applied stereotyped from which you want to retrieve icons. + * @return List of icons to use for this stereotype or <code>null</code> if no icon has been found. + * @see Stereotype#getIcons() + */ + private List<Object> getStereotypeIconsFromProfile(Stereotype appliedStereotype) { + List<Object> images = new ArrayList<Object>(); + + for (org.eclipse.uml2.uml.Image icon : appliedStereotype.getIcons()) { + String location = icon.getLocation(); + + if (!UML2Util.isEmpty(location)) { + Object img = getIconFromLocation(icon.eResource(), location); + if (img != null) { + images.add(img); + } + } else { + // TODO handle icons defined by the "content" feature... + } + } + if (images.isEmpty()) { + images = null; + } + return images; + } + + private Object getIconFromLocation(Resource eResource, String location) { + Object img = null; + if (eResource != null) { + ResourceSet resourceSet = eResource.getResourceSet(); + + if (resourceSet != null) { + URIConverter uriConverter = resourceSet.getURIConverter(); + URI normalizedURI = uriConverter.normalize(eResource.getURI()); + + URI uri = URI.createURI(location).resolve(normalizedURI); + + URL url; + try { + url = new URL(uriConverter.normalize(uri).toString()); + url.openStream().close(); + img = url; + } catch (MalformedURLException e) { + UMLCompareEditPlugin.getPlugin().getLog().log( + new Status(IStatus.WARNING, "org.eclipse.emf.compare.uml2.edit", //$NON-NLS-1$ + UMLCompareEditPlugin.INSTANCE.getString( + "Unable_To_Retreive_Icon_Error_Message", //$NON-NLS-1$ + new Object[] {location }), e)); + } catch (IOException e) { + UMLCompareEditPlugin.getPlugin().getLog().log( + new Status(IStatus.WARNING, "org.eclipse.emf.compare.uml2.edit", //$NON-NLS-1$ + UMLCompareEditPlugin.INSTANCE.getString( + "Unable_To_Retreive_Icon_Error_Message", //$NON-NLS-1$ + new Object[] {location }), e)); + } + } + } + return img; + } + + /** + * Retrieves the icon from registered item providers. + * <p> + * This implementation remove the {@link ReflectiveItemProvider} to prevent getting the basic EMF icon. + * </p> + * </p> + * + * @param object + * Input. + * @return The icon of the input object or <code>null</code> if no icon has been found. + */ + public Object getStereotypeIconFromItemProvider(Object object) { + /* + * Use the root adapter factory to retrieve the adapter factory of the static profiles. This only + * works if the EMF.edit code has been generated. + */ + ComposeableAdapterFactory rootAdapterFactory = ((ComposeableAdapterFactory)adapterFactory) + .getRootAdapterFactory(); + IItemLabelProvider itemLabelProvider = (IItemLabelProvider)rootAdapterFactory.adapt(object, + IItemLabelProvider.class); + if (itemLabelProvider instanceof IItemProviderDecorator) { + IChangeNotifier cNotifier = ((IItemProviderDecorator)itemLabelProvider) + .getDecoratedItemProvider(); + if (cNotifier instanceof IItemLabelProvider) { + itemLabelProvider = (IItemLabelProvider)cNotifier; + } + + } + if (itemLabelProvider == null || itemLabelProvider instanceof ReflectiveItemProvider) { + return null; + } else { + return itemLabelProvider.getImage(object); + } + + } + + public ResourceLocator getResourceLocator() { + return ((IChildCreationExtender)adapterFactory).getResourceLocator(); + } + +} diff --git a/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/decorator/UMLProfileItemProviderAdapterFactoryDecorator.java b/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/decorator/UMLProfileItemProviderAdapterFactoryDecorator.java new file mode 100644 index 000000000..00a5ef718 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.edit/src/org/eclipse/emf/compare/uml2/internal/provider/decorator/UMLProfileItemProviderAdapterFactoryDecorator.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2014 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.emf.compare.uml2.internal.provider.decorator; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.emf.edit.provider.DecoratorAdapterFactory; +import org.eclipse.emf.edit.provider.IChangeNotifier; +import org.eclipse.emf.edit.provider.IDisposable; +import org.eclipse.emf.edit.provider.IItemProviderDecorator; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.edit.providers.UMLItemProviderAdapterFactory; + +/** + * Decorator adapter factory for UML stereotyped element. + * + * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a> + */ +public class UMLProfileItemProviderAdapterFactoryDecorator extends DecoratorAdapterFactory { + + /** + * Map holding the {@link IItemProviderDecorator}s that decorate an + * {@link org.eclipse.emf.edit.provider.ItemProvider} of a stereotyped element. + */ + private Map<Object, IItemProviderDecorator> stereotypeItemProviderDecorators = new HashMap<Object, IItemProviderDecorator>(); + + /** + * Constructor. + */ + public UMLProfileItemProviderAdapterFactoryDecorator() { + super(new UMLItemProviderAdapterFactory()); + } + + @Override + public Object adapt(Object target, Object type) { + if (isStereotypedElement(target)) { + final Object adapter = decoratedAdapterFactory.adapt(target, type); + if (adapter instanceof IChangeNotifier) { + IItemProviderDecorator itemProviderDecorator = stereotypeItemProviderDecorators.get(adapter); + if (itemProviderDecorator == null) { + itemProviderDecorator = new StereotypedElementItemProviderDecorator(this); + stereotypeItemProviderDecorators.put(adapter, itemProviderDecorator); + itemProviderDecorator.setDecoratedItemProvider((IChangeNotifier)adapter); + } + return itemProviderDecorator; + } + } + return super.adapt(target, type); + } + + /** + * Returns <code>true</code> if the target is an UML {@link Element} with stereotypes. + * + * @param target + * Object to test. + * @return <code>true</code> if the input is a stereotyped {@link Element}. + */ + private boolean isStereotypedElement(Object target) { + return target instanceof Element && !((Element)target).getAppliedStereotypes().isEmpty(); + } + + @Override + protected IItemProviderDecorator createItemProviderDecorator(Object target, Object type) { + return new ForwardingItemProviderAdapterDecorator(this); + } + + @Override + public void dispose() { + for (Object object : stereotypeItemProviderDecorators.values()) { + if (object instanceof IDisposable) { + ((IDisposable)object).dispose(); + } + } + super.dispose(); + } +} |