From aea7ae97401e60b919cc0a824b8bdf12a40fb25a Mon Sep 17 00:00:00 2001 From: Remi Schnekenburger Date: Thu, 28 Apr 2016 23:12:30 +0200 Subject: Bug 492697: [UseCase Diagram] User should be able to change the representation of an Actor with the TypeSymbolDefinition stereotype https://bugs.eclipse.org/bugs/show_bug.cgi?id=492697 Change-Id: I9178d26555a141ed22990a48f4ad8aa279735969 Signed-off-by: Remi Schnekenburger --- .../provider/StereotypedElementShapeProvider.java | 529 ++++++++++++--------- .../provider/TypedElementShapeProvider.java | 81 +++- 2 files changed, 378 insertions(+), 232 deletions(-) (limited to 'plugins/uml') diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.symbols/src/org/eclipse/papyrus/uml/diagram/symbols/provider/StereotypedElementShapeProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.symbols/src/org/eclipse/papyrus/uml/diagram/symbols/provider/StereotypedElementShapeProvider.java index f28c5b42c7f..3ea2b95fa41 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.symbols/src/org/eclipse/papyrus/uml/diagram/symbols/provider/StereotypedElementShapeProvider.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.symbols/src/org/eclipse/papyrus/uml/diagram/symbols/provider/StereotypedElementShapeProvider.java @@ -1,231 +1,298 @@ -/***************************************************************************** - * Copyright (c) 2012-2013 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: - * - * CEA LIST - Initial API and implementation - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.diagram.symbols.provider; - -import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker; -import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener; -import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage; -import org.eclipse.gmf.runtime.draw2d.ui.render.factory.RenderedImageFactory; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.AbstractShapeProvider; -import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.ProviderNotificationManager; -import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.ShapeService; -import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil; -import org.eclipse.papyrus.uml.diagram.symbols.Activator; -import org.eclipse.papyrus.uml.tools.utils.ElementUtil; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.Stereotype; -import org.w3c.dom.svg.SVGDocument; - -/** - * This provider is linked to the {@link ShapeService}. It returns the shapes for a given element corresponding to the stereotypes applied on the - * business element. - */ -public class StereotypedElementShapeProvider extends AbstractShapeProvider { - - private static final String SHAPE_CONSTANT = "shape"; - - /** - * {@inheritDoc} - */ - @Override - public List getShapes(EObject view) { - if (!(view instanceof View)) { - return null; - } - EObject element = ((View) view).getElement(); - if (element instanceof Element) { - List images = new ArrayList(); - // it has already been checked that - - Iterator appliedStereotypes = ((Element) element).getAppliedStereotypes().iterator(); - while (appliedStereotypes.hasNext()) { - try { - Stereotype appliedStereotype = appliedStereotypes.next(); - View stereotypeLabel = StereotypeDisplayUtil.getInstance().getStereotypeLabel(((View) view), appliedStereotype); - if (stereotypeLabel != null && stereotypeLabel.isVisible()) { - org.eclipse.uml2.uml.Image icon = ElementUtil.getStereotypeImage(((Element) element), appliedStereotype, SHAPE_CONSTANT); - if (icon != null) { - if (!"".equals(icon.getLocation()) && icon.getLocation() != null) { - SVGDocument document = getSVGDocument(icon.getLocation()); - if (document != null) { - images.add(renderSVGDocument(view, document)); - } else { - URL url = new URL(icon.getLocation()); - images.add(RenderedImageFactory.getInstance(url)); - } - } - } - } - } catch (Exception ex) { - Activator.log.error(ex); - continue; - } - } - - return images; - } - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean providesShapes(EObject view) { - if (!(view instanceof View)) { - return false; - } - - EObject element = ((View) view).getElement(); - if (element instanceof Element) { - - // This is an element. does it have stereotypes ? If yes, do the stereotypes have shapes associated ? - Iterator appliedStereotypes = ((Element) element).getAppliedStereotypes().iterator(); - while (appliedStereotypes.hasNext()) { - - Stereotype appliedStereotype = appliedStereotypes.next(); - View stereotypeLabel = StereotypeDisplayUtil.getInstance().getStereotypeLabel(((View) view), appliedStereotype); - if (stereotypeLabel != null && stereotypeLabel.isVisible()) { - org.eclipse.uml2.uml.Image icon = ElementUtil.getStereotypeImage(((Element) element), appliedStereotype, SHAPE_CONSTANT); - - if (icon != null) { - if (icon.getLocation() != "" && icon.getLocation() != null) { - return true; - } - } - } - } - - - } - - return false; - } - - /** - * {@inheritDoc} - * - */ - @Override - public List getSVGDocument(EObject view) { - if (!(view instanceof View)) { - return null; - } - EObject element = ((View) view).getElement(); - if (element instanceof Element) { - List images = new ArrayList(); - // it has already been checked that - Iterator appliedStereotypes = ((Element) element).getAppliedStereotypes().iterator(); - while (appliedStereotypes.hasNext()) { - - Stereotype appliedStereotype = appliedStereotypes.next(); - View stereotypeLabel = StereotypeDisplayUtil.getInstance().getStereotypeLabel(((View) view), appliedStereotype); - if (stereotypeLabel != null && stereotypeLabel.isVisible()) { - org.eclipse.uml2.uml.Image icon = ElementUtil.getStereotypeImage(((Element) element), appliedStereotype, SHAPE_CONSTANT); - if (icon != null) { - if (icon.getLocation() != "" && icon.getLocation() != null) { - SVGDocument document = getSVGDocument(icon.getLocation()); - if (document != null) { - images.add(document); - } - } - } - } - } - return images; - } - - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public ProviderNotificationManager createProviderNotificationManager(DiagramEventBroker diagramEventBroker, EObject view, NotificationListener listener) { - // retrieve semantic element from the view and add a notification listener on the Type feature if the semantic element is a TypedElement - if (view == null || !(view instanceof View)) { - return null; - } - - StereotypedElementShapeProviderNotificationManager notificationManager = new StereotypedElementShapeProviderNotificationManager(diagramEventBroker, view, listener); - return notificationManager; - } - - /** - * Notification Manager for the {@link StereotypedElementShapeProvider}. - */ - public class StereotypedElementShapeProviderNotificationManager extends ProviderNotificationManager implements NotificationListener { - - /** - * Creates a new StereotypedElementShapeProviderNotificationManager. - * - * @param diagramEventBroker - * event broker specific to the diargam displaying the shapes. - * @param view - * the view from which all elements to listen will be computed. - * @param listener - * the listener to which notifications will be forwarded. - */ - public StereotypedElementShapeProviderNotificationManager(DiagramEventBroker diagramEventBroker, EObject view, NotificationListener listener) { - super(diagramEventBroker, view, listener); - } - - /** - * {@inheritDoc} - */ - @Override - protected void registerListeners() { - if (view == null || !(view instanceof View)) { - return; - } - diagramEventBroker.addNotificationListener(view, this); - } - - /** - * {@inheritDoc} - */ - @Override - public void dispose() { - if (view == null || !(view instanceof View)) { - return; - } - diagramEventBroker.removeNotificationListener(view, this); - super.dispose(); - } - - /** - * @see org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener#notifyChanged(org.eclipse.emf.common.notify.Notification) - * - * @param notification - */ - @Override - public void notifyChanged(Notification notification) { - // TODO - - } - - - - } - -} +/***************************************************************************** + * Copyright (c) 2012-2013 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: + * + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.symbols.provider; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker; +import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener; +import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage; +import org.eclipse.gmf.runtime.draw2d.ui.render.factory.RenderedImageFactory; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; +import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.AbstractShapeProvider; +import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.ProviderNotificationManager; +import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.ShapeService; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil; +import org.eclipse.papyrus.uml.diagram.symbols.Activator; +import org.eclipse.papyrus.uml.tools.utils.ElementUtil; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Stereotype; +import org.w3c.dom.svg.SVGDocument; + +/** + * This provider is linked to the {@link ShapeService}. It returns the shapes for a given element corresponding to the stereotypes applied on the + * business element. + */ +public class StereotypedElementShapeProvider extends AbstractShapeProvider { + + private static final String SHAPE_CONSTANT = "shape"; + + /** name of the CSS property that manages the enablement of that provider */ + protected static final String SHAPE_STEREOTYPE_PROPERTY = "shapeStereotype"; + + /** name of the CSS property that manages the enablement of that provider for decoration */ + protected static final String SHAPE_DECORATION_STEREOTYPE_PROPERTY = "shapeDecorationStereotype"; + + /** + * {@inheritDoc} + */ + @Override + public List getShapes(EObject view) { + if (!(view instanceof View)) { + return null; + } + View v = (View) view; + // check the css property for the status (enable or not) of that provider + if (!isShapeStereotypeEnable(v)) { + return null; + } + + return doGetShapes(v); + } + + protected List doGetShapes(View view) { + EObject element = view.getElement(); + if (element instanceof Element) { + List images = new ArrayList(); + // it has already been checked that + + Iterator appliedStereotypes = ((Element) element).getAppliedStereotypes().iterator(); + while (appliedStereotypes.hasNext()) { + try { + Stereotype appliedStereotype = appliedStereotypes.next(); + View stereotypeLabel = StereotypeDisplayUtil.getInstance().getStereotypeLabel(view, appliedStereotype); + if (stereotypeLabel != null && stereotypeLabel.isVisible()) { + org.eclipse.uml2.uml.Image icon = ElementUtil.getStereotypeImage(((Element) element), appliedStereotype, SHAPE_CONSTANT); + if (icon != null) { + if (icon.getLocation() != null && !("".equals(icon.getLocation()))) { + SVGDocument document = getSVGDocument(icon.getLocation()); + if (document != null) { + images.add(renderSVGDocument(view, document)); + } else { + URL url = new URL(icon.getLocation()); + images.add(RenderedImageFactory.getInstance(url)); + } + } + } + } + } catch (Exception ex) { + Activator.log.error(ex); + continue; + } + } + + return images; + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public List getShapesForDecoration(EObject view) { + if (!(view instanceof View)) { + return null; + } + View v = (View) view; + // check the css property for the status (enable or not) of that provider + if (!isShapeDecorationStereotypeEnable(v)) { + return null; + } + + return doGetShapesForDecoration(v); + } + + protected List doGetShapesForDecoration(View view) { + return doGetShapes(view); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean providesShapes(EObject view) { + if (!(view instanceof View)) { + return false; + } + + View v = (View) view; + if (!isShapeStereotypeEnable(v)) { + return false; + } + + EObject element = v.getElement(); + if (element instanceof Element) { + // This is an element. does it have stereotypes ? If yes, do the stereotypes have shapes associated ? + Iterator appliedStereotypes = ((Element) element).getAppliedStereotypes().iterator(); + while (appliedStereotypes.hasNext()) { + + Stereotype appliedStereotype = appliedStereotypes.next(); + View stereotypeLabel = StereotypeDisplayUtil.getInstance().getStereotypeLabel(v, appliedStereotype); + if (stereotypeLabel != null && stereotypeLabel.isVisible()) { + org.eclipse.uml2.uml.Image icon = ElementUtil.getStereotypeImage(((Element) element), appliedStereotype, SHAPE_CONSTANT); + + if (icon != null) { + if (!"".equals(icon.getLocation()) && icon.getLocation() != null) { + return true; + } + } + } + } + } + return false; + } + + /** + * Returns false if the given view specifically removes the support for shapes by stereotypes. + * + * @param view + * the view to check style + * @return false if the given view specifically removes the support for shapes by stereotypes, otherwise true. + */ + private boolean isShapeStereotypeEnable(View view) { + return NotationUtils.getBooleanValue(view, SHAPE_STEREOTYPE_PROPERTY, true); + } + + /** + * Returns false if the given view specifically removes the support for shapes as decoration by stereotypes. + * + * @param view + * the view to check style + * @return false if the given view specifically removes the support for shapes as decoration by stereotypes, otherwise true. + */ + private boolean isShapeDecorationStereotypeEnable(View view) { + return NotationUtils.getBooleanValue(view, SHAPE_DECORATION_STEREOTYPE_PROPERTY, true); + } + + /** + * {@inheritDoc} + * + */ + @Override + public List getSVGDocument(EObject view) { + if (!(view instanceof View)) { + return null; + } + + View v = (View) view; + if (!isShapeStereotypeEnable(v)) { + return null; + } + + EObject element = v.getElement(); + if (element instanceof Element) { + List images = new ArrayList(); + // it has already been checked that + Iterator appliedStereotypes = ((Element) element).getAppliedStereotypes().iterator(); + while (appliedStereotypes.hasNext()) { + + Stereotype appliedStereotype = appliedStereotypes.next(); + View stereotypeLabel = StereotypeDisplayUtil.getInstance().getStereotypeLabel(v, appliedStereotype); + if (stereotypeLabel != null && stereotypeLabel.isVisible()) { + org.eclipse.uml2.uml.Image icon = ElementUtil.getStereotypeImage(((Element) element), appliedStereotype, SHAPE_CONSTANT); + if (icon != null) { + if (icon.getLocation() != null && !("".equals(icon.getLocation()))) { + SVGDocument document = getSVGDocument(icon.getLocation()); + if (document != null) { + images.add(document); + } + } + } + } + } + return images; + } + + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public ProviderNotificationManager createProviderNotificationManager(DiagramEventBroker diagramEventBroker, EObject view, NotificationListener listener) { + // retrieve semantic element from the view and add a notification listener on the Type feature if the semantic element is a TypedElement + if (view == null || !(view instanceof View)) { + return null; + } + + StereotypedElementShapeProviderNotificationManager notificationManager = new StereotypedElementShapeProviderNotificationManager(diagramEventBroker, view, listener); + return notificationManager; + } + + /** + * Notification Manager for the {@link StereotypedElementShapeProvider}. + */ + public class StereotypedElementShapeProviderNotificationManager extends ProviderNotificationManager implements NotificationListener { + + /** + * Creates a new StereotypedElementShapeProviderNotificationManager. + * + * @param diagramEventBroker + * event broker specific to the diargam displaying the shapes. + * @param view + * the view from which all elements to listen will be computed. + * @param listener + * the listener to which notifications will be forwarded. + */ + public StereotypedElementShapeProviderNotificationManager(DiagramEventBroker diagramEventBroker, EObject view, NotificationListener listener) { + super(diagramEventBroker, view, listener); + } + + /** + * {@inheritDoc} + */ + @Override + protected void registerListeners() { + if (view == null || !(view instanceof View)) { + return; + } + diagramEventBroker.addNotificationListener(view, this); + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose() { + if (view == null || !(view instanceof View)) { + return; + } + diagramEventBroker.removeNotificationListener(view, this); + super.dispose(); + } + + /** + * @see org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener#notifyChanged(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + @Override + public void notifyChanged(Notification notification) { + // TODO + + } + + + + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.symbols/src/org/eclipse/papyrus/uml/diagram/symbols/provider/TypedElementShapeProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.symbols/src/org/eclipse/papyrus/uml/diagram/symbols/provider/TypedElementShapeProvider.java index e34d5a02626..cb764df4820 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.symbols/src/org/eclipse/papyrus/uml/diagram/symbols/provider/TypedElementShapeProvider.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.symbols/src/org/eclipse/papyrus/uml/diagram/symbols/provider/TypedElementShapeProvider.java @@ -31,6 +31,7 @@ import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener; import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage; import org.eclipse.gmf.runtime.draw2d.ui.render.factory.RenderedImageFactory; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.AbstractShapeProvider; import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.ProviderNotificationManager; import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.ShapeService; @@ -50,11 +51,29 @@ import org.w3c.dom.svg.SVGDocument; */ public class TypedElementShapeProvider extends AbstractShapeProvider { + /** name of the CSS property that manages the enablement of that provider */ + protected static final String SHAPE_TYPED_ELEMENT_PROPERTY = "shapeTypedElement"; + + /** name of the CSS property that manages the enablement of that provider as decoration */ + protected static final String SHAPE_DECORATION_TYPED_ELEMENT_PROPERTY = "shapeDecorationTypedElement"; + /** * {@inheritDoc} */ @Override public List getShapes(EObject view) { + if (!(view instanceof View)) { + return null; + } + View v = (View) view; + // check the css property for the status (enable or not) of that provider + if (!isShapeTypedElementEnable(v)) { + return null; + } + return doGetShapes(v); + } + + protected List doGetShapes(View view) { Type type = getType(view); String path = getSymbolPath(type); if (path != null && path.length() > 0) { @@ -98,12 +117,63 @@ public class TypedElementShapeProvider extends AbstractShapeProvider { return null; } + /** + * Returns false if the given view specifically removes the support for shapes by type. + * + * @param view + * the view to check style + * @return false if the given view specifically removes the support for shapes by type, otherwise true. + */ + private boolean isShapeTypedElementEnable(View view) { + return NotationUtils.getBooleanValue(view, SHAPE_TYPED_ELEMENT_PROPERTY, true); + } + + /** + * {@inheritDoc} + */ + @Override + public List getShapesForDecoration(EObject view) { + if (!(view instanceof View)) { + return null; + } + View v = (View) view; + // check the css property for the status (enable or not) of that provider + if (!isShapeDecorationTypedElementEnable(v)) { + return null; + } + return doGetShapesForDecoration(v); + } + + protected List doGetShapesForDecoration(View view) { + return doGetShapes(view); + } + + /** + * Returns false if the given view specifically removes the support for shapes decoration by type. + * + * @param view + * the view to check style + * @return false if the given view specifically removes the support for shapes decoration by type, otherwise true. + */ + private boolean isShapeDecorationTypedElementEnable(View view) { + return NotationUtils.getBooleanValue(view, SHAPE_DECORATION_TYPED_ELEMENT_PROPERTY, true); + } + /** * {@inheritDoc} */ @Override public List getSVGDocument(EObject view) { - Type type = getType(view); + if (!(view instanceof View)) { + return null; + } + View v = (View) view; + // check the css property for the status (enable or not) of that provider + if (!isShapeTypedElementEnable(v)) { + return null; + } + + Type type = getType(v); String path = getSymbolPath(type); if (path != null && path.length() > 0) { try { @@ -134,6 +204,15 @@ public class TypedElementShapeProvider extends AbstractShapeProvider { */ @Override public boolean providesShapes(EObject view) { + if (!(view instanceof View)) { + return false; + } + View v = (View) view; + // check the css property for the status (enable or not) of that provider + if (!isShapeTypedElementEnable(v)) { + return false; + } + Type type = getType(view); String path = getSymbolPath(type); if (path != null && path.length() > 0) { -- cgit v1.2.3