diff options
author | Céline Janssens | 2015-04-02 15:48:20 +0000 |
---|---|---|
committer | Céline Janssens | 2015-05-06 13:41:52 +0000 |
commit | 6cf730c33da825452060cbc50a4cddeb35905c2e (patch) | |
tree | bbe9d4369ad05101d14053a7e797f0e723f075b7 /plugins | |
parent | f57dace5ab8472395bac57ebe43f7175c947374f (diff) | |
download | org.eclipse.papyrus-6cf730c33da825452060cbc50a4cddeb35905c2e.tar.gz org.eclipse.papyrus-6cf730c33da825452060cbc50a4cddeb35905c2e.tar.xz org.eclipse.papyrus-6cf730c33da825452060cbc50a4cddeb35905c2e.zip |
Bug 463605: [Stereotype Display] Objective 5: Create the Graphical
Interface to display Labels and Properties to override the CSS.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=463605
- Connect the Property View Appearance to the New Stereotype Structure
- Hide/Show Label
- Hide/Show properties into Compartment
- Fix Icon display of Stereotype
- Fix Persitency on the modified Child only
- Fix the deletion of the Comment node if not displayed while removing
the reference.
- Fix issues with Comment when closing and reopening the diagram (The
comment is not deleted anymore)
- Change "AppliedStereotypeCommentCreationEditPolicy" Name
- NOT WORKING: Hide/Show in Comment with property View
- NOT WORKING: Hide/Show in Brace with property View
- NOT WORKING: Display Shape
Change-Id: Ib566d6ab915c505765ce0c36eff047d1c79b1286
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=462359
Signed-off-by: Céline Janssens <Celine.Janssens@all4tec.net>
Reviewed-on: https://git.eclipse.org/r/45228
Tested-by: Hudson CI
Reviewed-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
Reviewed-by: Mickael ADAM <mickael.adam@all4tec.net>
Diffstat (limited to 'plugins')
25 files changed, 1399 insertions, 635 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/command/ResetStyleCommand.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/command/ResetStyleCommand.java index 6c84c486bdc..d86203d2122 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/command/ResetStyleCommand.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/command/ResetStyleCommand.java @@ -8,6 +8,7 @@ *
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.css.command;
@@ -28,6 +29,8 @@ import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusC import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSAnnotations;
import org.eclipse.papyrus.infra.gmfdiag.css.notation.CSSStyles;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
public class ResetStyleCommand extends RecordingCommand {
@@ -39,12 +42,22 @@ public class ResetStyleCommand extends RecordingCommand { papyrusStyleAnnotations.add(VisualInformationPapyrusConstants.SHADOWFIGURE);
papyrusStyleAnnotations.add(VisualInformationPapyrusConstants.QUALIFIED_NAME);
papyrusStyleAnnotations.add(VisualInformationPapyrusConstants.CUSTOM_APPEARENCE_ANNOTATION);
+ papyrusStyleAnnotations.add(StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH);
}
private Iterator<?> iterator;
-
+ private TransactionalEditingDomain domain;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param domain
+ * @param iterator
+ */
public ResetStyleCommand(TransactionalEditingDomain domain, Iterator<?> iterator) {
super(domain);
+ this.domain = domain;
this.iterator = iterator;
}
@@ -67,6 +80,11 @@ public class ResetStyleCommand extends RecordingCommand { }
}
+ /**
+ * Reset the diagram
+ *
+ * @param diagram
+ */
private void resetDiagram(Diagram diagram) {
for (Object viewObject : diagram.getChildren()) {
if (viewObject instanceof View) {
@@ -80,6 +98,15 @@ public class ResetStyleCommand extends RecordingCommand { }
}
+
+ /**
+ * Reset a Style and its children
+ *
+ * @param view
+ * the view of which the style should be reset
+ * @param recursive
+ * true if the children should be reset as well
+ */
private void resetStyle(View view, boolean recursive) {
resetStyle(view);
if (recursive) {
@@ -91,12 +118,22 @@ public class ResetStyleCommand extends RecordingCommand { }
}
+ /**
+ * Reset the style of a view.
+ * Delete all the custom NamedStyle
+ * Reset EAnnotation
+ * Reset Stereotype Styles
+ *
+ * @param view
+ * the view to be reset
+ */
private void resetStyle(View view) {
// Reset the view (Except for volatile/transient elements which are already derived, e.g. Stereotype compartments)
if (view.eContainingFeature().isTransient()) {
return;
}
+ // remove all the named Style of the view.
Iterator<?> styleIterator = view.getStyles().iterator();
while (styleIterator.hasNext()) {
Object styleObject = styleIterator.next();
@@ -132,10 +169,35 @@ public class ResetStyleCommand extends RecordingCommand { // Remove the Papyrus Style EAnnotations
resetStyleAnnotations(view);
+ // Reset Stereotype Persistency
+ resetStereotypeView(view);
+
// Reset the visibility
view.eUnset(NotationPackage.eINSTANCE.getView_Visible());
}
+ /**
+ * This method reset the style of the Stereotype Node
+ *
+ * @param view
+ * Stereotype View
+ */
+ private void resetStereotypeView(final View view) {
+ StereotypeDisplayHelper helper = StereotypeDisplayHelper.getInstance();
+
+ if (helper.isStereotypeView(view)) {
+ helper.unsetPersistency(domain, view);
+
+ }
+
+ }
+
+ /**
+ * Reset a Style .
+ *
+ * @param style
+ * the Style to reset.
+ */
private void resetStyle(Style style) {
if (style instanceof NamedStyle) {
// Skip custom styles.
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/AbstractShapeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/AbstractShapeEditPart.java index dbe2825f21f..fc31f12efc6 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/AbstractShapeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/AbstractShapeEditPart.java @@ -14,9 +14,8 @@ package org.eclipse.papyrus.uml.diagram.common.editparts; import java.net.MalformedURLException; -import java.util.StringTokenizer; +import java.util.Iterator; -import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.core.editorsfactory.IPageIconsRegistry; @@ -24,11 +23,11 @@ import org.eclipse.papyrus.infra.core.editorsfactory.PageIconsRegistry; import org.eclipse.papyrus.infra.core.services.ServiceException; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart; import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart; -import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper; import org.eclipse.papyrus.uml.diagram.common.Activator; import org.eclipse.papyrus.uml.diagram.common.figure.node.ShapeNamedElementFigure; import org.eclipse.papyrus.uml.tools.utils.ElementUtil; import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Image; import org.eclipse.uml2.uml.Stereotype; /** @@ -38,7 +37,7 @@ import org.eclipse.uml2.uml.Stereotype; */ public abstract class AbstractShapeEditPart extends UMLNodeEditPart implements IPapyrusEditPart { - private static final String SHAPE_CONSTANT = "shape"; + private static final String SHAPE_CONSTANT = "shape";//$NON-NLS-1$ public AbstractShapeEditPart(View view) { super(view); @@ -97,6 +96,7 @@ public abstract class AbstractShapeEditPart extends UMLNodeEditPart implements I @Override public abstract ShapeNamedElementFigure getPrimaryShape(); + @Override public Element getUMLElement() { return (Element) resolveSemanticElement(); } @@ -113,23 +113,30 @@ public abstract class AbstractShapeEditPart extends UMLNodeEditPart implements I * refresh the icon by taking in account the type of the diagram */ private void refreshIcons() { - String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay((View) getModel()); - StringTokenizer tokenizer = new StringTokenizer(stereotypesToDisplay, ","); - if (tokenizer.hasMoreTokens()) { - String firstStereotypeName = tokenizer.nextToken(); - Stereotype stereotype = getUMLElement().getAppliedStereotype(firstStereotypeName); - org.eclipse.uml2.uml.Image icon = ElementUtil.getStereotypeImage(getUMLElement(), stereotype, SHAPE_CONSTANT); - if (icon != null) { - if (icon.getLocation() != "" && icon.getLocation() != null) { + + Iterator<Stereotype> iter = getUMLElement().getAppliedStereotypes().iterator(); + // FIXME For the time being the first stereotype Icon is Used. But should be improved + // when the user would be able to choose manually the Icon to applied. + Stereotype stereotype = iter.next(); + Image icon = ElementUtil.getStereotypeImage(getUMLElement(), stereotype, SHAPE_CONSTANT); + if (icon != null) { + ShapeNamedElementFigure shape = getPrimaryShape(); + if (shape != null) { + if (icon.getLocation() != null && !icon.getLocation().isEmpty()) { try { - getPrimaryShape().setIcon(icon.getLocation()); + + + shape.setIcon(icon.getLocation()); + } catch (MalformedURLException e) { - Activator.log.error(icon.getLocation() + " " + e.getLocalizedMessage(), e); + + Activator.log.error(String.format("$0 $1", icon.getLocation(), e.getLocalizedMessage()), e); } } else { - getPrimaryShape().setIcon(Activator.getShape(getUMLElement(), stereotype, false)); + shape.setIcon(Activator.getShape(getUMLElement(), stereotype, false)); } } } + } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java index e9e841f381e..20fd0beda5e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java @@ -20,7 +20,6 @@ package org.eclipse.papyrus.uml.diagram.common.editpolicies; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.StringTokenizer; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.EList; @@ -37,9 +36,8 @@ import org.eclipse.gmf.runtime.notation.DecorationNode; import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe; -import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper; -import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant; import org.eclipse.papyrus.uml.diagram.common.Activator; import org.eclipse.papyrus.uml.diagram.common.stereotype.CreateAppliedStereotypePropertyViewCommand; import org.eclipse.papyrus.uml.diagram.common.stereotype.CreateAppliedStereotypeViewCommand; @@ -61,7 +59,7 @@ import org.eclipse.uml2.uml.Stereotype; public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends GraphicalEditPolicyEx implements NotificationListener, IPapyrusListener { /** constant for this edit policy role */ - public final static String STEREOTYPE_LABEL_POLICY = "AppliedStereotypeDisplayEditPolicy"; + public final static String STEREOTYPE_LABEL_POLICY = "AppliedStereotypeDisplayEditPolicy";//$NON-NLS-1$ /** host semantic element */ protected Element hostSemanticElement; @@ -221,19 +219,16 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic */ public Image stereotypeIconToDisplay() { Image icon = null; - String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind((View) getHost().getModel()); - if (stereotypespresentationKind == null) { - icon = null; - } - if (stereotypespresentationKind.equals(UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION) || stereotypespresentationKind.equals(UMLVisualInformationPapyrusConstant.TEXT_ICON_STEREOTYPE_PRESENTATION)) { + boolean displayIcon = NotationUtils.getBooleanValue(hostView, StereotypeDisplayUtils.DISPLAY_ICON, false); + if (displayIcon) { // retrieve the first stereotype in the list of displayed stereotype - String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay((View) getHost().getModel()); - StringTokenizer tokenizer = new StringTokenizer(stereotypesToDisplay, ","); - if (tokenizer.hasMoreTokens()) { - String firstStereotypeName = tokenizer.nextToken(); - Stereotype stereotype = getUMLElement().getAppliedStereotype(firstStereotypeName); - icon = Activator.getIconElement(getUMLElement(), stereotype, false); + Stereotype appliedStereotype; + Iterator<Stereotype> stereotypeIterator = getUMLElement().getAppliedStereotypes().iterator(); + while (stereotypeIterator.hasNext() && null == icon) { + appliedStereotype = stereotypeIterator.next(); + icon = Activator.getIconElement(getUMLElement(), appliedStereotype, false); } + } return icon; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java index f0d5ecf4514..fc08291350a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java @@ -15,8 +15,6 @@ *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.common.editpolicies; -import java.util.Iterator; - import org.eclipse.draw2d.IFigure; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; @@ -133,31 +131,13 @@ public class CommentShapeForAppliedStereotypeEditPolicy extends AbstractAppliedS }); } - /** - * Get the number of Visible Compartments - * - * @param view - * The View where the number of visible Compartment are evaluated - * - * @return the number of Visible Stereotype Compartment - */ - protected int getAppliedStereotypeCompartmentNumber(View view) { - int nbVisibleCompartment = 0; - Iterator<View> iteratorView = view.getChildren().iterator(); - while (iteratorView.hasNext()) { - View subview = iteratorView.next(); - if (helper.isStereotypeBrace(subview) || helper.isStereotypeCompartment(subview)) { - nbVisibleCompartment++; - } - } - return nbVisibleCompartment; - } @Override public void activate() { + super.activate(); // retrieve the view and the element managed by the edit part View view = getView(); if (view == null) { @@ -167,6 +147,7 @@ public class CommentShapeForAppliedStereotypeEditPolicy extends AbstractAppliedS // adds a listener on the view and the element controlled by the // editpartrefr getDiagramEventBroker().addNotificationListener(view, this); + } /** @@ -214,6 +195,8 @@ public class CommentShapeForAppliedStereotypeEditPolicy extends AbstractAppliedS */ protected void refreshStereotypeDisplay() { + + IFigure figure = ((IPapyrusEditPart) getHost()).getPrimaryShape(); // refresh Brace display @@ -230,22 +213,18 @@ public class CommentShapeForAppliedStereotypeEditPolicy extends AbstractAppliedS if (getUMLElement() == null) { executeAppliedStereotypeCommentDeletion(domain, commentNode); } - - // If no more Compartment, delete the Comment - if (getAppliedStereotypeCompartmentNumber(commentNode) == 0) { - executeAppliedStereotypeCommentDeletion(domain, commentNode); - } - } } + /** * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AbstractAppliedStereotypeDisplayEditPolicy#refreshDisplay() * */ @Override public void refreshDisplay() { + refreshStereotypeDisplay(); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentViewCommand.java index c651d28ba43..f39c8d7fe79 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentViewCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentViewCommand.java @@ -99,7 +99,7 @@ public class CreateAppliedStereotypeCommentViewCommand extends RecordingCommand points.add(new RelativeBendpoint());
bendpoints.setPoints(points);
edge.setBendpoints(bendpoints);
- ViewUtil.insertChildView(owner.getDiagram(), edge, -1, StereotypeDisplayUtils.PERSISTENT);
+ ViewUtil.insertChildView(owner.getDiagram(), edge, -1, true);
edge.setType(StereotypeDisplayUtils.STEREOTYPE_COMMENT_LINK_TYPE);
edge.setElement(base_element);
IdentityAnchor anchor = NotationFactory.eINSTANCE.createIdentityAnchor();
@@ -153,7 +153,7 @@ public class CreateAppliedStereotypeCommentViewCommand extends RecordingCommand if (commonParent != null) {
((Bounds) commentNode.getLayoutConstraint()).setX(100);
((Bounds) commentNode.getLayoutConstraint()).setY(100);
- ViewUtil.insertChildView(commonParent, commentNode, ViewUtil.APPEND, StereotypeDisplayUtils.PERSISTENT);
+ ViewUtil.insertChildView(commonParent, commentNode, ViewUtil.APPEND, true);
return;
}
}
@@ -165,7 +165,7 @@ public class CreateAppliedStereotypeCommentViewCommand extends RecordingCommand econtainer = (View) econtainer.eContainer();
}
}
- ViewUtil.insertChildView(econtainer, commentNode, ViewUtil.APPEND, StereotypeDisplayUtils.PERSISTENT);
+ ViewUtil.insertChildView(econtainer, commentNode, ViewUtil.APPEND, true);
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/SetPersistentViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/SetPersistentViewCommand.java new file mode 100644 index 00000000000..54aff428314 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/SetPersistentViewCommand.java @@ -0,0 +1,80 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * This Command set a view and all its ancestors persistent.
+ * The method {@link View#persist()} makes all the sibling persistent, this Command does not.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class SetPersistentViewCommand extends RecordingCommand {
+
+ protected View view;
+
+ protected final static String LABEL_COMMAND = "Set Persistency"; //$NON-NLS-1$
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param domain
+ * Transactional Domain
+ * @param view
+ * The view to make persistent
+ */
+ public SetPersistentViewCommand(TransactionalEditingDomain domain, View view) {
+
+ super(domain, LABEL_COMMAND);
+ this.view = view;
+ }
+
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ *
+ */
+ @Override
+ protected void doExecute() {
+ makeViewPersistant(view);
+
+ }
+
+ /**
+ * Recursive method that makes a view and all its ancestors persistent.
+ *
+ * @param view
+ * The view to make persistent ( cannot be {@code null})
+ */
+ @SuppressWarnings("unchecked")
+ protected void makeViewPersistant(final View view) {
+ if (view != null) {
+ if (view.eContainer() != null && view.eContainer() instanceof View) {
+
+ // Make the Parent Persistent
+ makeViewPersistant((View) view.eContainer());
+ // Move the view from the Transient List to the Persistent Children list
+ ((View) view.eContainer()).getPersistedChildren().add(view);
+ ((View) view.eContainer()).getTransientChildren().remove(view);
+
+ }
+ }
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayHelper.java index ada69ce8eb3..fb40719a199 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayHelper.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayHelper.java @@ -17,20 +17,24 @@ package org.eclipse.papyrus.uml.diagram.common.stereotype; import java.util.Iterator;
import java.util.StringTokenizer;
+import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.notation.BasicCompartment;
import org.eclipse.gmf.runtime.notation.DecorationNode;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.commands.SetNodeVisibilityCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStyleValueCommand;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Stereotype;
@@ -168,31 +172,32 @@ public class StereotypeDisplayHelper { */
public String getStereotypeTextToDisplay(View model) {
- String textToDisplay = EMPTY_STRING;
- String finalText = EMPTY_STRING;
- Iterator<?> iter = model.getChildren().iterator();
+ StringBuilder textToDisplay = new StringBuilder();
+ StringBuilder finalText = new StringBuilder();
- // For all children, check if it's a StereotypeLabel and add the Name
- while (iter.hasNext()) {
- Object object = iter.next();
- if (object instanceof DecorationNode) {
- DecorationNode label = (DecorationNode) object;
+ Iterator<?> childrenIterator = model.getChildren().iterator();
- if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
- if (label.isVisible()) {
- textToDisplay = addStereotypeName(textToDisplay, label, model);
+ // For all children, check if it's a StereotypeLabel and add the Name
+ while (childrenIterator.hasNext()) {
+ Object object = childrenIterator.next();
+ if (isStereotypeLabel(object)) {
+ if (((View) object).isVisible()) {
+ if (!EMPTY_STRING.equals(textToDisplay.toString()) && (textToDisplay != null)) {
+ textToDisplay.append(StereotypeDisplayUtils.STEREOTYPE_LABEL_SEPARATOR);
}
+ textToDisplay.append(getStereotypeName((DecorationNode) object));
}
+
}
}
// Then add the ornament around the text.
- if ((textToDisplay != null) && (!EMPTY_STRING.equals(textToDisplay))) {
- finalText = StereotypeDisplayUtils.QUOTE_LEFT + textToDisplay + StereotypeDisplayUtils.QUOTE_RIGHT;
+ if ((textToDisplay.toString() != null) && (!EMPTY_STRING.equals(textToDisplay.toString()))) {
+ finalText.append(StereotypeDisplayUtils.QUOTE_LEFT).append(textToDisplay).append(StereotypeDisplayUtils.QUOTE_RIGHT);
}
// Return the text or null if empty
- return finalText;
+ return finalText.toString();
}
@@ -224,29 +229,25 @@ public class StereotypeDisplayHelper { }
/**
- * Add the Stereotype Name to the text to display.
+ * Get the Stereotype Name to the text to display.
*
- * @param textToDisplay
- * The actual string before adding the new Stereotype Name
* @param label
* The StereotypeLabel of the new stereotype to added
- * @param model
*
* @return The String with the new StereotypeName and
*/
- protected String addStereotypeName(String textToDisplay, DecorationNode label, View model) {
- String newTextToDisplay = textToDisplay;
- if (!EMPTY_STRING.equals(newTextToDisplay) && (newTextToDisplay != null)) {
- newTextToDisplay = (newTextToDisplay + StereotypeDisplayUtils.STEREOTYPE_LABEL_SEPARATOR);
- }
+ protected String getStereotypeName(DecorationNode label) {
+
+
// Retrieve Name and Depth from CSS or NamedStyle
String name = getName(label);
String depth = getDepth(label);
// Compute name according to the depth
String nameWithDepth = getStereotypeNameWithDepth(name, depth);
- newTextToDisplay = ((newTextToDisplay == null ? EMPTY_STRING : newTextToDisplay) + nameWithDepth);
- return newTextToDisplay;
+
+
+ return nameWithDepth;
}
@@ -379,6 +380,36 @@ public class StereotypeDisplayHelper { return null;
}
+ /**
+ * Return the associated DecorationNode of a node from it's qualified name.
+ *
+ * @param node
+ * Container Node of the StereotypeLabel
+ * @param qualifiedName
+ * Qualified Name of the Stereotype associated to this Label
+ * @return associated StereotypeLabel
+ */
+ public DecorationNode getStereotypeProperty(View node, Stereotype stereotype, Property property) {
+ DecorationNode propertyView = null;
+ if ((stereotype != null) && (property != null)) {
+ View compartment = getStereotypeCompartment(node, stereotype);
+ Object obj;
+ if (compartment != null) {
+ Iterator<?> iter = compartment.getChildren().iterator();
+ while (iter.hasNext()) {
+ obj = iter.next();
+ if (isStereotypeProperty(obj) && ((DecorationNode) obj).getElement().equals(property)) {
+ propertyView = (DecorationNode) obj;
+ }
+
+ }
+ }
+ }
+
+ return propertyView;
+ }
+
+
/**
* Return the associated DecorationNode of a node from it's stereotypeAppplication.
@@ -574,9 +605,14 @@ public class StereotypeDisplayHelper { */
public String getName(DecorationNode label) {
String name = EMPTY_STRING;
- if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
+
+ String defaultName = EMPTY_STRING;
+ if (label != null && label.getElement() instanceof Stereotype) {
+ defaultName = ((Stereotype) label.getElement()).getQualifiedName();
+ }
+ if (isStereotypeLabel(label)) {
// Retrieve Name from CSS or NamedStyle from the Notation model.
- name = NotationUtils.getStringValue(label, StereotypeDisplayUtils.STEREOTYPE_LABEL_NAME, EMPTY_STRING);
+ name = NotationUtils.getStringValue(label, StereotypeDisplayUtils.STEREOTYPE_LABEL_NAME, defaultName);
}
return name;
}
@@ -590,9 +626,13 @@ public class StereotypeDisplayHelper { */
public String getName(BasicCompartment compartment) {
String name = EMPTY_STRING;
+ String defaultName = EMPTY_STRING;
+ if (compartment != null && compartment.getElement() instanceof Stereotype) {
+ defaultName = ((Stereotype) compartment.getElement()).getQualifiedName();
+ }
if (isStereotypeCompartment(compartment) || isStereotypeBrace(compartment)) {
// Retrieve Name from CSS or NamedStyle from the Notation model.
- name = NotationUtils.getStringValue(compartment, StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_NAME, EMPTY_STRING);
+ name = NotationUtils.getStringValue(compartment, StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_NAME, defaultName);
}
return name;
}
@@ -704,17 +744,19 @@ public class StereotypeDisplayHelper { * @param isVisible
* True to make the Compartment visible
*/
- public void setVisibility(final IGraphicalEditPart editPart, final View view, final boolean isVisible) {
+ public void setVisibility(final TransactionalEditingDomain domain, final View view, final boolean isVisible) {
try {
- editPart.getEditingDomain().runExclusive(new Runnable() {
+ domain.runExclusive(new Runnable() {
@Override
public void run() {
- SetNodeVisibilityCommand setCommand = new SetNodeVisibilityCommand(editPart.getEditingDomain(), view, isVisible);
+
+ SetNodeVisibilityCommand setCommand = new SetNodeVisibilityCommand(domain, view, isVisible);
+
// use to avoid to put it in the command stack
try {
- GMFUnsafe.write(editPart.getEditingDomain(), setCommand);
+ GMFUnsafe.write(domain, setCommand);
} catch (Exception e) {
Activator.log.error(e);
}
@@ -727,6 +769,46 @@ public class StereotypeDisplayHelper { /**
+ * Set the visibility of a view
+ *
+ * @param view
+ * The view on which the visibility has to be set
+ * @param isVisible
+ * True to make the Compartment visible
+ */
+ public void setPersistency(final TransactionalEditingDomain domain, final View view) {
+ try {
+ domain.runExclusive(new Runnable() {
+
+
+ @Override
+ public void run() {
+ Display.getCurrent().syncExec(new Runnable() {
+
+
+ @Override
+ public void run() {
+
+ // use to avoid to put it in the command stack
+ SetPersistentViewCommand command = new SetPersistentViewCommand(domain, view);
+ try {
+ GMFUnsafe.write(domain, command);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
+ }
+ });
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+
+
+
+ /**
* Retrieves the property Text to display into the StereotypeCompartment
*
* @param view
@@ -923,7 +1005,9 @@ public class StereotypeDisplayHelper { public boolean isEmpty(Node compartment) {
boolean empty = true;
if (compartment != null) {
- for (Object property : compartment.getChildren()) {
+ Iterator<?> childrenIterator = compartment.getChildren().iterator();
+ while (childrenIterator.hasNext() && empty) {
+ Object property = childrenIterator.next();
if (isStereotypeProperty(property) || isStereotypeBraceProperty(property)) {
if (isDisplayed((Node) property)) {
empty &= false;
@@ -952,12 +1036,7 @@ public class StereotypeDisplayHelper { */
public boolean isStereotypeView(Object element) {
- boolean stereotypeView = (
- isStereotypeCompartment(element) ||
- isStereotypeBrace(element) ||
- isStereotypeLabel(element) ||
- isStereotypeBraceProperty(element) ||
- isStereotypeProperty(element));
+ boolean stereotypeView = (isStereotypeCompartment(element) || isStereotypeBrace(element) || isStereotypeLabel(element) || isStereotypeBraceProperty(element) || isStereotypeProperty(element));
return stereotypeView;
@@ -1047,6 +1126,115 @@ public class StereotypeDisplayHelper { return null;
}
+ /**
+ * Define if a Stereotype Compartment has visibleproperties.
+ *
+ * @param stereotypeCompartment
+ * The Compartment To Test
+ * @return true if at least one property is displayed
+ */
+ public boolean hasVisibleProperties(View stereotypeCompartment) {
+ boolean visibleProperties = false;
+ if (stereotypeCompartment != null) {
+ Iterator<?> iter = stereotypeCompartment.getChildren().iterator();
+ while (iter.hasNext() && !visibleProperties) {
+ Object child = iter.next();
+ if (isStereotypeProperty(child)) {
+ visibleProperties |= (((DecorationNode) child).isVisible());
+
+ }
+
+ }
+ }
+ return visibleProperties;
+ }
+
+ /**
+ * Set the depth Name of the Stereotype Label.
+ * It uses the NamedStyle to store the depth into a View.
+ *
+ * @param stereotype
+ * The Stereotype of the Label that should be modified.
+ * @param nodeView
+ * The view of the element that needs to be updated (i.e. The Class)
+ * @param depth
+ * The Depth value as a string (Can be "none", "full" or a negative number )
+ */
+ public void setDepth(final TransactionalEditingDomain domain, final Stereotype stereotype, final View nodeView, final String depth) {
+ final View label = getStereotypeLabel(nodeView, stereotype);
+ try {
+
+ domain.runExclusive(new Runnable() {
+
+ @Override
+ public void run() {
+ Command command = new CustomStyleValueCommand(label, depth, NotationPackage.eINSTANCE.getStringValueStyle(), NotationPackage.eINSTANCE.getStringValueStyle_StringValue(), StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH);
+
+ // use to avoid to put it in the command stack
+ try {
+ GMFUnsafe.write(domain, command);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+
+ }
+
+ /**
+ * @param domain
+ * @param view
+ * @return
+ */
+ public void unsetPersistency(final TransactionalEditingDomain domain, final View view) {
+ try {
+ domain.runExclusive(new Runnable() {
+
+
+ @Override
+ public void run() {
+ Display.getCurrent().asyncExec(new Runnable() {
+
+
+ @Override
+ public void run() {
+
+ // use to avoid to put it in the command stack
+ UnsetPersistentViewCommand command = new UnsetPersistentViewCommand(domain, view);
+ try {
+ GMFUnsafe.write(domain, command);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
+ }
+ });
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+
+ /**
+ * Define if the element is a Stereotype Comment Link
+ *
+ * @param element
+ * the object to test
+ * @return true if it is a Stereotype Comment Link
+ */
+ public boolean isStereotypeCommentLink(Object element) {
+ boolean stereotypeCommentLink = Boolean.FALSE;
+ if (element instanceof Edge) {
+ stereotypeCommentLink = StereotypeDisplayUtils.STEREOTYPE_COMMENT_LINK_TYPE.equals(((Edge) element).getType());
+ }
+ return stereotypeCommentLink;
+ }
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayUtils.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayUtils.java index 9def37aba2e..3e20303ecef 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayUtils.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayUtils.java @@ -68,11 +68,16 @@ public class StereotypeDisplayUtils { // Ornament Constants
public final static String QUOTE_LEFT = Activator.ST_LEFT;
public final static String QUOTE_RIGHT = Activator.ST_RIGHT;
- public final static String BRACE_LEFT = "{";
- public final static String BRACE_RIGHT = "}";
+ public final static String BRACE_LEFT = "{";// $NON-NLS-1$
+ public final static String BRACE_RIGHT = "}";// $NON-NLS-1$
+ // Define if Stereotype View are Persistent or not.
+ public static final boolean PERSISTENT = false;
- public static final boolean PERSISTENT = false;//$NON-NLS-1$
+ // Icon NamedStyle Property
+ public static final String DISPLAY_ICON = "displayIcon";// $NON-NLS-1$
+
+ public static final String STEREOTYPE_PROPERTY_LOCATION = "stereotypePropertyLocation";//$NON-NLS-1$
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/UnsetPersistentViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/UnsetPersistentViewCommand.java new file mode 100644 index 00000000000..4826f332a26 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/UnsetPersistentViewCommand.java @@ -0,0 +1,78 @@ +/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * This Command set a view Transcient.
+ *
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class UnsetPersistentViewCommand extends RecordingCommand {
+
+ protected View view;
+
+ protected final static String LABEL_COMMAND = "Unset Persistency"; //$NON-NLS-1$
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param domain
+ * Transactional Domain
+ * @param view
+ * The view to make persistent
+ */
+ public UnsetPersistentViewCommand(TransactionalEditingDomain domain, View view) {
+
+ super(domain, LABEL_COMMAND);
+ this.view = view;
+ }
+
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ *
+ */
+ @Override
+ protected void doExecute() {
+ makeViewTranscient(view);
+
+ }
+
+ /**
+ * Recursive method that makes a view and all its ancestors persistent.
+ *
+ * @param view
+ * The view to make persistent ( cannot be {@code null})
+ */
+ @SuppressWarnings("unchecked")
+ protected void makeViewTranscient(final View view) {
+ if (view != null) {
+ if (view.eContainer() != null && view.eContainer() instanceof View) {
+
+ // Move the view from the Transient List to the Persistent Children list
+ ((View) view.eContainer()).getTransientChildren().add(view);
+ ((View) view.eContainer()).getPersistedChildren().remove(view);
+
+ }
+ }
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java index 85aa058014e..d727139274b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/AbstractExecutionSpecificationEditPart.java @@ -63,7 +63,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes; import org.eclipse.papyrus.uml.diagram.sequence.util.HighlightUtil;
import org.eclipse.papyrus.uml.diagram.sequence.util.LifelineEditPartUtil;
import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceUtil;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentCreationEditPolicy;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentEditPolicy;
import org.eclipse.swt.graphics.Color;
import org.eclipse.uml2.uml.ExecutionSpecification;
import org.eclipse.uml2.uml.UMLPackage;
@@ -275,7 +275,7 @@ public abstract class AbstractExecutionSpecificationEditPart extends ShapeNodeEd }
});
// install a editpolicy to display stereotypes
- installEditPolicy(AppliedStereotypeCommentCreationEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
+ installEditPolicy(AppliedStereotypeCommentEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
}
@Override
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomDestructionOccurrenceSpecificationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomDestructionOccurrenceSpecificationEditPart.java index ccbfe4d0743..edd3d0742f3 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomDestructionOccurrenceSpecificationEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomDestructionOccurrenceSpecificationEditPart.java @@ -13,36 +13,17 @@ *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.parts;
-import org.eclipse.draw2d.ConnectionAnchor;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.gef.ConnectionEditPart;
-import org.eclipse.gef.EditPolicy;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gef.requests.CreateConnectionRequest;
-import org.eclipse.gef.requests.ReconnectRequest;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.GraphicalNodeEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableEditPolicyEx;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewAndElementRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeRequest;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.helpers.AnchorHelper;
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.AppliedStereotypeCommentCreationEditPolicyEx;
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.semantic.CustomDestructionOccurrenceSpecificationItemSemanticEditPolicy;
-import org.eclipse.papyrus.uml.diagram.sequence.util.HighlightUtil;
-import org.eclipse.papyrus.uml.diagram.sequence.util.LifelineMessageDeleteHelper;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentCreationEditPolicy;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentEditPolicy;
/**
* Add implementing interface IPapyrusEditPart to displaying Stereotypes.
@@ -67,60 +48,8 @@ public class CustomDestructionOccurrenceSpecificationEditPart extends Destructio protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomDestructionOccurrenceSpecificationItemSemanticEditPolicy());
- installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new GraphicalNodeEditPolicy() {
-
- @Override
- protected Command getReconnectTargetCommand(ReconnectRequest request) {
- INodeEditPart node = getConnectableEditPart();
- if (node == null) {
- return null;
- }
- // Set Edge.Target to the target lifeline
- Command cmd = super.getReconnectTargetCommand(request);
- cmd = cmd.chain(LifelineMessageDeleteHelper.getSetEdgeTargetCommand(request, getEditingDomain()));
- return cmd;
- }
-
- @Override
- protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
- Command cmd = super.getConnectionCompleteCommand(request);
- if (false == request instanceof CreateConnectionViewAndElementRequest) {
- return cmd;
- }
- // Set Edge.Target to the target lifeline
- cmd = cmd.chain(LifelineMessageDeleteHelper.getSetEdgeTargetCommand(request, getEditingDomain()));
- return cmd;
- }
- });
- installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new NonResizableEditPolicyEx() {
-
- @Override
- protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
- request.getMoveDelta().x = 0; // reset offset
- IFigure feedback = getDragSourceFeedbackFigure();
- PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
- getHostFigure().translateToAbsolute(rect);
- rect.translate(request.getMoveDelta());
- CustomLifelineEditPart parentEP = (CustomLifelineEditPart)getParent();
- Rectangle rectParent = parentEP.getFigure().getBounds().getCopy();
- parentEP.getFigure().translateToAbsolute(rectParent);
- int minY = parentEP.getMinimumHeight(-1, true) + rectParent.y;
- if (rect.y < minY) {
- request.getMoveDelta().y += minY - rect.y;
- rect.y = minY;
- }
- feedback.translateToRelative(rect);
- feedback.setBounds(rect);
- }
-
- @Override
- protected void eraseChangeBoundsFeedback(ChangeBoundsRequest request) {
- super.eraseChangeBoundsFeedback(request);
- HighlightUtil.unhighlight();
- }
- });
// install a editpolicy to display stereotypes
- installEditPolicy(AppliedStereotypeCommentCreationEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
+ installEditPolicy(AppliedStereotypeCommentEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
}
@Override
@@ -157,64 +86,4 @@ public class CustomDestructionOccurrenceSpecificationEditPart extends Destructio super.refreshVisuals();
refreshLineWidth();
}
-
- /**
- * Add connection on the center of the figure during the feedback.
- */
- @Override
- public ConnectionAnchor getTargetConnectionAnchor(Request request) {
- return new AnchorHelper.FixedAnchorEx(getFigure(), PositionConstants.CENTER);
- }
-
- /**
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.ConnectionEditPart)
- *
- * @param connEditPart
- * The connection edit part.
- * @return The anchor.
- */
- @Override
- public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connEditPart) {
- return new AnchorHelper.FixedAnchorEx(getFigure(), PositionConstants.CENTER);
- }
-
- /**
- * Override for redirecting creation request to the lifeline
- */
- @Override
- public void showSourceFeedback(Request request) {
- if (request instanceof CreateUnspecifiedTypeRequest) {
- getParent().showSourceFeedback(request);
- }
- super.showSourceFeedback(request);
- }
-
- /**
- * Override for redirecting creation request to the lifeline
- */
- @Override
- public void eraseSourceFeedback(Request request) {
- if (request instanceof CreateUnspecifiedTypeRequest) {
- getParent().eraseSourceFeedback(request);
- }
- super.eraseSourceFeedback(request);
- }
-
- @Override
- public void showTargetFeedback(Request request) {
- if (request instanceof CreateUnspecifiedTypeRequest) {
- getParent().showTargetFeedback(request);
- }
- super.showTargetFeedback(request);
- }
-
- @Override
- public void eraseTargetFeedback(Request request) {
- if (request instanceof CreateUnspecifiedTypeRequest) {
- getParent().eraseTargetFeedback(request);
- }
- super.eraseTargetFeedback(request);
- }
-
-
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomDurationConstraintEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomDurationConstraintEditPart.java index 76a1fd84b42..00e923a0bba 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomDurationConstraintEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomDurationConstraintEditPart.java @@ -76,7 +76,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.part.UMLVisualIDRegistry; import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceRequestConstant;
import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceUtil;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentCreationEditPolicy;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentEditPolicy;
import org.eclipse.uml2.uml.DurationConstraint;
import org.eclipse.uml2.uml.InteractionFragment;
import org.eclipse.uml2.uml.MessageOccurrenceSpecification;
@@ -113,7 +113,7 @@ public class CustomDurationConstraintEditPart extends DurationConstraintEditPart super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomDurationConstraintItemSemanticEditPolicy());
// install a editpolicy to display stereotypes, there's a bug on super class.
- installEditPolicy(AppliedStereotypeCommentCreationEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
+ installEditPolicy(AppliedStereotypeCommentEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomStateInvariantEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomStateInvariantEditPart.java index a12178396fd..f35a99ce0aa 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomStateInvariantEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomStateInvariantEditPart.java @@ -69,7 +69,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.locator.CenterLocator; import org.eclipse.papyrus.uml.diagram.sequence.part.UMLVisualIDRegistry;
import org.eclipse.papyrus.uml.diagram.sequence.util.CommandHelper;
import org.eclipse.papyrus.uml.diagram.sequence.util.NotificationHelper;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentCreationEditPolicy;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentEditPolicy;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.StateInvariant;
@@ -151,7 +151,7 @@ public class CustomStateInvariantEditPart extends StateInvariantEditPart impleme super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomStateInvariantItemSemanticEditPolicy());
// install a editpolicy to display stereotypes
- installEditPolicy(AppliedStereotypeCommentCreationEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
+ installEditPolicy(AppliedStereotypeCommentEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy());
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomTimeConstraintLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomTimeConstraintLabelEditPart.java index 484155c1e76..54dc5fe4a75 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomTimeConstraintLabelEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomTimeConstraintLabelEditPart.java @@ -19,7 +19,7 @@ import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.AppliedStereotypeCommentCreationEditPolicyEx;
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.CustomConnectionHandleEditPolicy;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentCreationEditPolicy;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentEditPolicy;
/**
@@ -54,7 +54,7 @@ public class CustomTimeConstraintLabelEditPart extends TimeConstraintLabelEditPa super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.CONNECTION_HANDLES_ROLE, new CustomConnectionHandleEditPolicy());
// install a editpolicy to display stereotypes
- installEditPolicy(AppliedStereotypeCommentCreationEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
+ installEditPolicy(AppliedStereotypeCommentEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomTimeObservationLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomTimeObservationLabelEditPart.java index 29a702f428b..3408aca1a6b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomTimeObservationLabelEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/parts/CustomTimeObservationLabelEditPart.java @@ -47,7 +47,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.AppliedStereotypeC import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.CustomConnectionHandleEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
import org.eclipse.papyrus.uml.diagram.sequence.util.ElementIconUtil;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentCreationEditPolicy;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentEditPolicy;
import org.eclipse.swt.graphics.Image;
/**
@@ -75,7 +75,7 @@ public class CustomTimeObservationLabelEditPart extends TimeObservationLabelEdit super.createDefaultEditPolicies();
installEditPolicy(EditPolicyRoles.CONNECTION_HANDLES_ROLE, new CustomConnectionHandleEditPolicy());
// install a editpolicy to display stereotypes
- installEditPolicy(AppliedStereotypeCommentCreationEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
+ installEditPolicy(AppliedStereotypeCommentEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/AppliedStereotypeCommentCreationEditPolicyEx.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/AppliedStereotypeCommentCreationEditPolicyEx.java index abf21cdf4ec..fcdee9fb386 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/AppliedStereotypeCommentCreationEditPolicyEx.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/AppliedStereotypeCommentCreationEditPolicyEx.java @@ -26,7 +26,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe; import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.sequence.command.CreateAppliedStereotypeCommentViewCommandEx;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CustomDurationConstraintEditPart;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentCreationEditPolicy;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentEditPolicy;
import org.eclipse.swt.widgets.Display;
@@ -37,7 +37,7 @@ import org.eclipse.swt.widgets.Display; *
* @author Jin Liu (jin.liu@soyatec.com)
*/
-public class AppliedStereotypeCommentCreationEditPolicyEx extends AppliedStereotypeCommentCreationEditPolicy {
+public class AppliedStereotypeCommentCreationEditPolicyEx extends AppliedStereotypeCommentEditPolicy {
@Override
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/PostEditPolicyProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/PostEditPolicyProvider.java index 4a3c951cf35..8b44affbac0 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/PostEditPolicyProvider.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/providers/PostEditPolicyProvider.java @@ -34,7 +34,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.GateEditPart; import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.GeneralOrderingEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.PackageEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.AppliedStereotypeCommentCreationEditPolicyEx;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentCreationEditPolicy;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentEditPolicy;
/**
@@ -99,7 +99,7 @@ public class PostEditPolicyProvider implements IEditPolicyProvider { if (editPart instanceof AbstractExecutionSpecificationEditPart || editPart instanceof CustomDestructionOccurrenceSpecificationEditPart || editPart instanceof CustomDurationConstraintEditPart || editPart instanceof CustomDurationConstraintEditPart
|| editPart instanceof CustomStateInvariantEditPart || editPart instanceof CustomTimeConstraintLabelEditPart || editPart instanceof CustomTimeObservationLabelEditPart || editPart instanceof AbstractMessageEditPart
|| editPart instanceof GeneralOrderingEditPart || editPart instanceof CustomContinuationEditPart || editPart instanceof CustomInteractionOperandEditPart || editPart instanceof GateEditPart) {
- editPart.installEditPolicy(AppliedStereotypeCommentCreationEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
+ editPart.installEditPolicy(AppliedStereotypeCommentEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicyEx());
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/META-INF/MANIFEST.MF index 1f463e97171..3f1d108f907 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/META-INF/MANIFEST.MF +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/META-INF/MANIFEST.MF @@ -1,6 +1,7 @@ Manifest-Version: 1.0
Export-Package: org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart,
- org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies
+ org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies,
+ org.eclipse.papyrus.uml.diagram.stereotype.edition.provider
Require-Bundle: org.eclipse.gmf.runtime.diagram.ui,
org.eclipse.papyrus.uml.diagram.common;bundle-version="1.1.0",
org.eclipse.papyrus.uml.tools.utils;bundle-version="1.1.0",
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCommentCreationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCommentEditPolicy.java index be51f4f434d..4b78c10e1ca 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCommentCreationEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCommentEditPolicy.java @@ -15,6 +15,9 @@ *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies; +import java.util.Iterator; + +import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; @@ -30,6 +33,7 @@ import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.gmf.runtime.notation.LayoutConstraint; import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe; import org.eclipse.papyrus.uml.diagram.common.Activator; import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy; @@ -51,7 +55,7 @@ import org.eclipse.uml2.uml.Stereotype; * * */ -public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy { +public class AppliedStereotypeCommentEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy { /** constant for this edit policy role */ @@ -60,6 +64,24 @@ public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotyp /** the comment node associated to the Host EditPart */ private Node comment; + + @Override + public void activate() { + super.activate(); + getDiagramEventBroker().addNotificationListener(hostView.eContainer(), this); + + }; + + /** + * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AbstractAppliedStereotypeDisplayEditPolicy#deactivate() + * + */ + @Override + public void deactivate() { + getDiagramEventBroker().removeNotificationListener(hostView.eContainer(), this); + super.deactivate(); + } + /** * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy#refreshNotationStructure() * @@ -71,12 +93,34 @@ public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotyp removeUnappliedStereotypes(comment); + if (!stereotypeList.isEmpty()) { refreshStereotypeCommentStructure(); } } } + /** + * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AbstractAppliedStereotypeDisplayEditPolicy#notifyChanged(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + @Override + public void notifyChanged(Notification notification) { + super.notifyChanged(notification); + if (comment != null) { + + int eventType = notification.getEventType(); + EObject object = NotationUtils.getEObjectValue(comment, StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME, null); + // If the reference object of the comment is removed, delete the Comment node itself. + if (eventType == Notification.REMOVE && notification.getOldValue().equals(hostView) && object == null) { + executeAppliedStereotypeCommentDeletion(hostEditPart.getEditingDomain(), comment); + } + } + + + } + /** * Refresh the structure for the Stereotype List @@ -103,6 +147,43 @@ public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotyp } + + /** + * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy#refreshStereotypeDisplay() + * + */ + @Override + protected void refreshStereotypeDisplay() { + + super.refreshStereotypeDisplay(); + // If no more Compartment, delete the Comment + if (comment != null && getAppliedStereotypeCompartmentNumber(comment) == 0) { + executeAppliedStereotypeCommentDeletion(hostEditPart.getEditingDomain(), comment); + } + } + + + /** + * Get the number of Visible Compartments + * + * @param view + * The View where the number of visible Compartment are evaluated + * + * @return the number of Visible Stereotype Compartment + */ + protected int getAppliedStereotypeCompartmentNumber(View view) { + int nbVisibleCompartment = 0; + Iterator<View> iteratorView = view.getChildren().iterator(); + while (iteratorView.hasNext()) { + View subview = iteratorView.next(); + if (helper.isStereotypeBrace(subview) || helper.isStereotypeCompartment(subview)) { + nbVisibleCompartment++; + } + } + return nbVisibleCompartment; + } + + /** * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy#refreshStereotypeCompartmentStructure(org.eclipse.uml2.uml.Stereotype) * diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentForCommentShapeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentForCommentShapeEditPolicy.java index 5f67f1c2db7..4209992f0cf 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentForCommentShapeEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentForCommentShapeEditPolicy.java @@ -24,8 +24,8 @@ import org.eclipse.uml2.uml.Element; /**
* • AppliedStereotypeCompartmentForCommentShapeEditPolicy is another editpolicy attached
* to StereotypeCommentEdipart. It does the same work as AppliedStereotypeCompartmentEditPolicy.
- * Because the StereotypeCommentEdipart is not attached to a semantic element by the attribute element of the notation view. It specializes the method
- * getUMLElement to find the semantic element
+ * Because the StereotypeCommentEdipart is not attached to a semantic element by the attribute element of the notation view.
+ * It specializes the method getUMLElement to find the semantic element
*
*/
public class AppliedStereotypeCompartmentForCommentShapeEditPolicy extends AppliedStereotypeCompartmentEditPolicy {
@@ -35,6 +35,17 @@ public class AppliedStereotypeCompartmentForCommentShapeEditPolicy extends Appli *
* @return the uml element controlled by the host edit part
*/
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AbstractAppliedStereotypeDisplayEditPolicy#activate()
+ *
+ */
+ @Override
+ public void activate() {
+ // TODO Auto-generated method stub
+ super.activate();
+ }
+
@Override
protected Element getUMLElement() {
if ((Element) getView().getElement() != null) {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/CustomEditPolicyProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/CustomEditPolicyProvider.java index c16bb6d1d47..1fb91e42347 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/CustomEditPolicyProvider.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/CustomEditPolicyProvider.java @@ -24,7 +24,7 @@ import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvide import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypeMultilinePropertyEditPart;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentCreationEditPolicy;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentEditPolicy;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCompartmentEditPolicy;
import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
@@ -45,7 +45,7 @@ public class CustomEditPolicyProvider extends AbstractProvider implements IEditP if (editPart instanceof IPrimaryEditPart) {
if (UMLUtil.resolveUMLElement(editPart) != null) {
- editPart.installEditPolicy(AppliedStereotypeCommentCreationEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentCreationEditPolicy());
+ editPart.installEditPolicy(AppliedStereotypeCommentEditPolicy.APPLIED_STEREOTYPE_COMMENT, new AppliedStereotypeCommentEditPolicy());
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/DisplayedProfileElementLabelProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/DisplayedProfileElementLabelProvider.java new file mode 100644 index 00000000000..29e33ab2850 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/DisplayedProfileElementLabelProvider.java @@ -0,0 +1,573 @@ +/***************************************************************************** + * Copyright (c) 2008 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: + * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation + * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.stereotype.edition.provider; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.common.util.Enumerator; +import org.eclipse.emf.ecore.EEnumLiteral; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; +import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper; +import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils; +import org.eclipse.papyrus.uml.profile.ImageManager; +import org.eclipse.papyrus.uml.profile.Message; +import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypePropertyTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypeTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.BooleanValueTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.DataTypeValueTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.EnumerationValueTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.IntegerValueTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.MetaclassValueTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.PrimitiveTypeValueTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.StereotypeValueTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.StringValueTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.UnlimitedNaturalValueTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.UserPrimitiveTypeValueTreeObject; +import org.eclipse.papyrus.uml.profile.tree.objects.ValueTreeObject; +import org.eclipse.papyrus.uml.profile.utils.Util; +import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.Class; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Enumeration; +import org.eclipse.uml2.uml.EnumerationLiteral; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Stereotype; +import org.eclipse.uml2.uml.Type; +import org.eclipse.uml2.uml.ValueSpecification; +import org.eclipse.uml2.uml.util.UMLUtil; + +/** + * The Class ProfileElementLabelProvider. + */ +public class DisplayedProfileElementLabelProvider extends LabelProvider { + + + private StereotypeDisplayHelper helper = StereotypeDisplayHelper.getInstance(); + + + private View mainView; + + /** + * @return the mainView + */ + public View getMainView() { + return mainView; + } + + /** + * @param mainView + * the mainView to set + */ + public void setMainView(View mainView) { + this.mainView = mainView; + } + + /** + * @return the qualifiedNameDisplay + */ + public boolean isQualifiedNameDisplay(View labelView) { + + String depth = NotationUtils.getStringValue(labelView, StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH, StereotypeDisplayUtils.DEFAULT_DEPTH_VALUE); + + return StereotypeDisplayUtils.DEPTH_MAX.equals(depth); + } + + + /** The Constant TAB. */ + public static final String TAB = " "; + + /** + * Gets the image. + * + * @param object + * the object + * + * @return the image + */ + @Override + public Image getImage(Object object) { + Image image = null; + // If the object is an Applied Stereotype Tree Object + if (object instanceof AppliedStereotypeTreeObject) { + Stereotype stereotype = ((AppliedStereotypeTreeObject) object).getStereotype(); + // retrieve the StereotypeLabel Node + View labelView = helper.getStereotypeLabel(mainView, stereotype); + // if the Label is visible, check if the Qualified Name is displayed + // and set the Stereotype Image accordingly. + if (labelView != null && labelView.isVisible()) { + if (isQualifiedNameDisplay(labelView)) { + image = ImageManager.DISPLAYED_STEREOTYPE_QN; + } else { + image = ImageManager.IMG_STEREOTYPEDISPLAYED; + } + } else { // If the Label is not visible the Image is the default Stereotype image + image = ImageManager.IMG_STEREOTYPE; + } + + return image; + + // If the object is a Stereotype Property + } else if (object instanceof AppliedStereotypePropertyTreeObject) { + Property property = ((AppliedStereotypePropertyTreeObject) object).getProperty(); + Stereotype stereotype = ((AppliedStereotypePropertyTreeObject) object).getStereotype(); + View compartmentView = helper.getStereotypeCompartment(mainView, stereotype); + View propertyView = helper.getStereotypeProperty(mainView, stereotype, property); + // check if the Property is displayed, set the image accordingly + if (propertyView != null && propertyView.isVisible() && compartmentView.isVisible()) { + image = ImageManager.IMG_DISPLAYEDPROPERTY; + } else { + image = ImageManager.IMG_PROPERTY; + } + return image; + + } else if (object instanceof BooleanValueTreeObject) { + return ImageManager.IMG_LITERALBOOLEAN; + } else if (object instanceof StringValueTreeObject) { + return ImageManager.IMG_LITERALSTRING; + } else if (object instanceof IntegerValueTreeObject) { + return ImageManager.IMG_LITERALINTEGER; + } else if (object instanceof UnlimitedNaturalValueTreeObject) { + return ImageManager.IMG_LITERALUNLIMITEDNATURAL; + } else if (object instanceof UserPrimitiveTypeValueTreeObject) { + return ImageManager.IMG_PRIMITIVETYPE; + } else if (object instanceof EnumerationValueTreeObject) { + return ImageManager.IMG_ENUMERATION; + } else if (object instanceof DataTypeValueTreeObject) { + return ImageManager.IMG_DATATYPE; + } else if (object instanceof StereotypeValueTreeObject) { + return ImageManager.IMG_STEREOTYPEPROPERTY; + } else if (object instanceof MetaclassValueTreeObject) { + return ImageManager.IMG_METACLASS; + } else { + return ImageManager.IMG_UNKNOWN; + } + + } + + /** + * Gets the text. + * + * @param object + * the object + * + * @return the text + */ + @Override + public String getText(Object object) { + + if (object == null) { + return "null"; + } + + if (object instanceof AppliedStereotypeTreeObject) { + Stereotype st = ((AppliedStereotypeTreeObject) object).getStereotype(); + String stName = st.getName(); + String profileName = st.getProfile().getQualifiedName(); + String label = stName + TAB + "(from " + profileName + ")"; + return label; + + } else if (object instanceof AppliedStereotypePropertyTreeObject) { + AppliedStereotypePropertyTreeObject pTO = (AppliedStereotypePropertyTreeObject) object; + Property prop = pTO.getProperty(); + Type propType = prop.getType(); + Object propValue = pTO.getValue(); + + return getPropLabel(prop, propType, propValue); + + } else if (object instanceof ValueTreeObject) { + return getLabel((ValueTreeObject) object); + + } else { + return object.toString(); + } + } + + /** + * Returns the label to show for a property. + * + * @param currentPropType + * current property type + * @param currentProp + * current property + * @param currentPropValue + * current property value + * + * @return the String label + */ + private String getPropLabel(Property currentProp, Type currentPropType, Object currentPropValue) { + + String label = getPropertyShortLabel(currentProp); + + if (currentPropValue == null) { + label = label + " = null"; + return label; + } + + // Test property type + // Various cases possible for property type + // property is an enumeration + // property is a metaclass + // property is a stereotype + // property is a composite class + // default case + if (currentPropType instanceof Enumeration) { + label = getPropEnumerationLabel(currentProp, currentPropType, currentPropValue); + } else if (currentPropType instanceof Stereotype) { + label = getPropStereotypeLabel(currentProp, currentPropType, currentPropValue); + } else if (currentPropType instanceof Class) { + label = getPropClassLabel(currentProp, currentPropType, currentPropValue); + } else { + label = getPropDefaultLabel(currentProp, currentPropValue); + } + + return label; + } + + /** + * Returns the label to show for a property with type that is a Enumeration. + * + * @param currentPropType + * current property type + * @param currentProp + * current property + * @param currentPropValue + * current property value + * + * @return the String label + */ + private String getPropEnumerationLabel(Property currentProp, Type currentPropType, Object currentPropValue) { + String label = getPropertyShortLabel(currentProp); + + if (currentProp.getUpper() == 1) { // Multiplicity = 1 + if (currentPropValue != null) { + // Retrieve literal + if (currentPropValue instanceof EnumerationLiteral) { + label = label + " = " + ((EnumerationLiteral) currentPropValue).getLabel(); + } else { + label = label + " = " + currentPropValue; + } + } + + } else { // Multiplicity > 1 + label = label + " = " + currentPropValue; + } + + return label; + } + + /** + * Returns the label to show for a property with type that is a Stereotype. + * + * @param currentPropType + * current property type + * @param currentProp + * current property + * @param currentPropValue + * current property value + * + * @return the String label + */ + private String getPropStereotypeLabel(Property currentProp, Type currentPropType, Object currentPropValue) { + String label = getPropertyShortLabel(currentProp); + + if (currentProp.getUpper() == 1) { // Multiplicity = 1 + + // retrieve the base element from the stereotype application + Element baseElement = UMLUtil.getBaseElement((EObject) currentPropValue); + // display the base element's qualified name + label = label + " = " + Util.getLabel(baseElement, true); + + } else { // Multiplicity > 1 + + // retrieve the base element from the stereotype application + @SuppressWarnings("unchecked") + List<Object> values = (List<Object>) currentPropValue; + ArrayList<String> baseElements = new ArrayList<String>(); + + for (int i = 0; i < values.size(); i++) { + // display the base element's qualified name + Element baseElement = UMLUtil.getBaseElement((EObject) values.get(i)); + String name = Util.getLabel(baseElement, true); + if (name != null) { + baseElements.add(name); + } + } + + label = label + " = " + baseElements; + } + + return label; + } + + /** + * Returns the label to show for a property with type that is a Metaclass or Composite. + * + * @param currentPropType + * current property type + * @param currentProp + * current property + * @param currentPropValue + * current property value + * + * @return the String label + */ + private String getPropClassLabel(Property currentProp, Type currentPropType, Object currentPropValue) { + String label = getPropertyShortLabel(currentProp); + + if (Util.isMetaclass(currentPropType)) { + if (currentProp.getUpper() == 1) { // Multiplicity = 1 + label = label + " = " + Util.getLabel(currentPropValue, true); + + } else { // Multiplicity > 1 + + @SuppressWarnings("unchecked") + List<Object> values = (List<Object>) currentPropValue; + ArrayList<String> elementNames = new ArrayList<String>(); + if (values != null) { + for (int i = 0; i < values.size(); i++) { + elementNames.add(Util.getLabel(values.get(i), true)); + } + } + + label = label + " = " + elementNames; + } + } + + return label; + } + + /** + * Returns the label to show for a property with type that is neither Metaclass / Composite / Enumeration / Stereotype. + * + * @param currentProp + * current property + * @param currentPropValue + * current property value + * + * @return the String label + */ + private String getPropDefaultLabel(Property currentProp, Object currentPropValue) { + String label = getPropertyShortLabel(currentProp); + + if (currentPropValue != null) { + label = label + " = " + currentPropValue; + } + + return label; + } + + /** + * Creates the label based on type + multiplicity for the selected property. + * + * @param property + * the property + * + * @return the property short label + */ + private String getPropertyShortLabel(Property property) { + + String label = ""; + + int upper = property.getUpper(); + int lower = property.getLower(); + + Type type = property.getType(); + + String typeName = type.getName(); + String name = property.getName(); + + if (upper != -1) { + label = name + ": " + typeName + " " + "[" + lower + ".." + upper + "]"; + } else { + label = name + ": " + typeName + " " + "[" + lower + "..*]"; + } + + return label; + } + + /** + * Gets the label. + * + * @param object + * the object + * + * @return the label + */ + private String getLabel(ValueTreeObject object) { + + if (object instanceof PrimitiveTypeValueTreeObject) { + return getLabel((PrimitiveTypeValueTreeObject) object); + } else if (object instanceof EnumerationValueTreeObject) { + return getLabel((EnumerationValueTreeObject) object); + } else if (object instanceof DataTypeValueTreeObject) { + return getLabel((DataTypeValueTreeObject) object); + } else if (object instanceof StereotypeValueTreeObject) { + return getLabel((StereotypeValueTreeObject) object); + } else if (object instanceof MetaclassValueTreeObject) { + return getLabel((MetaclassValueTreeObject) object); + } // else + return object.getValue().toString(); + } + + /** + * Gets the label. + * + * @param object + * the object + * + * @return the label + */ + private String getLabel(PrimitiveTypeValueTreeObject object) { + + Object value = object.getValue(); + if (value != null) { + return value.toString(); + } + + return "undefined"; + } + + /** + * Gets the label. + * + * @param object + * the object + * + * @return the label + */ + private String getLabel(DataTypeValueTreeObject object) { + + Object value = object.getValue(); + if (value != null) { + return value.toString(); + } + + return "undefined"; + } + + /** + * Gets the label. + * + * @param object + * the object + * + * @return the label + */ + private String getLabel(EnumerationValueTreeObject object) { + EnumerationValueTreeObject eTO = object; + Property property = ((AppliedStereotypePropertyTreeObject) eTO.getParent()).getProperty(); + Object value = eTO.getValue(); + + EnumerationLiteral eLiteral = null; + // Prepare Item data + if (value instanceof EnumerationLiteral) { + eLiteral = (EnumerationLiteral) value; + + } else if (value instanceof EEnumLiteral) { + EEnumLiteral eEnumLiteral = (EEnumLiteral) value; + Object tmp = Util.getValueObjectFromString(eEnumLiteral.getName(), property.getType()); + eLiteral = ((EnumerationLiteral) tmp); + + } else if (value instanceof String) { + String literalString = (String) value; + Object tmp = Util.getValueObjectFromString(literalString, property.getType()); + eLiteral = ((EnumerationLiteral) tmp); + + } else if (value instanceof Enumerator) { // Enumeration in static profile + String literalString = ((Enumerator) value).getLiteral(); + Object tmp = Util.getValueObjectFromString(literalString, property.getType()); + eLiteral = ((EnumerationLiteral) tmp); + + } else { // Error + String err = "Value " + value.toString() + " of Property " + property.getName() + " is not an EnumerationLiteral."; + Message.error(err); + } + + if (eLiteral != null) { + return eLiteral.getName(); + } else { + return "undefined"; + } + } + + /** + * Gets the label. + * + * @param object + * the object + * + * @return the label + */ + private String getLabel(StereotypeValueTreeObject object) { + StereotypeValueTreeObject sTO = object; + Property property = ((AppliedStereotypePropertyTreeObject) sTO.getParent()).getProperty(); + Object value = sTO.getValue(); + + Element baseElement = null; + + if (value instanceof EObject) { + // retrieve the base element from the stereotype application + baseElement = UMLUtil.getBaseElement((EObject) value); + + } else { // Error + String err = "Type " + value.toString() + " of Property " + property.getName() + " is not an EObject."; + Message.error(err); + } + + if (baseElement != null) { + String label = baseElement.toString(); + if (baseElement instanceof ValueSpecification) { + return Util.getOriginLabel((ValueSpecification) baseElement); + + } else if (baseElement instanceof NamedElement) { + NamedElement baseNamedElement = (NamedElement) baseElement; + if (baseNamedElement.isSetName()) { + label = baseNamedElement.getQualifiedName(); + } + } + + return label; + } + + return "undefined"; + } + + /** + * Gets the label. + * + * @param object + * the object + * + * @return the label + */ + private String getLabel(MetaclassValueTreeObject object) { + MetaclassValueTreeObject sTO = object; + Object value = sTO.getValue(); + + if (value instanceof ValueSpecification) { + return Util.getOriginLabel((ValueSpecification) value); + + } else if (value instanceof Element) { + return Util.getLabel(value, false); + } + + return "undefined"; + } +} diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/META-INF/MANIFEST.MF b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/META-INF/MANIFEST.MF index a70501934a7..49f7cefbd0d 100644 --- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/META-INF/MANIFEST.MF +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/META-INF/MANIFEST.MF @@ -50,7 +50,8 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.gef;bundle-version="3.8.1", org.eclipse.gmf.runtime.notation;bundle-version="1.5.0", org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.1.0", - org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.1.0" + org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.1.0", + org.eclipse.papyrus.uml.diagram.stereotype.edition;bundle-version="1.1.0" Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy Bundle-Version: 1.1.0.qualifier diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/StereotypeAppearanceObservableValue.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/StereotypeAppearanceObservableValue.java index 60ac5ff4713..b01805ebe93 100644 --- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/StereotypeAppearanceObservableValue.java +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/StereotypeAppearanceObservableValue.java @@ -9,6 +9,7 @@ * Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - 402525
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 Stereotype Display
*
*****************************************************************************/
package org.eclipse.papyrus.uml.properties.databinding;
@@ -27,6 +28,7 @@ import org.eclipse.core.databinding.observable.Diffs; import org.eclipse.core.databinding.observable.IObserving;
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.core.internal.databinding.Util;
+import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
@@ -34,9 +36,14 @@ import org.eclipse.emf.ecore.EModelElement; import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStyleValueCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe;
import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
import org.eclipse.papyrus.uml.properties.Activator;
import org.eclipse.papyrus.uml.tools.utils.ElementUtil;
import org.eclipse.uml2.uml.Element;
@@ -49,6 +56,8 @@ import org.eclipse.uml2.uml.Stereotype; */
public class StereotypeAppearanceObservableValue extends AbstractObservableValue implements IObserving {
+
+ protected final static String DEFAULT_LOCATION = "Compartment";//$NON-NLS-1$
/**
* The name of the property being observed
*/
@@ -190,7 +199,7 @@ public class StereotypeAppearanceObservableValue extends AbstractObservableValue private String getDisplayPlaceValue() {
if (diagramElement != null) {
- return AppliedStereotypeHelper.getAppliedStereotypesPropertiesLocalization(diagramElement);
+ return NotationUtils.getStringValue((View) diagramElement, StereotypeDisplayUtils.STEREOTYPE_PROPERTY_LOCATION, DEFAULT_LOCATION);
} else {
return null;
}
@@ -268,9 +277,29 @@ public class StereotypeAppearanceObservableValue extends AbstractObservableValue }
- private void setDisplayPlaceValue(String stereotypePlacePresentation) {
- RecordingCommand command = AppliedStereotypeHelper.getSetAppliedStereotypePropertiesLocalizationCommand(domain, diagramElement, stereotypePlacePresentation);
- domain.getCommandStack().execute(command);
+ private void setDisplayPlaceValue(final String stereotypePlacePresentation) {
+ if (diagramElement instanceof View) {
+ try {
+
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+ Command command = new CustomStyleValueCommand((View) diagramElement, stereotypePlacePresentation, NotationPackage.eINSTANCE.getStringValueStyle(), NotationPackage.eINSTANCE.getStringValueStyle_StringValue(),
+ StereotypeDisplayUtils.STEREOTYPE_PROPERTY_LOCATION);
+
+ // use to avoid to put it in the command stack
+ try {
+ GMFUnsafe.write(domain, command);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+
}
public Object getObserved() {
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositeforview/AppearanceForAppliedStereotypeComposite.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositeforview/AppearanceForAppliedStereotypeComposite.java index 003d3c5e012..8f372fd0c5f 100644 --- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositeforview/AppearanceForAppliedStereotypeComposite.java +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositeforview/AppearanceForAppliedStereotypeComposite.java @@ -16,12 +16,15 @@ *****************************************************************************/ package org.eclipse.papyrus.uml.properties.profile.ui.compositeforview; +import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.ecore.EModelElement; -import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.ui.parts.TreeViewer; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; import org.eclipse.jface.resource.JFaceColors; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -29,10 +32,14 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject; -import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper; +import org.eclipse.papyrus.infra.gmfdiag.common.commands.SetNodeVisibilityCommand; +import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStyleValueCommand; +import org.eclipse.papyrus.uml.diagram.common.stereotype.SetPersistentViewCommand; +import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper; +import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils; +import org.eclipse.papyrus.uml.diagram.stereotype.edition.provider.DisplayedProfileElementLabelProvider; import org.eclipse.papyrus.uml.profile.Activator; import org.eclipse.papyrus.uml.profile.ImageManager; -import org.eclipse.papyrus.uml.profile.tree.DisplayedProfileElementLabelProvider; import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypePropertyTreeObject; import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypeTreeObject; import org.eclipse.papyrus.uml.profile.tree.objects.StereotypedElementTreeObject; @@ -62,7 +69,21 @@ import org.eclipse.uml2.uml.Stereotype; */ public class AppearanceForAppliedStereotypeComposite extends org.eclipse.papyrus.uml.properties.profile.ui.compositeforview.AppliedStereotypeDisplayComposite implements IViewComposite { - DisplayedProfileElementLabelProvider displayedProfileElementLabelProvider = new DisplayedProfileElementLabelProvider(); + + private final static String STEREOTYPE_DISPLAY_TOOLTIP = "Display selected stereotype for the element in the diagram"; + + private final static String STEREOTYPE_QN_DISPLAY_TOOLTIP = "Display selected stereotypes with their qualified name for the element in the diagram"; + + private final static String STEREOTYPE_DISPLAY_NON_GRAPHICAL_TOOLTIP = "Stereotypes can only be displayed for elements with graphical representation. " + "Currently edited element is a non graphical element. " + + "(example: an element selected in the outline is not a graphical element)"; + + + protected DisplayedProfileElementLabelProvider displayedProfileElementLabelProvider = new DisplayedProfileElementLabelProvider(); + + protected StereotypeDisplayHelper helper = StereotypeDisplayHelper.getInstance(); + + + /** * Listener for the Display Button Specific behavior is implemented in {@link DecoratedTreeComposite#downButtonPressed()}. @@ -71,6 +92,8 @@ public class AppearanceForAppliedStereotypeComposite extends org.eclipse.papyrus */ private class DisplayButtonListener implements MouseListener { + + /** * Mouse double click. * @@ -163,7 +186,7 @@ public class AppearanceForAppliedStereotypeComposite extends org.eclipse.papyrus displayButton = factory.createButton(this, "", SWT.PUSH); displayButton.setVisible(true); displayButton.setImage(ImageManager.IMG_DISPLAY); - displayButton.setToolTipText("Display selected stereotype for the element in the diagram"); + displayButton.setToolTipText(STEREOTYPE_DISPLAY_TOOLTIP); data = new FormData(); // data.top = new FormAttachment(addButton, ITabbedPropertyConstants.HSPACE); data.top = new FormAttachment(0, 0); @@ -175,7 +198,7 @@ public class AppearanceForAppliedStereotypeComposite extends org.eclipse.papyrus displayButtonQN = factory.createButton(this, "", SWT.PUSH); displayButtonQN.setVisible(true); displayButtonQN.setImage(ImageManager.IMG_CONSOLEVIEW_WITH_QN); - displayButtonQN.setToolTipText("Display selected stereotypes with their qualified name for the element in the diagram"); + displayButtonQN.setToolTipText(STEREOTYPE_QN_DISPLAY_TOOLTIP); data = new FormData(); // data.top = new FormAttachment(addButton, ITabbedPropertyConstants.HSPACE); data.top = new FormAttachment(0, 0); @@ -261,79 +284,46 @@ public class AppearanceForAppliedStereotypeComposite extends org.eclipse.papyrus TreeItem[] treeSelection = getTree().getSelection(); for (int i = 0; i < treeSelection.length; i++) { - // stereotypesTree.getSelection()[0] + // In case of Stereotype if (treeSelection[i].getData() instanceof AppliedStereotypeTreeObject) { Stereotype stereo = ((AppliedStereotypeTreeObject) treeSelection[i].getData()).getStereotype(); - - if (treeSelection[i].getImage().equals(ImageManager.IMG_STEREOTYPE)) { - displayStereotype(stereo); - treeSelection[i].setImage(ImageManager.IMG_STEREOTYPEDISPLAYED); + // test the image to know if the selection is already visible + if (treeSelection[i].getImage().equals(ImageManager.IMG_STEREOTYPE)) { // if not visible display it with the proper depth. + displayStereotypeLabel(stereo); if (withQualifiedName) { - displayStereotypeWithQN(stereo); - + setDepth(getDomain(), stereo, (View) diagramElement, StereotypeDisplayUtils.DEPTH_MAX); treeSelection[i].setImage(ImageManager.DISPLAYED_STEREOTYPE_QN); + } else { + setDepth(getDomain(), stereo, (View) diagramElement, StereotypeDisplayUtils.DEPTH_MIN); + treeSelection[i].setImage(ImageManager.IMG_STEREOTYPEDISPLAYED); } } else { // if we remove the stereotype we have to remove its properties also - removeDisplayStereotype(stereo); + hideStereotypeLabel(stereo); treeSelection[i].setImage(ImageManager.IMG_STEREOTYPE); } - } - - else if (treeSelection[i].getData() instanceof AppliedStereotypePropertyTreeObject) { - Property prop = ((AppliedStereotypePropertyTreeObject) treeSelection[i].getData()).getProperty(); + // In case of Stereotype Property + } else if (treeSelection[i].getData() instanceof AppliedStereotypePropertyTreeObject) { + Property property = ((AppliedStereotypePropertyTreeObject) treeSelection[i].getData()).getProperty(); + Stereotype stereotype = ((AppliedStereotypePropertyTreeObject) treeSelection[i].getData()).getStereotype(); + // test the image to know if the selection is already visible if (treeSelection[i].getImage().equals(ImageManager.IMG_DISPLAYEDPROPERTY)) { - // removeStereotypePropertyDisplay(prop, ((StereotypeTreeObject) (treeSelection[i].getParentItem().getData())).getStereotype()); - removeStereotypeProperty(((AppliedStereotypeTreeObject) (treeSelection[i].getParentItem().getData())).getStereotype(), ((AppliedStereotypePropertyTreeObject) treeSelection[i].getData()).getProperty()); + hideStereotypeProperty(stereotype, property); treeSelection[i].setImage(ImageManager.IMG_PROPERTY); - } - - else { - // if the stereotype owning the property we want to display is not displayed, we display it! - if (!isInStereotypeDisplay(((AppliedStereotypeTreeObject) (treeSelection[i].getParentItem().getData())).getStereotype())) { - displayStereotype(((AppliedStereotypeTreeObject) (treeSelection[i].getParentItem().getData())).getStereotype()); - } - addStereotypePropertyDisplay(prop, ((AppliedStereotypeTreeObject) (treeSelection[i].getParentItem().getData())).getStereotype()); + } else { + displayStereotypeProperty(stereotype, property); treeSelection[i].setImage(ImageManager.IMG_DISPLAYEDPROPERTY); } } - } - - } - protected void addStereotypePropertyDisplay(final Property prop, final Stereotype stereotype) { - // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - if (diagramElement == null) { - return; - } - try { - - getDomain().runExclusive(new Runnable() { - - public void run() { - - Display.getCurrent().asyncExec(new Runnable() { - - public void run() { - - String appliedStereotypeListToAdd = stereotype.getQualifiedName() + "." + prop.getName(); - RecordingCommand command = AppliedStereotypeHelper.getAddAppliedStereotypePropertiesCommand(getDomain(), diagramElement, appliedStereotypeListToAdd); - getDomain().getCommandStack().execute(command); - // refresh(); - } - }); - } - }); - - } catch (Exception e) { - Activator.logException(e); } } + /** * {@inheritDoc} */ @@ -374,53 +364,22 @@ public class AppearanceForAppliedStereotypeComposite extends org.eclipse.papyrus /** * {@inheritDoc} */ - protected Boolean isInStereotypeDisplay(Stereotype st) { - // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - if (getDiagramElement() == null) { - return false; - } - String stereotypeList = AppliedStereotypeHelper.getStereotypesToDisplay(getDiagramElement()); - if (stereotypeList.contains(st.getQualifiedName())) { - return true; - } - return false; - } - - /** - * {@inheritDoc} - */ @Override public void refresh() { if (diagramElement != null) { - displayedProfileElementLabelProvider.setDisplayedStereotype(AppliedStereotypeHelper.getStereotypesToDisplay(diagramElement)); - displayedProfileElementLabelProvider.setDisplayedStereotypeWithQN(AppliedStereotypeHelper.getStereotypesQNToDisplay(diagramElement)); - displayedProfileElementLabelProvider.setDisplayedProperty(AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay(diagramElement)); + + displayedProfileElementLabelProvider.setMainView((View) diagramElement); } super.refresh(); + // Update ToolTip text according to the diagramElement Value if ((diagramElement == null) && (!displayButton.isDisposed())) { - // displayButton.setEnabled(false); - displayButton.setToolTipText("Stereotypes can only be displayed for elements with graphical representation. " + "Currently edited element is a non graphical element. " + "(example: an element selected in the outline is not a graphical element)"); + displayButton.setToolTipText(STEREOTYPE_DISPLAY_NON_GRAPHICAL_TOOLTIP); } else if (!displayButton.isDisposed()) { - // button should be enabled only if a stereotype is selected, but it requires a listener on the tree selection - // displayButton.setEnabled(true); - displayButton.setToolTipText("Display selected stereotype for the currently selected element in the diagram"); + displayButton.setToolTipText(STEREOTYPE_DISPLAY_TOOLTIP); } refreshButtons(); } - /** - * {@inheritDoc} - */ - protected void removeStereotypeDisplay(Stereotype st) { - // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - if (diagramElement == null) { - return; - } - String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(diagramElement); - RecordingCommand command = AppliedStereotypeHelper.getRemoveAppliedStereotypeCommand(getDomain(), diagramElement, st.getQualifiedName(), presentationKind); - getDomain().getCommandStack().execute(command); - - } /** * {@inheritDoc} @@ -504,275 +463,93 @@ public class AppearanceForAppliedStereotypeComposite extends org.eclipse.papyrus this.selection = selection; } - // /** - // * {@inheritDoc} - // */ - // protected void buildStereotypeDisplay(EList appliedStereotypes) { - // // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - // if (getDiagramElement() == null) { - // return; - // } - // - // EList propList = getDiagramElement().getProperty(); - // - // // temporary list to avoid concurrent access to propList - // ArrayList tempPropList = new ArrayList(); - // - // // list containing stereotype display properties of the current graphElement - // ArrayList<com.cea.papyrus.diagraminterchange2.di2.Property> stereoDiplayList = new ArrayList<com.cea.papyrus.diagraminterchange2.di2.Property>(); - // - // // copy propList to tempPropList - // for (int i = 0; i < propList.size(); i++) { - // tempPropList.add(propList.get(i)); - // } - // - // // build stereoDiplayList and remove stereotype display properties form propList - // Iterator<com.cea.papyrus.diagraminterchange2.di2.Property> iter = tempPropList.iterator(); - // while (iter.hasNext()) { - // com.cea.papyrus.diagraminterchange2.di2.Property prop = iter.next(); - // if (prop.getKey().equals(ModelerHelper.PROPERTY_STEREOTYPE_DISPLAY)) { - // stereoDiplayList.add(prop); - // propList.remove(prop); - // } - // } - // - // // add stereotype display properties in the appropriate order - // Iterator<Stereotype> stereoIter = appliedStereotypes.iterator(); - // while (stereoIter.hasNext()) { - // String stereoName = stereoIter.next().getQualifiedName(); - // Iterator<com.cea.papyrus.diagraminterchange2.di2.Property> propIter = stereoDiplayList.iterator(); - // while (propIter.hasNext()) { - // com.cea.papyrus.diagraminterchange2.di2.Property prop = propIter.next(); - // if (prop.getValue().equals(stereoName)) { - // propList.add(prop); - // } - // } - // } - // } - // - // /** Stereotype properties values display operations **********************/ - // - // /** - // * Adds a stereotype property to the list of properties to display for a diagram element. - // * - // * @param owner - // * the owner - // * @param prop - // * the stereotype property to add - // */ - // private void addStereotypePropertyDisplay(Property prop, Stereotype owner) { - // // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - // if (getDiagramElement() == null) { - // return; - // } - // - // // property to add creation - // com.cea.papyrus.diagraminterchange2.di2.Property property = Di2Factory.eINSTANCE.createProperty(); - // property.setKey(ModelerHelper.PROPERTY_STEREOTYPE_PROPERTY_VALUES_DISPLAY); - // property.setValue(owner.getQualifiedName() + "::" + prop.getName()); - // - // // add the property - // getDiagramElement().getProperty().add(property); - // - // // command creation: display stereotype properties in active diagram - // Command command = new StereotypePropertiesDisplayCreateCommand(getSelectedEditPart(), getDiagramElement(), (DiagramElement) getDiagramElement().getContainer()); - // CommandStack stack = CommandStackUtils.getCommandStack(); - // - // Assert.isNotNull(stack, "Impossible to adapt current editor into a CommandStackUtils"); - // stack.execute(command); - // - // } - // - // /** - // * Removes a stereotype property from the list of properties to display for a diagram element. - // * - // * @param owner - // * the owner - // * @param property - // * the stereotype property to remove - // */ - // protected void removeStereotypePropertyDisplay(Property property, Stereotype owner) { - // // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - // if (getDiagramElement() == null) { - // return; - // } - // - // EList propList = getDiagramElement().getProperty(); - // ArrayList<com.cea.papyrus.diagraminterchange2.di2.Property> tempPropList = new ArrayList<com.cea.papyrus.diagraminterchange2.di2.Property>(); - // for (int i = 0; i < propList.size(); i++) { - // tempPropList.add(i, ((com.cea.papyrus.diagraminterchange2.di2.Property) propList.get(i))); - // } - // - // Iterator iter = tempPropList.iterator(); - // - // while (iter.hasNext()) { - // com.cea.papyrus.diagraminterchange2.di2.Property prop = (com.cea.papyrus.diagraminterchange2.di2.Property) iter.next(); - // if (prop.getKey().equals(ModelerHelper.PROPERTY_STEREOTYPE_PROPERTY_VALUES_DISPLAY)) { - // if (prop.getValue().equals(owner.getQualifiedName() + "::" + property.getName())) { - // propList.remove(prop); - // } - // } - // } - // - // // count the number of stereotype properties to display - // Iterator<com.cea.papyrus.diagraminterchange2.di2.Property> iterProp = getDiagramElement().getProperty().iterator(); - // int count = 0; - // while (iterProp.hasNext()) { - // com.cea.papyrus.diagraminterchange2.di2.Property diProp = iterProp.next(); - // if (diProp.getKey().equals(ModelerHelper.PROPERTY_STEREOTYPE_PROPERTY_VALUES_DISPLAY)) { - // count++; - // } - // } - // - // if (count == 0) { - // Command command; - // - // CommandStack stack = CommandStackUtils.getCommandStack(); - // - // command = DiagramElementDeleteCommandFactory.eINSTANCE.createCommand((GraphNode) LookForElement.getSemanticChildWithoutUmlSemanticAndNoContent(getDiagramElement())); - // - // Assert.isNotNull(stack, "Impossible to adapt current editor into a CommandStackUtils"); - // stack.execute(command); - // } - // } - // - // /** - // * Checks wether the stereotype property is in the display list or not. - // * - // * @param owner - // * the owner - // * @param property - // * to check out - // * - // * @return true if the stereotype property is in the display list, false otherwise - // */ - // private Boolean isInStereoPropertyDisplay(Property property, Stereotype owner) { - // // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - // if (getDiagramElement() == null) { - // return false; - // } - // - // EList propList = getDiagramElement().getProperty(); - // Iterator iter = propList.iterator(); - // while (iter.hasNext()) { - // com.cea.papyrus.diagraminterchange2.di2.Property prop = (com.cea.papyrus.diagraminterchange2.di2.Property) iter.next(); - // if (prop.getKey().equals(ModelerHelper.PROPERTY_STEREOTYPE_PROPERTY_VALUES_DISPLAY)) { - // if (prop.getValue().equals(owner.getQualifiedName() + "::" + property.getName())) { - // return true; - // } - // } - // } - // return false; - // } - // - // /** - // * {@inheritDoc} - // */ - // protected void removeStereotypePropertiesDisplay(Stereotype stereotype) { - // Iterator<Property> stereoPropIter = stereotype.getAllAttributes().iterator(); - // while (stereoPropIter.hasNext()) { - // Property currentProp = stereoPropIter.next(); - // if (isInStereoPropertyDisplay(currentProp, stereotype)) { - // removeStereotypePropertyDisplay(currentProp, stereotype); - // } - // } - // } /** * Display the stereotype once it is applied * - * @param st + * @param stereotype * the stereotype to add + * @param prop */ - protected void displayStereotype(final Stereotype st) { + protected void displayStereotypeProperty(final Stereotype stereotype, final Property prop) { // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - if (diagramElement == null) { - return; - } - try { - - getDomain().runExclusive(new Runnable() { - - public void run() { + if (diagramElement != null) { - Display.getCurrent().asyncExec(new Runnable() { + try { - public void run() { - String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(diagramElement); - RecordingCommand command = AppliedStereotypeHelper.getAddAppliedStereotypeCommand(getDomain(), diagramElement, st.getQualifiedName(), presentationKind); - getDomain().getCommandStack().execute(command); - // refresh(); - } - }); + View nodeToDisplay = StereotypeDisplayHelper.getInstance().getStereotypeProperty((View) diagramElement, stereotype, prop); + View compartment = helper.getStereotypeCompartment((View) diagramElement, stereotype); + setPersistency(getDomain(), nodeToDisplay); + setVisibility(getDomain(), nodeToDisplay, true); + if (!compartment.isVisible()) { + setPersistency(getDomain(), compartment); + setVisibility(getDomain(), compartment, true); + hideOtherProperties(compartment, nodeToDisplay); } - }); - } catch (Exception e) { - Activator.logException(e); + + } catch (Exception e) { + Activator.logException(e); + } } } - protected void removeStereotypeProperty(final Stereotype st, final Property property) { - // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - if (diagramElement == null) { - return; - } - try { - getDomain().runExclusive(new Runnable() { - public void run() { - Display.getCurrent().asyncExec(new Runnable() { - public void run() { - String stringToRemove = st.getQualifiedName() + "." + property.getName(); - RecordingCommand command = AppliedStereotypeHelper.getRemoveAppliedStereotypePropertiesCommand(getDomain(), diagramElement, stringToRemove); - getDomain().getCommandStack().execute(command); - // refresh(); - } - }); + /** + * Display the stereotype once it is applied + * + * @param stereotype + * the stereotype to add + * @param propertyToHide + */ + protected void hideStereotypeProperty(final Stereotype stereotype, final Property propertyToHide) { + // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) + if (diagramElement != null) { + + try { + if (stereotype != null && propertyToHide != null) { + // Retrieve the Stereotype Property View in Notation Model then make it persistent and hide it. + View nodeToDisplay = StereotypeDisplayHelper.getInstance().getStereotypeProperty((View) diagramElement, stereotype, propertyToHide); + View compartment = helper.getStereotypeCompartment((View) diagramElement, stereotype); + + setPersistency(getDomain(), nodeToDisplay); + setVisibility(getDomain(), nodeToDisplay, false); + // Then update the Compartment Visibility Accordingly + updateCompartmentVisibility(compartment); } - }); - } catch (Exception e) { - Activator.logException(e); + } catch (Exception e) { + Activator.logException(e); + } } } + + /** * Display the stereotype once it is applied * - * @param st - * the stereotype to add + * @param stereotype + * the stereotype of the Label to display */ - protected void displayStereotypeProperties(final Stereotype st) { - // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - if (diagramElement == null) { - return; - } - try { - - getDomain().runExclusive(new Runnable() { - - public void run() { + protected void displayStereotypeLabel(final Stereotype stereotype) { + if (diagramElement != null) { - Display.getCurrent().asyncExec(new Runnable() { + try { - public void run() { - String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(diagramElement); - RecordingCommand command = AppliedStereotypeHelper.getAddAppliedStereotypeCommand(getDomain(), diagramElement, st.getQualifiedName(), presentationKind); - getDomain().getCommandStack().execute(command); - // refresh(); - } - }); - } - }); + // Retrieve the Stereotype Label View in Notation Model then make it persistent and show it. + View nodeToDisplay = helper.getStereotypeLabel((View) diagramElement, stereotype); + setPersistency(getDomain(), nodeToDisplay); + setVisibility(getDomain(), nodeToDisplay, true); - } catch (Exception e) { - Activator.logException(e); + } catch (Exception e) { + Activator.logException(e); + } } } @@ -783,65 +560,93 @@ public class AppearanceForAppliedStereotypeComposite extends org.eclipse.papyrus * @param st * the stereotype to add */ - protected void displayStereotypeWithQN(final Stereotype st) { - // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - if (diagramElement == null) { - return; + protected void hideStereotypeLabel(final Stereotype stereotype) { + + if (diagramElement != null) { + + try { + // Retrieve the Stereotype Label View in Notation Model then make it persistent and hide it. + View nodeToDisplay = helper.getStereotypeLabel((View) diagramElement, stereotype); + setPersistency(getDomain(), nodeToDisplay); + setVisibility(getDomain(), nodeToDisplay, false); + + } catch (Exception e) { + Activator.logException(e); + } } - try { - getDomain().runExclusive(new Runnable() { + } - public void run() { - Display.getCurrent().asyncExec(new Runnable() { + /** + * If the display of the Compartment changed, make the Compartment Persistent. + * + * @param stereotypeCompartment + */ + private void updateCompartmentVisibility(final View stereotypeCompartment) { + // If any Children visible, set Visibility + // Else hide the Compartment + boolean display = stereotypeCompartment.isVisible(); + // if display change, make the node persistent. + // if the compartment has visible properties but is not displayed then change the visibility + // if the compartment doesn't have visible property but is displayed then change the visibility + if (helper.hasVisibleProperties(stereotypeCompartment) != display) { + setPersistency(getDomain(), stereotypeCompartment); + setVisibility(getDomain(), stereotypeCompartment, helper.hasVisibleProperties(stereotypeCompartment)); + + } + } - public void run() { - RecordingCommand command = AppliedStereotypeHelper.getAddAppliedStereotypeToDisplayWithQNCommand(getDomain(), diagramElement, st.getQualifiedName()); - getDomain().getCommandStack().execute(command); - // refresh(); - } - }); - } - }); - } catch (Exception e) { - Activator.logException(e); + + /** + * Make the Properties node not visible except one. + * + * @param compartment + * The Stereotype Compartment that contains the properties. + * @param propertyToDisplay + * The StereotypeProperty Node to keep visible. + */ + private void hideOtherProperties(final View compartment, final View propertyToDisplay) { + for (Object child : compartment.getChildren()) { + if (helper.isStereotypeProperty(child) && propertyToDisplay != child) { + setVisibility(getDomain(), (View) child, false); + } } } + + private void setDepth(TransactionalEditingDomain domain, Stereotype stereotype, View nodeView, String depth) { + final View label = helper.getStereotypeLabel(nodeView, stereotype); + Command command = new CustomStyleValueCommand(label, depth, NotationPackage.eINSTANCE.getStringValueStyle(), NotationPackage.eINSTANCE.getStringValueStyle_StringValue(), StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH); + domain.getCommandStack().execute(command); + } + /** - * Remove a stereotype from the list of stereotypes to display. - * - * @param st - * the stereotype to remove + * Set The visibility + * + * @param domain + * @param view + * @param visible */ - protected void removeDisplayStereotype(final Stereotype st) { - // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline) - if (diagramElement == null) { - return; - } - try { - getDomain().runExclusive(new Runnable() { + private void setVisibility(TransactionalEditingDomain domain, View view, boolean visible) { - public void run() { + SetNodeVisibilityCommand setCommand = new SetNodeVisibilityCommand(domain, view, visible); + domain.getCommandStack().execute(setCommand); - Display.getCurrent().asyncExec(new Runnable() { + } - public void run() { - String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(diagramElement); - RecordingCommand command = AppliedStereotypeHelper.getRemoveAppliedStereotypeCommand(getDomain(), diagramElement, st.getQualifiedName(), presentationKind); + /** + * Set the Persistency + * + * @param domain + * @param view + */ + private void setPersistency(TransactionalEditingDomain domain, View view) { - getDomain().getCommandStack().execute(command); - // refresh(); - } - }); - } - }); - } catch (Exception e) { - Activator.logException(e); - } + SetPersistentViewCommand command = new SetPersistentViewCommand(domain, view); + domain.getCommandStack().execute(command); } |