Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCéline Janssens2015-02-23 05:54:33 -0500
committerCéline Janssens2015-05-06 09:12:47 -0400
commit7d79f366cef733c758d3d21b02103f52eb7c8eec (patch)
treea73df70f298f17d7630cac101808b99b9e4269fe
parentdb0a842e0e90d28754bfc88acd19743223515cc9 (diff)
downloadorg.eclipse.papyrus-7d79f366cef733c758d3d21b02103f52eb7c8eec.tar.gz
org.eclipse.papyrus-7d79f366cef733c758d3d21b02103f52eb7c8eec.tar.xz
org.eclipse.papyrus-7d79f366cef733c758d3d21b02103f52eb7c8eec.zip
Bug 460356: [Stereotype Display] Objective 4c. Display properties into a
comment thanks to CSS. - Refactor EditPolicies - Add creation of Stereotype Structure at the ASLabelDisplayEditPolicy - creation of Comment with new Structure as a copy of the Compartment. - Comment Compartment Displayed and deleted - Small refactor - Default display: All is displayed everywhere by Default Change-Id: Ief7bf1d8b8cbffa8301b0e342c7f26d5c66941b5 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=460356 Signed-off-by: Céline Janssens <Celine.Janssens@all4tec.net>
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF1
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/CSSDOMSemanticElementHelper.java26
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/OneTopLineResizableBorder.java46
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java26
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/AcceptTimeEventActionStereotypeExternalNodeEditPolicy.java42
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java7
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeExternalNodeEditPolicy.java3
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeLabelDisplayEditPolicy.java436
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeNodeLabelDisplayEditPolicy.java75
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java119
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/CornerBentFigure.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/StereotypedElementLabelHelper.java113
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java17
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentContentCommand.java103
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentViewCommand.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypeCommentViewCommand.java)40
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypePropertyViewCommand.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypePropertyViewCommand.java)3
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeViewCommand.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypeViewCommand.java)8
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateStereotypeLabelCommand.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateStereotypeLabelCommand.java)3
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayHelper.java424
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayUtils.java37
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeLocationEnum.java21
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.css/src/org/eclipse/papyrus/uml/diagram/css/dom/GMFUMLElementAdapter.java28
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/AppliedStereotypeCommentCreationEditPolicyEx.java96
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionCompartmentXYLayoutEditPolicy.java4
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionFragmentsCreationEditPolicy.java4
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandAppliedStereotypeLabelDisplayEditPolicy.java9
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/LifelineAppliedStereotypeNodeLabelDisplayEditPolicy.java8
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/META-INF/MANIFEST.MF6
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/plugin.xml2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeCommentEditPart.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypesCommentEditPart.java)6
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeCompartmentEditPart.java41
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeMultilinePropertyEditPart.java6
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCommentCreationEditPolicy.java399
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentEditPolicy.java420
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentForCommentShapeEditPolicy.java29
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeLabelEditPolicy.java112
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypePropertiesEditPolicy.java58
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/CustomEditPolicyProvider.java6
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/StereotypePropertiesEditPartProvider.java6
40 files changed, 1637 insertions, 1157 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF
index 8f3aa2771cd..0fa8eca0b6b 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/META-INF/MANIFEST.MF
@@ -40,6 +40,7 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.1.0",
org.eclipse.papyrus.views.properties;bundle-version="1.1.0",
org.eclipse.papyrus.views.properties.model;bundle-version="1.1.0",
+ org.eclipse.papyrus.uml.diagram.common;bundle-version="1.1.0",
com.google.guava;bundle-version="11.0.0"
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/CSSDOMSemanticElementHelper.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/CSSDOMSemanticElementHelper.java
index 756c26990e0..31367b0f6f2 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/CSSDOMSemanticElementHelper.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/CSSDOMSemanticElementHelper.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 460356 : Refactor Stereotype Display
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.css.helper;
@@ -18,6 +19,7 @@ import org.eclipse.gmf.runtime.notation.DecorationNode;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper;
/**
@@ -44,6 +46,7 @@ public class CSSDOMSemanticElementHelper {
*/
public static EObject findSemanticElement(EObject notationElement) {
+
if (notationElement == null) {
return null;
}
@@ -53,11 +56,26 @@ public class CSSDOMSemanticElementHelper {
return notationElement;
}
+ // Add Stereotype Comment
+ if (notationElement instanceof Shape) {
+ if (StereotypeDisplayHelper.getInstance().isStereotypeComment(notationElement)) {
+ return notationElement;
+ }
+ }
+
// Add compartments to the DOM model
if (notationElement instanceof BasicCompartment) {
return notationElement;
}
+
+ // Add StereotypeProperty to the DOM model
+ if (notationElement instanceof DecorationNode) {
+ if (StereotypeDisplayHelper.getInstance().isStereotypeProperty(notationElement)) {
+ return notationElement;
+ }
+ }
+
// Add floating labels to the DOM model
if (isFloatingLabel(notationElement)) {
return notationElement;
@@ -71,6 +89,7 @@ public class CSSDOMSemanticElementHelper {
return semanticElement;
}
+
// The graphical element isn't related to a Semantic Element. The view becomes the semantic element.
// e.g. : Links in UML
return view;
@@ -170,13 +189,6 @@ public class CSSDOMSemanticElementHelper {
}
}
- // TODO Check if relevant
- if (node.eContainer() instanceof BasicCompartment) {
- if (node.getLayoutConstraint() != null) {
- return true;
- }
- }
-
return false;
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/OneTopLineResizableBorder.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/OneTopLineResizableBorder.java
index b9c24c67419..ad9adb3856e 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/OneTopLineResizableBorder.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/OneTopLineResizableBorder.java
@@ -121,7 +121,7 @@ public class OneTopLineResizableBorder extends OneLineBorder {
// get the length of the line according to the corner
int length = getLineLength(figure);
- tempRect.width = (int) (length);
+ tempRect.width = (length);
// if the length is forced or a ratio is applied
if (forcedLength != -1) {
@@ -179,29 +179,31 @@ public class OneTopLineResizableBorder extends OneLineBorder {
SVGNodePlateFigure mainFigure = FigureUtils.findParentFigureInstance(figure, SVGNodePlateFigure.class);
// Get the connection anchor
- ConnectionAnchor connectionAnchor = ((SVGNodePlateFigure) mainFigure).getConnectionAnchor("");
- if (connectionAnchor instanceof SlidableRoundedRectangleAnchor && !(mainFigure.getBounds().equals(new Rectangle()))) {
- // Calculate the length off the border thanks the SlidableRoundedRectangleAnchor
- Rectangle rect = figure.getBounds().getCopy();
- figure.translateToAbsolute(rect);
-
- Point locationLeft = ((SlidableRoundedRectangleAnchor) connectionAnchor).getLocation(rect.getTopLeft().translate(rect.width / 2, 0), rect.getTopLeft());
- Point locationRight = ((SlidableRoundedRectangleAnchor) connectionAnchor).getLocation(rect.getTopLeft().translate(rect.width / 2, 0), rect.getTopRight());
-
- if (locationLeft != null && locationRight != null) {
-
- rect.width = locationRight.x - locationLeft.x;
- // translate the length according to the zoom
- figure.translateToRelative(rect);
- length = rect.width;
-
- // set the position at the figure bounds.x to the position on x of the left location
- // TODO: don't do it on a getLenght method.
- figure.translateToRelative(locationLeft);
- tempRect.x = locationLeft.x;
+ if (mainFigure != null) {
+ ConnectionAnchor connectionAnchor = mainFigure.getConnectionAnchor("");
+ if (connectionAnchor instanceof SlidableRoundedRectangleAnchor && !(mainFigure.getBounds().equals(new Rectangle()))) {
+ // Calculate the length off the border thanks the SlidableRoundedRectangleAnchor
+ Rectangle rect = figure.getBounds().getCopy();
+ figure.translateToAbsolute(rect);
+
+ Point locationLeft = ((SlidableRoundedRectangleAnchor) connectionAnchor).getLocation(rect.getTopLeft().translate(rect.width / 2, 0), rect.getTopLeft());
+ Point locationRight = ((SlidableRoundedRectangleAnchor) connectionAnchor).getLocation(rect.getTopLeft().translate(rect.width / 2, 0), rect.getTopRight());
+
+ if (locationLeft != null && locationRight != null) {
+
+ rect.width = locationRight.x - locationLeft.x;
+ // translate the length according to the zoom
+ figure.translateToRelative(rect);
+ length = rect.width;
+
+ // set the position at the figure bounds.x to the position on x of the left location
+ // TODO: don't do it on a getLenght method.
+ figure.translateToRelative(locationLeft);
+ tempRect.x = locationLeft.x;
+ }
}
}
- return (int) (length);
+ return (length);
}
/**
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
index 6fd7c06a7df..bc476fb091e 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java
@@ -26,6 +26,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.EObjectValueStyle;
import org.eclipse.gmf.runtime.notation.IntValueStyle;
import org.eclipse.gmf.runtime.notation.NamedStyle;
import org.eclipse.gmf.runtime.notation.NotationPackage;
@@ -339,6 +340,31 @@ public class NotationUtils {
}
/**
+ * Gets the EObject value from a NamedStyle property.
+ *
+ * @param view
+ * the view
+ * @param property
+ * the property
+ * @param defaultValue
+ * the default value
+ * @return the EObject
+ */
+ public static EObject getEObjectValue(View view, String property, EObject defaultValue) {
+ EObject value = defaultValue;
+ EClass eObjectValueStyle = NotationPackage.eINSTANCE.getEObjectValueStyle();
+
+ if (eObjectValueStyle != null) {
+ NamedStyle style = view.getNamedStyle(eObjectValueStyle, property);
+ if (style instanceof EObjectValueStyle) {
+ value = ((EObjectValueStyle) style).getEObjectValue();
+ }
+ }
+ return value;
+ }
+
+
+ /**
* Get the list as a String list and convert it to Int list
*
* @param model
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/AcceptTimeEventActionStereotypeExternalNodeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/AcceptTimeEventActionStereotypeExternalNodeEditPolicy.java
index 81e99146695..976fa543baa 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/AcceptTimeEventActionStereotypeExternalNodeEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/AcceptTimeEventActionStereotypeExternalNodeEditPolicy.java
@@ -17,11 +17,9 @@ import org.eclipse.draw2d.IFigure;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
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.editpolicies.AppliedStereotypeExternalNodeEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusUMLElementFigure;
-import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper;
import org.eclipse.uml2.uml.AcceptEventAction;
import org.eclipse.uml2.uml.TimeEvent;
import org.eclipse.uml2.uml.UMLPackage;
@@ -81,44 +79,10 @@ public class AcceptTimeEventActionStereotypeExternalNodeEditPolicy extends Appli
// try to display stereotype properties
String stereotypespresentationLocation = AppliedStereotypeHelper.getAppliedStereotypesPropertiesLocalization(parentView);
String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay(parentView);
- String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay(parentView);
+ String stereotypesToDisplay = StereotypeDisplayHelper.getInstance().getStereotypeTextToDisplay(parentView);
String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(parentView);
+ return stereotypesToDisplay;
-
- // now check presentation.
- // if horizontal => equivalent to the inBrace visualization in nodes
- // (i.e. only name =
- // value, separator = comma, delimited with brace
- // if vertical => equivalent to compartment visualization name of
- // stereotype, NL, property =
- // value, NL, etC.
-
- // check the presentation kind. if only icon => do not display
- // stereotype, only values
- if (UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION.equals(stereotypespresentationKind)) {
- return StereotypeUtil.getPropertiesValuesInBrace(stereotypesPropertiesToDisplay, getUMLElement());
- }
- String display = "";
- if (!UMLVisualInformationPapyrusConstant.STEREOTYPE_COMMENT_LOCATION.equals(stereotypespresentationLocation)) {
- String stereotypesToDisplayWithQN = AppliedStereotypeHelper.getStereotypesQNToDisplay(parentView);
-
- if (UMLVisualInformationPapyrusConstant.STEREOTYPE_TEXT_VERTICAL_PRESENTATION.equals(stereotypespresentationKind)) {
- display += stereotypesAndPropertiesToDisplay("\n", stereotypesToDisplay, stereotypesPropertiesToDisplay);
- } else {
- final String st = stereotypesToDisplay();
- if (st != null && !st.equals("")) {
- display += Activator.ST_LEFT + st + Activator.ST_RIGHT;
- }
- final String propSt = StereotypeUtil.getPropertiesValuesInBrace(stereotypesPropertiesToDisplay, getUMLElement());
- if (propSt != null && !propSt.equals("")) {
- if (st != null && !st.equals("")) {
- display += "\n";
- }
- display += "{" + propSt + "}";
- }
- }
- }
- return display;
}
/**
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 6407015f5e4..b22e74bd8a8 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
@@ -43,6 +43,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
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.StereotypeDisplayHelper;
import org.eclipse.papyrus.uml.modelrepair.service.IStereotypeRepairService;
import org.eclipse.papyrus.uml.tools.listeners.StereotypeElementListener.StereotypeExtensionNotification;
import org.eclipse.swt.graphics.Image;
@@ -64,6 +65,9 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic
/** host semantic element */
protected Element hostSemanticElement;
+ /** Helper to manipulate applied Stereotype Display model */
+ protected StereotypeDisplayHelper helper = StereotypeDisplayHelper.getInstance();
+
/**
* Creates a new AppliedStereotype display edit policy
*/
@@ -155,8 +159,7 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic
getDiagramEventBroker().addNotificationListener(stereotypeApplication, this);
}
refreshDisplay();
- // try to display stereotype properties
- cleanStereotypeDisplayInEAnnotation();
+
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeExternalNodeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeExternalNodeEditPolicy.java
index 450d8e9b934..efb168b467f 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeExternalNodeEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeExternalNodeEditPolicy.java
@@ -20,7 +20,6 @@ import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusUMLElementFigure;
-import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
/**
@@ -90,7 +89,7 @@ public class AppliedStereotypeExternalNodeEditPolicy extends AppliedStereotypeLa
// try to display stereotype properties
String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay(parentView);
- String stereotypesToDisplay = StereotypeDisplayHelper.getStereotypeTextToDisplay(parentView);
+ String stereotypesToDisplay = helper.getStereotypeTextToDisplay(parentView);
String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(parentView);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeLabelDisplayEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeLabelDisplayEditPolicy.java
index ae916874660..1638064687a 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeLabelDisplayEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeLabelDisplayEditPolicy.java
@@ -9,30 +9,46 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotypes Display
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.editpolicies;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
+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.util.TransactionUtil;
+import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.notation.BasicCompartment;
import org.eclipse.gmf.runtime.notation.DecorationNode;
+import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
+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.StereotypeDisplayHelper;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.CreateAppliedStereotypePropertyViewCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.CreateAppliedStereotypeViewCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.CreateStereotypeLabelCommand;
import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
+import org.eclipse.papyrus.uml.tools.listeners.StereotypeElementListener.StereotypeExtensionNotification;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Extension;
+import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.Usage;
+import org.eclipse.uml2.uml.util.UMLUtil;
/**
* Specific edit policy for label displaying stereotypes and their properties
@@ -52,12 +68,16 @@ public abstract class AppliedStereotypeLabelDisplayEditPolicy extends AbstractAp
/**
* Map between Stereotype Name and StereotypeLabel displayed
*/
- public Map<EObject, DecorationNode> stereotypeMap = new HashMap<EObject, DecorationNode>();
+ private Map<EObject, DecorationNode> stereotypeMap = new HashMap<EObject, DecorationNode>();
/**
* Map between Stereotype Name and StereotypeLabel displayed
*/
- public Map<EObject, BasicCompartment> stereotypePropertyMap = new HashMap<EObject, BasicCompartment>();
+ private Map<EObject, BasicCompartment> stereotypePropertyMap = new HashMap<EObject, BasicCompartment>();
+
+
+ private GraphicalEditPart hostEditPart;
+
/**
* Creates a new AppliedStereotypeLabelDisplayEditPolicy, with the specified
@@ -81,6 +101,21 @@ public abstract class AppliedStereotypeLabelDisplayEditPolicy extends AbstractAp
}
/**
+ * @return the stereotypePropertyMap
+ */
+ public Map<EObject, BasicCompartment> getStereotypePropertyMap() {
+ return stereotypePropertyMap;
+ }
+
+ /**
+ * @param stereotypePropertyMap
+ * the stereotypePropertyMap to set
+ */
+ public void setStereotypePropertyMap(Map<EObject, BasicCompartment> stereotypePropertyMap) {
+ this.stereotypePropertyMap = stereotypePropertyMap;
+ }
+
+ /**
* {@inheritDoc}
*/
@Override
@@ -88,10 +123,61 @@ public abstract class AppliedStereotypeLabelDisplayEditPolicy extends AbstractAp
refreshStereotypeDisplay();
}
+ @Override
+ public void activate() {
+ super.activate();
+ if (getHost() instanceof GraphicalEditPart) {
+ hostEditPart = (GraphicalEditPart) getHost();
+ }
+ // if stereotype has been applied, compartment has to be created
+ Element umlElement = getUMLElement();
+ // umlElement may be null if the semantic element has been deleted and the view hasn't been cleaned
+ if (umlElement != null) {
+ Iterator<EObject> iterator = umlElement.getStereotypeApplications().iterator();
+ while (iterator.hasNext()) {
+ final EObject appliedstereotype = iterator.next();
+ createAppliedStereotypeLabel(appliedstereotype);
+ createAppliedStereotypeCompartment(appliedstereotype);
+ createAppliedStereotypeProperty(appliedstereotype);
+ }
+ }
+ }
+
/**
- * Refreshes the stereotype display
+ *
+ * {@inheritedDoc}
*/
- protected abstract void refreshStereotypeDisplay();
+ @Override
+ public void notifyChanged(Notification notification) {
+ // change the label of the figure managed by the host edit part (managed
+ // by the parent edit part in general...)
+ // it must be changed only if:
+ // - the stereotype application list has changed
+ final int eventType = notification.getEventType();
+
+ if (eventType == StereotypeExtensionNotification.STEREOTYPE_APPLIED_TO_ELEMENT) {
+ // a stereotype was applied to the notifier
+ // then a new listener should be added to the stereotype application
+ getDiagramEventBroker().addNotificationListener((EObject) notification.getNewValue(), this);
+ createAppliedStereotypeLabel((EObject) notification.getNewValue());
+ createAppliedStereotypeCompartment((EObject) notification.getNewValue());
+ createAppliedStereotypeProperty((EObject) notification.getNewValue());
+
+ // Store entry in the Map
+ storeInMap((EObject) notification.getNewValue(), hostEditPart.getNotationView());
+
+
+ } else if (eventType == StereotypeExtensionNotification.STEREOTYPE_UNAPPLIED_FROM_ELEMENT) {
+ getDiagramEventBroker().removeNotificationListener((EObject) notification.getOldValue(), this);
+ removeAppliedStereotypeLabel((EObject) notification.getOldValue());
+ removeAppliedStereotypeCompartment((EObject) notification.getOldValue());
+
+ // delete entry in the Map
+ deleteInMap((EObject) notification.getOldValue());
+
+ }
+
+ }
/**
* Returns the image to be displayed for the applied stereotypes.
@@ -183,8 +269,344 @@ public abstract class AppliedStereotypeLabelDisplayEditPolicy extends AbstractAp
public String stereotypesToDisplay() {
// try to display stereotype properties
- String stereotypesToDisplay = StereotypeDisplayHelper.getStereotypeTextToDisplay((View) getHost().getModel());
+ String stereotypesToDisplay = helper.getStereotypeTextToDisplay((View) getHost().getModel());
return stereotypesToDisplay;
}
+ /**
+ * @return the stereotypeMap
+ */
+ public Map<EObject, DecorationNode> getStereotypeMap() {
+ return stereotypeMap;
+ }
+
+ /**
+ * @param stereotypeMap
+ * the stereotypeMap to set
+ */
+ public void setStereotypeMap(Map<EObject, DecorationNode> stereotypeMap) {
+ this.stereotypeMap = stereotypeMap;
+ }
+
+
+ /**
+ * the goal of this method is to execute the a command to create a notation node for a compartment of stereotype
+ *
+ * @param editPart
+ * the editPart owner of the new compartment
+ * @param appliedstereotype
+ * the stereotype application
+ */
+ protected void executeAppliedStereotypeCompartmentCreation(final GraphicalEditPart editPart, final EObject stereotypeApplication) {
+ try {
+ editPart.getEditingDomain().runExclusive(new Runnable() {
+
+ @Override
+ public void run() {
+ Display.getCurrent().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ CreateAppliedStereotypeViewCommand command = new CreateAppliedStereotypeViewCommand(editPart.getEditingDomain(), editPart.getNotationView(), stereotypeApplication);
+
+ // use to avoid to put it in the command stack
+ try {
+ GMFUnsafe.write(editPart.getEditingDomain(), command);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
+
+ }
+ });
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+
+
+ /**
+ * this method is used to create a notation node for the property of the stereotype
+ *
+ * @param editPart
+ * the editPart container
+ * @param compartment
+ * @param stereotypeApplication
+ * @param stereotype
+ * the stereotype associated to compartment node
+ */
+ protected void executeAppliedStereotypePropertyViewCreation(final GraphicalEditPart editPart, final Node compartment, final Property stereotypeProperty) {
+ try {
+ editPart.getEditingDomain().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
+ CreateAppliedStereotypePropertyViewCommand command = new CreateAppliedStereotypePropertyViewCommand(editPart.getEditingDomain(), compartment, stereotypeProperty);
+ try {
+ GMFUnsafe.write(editPart.getEditingDomain(), command);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
+ }
+ });
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+
+
+ /**
+ * Execute the command to remove the Stereotype Compartment with Properties.
+ *
+ * @param editPart
+ * Edit Part on which the command is executed
+ * @param label
+ * DecorationNode of the Stereotype Label that has to be removed
+ */
+ protected void executeAppliedStereotypeCompartmentRemove(final GraphicalEditPart editPart, final View compartment) {
+ try {
+
+ editPart.getEditingDomain().runExclusive(new Runnable() {
+
+ @Override
+ public void run() {
+ DeleteCommand command = new DeleteCommand(compartment);
+ // use to avoid to put it in the command stack
+ try {
+ GMFUnsafe.write(editPart.getEditingDomain(), command);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+
+ /**
+ * This method creates a node for the compartment of stereotype if it does not exist.
+ *
+ * @param stereotypeApplication
+ * the stereotype application
+ */
+ protected void createAppliedStereotypeLabel(final EObject stereotypeApplication) {
+
+
+ if (hostEditPart instanceof IPapyrusEditPart) {
+
+ final View node = hostEditPart.getNotationView();
+ // create only if the Label doesn't exist yet
+ if (!helper.isLabelExist(node, stereotypeApplication)) {
+ // Create the Decoration Node
+ executeStereotypeLabelCreation(hostEditPart, stereotypeApplication, StereotypeDisplayUtils.DEFAULT_VISIBILITY_VALUE);
+
+
+ }
+ }
+
+ }
+
+
+ /**
+ * This method creates a node for the compartment of stereotype if it does not exist.
+ *
+ * @param stereotypeApplication
+ * the stereotype application
+ */
+ protected void createAppliedStereotypeCompartment(final EObject stereotypeApplication) {
+ final View node = hostEditPart.getNotationView();
+ // doesn't exist already
+ if (!helper.isCompartmentExist(node, stereotypeApplication)) {
+ // Create Compartment
+ executeAppliedStereotypeCompartmentCreation(hostEditPart, stereotypeApplication);
+ }
+ }
+
+
+ /**
+ * In charge of property view creation
+ *
+ * @param eObject
+ * The Edit Part of which the Properties should be created
+ */
+ protected void createAppliedStereotypeProperty(EObject stereotypeApplication) {
+
+ Node compartment = helper.getStereotypeCompartment(hostEditPart.getNotationView(), stereotypeApplication);
+ if (compartment != null && helper.isStereotypeCompartment(compartment)) {
+ Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
+ if (stereotype != null) {
+ EList<Property> properties = stereotype.allAttributes();
+ for (Property property : properties) {
+ // if stereotype is null all property of stereotype has to be removed!
+ if (property != null && !property.getName().startsWith(Extension.METACLASS_ROLE_PREFIX)) {
+ if (!helper.isPropertyExist((BasicCompartment) compartment, property)) {
+ // go through each stereotype property
+ executeAppliedStereotypePropertyViewCreation(hostEditPart, compartment, property);
+
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * this method suppress the sub-nodes that references the stereotype application
+ * it cleans also all sub-nodes with the type ApplicationStereotype that not references an application of stereotypes
+ * (this is the case when a stereotype has been unapplied without suppress the compartment.
+ *
+ * @param stereotypeApplication
+ */
+ protected void removeAppliedStereotypeCompartment(final EObject stereotypeApplication) {
+
+ GraphicalEditPart editPart = (GraphicalEditPart) getHost();
+
+ // Remove the Label node
+ BasicCompartment compartment = getStereotypePropertyMap().get(stereotypeApplication);
+ if (compartment != null && TransactionUtil.getEditingDomain(compartment) != null) {
+ executeAppliedStereotypeCompartmentRemove(editPart, compartment);
+ }
+ }
+
+
+ /**
+ * Remove the stereotype entry from the Map
+ *
+ * @param stereotypeApplication
+ * The Stereotype Application reference to delete
+ */
+ protected void deleteInMap(EObject stereotypeApplication) {
+ getStereotypePropertyMap().remove(stereotypeApplication);
+ getStereotypeMap().remove(stereotypeApplication);
+ }
+
+
+ /**
+ * Store the entry (stereotypeApplication, StereotypeLabel)
+ *
+ * @param stereotypeApplication
+ * The Stereotype Application instance to store
+ * @param node
+ * The parent view (i.e: CSSShapeImpl)
+ */
+ protected void storeInMap(EObject stereotypeApplication, View node) {
+
+ // String stereoQN = UMLUtil.getStereotype(stereotypeApplication).getQualifiedName();
+ if (stereotypeApplication != null && node != null) {
+ BasicCompartment compartment = helper.getStereotypeCompartment(node, stereotypeApplication);
+ getStereotypePropertyMap().put(stereotypeApplication, compartment);
+ DecorationNode label = helper.getStereotypeLabel(node, stereotypeApplication);
+ getStereotypeMap().put(stereotypeApplication, label);
+ }
+ }
+
+
+ /**
+ * The goal of this method is to execute the a command to create a notation node for a stereotype Label.
+ *
+ * @param editPart
+ * the editPart owner of the new compartment
+ * @param appliedstereotype
+ * the stereotype application
+ */
+ protected void executeStereotypeLabelCreation(final GraphicalEditPart editPart, final EObject appliedstereotype, final boolean isVisible) {
+ try {
+ editPart.getEditingDomain().runExclusive(new Runnable() {
+ @Override
+ public void run() {
+ Display.getCurrent().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+
+ CreateStereotypeLabelCommand command = new CreateStereotypeLabelCommand(editPart.getEditingDomain(), editPart.getNotationView(), appliedstereotype, isVisible);
+ // use to avoid to put it in the command stack
+ try {
+ GMFUnsafe.write(editPart.getEditingDomain(), command);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
+
+ }
+ });
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+
+
+ /**
+ * Execute the command to remove the Stereotype.
+ *
+ * @param editPart
+ * Edit Part on which the command is executed
+ * @param label
+ * DecorationNode of the Stereotype Label that has to be removed
+ */
+ protected void executeStereotypeLabelRemove(final GraphicalEditPart editPart, final View label) {
+ try {
+
+
+ TransactionUtil.getEditingDomain(getView()).runExclusive(new Runnable() {
+
+ @Override
+ public void run() {
+ DeleteCommand command = new DeleteCommand(label);
+ // use to avoid to put it in the command stack
+ try {
+ GMFUnsafe.write(editPart.getEditingDomain(), command);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+
+
+ /**
+ * Remove the StereotypeLabel from an element from it's stereotype application.
+ *
+ * @param stereotypeApplication
+ * Associated Stereotype application to remove
+ */
+ protected void removeAppliedStereotypeLabel(EObject stereotypeApplication) {
+ if (stereotypeApplication == null) {
+ return;
+ }
+
+ // Remove the Label node
+ DecorationNode label = getStereotypeMap().get(stereotypeApplication);
+ if (label != null && TransactionUtil.getEditingDomain(label) != null) {
+ executeStereotypeLabelRemove(hostEditPart, label);
+ }
+
+
+ }
+
+
+ /**
+ * Refreshes the stereotype display
+ */
+ protected abstract void refreshStereotypeDisplay();
+
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeNodeLabelDisplayEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeNodeLabelDisplayEditPolicy.java
index 3bc0da63051..e2ec84e7bd0 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeNodeLabelDisplayEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeNodeLabelDisplayEditPolicy.java
@@ -10,21 +10,13 @@
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 429275
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 460356 : Refactor Stereotype Display
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.editpolicies;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
-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.common.editparts.NamedElementEditPart;
-import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeNamedElementFigure;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure;
-import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper;
-import org.eclipse.swt.graphics.Image;
/**
* this edit policy can be apply only on {@link IPapyrusEditPart} in order to
@@ -45,72 +37,9 @@ public class AppliedStereotypeNodeLabelDisplayEditPolicy extends AppliedStereoty
*/
@Override
protected void refreshStereotypeDisplay() {
- if (getHost() instanceof IPapyrusEditPart) {
- IFigure figure = ((IPapyrusEditPart) getHost()).getPrimaryShape();
-
- // calculate text and icon to display
- final String stereotypesToDisplay = StereotypeDisplayHelper.getStereotypeTextToDisplay((View) getHost().getModel());
- // computes the icon to be displayed
- final Image imageToDisplay = stereotypeIconToDisplay();
-
- // if the string is not empty, then, the figure has to display it.
- // Else, it displays nothing
- if (figure instanceof IPapyrusNodeUMLElementFigure) {
- // Stereotype should be passed as "" if null, in order to avoid "null" string.
- ((IPapyrusNodeUMLElementFigure) figure).setStereotypeDisplay(tag + (stereotypesToDisplay == null ? "" : stereotypesToDisplay), imageToDisplay);
-
- if (figure instanceof IPapyrusNodeNamedElementFigure) {
- refreshAppliedStereotypesProperties((IPapyrusNodeNamedElementFigure) figure);
- } else {
- refreshAppliedStereotypesProperties((IPapyrusNodeUMLElementFigure) figure);
- }
- }
- // TODO we should manage PapyrusNodeFigure here too (and
- // WrappingLabel ?)
- }
+ // do nothing
}
- /**
- * Refreshes the displayed stereotypes properties for this edit part.
- */
- protected void refreshAppliedStereotypesProperties(IPapyrusNodeNamedElementFigure figure) {
- refreshAppliedStereotypesPropertiesInBrace(figure);
-
- BooleanValueStyle displayStereotypes = (BooleanValueStyle) getView().getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), NamedElementEditPart.DISPLAY_STEREOTYPES);
- if (displayStereotypes != null && !displayStereotypes.isBooleanValue()) {
- figure.removeStereotypeLabel();
- } else {
- figure.restoreStereotypeLabel();
- }
- }
-
- /**
- * Refreshes the displayed stereotypes properties for this edit part.
- */
- protected void refreshAppliedStereotypesProperties(IPapyrusNodeUMLElementFigure figure) {
-
- refreshAppliedStereotypesPropertiesInBrace(figure);
- }
-
-
- /**
- * Refreshes the stereotypes properties displayed above name of the element
- * in this edit part.
- *
- * @param stereotypesPropertiesToDisplay
- */
- protected void refreshAppliedStereotypesPropertiesInBrace(IPapyrusNodeUMLElementFigure figure) {
- String toDisplayInBrace = StereotypeDisplayHelper.getStereotypePropertiesInBrace(((GraphicalEditPart) getHost()).getNotationView());
- // if the string is not empty, then, the figure has to display it. Else,
- // it displays nothing
- if (!"".equals(toDisplayInBrace)) {
- // it has to be displayed in braces, so compute the string to
- // display
- figure.setStereotypePropertiesInBrace(toDisplayInBrace);
- } else {
- figure.setStereotypePropertiesInBrace(null);
- }
- }
}
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 28ae3a53202..7be9f8e68d8 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
@@ -10,6 +10,7 @@
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 323802
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 460356 : Refactor Stereotype Display
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.editpolicies;
@@ -23,46 +24,50 @@ import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
-import org.eclipse.gmf.runtime.notation.EObjectValueStyle;
+import org.eclipse.gmf.runtime.gef.ui.internal.editpolicies.GraphicalEditPolicyEx;
import org.eclipse.gmf.runtime.notation.NotationPackage;
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.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
import org.eclipse.swt.widgets.Display;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.util.UMLUtil;
/**
- * this editpolicy attached to StereotypeCommentEdipart has in charge to prevent the remove form model
- * and launch command of deletion if it detect that any properties of applied stereotype are displayed
+ * This Edit Policy is attached to AppliedStereotypeCommentEdipart, and is in charge to prevent the deletion of the Comment from model
+ * and launch command of deletion if it detect that no property of applied stereotype are displayed.
*
*/
-public class CommentShapeForAppliedStereotypeEditPolicy extends GraphicalEditPolicy implements NotificationListener, IPapyrusListener {
+public class CommentShapeForAppliedStereotypeEditPolicy extends GraphicalEditPolicyEx implements NotificationListener, IPapyrusListener {
@Override
public void notifyChanged(Notification notification) {
View commentNode = getView();
- final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(commentNode);
- if (getUMLElement() == null) {
- executeAppliedStereotypeCommentDeletion(domain, commentNode);
- }
- final int eventType = notification.getEventType();
- if (eventType == Notification.SET && notification.getFeature().equals(NotationPackage.eINSTANCE.getView_Visible())) {
-
- if (getView() != null) {
+ if (commentNode != null) {
+ final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(commentNode);
- if (getvisibleAppliedStereotypeCompartment(commentNode, getUMLElement()) == 0) {
+ // if Base_Element is deleted, the Comment is deleted as well
+ if (getUMLElement() == null) {
+ executeAppliedStereotypeCommentDeletion(domain, commentNode);
+ }
+ // if notification Set the visibility and none of Compartment is Visible, delete the Comment
+ final int eventType = notification.getEventType();
+ if (eventType == Notification.SET && notification.getFeature().equals(NotationPackage.eINSTANCE.getView_Visible())) {
+ if (getVisibleAppliedStereotypeCompartmentNumber(commentNode) == 0) {
executeAppliedStereotypeCommentDeletion(domain, commentNode);
-
}
+
}
}
}
@@ -73,14 +78,23 @@ public class CommentShapeForAppliedStereotypeEditPolicy extends GraphicalEditPol
* @return the uml element controlled by the host edit part
*/
protected Element getUMLElement() {
+ Element element = null;
if ((Element) getView().getElement() != null) {
- return (Element) getView().getElement();
- }
- if (getView().getNamedStyle(NotationPackage.eINSTANCE.getEObjectValueStyle(), "BASE_ELEMENT") != null) {
- EObjectValueStyle eObjectValueStyle = (EObjectValueStyle) getView().getNamedStyle(NotationPackage.eINSTANCE.getEObjectValueStyle(), "BASE_ELEMENT");
- return (Element) eObjectValueStyle.getEObjectValue();
+ element = (Element) getView().getElement();
+ } else {
+
+ EObject object = NotationUtils.getEObjectValue(getView(), StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME, null);
+ if (object != null) {
+ if (object instanceof Element) {
+ element = (Element) object;
+ } else {
+ if (UMLUtil.getStereotype(object) != null) {
+ element = UMLUtil.getStereotype(object);
+ }
+ }
+ }
}
- return null;
+ return element;
}
@Override
@@ -94,32 +108,61 @@ public class CommentShapeForAppliedStereotypeEditPolicy extends GraphicalEditPol
}
+ /**
+ * @see org.eclipse.gmf.runtime.gef.ui.internal.editpolicies.GraphicalEditPolicyEx#refresh()
+ *
+ */
+ @Override
+ public void refresh() {
+ View commentNode = getView();
+ final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(commentNode);
+ if (getVisibleAppliedStereotypeCompartmentNumber(commentNode) == 0) {
+ executeAppliedStereotypeCommentDeletion(domain, commentNode);
+ }
+ super.refresh();
+ }
+
+ /**
+ * Execute Comment Deletion
+ *
+ * @param domain
+ * TransactionalDomain
+ * @param commentNode
+ * Node of the Comment to be deleted.
+ */
protected void executeAppliedStereotypeCommentDeletion(final TransactionalEditingDomain domain, final View commentNode) {
- if (commentNode != null) {
- Display.getCurrent().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- // because it is asynchronous the comment node's domain maybe become null
- if (TransactionUtil.getEditingDomain(commentNode) == domain) {
- DeleteCommand command = new DeleteCommand(commentNode);
- try {
- GMFUnsafe.write(domain, command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
+
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ // because it is asynchronous the comment node's domain maybe become null
+ if (TransactionUtil.getEditingDomain(commentNode) == domain) {
+ DeleteCommand command = new DeleteCommand(commentNode);
+ try {
+ GMFUnsafe.write(domain, command);
+ } catch (Exception e) {
+ Activator.log.error(e);
}
}
- });
- }
+ }
+ });
}
- protected int getvisibleAppliedStereotypeCompartment(View view, EObject eobject) {
+ /**
+ * 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 getVisibleAppliedStereotypeCompartmentNumber(View view) {
int nbVisibleCompartment = 0;
Iterator<View> iteratorView = view.getChildren().iterator();
while (iteratorView.hasNext()) {
View subview = iteratorView.next();
- if (subview.isVisible() == true) {
+ if (subview.isVisible() && StereotypeDisplayHelper.getInstance().isStereotypeCompartment(subview)) {
nbVisibleCompartment++;
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/CornerBentFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/CornerBentFigure.java
index 456a8ab267e..c2ac28a81dc 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/CornerBentFigure.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/CornerBentFigure.java
@@ -233,7 +233,7 @@ public class CornerBentFigure extends NoteFigure implements IPapyrusNodeUMLEleme
* @param stereotypes
* the string representing the stereotypes to be displayed
*/
- public void setStereotypes(String stereotypes) {
+ protected void setStereotypes(String stereotypes) {
if (stereotypes == null) {
// Remove label if any
if (this.stereotypesLabel != null) {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java
index b3fd48341d8..044afc93658 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/NodeNamedElementFigure.java
@@ -67,7 +67,7 @@ public class NodeNamedElementFigure extends PapyrusNodeFigure implements IPapyru
protected Label qualifiedLabel;
/**
- * Added for stereptypes properties
+ * Added for stereotypes properties
*/
private RectangleFigure stereotypePropertiesContent;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/StereotypedElementLabelHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/StereotypedElementLabelHelper.java
index 8f88dd069b8..f1cd20bb549 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/StereotypedElementLabelHelper.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/StereotypedElementLabelHelper.java
@@ -34,6 +34,7 @@ import org.eclipse.papyrus.infra.emf.appearance.helper.AppearanceHelper;
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.StereotypeDisplayHelper;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
import org.eclipse.swt.graphics.Image;
@@ -196,7 +197,7 @@ public abstract class StereotypedElementLabelHelper {
}
/**
- * get the list of stereotype to display from the eannotation
+ * get Stereotype String to display
*
* @return the list of stereotypes to display
*/
@@ -204,116 +205,12 @@ public abstract class StereotypedElementLabelHelper {
View view = (View) editPart.getModel();
// retrieve all stereotypes to be displayed
// try to display stereotype properties
- String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay(view);
- String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay(view);
- String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(view);
- // now check presentation.
- // if horizontal => equivalent to the inBrace visualization in nodes
- // (i.e. only name =
- // value, separator = comma, delimited with brace
- // if vertical => equivalent to compartment visualization name of
- // stereotype, NL, property =
- // value, NL, etC.
- // check the presentation kind. if only icon => do not display
- // stereotype, only values
- if (UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION.equals(stereotypespresentationKind)) {
- return StereotypeUtil.getPropertiesValuesInBrace(stereotypesPropertiesToDisplay, getUMLElement(editPart));
- }
- String stereotypesToDisplayWithQN = AppliedStereotypeHelper.getStereotypesQNToDisplay(view);
- String display = "";
- if (UMLVisualInformationPapyrusConstant.STEREOTYPE_TEXT_VERTICAL_PRESENTATION.equals(stereotypespresentationKind)) {
- display += stereotypesAndPropertiesToDisplay(editPart, "\n", stereotypesToDisplay, stereotypesToDisplayWithQN, stereotypesPropertiesToDisplay);
- } else {
- final String st = stereotypesToDisplay(editPart, ", ", stereotypesToDisplay, stereotypesToDisplayWithQN);
- if (st != null && !st.equals("")) {
- display += Activator.ST_LEFT + st + Activator.ST_RIGHT + " ";
- }
- final String propSt = StereotypeUtil.getPropertiesValuesInBrace(stereotypesPropertiesToDisplay, getUMLElement(editPart));
- if (propSt != null && !propSt.equals("")) {
- if (st != null && !st.equals("")) {
- // display += "\n";
- }
- display += "{" + propSt + "} ";
- }
- }
- return display;
- }
+ String stereotypesToDisplay = StereotypeDisplayHelper.getInstance().getStereotypeTextToDisplay(view);
- /**
- * Computes the string that displays the stereotypes for the current element
- *
- * @param separator
- * the separator used to split the string representing the
- * stereotypes.
- * @param stereotypesToDisplay
- * the list of stereotypes displayed
- * @param stereotypeWithQualifiedName
- * the list of stereotypes displayed using their qualified names
- * @return the string that represent the stereotypes
- */
- public String stereotypesToDisplay(GraphicalEditPart editPart, String separator, String stereotypesToDisplay, String stereotypeWithQualifiedName) {
- // AL Changes Feb. 07 - Beg
- // Style Handling for STEREOTYPE_NAME_APPEARANCE from
- // ProfileApplicationPreferencePage
- // Stereotype displayed according to UML standard (first letter forced
- // to lower case) -
- // default -
- // or kept as entered by user (user controlled)
- // Get the preference from PreferenceStore. there should be an assert
- final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
- if (store == null) {
- Activator.log.warn("The preference store was not found");
- return "";
- }
- String sNameAppearance = store.getString(UMLVisualInformationPapyrusConstant.P_STEREOTYPE_NAME_APPEARANCE);
- StringTokenizer strQualifiedName = new StringTokenizer(stereotypesToDisplay, ",");
- String out = "";
- while (strQualifiedName.hasMoreElements()) {
- String currentStereotype = strQualifiedName.nextToken();
- // check if current stereotype is applied
- final Element umlElement = getUMLElement(editPart);
- Stereotype stereotype = umlElement.getAppliedStereotype(currentStereotype);
- if (stereotype != null) {
- String name = currentStereotype;
- if ((stereotypeWithQualifiedName.indexOf(currentStereotype)) == -1) {
- // property value contains qualifiedName ==> extract name
- // from it
- StringTokenizer strToken = new StringTokenizer(currentStereotype, "::");
- while (strToken.hasMoreTokens()) {
- name = strToken.nextToken();
- }
- }
- // AL Changes Feb. 07 - Beg
- // Handling STEREOTYPE_NAME_APPEARANCE preference (from
- // ProfileApplicationPreferencePage)
- // Previously lowercase forced onto first letter (standard UML)
- // stereotypesToDisplay = stereotypesToDisplay+name.substring(0,
- // 1).toLowerCase()+name.substring(1,
- // name.length())+","+separator;
- // check that the name has not already been added to the
- // displayed string
- if (sNameAppearance.equals(UMLVisualInformationPapyrusConstant.P_STEREOTYPE_NAME_DISPLAY_USER_CONTROLLED)) {
- if (out.indexOf(name) == -1) {
- out = out + name + separator;
- }
- } else { // VisualInformationPapyrusConstants.P_STEREOTYPE_NAME_DISPLAY_UML_CONFORM))
- // {
- name = name.substring(0, 1).toLowerCase() + name.substring(1, name.length());
- if (out.indexOf(name) == -1) {
- out = out + name + separator;
- }
- }
- }
- }
- if (out.endsWith(",")) {
- return out.substring(0, out.length() - 1);
- }
- if (out.endsWith(separator)) {
- return out.substring(0, out.length() - separator.length());
- }
- return out;
+ return stereotypesToDisplay;
}
+
/**
* Refreshes the label of the figure associated to the specified edit part
*
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java
index ec4fcc006f3..c12c824aa2b 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java
@@ -30,6 +30,7 @@ import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
+import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
@@ -47,6 +48,8 @@ import org.eclipse.uml2.uml.util.UMLUtil;
*/
public class StereotypePropertyParser implements IParser, ISemanticParser {
+ private static final String DEFAULT_VALUE = "<UNDEFINED>";
+
/**
*
* @see org.eclipse.gmf.runtime.common.ui.services.parser.IParser#getCompletionProcessor(org.eclipse.core.runtime.IAdaptable)
@@ -88,7 +91,7 @@ public class StereotypePropertyParser implements IParser, ISemanticParser {
}
}
- return "<UNDEFINED>";
+ return DEFAULT_VALUE;
}
/**
@@ -147,15 +150,23 @@ public class StereotypePropertyParser implements IParser, ISemanticParser {
@Override
public String getPrintString(IAdaptable element, int flags) {
+ StereotypeDisplayHelper helper = StereotypeDisplayHelper.getInstance();
if (element instanceof IAdaptable) {
final Property property = ((Property) (EMFHelper.getEObject(element)));
final View view = ((View) element.getAdapter(View.class));
+ StereotypeLocationEnum location;
+ if (helper.isInStereotypeComment((Node) view)) {
+ location = StereotypeLocationEnum.IN_COMMENT_COMPARTMENT;
+ } else {
+ location = StereotypeLocationEnum.IN_COMPARTMENT;
+ }
+
if (view != null && property != null) {
- return StereotypeDisplayHelper.getStereotypePropertyToDisplay(view, property, StereotypeLocationEnum.IN_COMPARTMENT);
+ return helper.getStereotypePropertyToDisplay(view, property, location);
}
}
- return "<UNDEFINED>";
+ return DEFAULT_VALUE;
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentContentCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentContentCommand.java
new file mode 100644
index 00000000000..206c021efa8
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentContentCommand.java
@@ -0,0 +1,103 @@
+/*****************************************************************************
+ * 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 - Bug 460356 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype;
+
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.BasicCompartment;
+import org.eclipse.gmf.runtime.notation.Node;
+
+/**
+ * @author Céline JANSSENS
+ *
+ */
+public class CreateAppliedStereotypeCommentContentCommand extends RecordingCommand {
+
+ private StereotypeDisplayHelper helper = StereotypeDisplayHelper.getInstance();
+
+ private Node appliedStereotypeComment;
+ private GraphicalEditPart host;
+ private Node originalCompartment;
+
+ /**
+ * Constructor.
+ *
+ */
+ public CreateAppliedStereotypeCommentContentCommand(TransactionalEditingDomain domain, String name) {
+ super(domain, name);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param stereotypeApplication
+ *
+ */
+ public CreateAppliedStereotypeCommentContentCommand(String name, Node appliedStereotypeComment, GraphicalEditPart host, Node compartment) {
+ super(host.getEditingDomain(), name);
+ this.appliedStereotypeComment = appliedStereotypeComment;
+ this.host = host;
+ this.originalCompartment = compartment;
+
+ }
+
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ *
+ */
+ @Override
+ protected void doExecute() {
+
+ // if it has to be displayed into the comment
+
+ BasicCompartment compartmentComment = helper.getStereotypeCompartment(appliedStereotypeComment, originalCompartment.getElement());
+
+ if (helper.isStereotypeCompartment(originalCompartment)) {
+
+ if (compartmentComment == null) {
+
+ boolean visibility = !isCommentEmpty((BasicCompartment) originalCompartment);
+ BasicCompartment compartmentCopy = EcoreUtil.copy((BasicCompartment) originalCompartment); // Copy the compartment into the Comment EditPart
+ compartmentCopy.setVisible(visibility);
+ ViewUtil.insertChildView(appliedStereotypeComment, compartmentCopy, ViewUtil.APPEND, true);
+
+ }
+ }
+
+ }
+
+ /**
+ * Define if the Comment is empty and should be displayed.
+ *
+ * @param compartment
+ * The Compartment view
+ * @return false by default, true if properties displayed in Brace and in Compartment Comment are empty
+ */
+ private boolean isCommentEmpty(BasicCompartment compartment) {
+ boolean commentEmpty = false;
+
+ if ((helper.isEmpty(compartment, StereotypeLocationEnum.IN_COMMENT_BRACE))
+ && (helper.isEmpty(compartment, StereotypeLocationEnum.IN_COMMENT_COMPARTMENT))) {
+ commentEmpty |= true;
+
+ }
+ return commentEmpty;
+ }
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypeCommentViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentViewCommand.java
index ce724f0e27e..30b0a90f7d5 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypeCommentViewCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentViewCommand.java
@@ -9,15 +9,14 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 460356 : Refactor Stereotype Display
*
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.stereotype.edition.command;
+package org.eclipse.papyrus.uml.diagram.common.stereotype;
import java.util.ArrayList;
-import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
@@ -35,10 +34,6 @@ import org.eclipse.gmf.runtime.notation.RelativeBendpoints;
import org.eclipse.gmf.runtime.notation.TitleStyle;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint;
-import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
-import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypesCommentEditPart;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypesCommentLinkEditPart;
/**
* the goal of this command is to create a comment in the notation that represent a compartment of stereotypes
@@ -47,15 +42,10 @@ import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereo
public class CreateAppliedStereotypeCommentViewCommand extends RecordingCommand {
protected View owner;
-
protected EObject base_element;
-
protected int x;
-
protected int y;
-
protected TransactionalEditingDomain domain;
-
protected Boolean isBorderedElement;
/**
@@ -93,15 +83,13 @@ public class CreateAppliedStereotypeCommentViewCommand extends RecordingCommand
ts.setShowTitle(true);
node.getStyles().add(ts);
node.setElement(null);
- node.setType(AppliedStereotypesCommentEditPart.ID);
+ node.setType(StereotypeDisplayUtils.STEREOTYPE_COMMENT_TYPE);
connectCommentNode(owner, node);
-
-
EObjectValueStyle eObjectValueStyle = (EObjectValueStyle) node.createStyle(NotationPackage.eINSTANCE.getEObjectValueStyle());
eObjectValueStyle.setEObjectValue(base_element);
- eObjectValueStyle.setName("BASE_ELEMENT");
+ eObjectValueStyle.setName(StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME);
// create the link
Connector edge = NotationFactory.eINSTANCE.createConnector();
@@ -113,7 +101,7 @@ public class CreateAppliedStereotypeCommentViewCommand extends RecordingCommand
bendpoints.setPoints(points);
edge.setBendpoints(bendpoints);
ViewUtil.insertChildView(owner.getDiagram(), edge, -1, true);
- edge.setType(AppliedStereotypesCommentLinkEditPart.ID);
+ edge.setType(StereotypeDisplayUtils.STEREOTYPE_COMMENT_LINK_TYPE);
edge.setElement(base_element);
IdentityAnchor anchor = NotationFactory.eINSTANCE.createIdentityAnchor();
edge.setSourceAnchor(anchor);
@@ -124,18 +112,12 @@ public class CreateAppliedStereotypeCommentViewCommand extends RecordingCommand
edge.setElement(null);
eObjectValueStyle = (EObjectValueStyle) edge.createStyle(NotationPackage.eINSTANCE.getEObjectValueStyle());
eObjectValueStyle.setEObjectValue(base_element);
- eObjectValueStyle.setName("BASE_ELEMENT");
-
- // copy EAnnotation
- final EAnnotation stereotypeAnnotation = owner.getEAnnotation(UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION);
- EAnnotation stereotypeAnnotationCopy = EcoreUtil.copy(stereotypeAnnotation);
- node.getEAnnotations().add(stereotypeAnnotationCopy);
- RecordingCommand cmd = AppliedStereotypeHelper.getSetAppliedStereotypePropertiesLocalizationCommand(domain, node, UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION);
- cmd.execute();
-
- String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(node);
- cmd = AppliedStereotypeHelper.getRemoveAppliedStereotypeCommand(domain, node, AppliedStereotypeHelper.getStereotypesToDisplay(node), presentationKind);
- cmd.execute();
+ eObjectValueStyle.setName(StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME);
+
+
+
+
+
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypePropertyViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypePropertyViewCommand.java
index de20ff0f0ec..afb56815d33 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypePropertyViewCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypePropertyViewCommand.java
@@ -12,7 +12,7 @@
* Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotypes Display
*
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.stereotype.edition.command;
+package org.eclipse.papyrus.uml.diagram.common.stereotype;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.RecordingCommand;
@@ -21,7 +21,6 @@ import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.notation.DecorationNode;
import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypeViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeViewCommand.java
index c38574288c0..342d0c20f7e 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypeViewCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeViewCommand.java
@@ -11,7 +11,7 @@
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
*
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.stereotype.edition.command;
+package org.eclipse.papyrus.uml.diagram.common.stereotype;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.RecordingCommand;
@@ -22,8 +22,6 @@ import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.StringValueStyle;
import org.eclipse.gmf.runtime.notation.TitleStyle;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper;
-import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.util.UMLUtil;
@@ -33,6 +31,8 @@ import org.eclipse.uml2.uml.util.UMLUtil;
*/
public class CreateAppliedStereotypeViewCommand extends RecordingCommand {
+ protected StereotypeDisplayHelper helper = StereotypeDisplayHelper.getInstance();
+
protected View node;
protected EObject stereotypeApplication;
@@ -53,7 +53,7 @@ public class CreateAppliedStereotypeViewCommand extends RecordingCommand {
super(domain, "CreateStereotypeCompartment");
this.node = node;
this.stereotypeApplication = stereotypeApplication;
- parent = StereotypeDisplayHelper.getStereotypeLabel(node, stereotypeApplication);
+ parent = helper.getStereotypeLabel(node, stereotypeApplication);
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateStereotypeLabelCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateStereotypeLabelCommand.java
index e2892072532..cbd917f6bdd 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateStereotypeLabelCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateStereotypeLabelCommand.java
@@ -12,7 +12,7 @@
*
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.stereotype.edition.command;
+package org.eclipse.papyrus.uml.diagram.common.stereotype;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.RecordingCommand;
@@ -22,7 +22,6 @@ import org.eclipse.gmf.runtime.notation.DecorationNode;
import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.StringValueStyle;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.util.UMLUtil;
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 16e4247847e..a863e9bd5ef 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
@@ -22,7 +22,9 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
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.Shape;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.commands.SetNodeVisibilityCommand;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
@@ -41,9 +43,26 @@ import org.eclipse.uml2.uml.util.UMLUtil;
* @author Céline JANSSENS
*
*/
-public abstract class StereotypeDisplayHelper {
+public class StereotypeDisplayHelper {
- private static final String EMPTY_SPACE = ""; // $NON-NLS-1$
+ /**
+ * singleton instance
+ */
+ private static StereotypeDisplayHelper labelHelper;
+
+ /**
+ * Returns the singleton instance of this class
+ *
+ * @return the singleton instance.
+ */
+ public static StereotypeDisplayHelper getInstance() {
+ if (labelHelper == null) {
+ labelHelper = new StereotypeDisplayHelper();
+ }
+ return labelHelper;
+ }
+
+ private static final String EMPTY_STRING = ""; // $NON-NLS-1$
/**
* Get the Full label to display into the header
@@ -52,8 +71,9 @@ public abstract class StereotypeDisplayHelper {
* The corresponding View
* @return The label with Stereotype Name to display (i.e: "Blocks::Block, Allocation, SysML::Requirements::Requirement" )
*/
- public static String getStereotypeTextToDisplay(View model) {
+ public String getStereotypeTextToDisplay(View model) {
String textToDisplay = null;
+ String finalText = null;
Iterator<?> iter = model.getChildren().iterator();
Object object;
DecorationNode label;
@@ -72,12 +92,40 @@ public abstract class StereotypeDisplayHelper {
}
// Then add the ornament around the text.
- if ((textToDisplay != null) && (!EMPTY_SPACE.equals(textToDisplay))) {
- textToDisplay = StereotypeDisplayUtils.BRACE_LEFT + textToDisplay + StereotypeDisplayUtils.BRACE_RIGHT;
+ if ((textToDisplay != null) && (!EMPTY_STRING.equals(textToDisplay))) {
+ finalText = StereotypeDisplayUtils.BRACE_LEFT + textToDisplay + StereotypeDisplayUtils.BRACE_RIGHT;
}
// Return the text or null if empty
- return (EMPTY_SPACE.equals(textToDisplay) ? null : textToDisplay);
+ return finalText;
+ }
+
+
+ /**
+ * Get the entire String to display between braces.
+ *
+ * @param notationView
+ * The View of the Element on which the Stereotype has been applied.
+ * @param inComment
+ * if this is the Property in the comment
+ *
+ * @return The entire string to be displayed in braces
+ */
+ public String getStereotypePropertiesInBrace(View notationView) {
+ String textToDisplay = null;
+ Iterator<?> iter = notationView.getChildren().iterator();
+ Object object;
+ // For each Stereotype Compartment, retrieve the property text to be added in Braces
+ while (iter.hasNext()) {
+ object = iter.next();
+ if (isStereotypeCompartment(object)) {
+ BasicCompartment compartment = (BasicCompartment) object;
+
+ textToDisplay = addStereotypeCompartmentProperties(textToDisplay, compartment);
+
+ }
+ }
+ return textToDisplay;
}
/**
@@ -91,18 +139,18 @@ public abstract class StereotypeDisplayHelper {
*
* @return The String with the new StereotypeName and
*/
- protected static String addStereotypeName(String textToDisplay, DecorationNode label, View model) {
+ protected String addStereotypeName(String textToDisplay, DecorationNode label, View model) {
String newTextToDisplay = textToDisplay;
- if (!EMPTY_SPACE.equals(newTextToDisplay) && (newTextToDisplay != null)) {
+ if (!EMPTY_STRING.equals(newTextToDisplay) && (newTextToDisplay != null)) {
newTextToDisplay = (newTextToDisplay + StereotypeDisplayUtils.STEREOTYPE_LABEL_SEPARATOR);
}
// Retrieve Name and Depth from CSS or NamedStyle
- String name = StereotypeDisplayHelper.getName(label);
- String depth = StereotypeDisplayHelper.getDepth(label);
+ String name = getName(label);
+ String depth = getDepth(label);
// Compute name according to the depth
String nameWithDepth = getStereotypeNameWithDepth(name, depth);
- newTextToDisplay = ((newTextToDisplay == null ? EMPTY_SPACE : newTextToDisplay) + nameWithDepth);
+ newTextToDisplay = ((newTextToDisplay == null ? EMPTY_STRING : newTextToDisplay) + nameWithDepth);
return newTextToDisplay;
}
@@ -116,9 +164,9 @@ public abstract class StereotypeDisplayHelper {
* The Depth value (i.e: "-1" )
* @return The stereotype Name with the proper Depth (i.e: "Blocks::Block")
*/
- protected static String getStereotypeNameWithDepth(String qualifiedName, String depth) {
+ protected String getStereotypeNameWithDepth(String qualifiedName, String depth) {
- if (depth != null && !EMPTY_SPACE.equals(depth)) {
+ if (depth != null && !EMPTY_STRING.equals(depth)) {
if (StereotypeDisplayUtils.DEPTH_MIN.equals(depth)) {
return getMinimumDepthName(qualifiedName);
} else if (StereotypeDisplayUtils.DEPTH_MAX.equals(depth)) {
@@ -132,12 +180,16 @@ public abstract class StereotypeDisplayHelper {
int depthRetrieve = Integer.parseInt(depth);
// Case the number is coherent
if (depthRetrieve > -getMaxDepth(qualifiedName) && depthRetrieve < 0) {
+ // Nominal Case (i.e : Depth = -1 => Compute the name accordingly)
return computeDepthName(depthRetrieve, qualifiedName);
} else if (depthRetrieve <= -getMaxDepth(qualifiedName)) {
+ // Depth is too Small (i.e : -24 ) => Return the last segment
return getMinimumDepthName(qualifiedName);
} else if (depthRetrieve == 0) {
+ // Depth is null => return the full name
return qualifiedName;
} else {
+ // in all other cases return the full name
return qualifiedName;
}
@@ -158,7 +210,7 @@ public abstract class StereotypeDisplayHelper {
* The Full Qualified Name
* @return the Name computed with the appropriate Depth
*/
- protected static String computeDepthName(int depthRetrieve, String qualifiedName) {
+ protected String computeDepthName(int depthRetrieve, String qualifiedName) {
StringBuffer name = new StringBuffer(qualifiedName);
try {
@@ -180,8 +232,8 @@ public abstract class StereotypeDisplayHelper {
* The full path name
* @return The Last segment of the path.
*/
- public static String getMinimumDepthName(String qualifiedName) {
- String segment = EMPTY_SPACE;
+ public String getMinimumDepthName(String qualifiedName) {
+ String segment = EMPTY_STRING;
StringBuffer name = new StringBuffer(qualifiedName);
int index = name.lastIndexOf(StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR);
segment = name.substring(index + StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR.length());
@@ -195,7 +247,7 @@ public abstract class StereotypeDisplayHelper {
* The full path name
* @return Number of deepness level of the full path
*/
- protected static int getMaxDepth(String qualifiedName) {
+ protected int getMaxDepth(String qualifiedName) {
StringTokenizer tok = new StringTokenizer(qualifiedName, StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR);
return tok.countTokens();
@@ -211,9 +263,9 @@ public abstract class StereotypeDisplayHelper {
* Qualified Name of the Stereotype associated to this Label
* @return associated StereotypeLabel
*/
- public static DecorationNode getStereotypeLabel(View node, String qualifiedName) {
+ public DecorationNode getStereotypeLabel(View node, String qualifiedName) {
- if ((qualifiedName != null) && (qualifiedName != EMPTY_SPACE)) {
+ if ((qualifiedName != null) && (qualifiedName != EMPTY_STRING)) {
Object obj;
Iterator<?> iter = node.getChildren().iterator();
while (iter.hasNext()) {
@@ -242,7 +294,7 @@ public abstract class StereotypeDisplayHelper {
* Stereotype Application of the Label to be retrieved.
* @return associated StereotypeLabel
*/
- public static DecorationNode getStereotypeLabel(View node, EObject stereotypeApplication) {
+ public DecorationNode getStereotypeLabel(View node, EObject stereotypeApplication) {
if ((stereotypeApplication != null) && (node != null)) {
Object obj;
@@ -270,18 +322,18 @@ public abstract class StereotypeDisplayHelper {
* Node on which the Stereotype Label is retrieved
* @param stereotypeApplication
* Stereotype Application of the Label to be retrieved.
- * @return associated StereotypeLabel
+ * @return associated StereotypeLabel or null if none
*/
- public static BasicCompartment getStereotypeCompartment(View node, EObject stereotypeApplication) {
+ public BasicCompartment getStereotypeCompartment(View node, EObject stereotypeApplication) {
if ((stereotypeApplication != null) && (node != null)) {
Object obj;
Iterator<?> iter = node.getChildren().iterator();
while (iter.hasNext()) {
obj = iter.next();
- if (obj instanceof BasicCompartment) {
+ if (isStereotypeCompartment(obj)) {
BasicCompartment compartment = (BasicCompartment) obj;
- if (StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_TYPE.equals(compartment.getType())) {
+ if (compartment.getElement() != null) {
if (compartment.getElement().equals(stereotypeApplication)) {
return compartment;
}
@@ -293,6 +345,32 @@ public abstract class StereotypeDisplayHelper {
}
/**
+ * return the comment nodes that represent stereotype properties
+ *
+ * @return may be null if nothing is founded
+ */
+ public Node getStereotypeComment(View SemanticView) {
+ Node node = null;
+ if (SemanticView != null && SemanticView.getSourceEdges() != null) {
+ // look for all links with the id AppliedStereotypesCommentLinkEditPart.ID
+ Iterator<Edge> edgeIterator = SemanticView.getSourceEdges().iterator();
+ Edge appliedStereotypeLink = null;
+ while (edgeIterator.hasNext() && appliedStereotypeLink == null) {
+ Edge edge = edgeIterator.next();
+ if (edge.getType().equals(StereotypeDisplayUtils.STEREOTYPE_COMMENT_LINK_TYPE)) {
+ appliedStereotypeLink = edge;
+ }
+ }
+ if (appliedStereotypeLink == null) {
+ return null;
+ }
+ node = (Node) appliedStereotypeLink.getTarget();
+ }
+ return node;
+
+ }
+
+ /**
* Define if the Object is a StereotypeLabel
*
* @param element
@@ -300,7 +378,7 @@ public abstract class StereotypeDisplayHelper {
*
* @return True if the Object is of type "StereotypeLabel"
*/
- public static boolean isStereotypeLabel(Object element) {
+ public boolean isStereotypeLabel(Object element) {
boolean stereotypeLabel = Boolean.FALSE;
if (element instanceof DecorationNode) {
stereotypeLabel = StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(((DecorationNode) element).getType());
@@ -316,7 +394,7 @@ public abstract class StereotypeDisplayHelper {
* The object on which the test is done
* @return True if Object is a StereotypeCompartment
*/
- public static boolean isStereotypeCompartment(Object element) {
+ public boolean isStereotypeCompartment(Object element) {
boolean stereotypeCompartment = Boolean.FALSE;
if (element instanceof BasicCompartment) {
stereotypeCompartment = StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_TYPE.equals(((DecorationNode) element).getType());
@@ -332,7 +410,7 @@ public abstract class StereotypeDisplayHelper {
*
* @return true if Object is a StereotypeProperty Label
*/
- public static boolean isStereotypeProperty(Object element) {
+ public boolean isStereotypeProperty(Object element) {
boolean stereotypeProperty = Boolean.FALSE;
if (element instanceof DecorationNode) {
stereotypeProperty = StereotypeDisplayUtils.STEREOTYPE_PROPERTY_TYPE.equals(((DecorationNode) element).getType());
@@ -341,17 +419,35 @@ public abstract class StereotypeDisplayHelper {
}
/**
+ * Defines if the Object is a StereotypeComment
+ *
+ * @param element
+ * The object on which the test is done
+ *
+ * @return true if Object is a StereotypeProperty Label
+ */
+ public boolean isStereotypeComment(Object element) {
+ boolean stereotypeComment = Boolean.FALSE;
+ if (element instanceof Shape) {
+ stereotypeComment = StereotypeDisplayUtils.STEREOTYPE_COMMENT_TYPE.equals(((Shape) element).getType());
+ }
+ return stereotypeComment;
+ }
+
+
+
+ /**
* Get the name of the Stereotype Label (it should be the Qualified Name of the related Stereotype )
*
* @param label
* The DecorationNode of type StereotypeLabel of which the name is retrieved
* @return The name of the Label
*/
- public static String getName(DecorationNode label) {
- String name = EMPTY_SPACE;
+ public String getName(DecorationNode label) {
+ String name = EMPTY_STRING;
if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
// Retrieve Name from CSS or NamedStyle from the Notation model.
- name = NotationUtils.getStringValue(label, StereotypeDisplayUtils.STEREOTYPE_LABEL_NAME, EMPTY_SPACE);
+ name = NotationUtils.getStringValue(label, StereotypeDisplayUtils.STEREOTYPE_LABEL_NAME, EMPTY_STRING);
}
return name;
}
@@ -363,11 +459,11 @@ public abstract class StereotypeDisplayHelper {
* The BasicCompartment of the Applied Stereotype
* @return The name of the Compartment containing the Stereotype properties
*/
- public static String getName(BasicCompartment compartment) {
- String name = EMPTY_SPACE;
+ public String getName(BasicCompartment compartment) {
+ String name = EMPTY_STRING;
if (StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_TYPE.equals(compartment.getType())) {
// Retrieve Name from CSS or NamedStyle from the Notation model.
- name = NotationUtils.getStringValue(compartment, StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_NAME, EMPTY_SPACE);
+ name = NotationUtils.getStringValue(compartment, StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_NAME, EMPTY_STRING);
}
return name;
}
@@ -380,8 +476,8 @@ public abstract class StereotypeDisplayHelper {
* StereotypeLabel Node
* @return the Depth as a String
*/
- public static String getDepth(DecorationNode label) {
- String depth = EMPTY_SPACE;
+ public String getDepth(DecorationNode label) {
+ String depth = EMPTY_STRING;
if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
// Retrieve Depth from CSS or NamedStyle from the Notation model.
depth = NotationUtils.getStringValue(label, StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH, StereotypeDisplayUtils.DEFAULT_DEPTH_VALUE);
@@ -400,7 +496,7 @@ public abstract class StereotypeDisplayHelper {
* The stereotype Application of the Label on which the test is done.
* @return True is the Node contains already a Label for the stereotype Application
*/
- public static boolean isLabelExist(View node, EObject stereotypeApplication) {
+ public boolean isLabelExist(View node, EObject stereotypeApplication) {
boolean exist = false;
Iterator<?> iter = node.getChildren().iterator();
@@ -427,7 +523,7 @@ public abstract class StereotypeDisplayHelper {
* The stereotype Application of the Label on which the test is done.
* @return True is the Node contains already a Label for the stereotype Application
*/
- public static boolean isCompartmentExist(View node, EObject stereotypeApplication) {
+ public boolean isCompartmentExist(View node, EObject stereotypeApplication) {
boolean exist = false;
Iterator<?> iter = node.getChildren().iterator();
while (!exist && iter.hasNext()) {
@@ -445,6 +541,33 @@ public abstract class StereotypeDisplayHelper {
}
/**
+ * Defines if the corresponding property is present into the node
+ *
+ * @param node
+ * The Compartment of the
+ * @param stereotypeApplication
+ * @return
+ */
+ public boolean isPropertyExist(BasicCompartment compartment, Property propertyUML) {
+ boolean exist = false;
+ Iterator<?> iter = compartment.getChildren().iterator();
+ while (!exist && iter.hasNext()) {
+ Object obj = iter.next();
+ if (obj instanceof DecorationNode) {
+
+ DecorationNode property = (DecorationNode) obj;
+
+ if (StereotypeDisplayUtils.STEREOTYPE_PROPERTY_TYPE.equals(property.getType())) {
+ exist = property.getElement().equals(propertyUML);
+ }
+ }
+ }
+ return exist;
+
+ }
+
+
+ /**
* Set the visibility of a view
*
* @param view
@@ -452,7 +575,7 @@ public abstract class StereotypeDisplayHelper {
* @param isVisible
* True to make the Compartment visible
*/
- public static void setVisibility(final GraphicalEditPart editPart, final View view, final boolean isVisible) {
+ public void setVisibility(final GraphicalEditPart editPart, final View view, final boolean isVisible) {
try {
editPart.getEditingDomain().runExclusive(new Runnable() {
@@ -483,11 +606,11 @@ public abstract class StereotypeDisplayHelper {
* The UML Property required to retrieve the value
* @return The property text to be displayed with the property name and its value (i.e.: "allocatedFrom=[]")
*/
- public static String getStereotypePropertyToDisplay(View view, Property property, StereotypeLocationEnum location) {
- String propertyAndValue = EMPTY_SPACE;
+ public String getStereotypePropertyToDisplay(View view, Property property, StereotypeLocationEnum location) {
+ String propertyAndValue = EMPTY_STRING;
if (view instanceof DecorationNode) {
DecorationNode node = ((DecorationNode) view);
- if (node.getType().equals(StereotypeDisplayUtils.STEREOTYPE_PROPERTY_TYPE)) {
+ if (isStereotypeProperty(node)) {
final EObject stereotypeApplication = ((View) node.eContainer()).getElement();
final Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
final Element umlElement = UMLUtil.getBaseElement(stereotypeApplication);
@@ -495,7 +618,7 @@ public abstract class StereotypeDisplayHelper {
if (isDisplayedAtLocation(node, location)) {
if (stereotype != null && property != null && umlElement != null) {
- propertyAndValue = StereotypeUtil.displayPropertyValue(stereotype, property, umlElement, EMPTY_SPACE);
+ propertyAndValue = StereotypeUtil.displayPropertyValue(stereotype, property, umlElement, EMPTY_STRING);
}
}
@@ -514,18 +637,21 @@ public abstract class StereotypeDisplayHelper {
* The Location on which the test is done
* @return True if the property node should be displayed at the location.
*/
- public static boolean isDisplayedAtLocation(Node node, StereotypeLocationEnum location) {
+ public boolean isDisplayedAtLocation(Node node, StereotypeLocationEnum location) {
boolean visibility = true;
switch (location) {
case IN_BRACE:
- visibility = isDisplayInBrace(node) && node.isVisible();
+ visibility = isDisplayInBrace(node) && node.isVisible() && ((Node) node.eContainer()).isVisible();
break;
case IN_COMPARTMENT:
- visibility = isDisplayInCompartment(node) && node.isVisible();
+ visibility = isDisplayInCompartment(node) && node.isVisible() && ((Node) node.eContainer()).isVisible();
+ break;
+ case IN_COMMENT_BRACE:
+ visibility = isDisplayInCommentBrace(node) && node.isVisible() && ((Node) node.eContainer()).isVisible();
break;
- case IN_COMMENT:
- visibility = isDisplayInComment(node) && node.isVisible();
+ case IN_COMMENT_COMPARTMENT:
+ visibility = isDisplayInCommentCompartment(node) && node.isVisible() && ((Node) node.eContainer()).isVisible();
break;
default:
break;
@@ -536,17 +662,37 @@ public abstract class StereotypeDisplayHelper {
}
/**
+ * Tests if the Property node should be displayed in the compartment of the Comment .
+ *
+ * @param node
+ * The property Node or the Compartment Node
+ * @return true if it should be displayed in The Compartment Comment
+ */
+ protected boolean isDisplayInCommentCompartment(Node node) {
+ boolean display = false;
+ if (isStereotypeProperty(node)) {
+ display = NotationUtils.getBooleanValue(node, StereotypeDisplayUtils.STEREOTYPE_PROPERTY_LOCATION_COMMENT, StereotypeDisplayUtils.DEFAULT_STEREOTYPE_PROPERTY_DISPLAY_COMMENT);
+ } else {
+ Activator.log.warn("The node " + node + " is not a StereotypeProperty node 1 ");
+ }
+ return display;
+ }
+
+ /**
* Tests if the Property node should be displayed in Comment.
*
* @param property
* The property Node
* @return the NamedStyle Value of the property "inBrace" that define if the node should be displayed into braces
*/
- private static boolean isDisplayInComment(Node property) {
+ protected boolean isDisplayInCommentBrace(Node node) {
boolean display = false;
- if (StereotypeDisplayUtils.STEREOTYPE_PROPERTY_TYPE.equals(property.getType())) {
- display = NotationUtils.getBooleanValue(property, StereotypeDisplayUtils.STEREOTYPE_PROPERTY_LOCATION_COMMENT, false);
+ if (isStereotypeProperty(node)) {
+ display = NotationUtils.getBooleanValue(node, StereotypeDisplayUtils.STEREOTYPE_PROPERTY_LOCATION_COMMENT_BRACE, StereotypeDisplayUtils.DEFAULT_STEREOTYPE_PROPERTY_DISPLAY_COMMENT_BRACE);
+ } else {
+ Activator.log.warn("The node " + node + " is not a StereotypeProperty node 2 ");
}
+
return display;
}
@@ -558,10 +704,12 @@ public abstract class StereotypeDisplayHelper {
* The property Node
* @return the NamedStyle Value of the property "inBrace" that define if the node should be displayed into braces
*/
- private static boolean isDisplayInCompartment(Node property) {
+ protected boolean isDisplayInCompartment(Node node) {
boolean display = false;
- if (StereotypeDisplayUtils.STEREOTYPE_PROPERTY_TYPE.equals(property.getType())) {
- display = NotationUtils.getBooleanValue(property, StereotypeDisplayUtils.STEREOTYPE_PROPERTY_LOCATION_COMPARTMENT, true);
+ if (isStereotypeProperty(node)) {
+ display = NotationUtils.getBooleanValue(node, StereotypeDisplayUtils.STEREOTYPE_PROPERTY_LOCATION_COMPARTMENT, StereotypeDisplayUtils.DEFAULT_STEREOTYPE_PROPERTY_DISPLAY_COMPARTMENT);
+ } else {
+ Activator.log.warn("The node " + node + " is not a StereotypeProperty node 3");
}
return display;
}
@@ -573,39 +721,40 @@ public abstract class StereotypeDisplayHelper {
* The property Node
* @return the NamedStyle Value of the property "inBrace" that define if the node should be displayed into braces
*/
- private static boolean isDisplayInBrace(Node property) {
+ protected boolean isDisplayInBrace(Node node) {
boolean display = false;
- if (StereotypeDisplayUtils.STEREOTYPE_PROPERTY_TYPE.equals(property.getType())) {
- display = NotationUtils.getBooleanValue(property, StereotypeDisplayUtils.STEREOTYPE_PROPERTY_LOCATION_BRACE, true);
+ if (isStereotypeProperty(node)) {
+ display = NotationUtils.getBooleanValue(node, StereotypeDisplayUtils.STEREOTYPE_PROPERTY_LOCATION_BRACE, StereotypeDisplayUtils.DEFAULT_STEREOTYPE_PROPERTY_DISPLAY_BRACE);
+ } else {
+ Activator.log.warn("The node " + node + " is not a StereotypeProperty node 4");
}
return display;
}
/**
- * Get the entire String to display between braces.
+ * Tests if the node is contained into a Stereotype Comment.
*
- * @param notationView
- * The View of the Element on which the Stereotype has been applied.
- *
- * @return The entire string to be displayed in braces
+ * @param node
+ * The Node tested
+ * @return True if the Node is contained into a Stereotype Comment
+ * False by default
*/
- public static String getStereotypePropertiesInBrace(View notationView) {
- String textToDisplay = null;
- Iterator<?> iter = notationView.getChildren().iterator();
- Object object;
- // For each Stereotype Compartment, retrieve the property text to be added in Braces
- while (iter.hasNext()) {
- object = iter.next();
- if (isStereotypeCompartment(object)) {
- BasicCompartment compartment = (BasicCompartment) object;
- if (compartment.isVisible()) {
- textToDisplay = addStereotypeCompartmentProperties(textToDisplay, compartment);
- }
+ public boolean isInStereotypeComment(Node node) {
+ boolean isComment = false;
+ Object container = node.eContainer();
+ if (container != null) {
+ if (isStereotypeCompartment(node) || isStereotypeLabel(node)) {
+ isComment = isStereotypeComment(node.eContainer());
+
+ } else if (isStereotypeProperty(node)) {
+ isComment = isStereotypeComment(node.eContainer().eContainer());
}
}
- return textToDisplay;
+
+ return isComment;
}
+
/**
* Adds properties and value to the existing text.
*
@@ -613,14 +762,16 @@ public abstract class StereotypeDisplayHelper {
* Initial Text (ie: "")
* @param compartment
* Compartment containing the Properties to be added (i.e: Allocation property Compartment )
+ * @param inComment
*
* @return the String with the new Properties and their values concatenated. (i.e: "allocatedFrom=[], allocatedTo[]")
*/
- protected static String addStereotypeCompartmentProperties(String textToDisplay, BasicCompartment compartment) {
+ protected String addStereotypeCompartmentProperties(String textToDisplay, BasicCompartment compartment) {
+
- String newTextToDisplay = (textToDisplay == null ? EMPTY_SPACE : textToDisplay);
+ StringBuilder newTextToDisplay = new StringBuilder(textToDisplay == null ? "" : textToDisplay);
- String propertiesText = EMPTY_SPACE;
+ StringBuilder propertiesText = new StringBuilder(EMPTY_STRING);
EList<?> properties = compartment.getChildren();
// For the compartment, concatenate all the properties Text (property name and values) that should be displayed in Braces
for (Object property : properties) {
@@ -628,66 +779,129 @@ public abstract class StereotypeDisplayHelper {
DecorationNode propertyNode = (DecorationNode) property;
Property propertyElement = (Property) propertyNode.getElement();
// get the properties and values text (i.e: "allocatedFrom=[]")
- String propAndValueText = getStereotypePropertyToDisplay(propertyNode, propertyElement, StereotypeLocationEnum.IN_BRACE);
+ StereotypeLocationEnum location;
+ if (isInStereotypeComment(compartment)) {
+ location = StereotypeLocationEnum.IN_COMMENT_BRACE;
+ } else {
+ location = StereotypeLocationEnum.IN_BRACE;
+ }
+ String propAndValueText = getStereotypePropertyToDisplay(propertyNode, propertyElement, location);
+
// add it to the String (i.e: "allocatedTo=[], allocatedFrom=[]")
propertiesText = addTextWithSeparator(propertiesText, propAndValueText, StereotypeDisplayUtils.STEREOTYPE_LABEL_SEPARATOR);
+
}
}
// And concatenate it to the existing text.(i.e: "isEncapsulated=false, allocatedTo=[], allocatedFrom=[]" )
- newTextToDisplay = addTextWithSeparator(newTextToDisplay, propertiesText, StereotypeDisplayUtils.STEREOTYPE_LABEL_SEPARATOR);
- return newTextToDisplay;
+ newTextToDisplay = addTextWithSeparator(newTextToDisplay, propertiesText.toString(), StereotypeDisplayUtils.STEREOTYPE_LABEL_SEPARATOR);
+
+ String finalText = newTextToDisplay.toString();
+ return finalText;
}
/**
* Concatenates Text to another text with a separator.
*
- * @param intialText
- * The Initial Text String
* @param textToAdd
* The fragment to add
* @param separator
* The separator String (i.e: ", " or "; " or " ")
+ *
* @return The new text with separator and no empty space
*/
- private static String addTextWithSeparator(String intialText, String textToAdd, String separator) {
- String result = (intialText == null ? EMPTY_SPACE : intialText);
+ protected StringBuilder addTextWithSeparator(final StringBuilder initialText, final String textToAdd, final String separator) {
+
+ StringBuilder result = new StringBuilder(initialText == null ? "" : initialText);
// if result and text to add is not empty, then add a separator
- if ((!EMPTY_SPACE.equals(textToAdd) && (textToAdd != null))) {
- if (!EMPTY_SPACE.equals(result) && (result != null)) {
- result = (result + separator);
+ if ((!EMPTY_STRING.equals(textToAdd) && (textToAdd != null))) {
+ if ((result != null) && (!result.toString().equals(EMPTY_STRING))) {
+ result.append(separator);
}
- result = result + textToAdd;
+ result.append(textToAdd);
}
return result;
}
+
+
+ /**
+ * Defines if the Comment has Property to display in brace
+ *
+ * @param comment
+ * the Comment Node
+ * @return true if the Brace text is not empty.
+ */
+ protected boolean hasBraceLabel(Node comment) {
+ boolean hasBrace = false;
+ String braceTextInComment = getStereotypePropertiesInBrace(comment);
+
+ if (braceTextInComment != null) {
+ hasBrace = !braceTextInComment.isEmpty();
+ }
+
+ return hasBrace;
+ }
+
+ /**
+ * Defines if the Node has at least one Stereotype Compartment as Child
+ *
+ * @param node
+ * The node on which we do the test
+ * @return true if at least one Stereotype Compartment
+ */
+ public boolean hasStereotypeCompartment(Node node) {
+ Object obj;
+ Iterator<?> iter = node.getChildren().iterator();
+ boolean compartmentExist = false;
+ while (iter.hasNext() && !compartmentExist) {
+ obj = iter.next();
+ compartmentExist = isStereotypeCompartment(obj);
+
+ }
+ return compartmentExist;
+ }
+
+
+
+ /**
+ * Defines if a Stereotype Comment Node has at least a brace or a compartment
+ *
+ * @param comment
+ * The Stereotype Comment Node on which the test is done
+ * @return true if the comment has no compartment and no braceLabel, false by default
+ */
+ public boolean isCommentEmpty(Node comment) {
+ boolean empty = false;
+ empty = (!hasStereotypeCompartment(comment)) && (!hasBraceLabel(comment));
+ return empty;
+ }
+
/**
- * Test if Compartment is no property to be displayed
+ * Define if a Node is empty or not. If at least one property should be displayed, the node is not empty for this location.
*
* @param compartment
- * @return True if none of the Property should be displayed
- */
- public static boolean isCompartmentEmpty(BasicCompartment compartment) {
- int count = 0;
- if (isStereotypeCompartment(compartment)) {
- Iterator<?> iter = compartment.getChildren().iterator();
- Object child;
- while (iter.hasNext() && count == 0) {
- child = iter.next();
- if (isStereotypeProperty(child)) {
- if (isDisplayedAtLocation((DecorationNode) child, StereotypeLocationEnum.IN_COMPARTMENT)) {
- count++;
+ * The main StereotypeCompartment that contains that property Nodes (not the Comment StereotypeCompartment)
+ * @param location
+ * Location for which the test is done.
+ * @return true by default, false if at least one property node is displayed.
+ */
+ public boolean isEmpty(Node compartment, StereotypeLocationEnum location) {
+ boolean empty = true;
+ if (compartment != null) {
+ for (Object property : compartment.getChildren()) {
+ if (isStereotypeProperty(property)) {
+ if (isDisplayedAtLocation((Node) property, location)) {
+ empty &= false;
}
}
}
- return (count == 0);
- } else {
- Activator.log.warn("Compartment passed is not a Stereotype Compartment");
}
- return false;
+ return empty;
}
+
+
}
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 be1b60f3625..134b9eacd01 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
@@ -14,44 +14,65 @@
package org.eclipse.papyrus.uml.diagram.common.stereotype;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+
/**
* This Class regroups the Constants required for the Stereotype Display
*
- * @author Céline JANSSENS
+ * @author Celine JANSSENS
*
*/
public class StereotypeDisplayUtils {
+ // Depth Separator of the Stereotype Name
public static final String STEREOTYPE_LABEL_DEPTH_SEPARATOR = "::";//$NON-NLS-1$
+ // Name of Style for Comment Node to point to related main Object
+ public static final String STEREOTYPE_COMMENT_RELATION_NAME = "BASE_ELEMENT";//$NON-NLS-1$
+
+ // Name Style of Name, Type and Depth for Stereotype Display
public static final String STEREOTYPE_LABEL_TYPE = "StereotypeLabel"; //$NON-NLS-1$
public static final String STEREOTYPE_PROPERTY_TYPE = "StereotypeProperty";//$NON-NLS-1$
public static final String STEREOTYPE_COMPARTMENT_TYPE = "StereotypeCompartment";//$NON-NLS-1$
+ public static final String STEREOTYPE_COMMENT_TYPE = "StereotypeComment";//$NON-NLS-1$
+ public static final String STEREOTYPE_COMMENT_LINK_TYPE = "StereotypeCommentLink";
public static final String STEREOTYPE_LABEL_NAME = "stereotype";//$NON-NLS-1$
public static final String STEREOTYPE_COMPARTMENT_NAME = "stereotype";//$NON-NLS-1$
public static final String STEREOTYPE_PROPERTY_NAME = "property";//$NON-NLS-1$
public static final String STEREOTYPE_LABEL_DEPTH = "depth";//$NON-NLS-1$
- public static final String DEFAULT_DEPTH_VALUE = "full";//$NON-NLS-1$
+
+ // Visibility Constants
public static final String STEREOTYPE_LABEL_VSISIBLE = "visible";//$NON-NLS-1$
public static final Boolean DEFAULT_VISIBILITY_VALUE = Boolean.TRUE;//$NON-NLS-1$
public static final Boolean DEFAULT_PROPERTY_VISIBILITY_VALUE = Boolean.TRUE;//$NON-NLS-1$
+ // Depth Constants
public static final String DEPTH_MAX = "full";//$NON-NLS-1$
public static final String DEPTH_MIN = "none";//$NON-NLS-1$
public static final String DEPTH_AUTO = "auto";//$NON-NLS-1$
+ public static final String DEFAULT_DEPTH_VALUE = "full";//$NON-NLS-1$
- public static final String DEFAULT_STEREOTYPE_PROPERTY_LOCATION = "compartment";//$NON-NLS-1$
+ // Property Constants
public static final String STEREOTYPE_PROPERTY_LOCATION_BRACE = "inBrace";//$NON-NLS-1$
public static final String STEREOTYPE_PROPERTY_LOCATION_COMPARTMENT = "inCompartment";//$NON-NLS-1$
- public static final String STEREOTYPE_PROPERTY_LOCATION_COMMENT = "inComment";//$NON-NLS-1$
+ public static final String STEREOTYPE_PROPERTY_LOCATION_COMMENT_BRACE = "inCommentBrace";//$NON-NLS-1$
+ public static final String STEREOTYPE_PROPERTY_LOCATION_COMMENT = "inCommentCompartment";//$NON-NLS-1$
+
+ // Default Display Location
+ public static final boolean DEFAULT_STEREOTYPE_PROPERTY_DISPLAY_BRACE = true;//$NON-NLS-1$
+ public static final boolean DEFAULT_STEREOTYPE_PROPERTY_DISPLAY_COMPARTMENT = true;//$NON-NLS-1$
+ public static final boolean DEFAULT_STEREOTYPE_PROPERTY_DISPLAY_COMMENT_BRACE = true;//$NON-NLS-1$
+ public static final boolean DEFAULT_STEREOTYPE_PROPERTY_DISPLAY_COMMENT = true;//$NON-NLS-1$
+ // Special Char Constants
public final static String STEREOTYPE_LABEL_SEPARATOR = ", ";//$NON-NLS-1$
public static final String STEREOTYPE_PROPERTY_SEPARATOR = "\n";//$NON-NLS-1$
public static final String STEREOTYPE_PROPERTY_VALUE_SEPARATOR = " = ";//$NON-NLS-1$
- // TODO To be changed with the French brackets
- // In order to distinguish the NamedStyle Label from the EAnnotation
- public final static String BRACE_LEFT = "<== "; // String.valueOf("\u00AB");
- public final static String BRACE_RIGHT = " ==>"; // String.valueOf("\u00AA");
+ // Ornament Constants
+ public final static String BRACE_LEFT = Activator.ST_LEFT;
+ public final static String BRACE_RIGHT = Activator.ST_RIGHT;
+
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeLocationEnum.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeLocationEnum.java
index 47fa1fad9bf..31275816342 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeLocationEnum.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeLocationEnum.java
@@ -7,7 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * CEA LIST - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 460356 : Refactor Stereotype Display
*
*****************************************************************************/
@@ -15,17 +16,31 @@ package org.eclipse.papyrus.uml.diagram.common.stereotype;
/**
+ * This enumeration is used to list the existing possible locations of a Stereotype property to be displayed
+ *
* @author Céline JANSSENS
*
*/
public enum StereotypeLocationEnum {
-
+ /**
+ * Defines the Brace Label on top of the figure that contains the list of Stereotype Properties
+ */
IN_BRACE,
+ /**
+ * Defines the Compartment into the figure dedicated to the Stereotype Properties
+ */
IN_COMPARTMENT,
- IN_COMMENT
+ /**
+ * Defines the Brace Label into a separate Comment Figure that contains the list of Stereotype Properties
+ */
+ IN_COMMENT_BRACE,
+ /**
+ * Defines the Compartment into a separate Comment Figure dedicated to the Stereotype Properties
+ */
+ IN_COMMENT_COMPARTMENT
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.css/src/org/eclipse/papyrus/uml/diagram/css/dom/GMFUMLElementAdapter.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.css/src/org/eclipse/papyrus/uml/diagram/css/dom/GMFUMLElementAdapter.java
index e3f90044eb0..724a8fe7f4c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.css/src/org/eclipse/papyrus/uml/diagram/css/dom/GMFUMLElementAdapter.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.css/src/org/eclipse/papyrus/uml/diagram/css/dom/GMFUMLElementAdapter.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 : Refactor Stereotypes Display
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.css.dom;
@@ -40,6 +41,7 @@ import org.eclipse.uml2.uml.Stereotype;
*/
public class GMFUMLElementAdapter extends GMFElementAdapter {
+ public final StereotypeDisplayHelper helper = StereotypeDisplayHelper.getInstance();
public static final String APPLIED_STEREOTYPES_PROPERTY = "appliedStereotypes"; //$NON-NLS-1$
/**
@@ -61,13 +63,16 @@ public class GMFUMLElementAdapter extends GMFElementAdapter {
*/
@Override
protected String doGetAttribute(String attr) {
+
String parentValue = super.doGetAttribute(attr);
+
if (parentValue != null) {
return parentValue;
}
+
// get stereotype Label attribute
- if (StereotypeDisplayHelper.isStereotypeLabel(semanticElement)) {
+ if (helper.isStereotypeLabel(semanticElement)) {
String value = getStereotypeLabelAttribute(attr);
if (value != null && !value.isEmpty()) {
return value;
@@ -75,15 +80,16 @@ public class GMFUMLElementAdapter extends GMFElementAdapter {
}
// get stereotype Compartment attribute
- if (StereotypeDisplayHelper.isStereotypeCompartment(semanticElement)) {
+ if (helper.isStereotypeCompartment(semanticElement)) {
String value = getStereotypeCompartmentAttribute(attr);
if (value != null && !value.isEmpty()) {
return value;
}
}
+
// get stereotype Property attribute
- if (StereotypeDisplayHelper.isStereotypeProperty(semanticElement)) {
+ if (helper.isStereotypeProperty(semanticElement)) {
String value = getStereotypePropertyAttribute(attr);
if (value != null && !value.isEmpty()) {
@@ -91,7 +97,6 @@ public class GMFUMLElementAdapter extends GMFElementAdapter {
}
}
-
if (semanticElement instanceof Element) {
// Applied stereotypes
@@ -125,6 +130,7 @@ public class GMFUMLElementAdapter extends GMFElementAdapter {
}
}
}
+
if (attr.contains(QUALIFIER_SEPARATOR)) {
List<String> qualifiers = ListHelper.asList(attr.split(QUALIFIER_SEPARATOR)); // Writable list
String propertyName = qualifiers.remove(qualifiers.size() - 1); // Last element is the property name
@@ -144,6 +150,7 @@ public class GMFUMLElementAdapter extends GMFElementAdapter {
return null;
}
+
/**
* Retrieve the Matching String Value for the StereotypeCompartment Element
*
@@ -155,7 +162,7 @@ public class GMFUMLElementAdapter extends GMFElementAdapter {
if (StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_NAME.equals(attr)) {
BasicCompartment propertyCompartment = (BasicCompartment) semanticElement;
- return StereotypeDisplayHelper.getName(propertyCompartment);
+ return helper.getName(propertyCompartment);
}
return "";
@@ -169,6 +176,7 @@ public class GMFUMLElementAdapter extends GMFElementAdapter {
* @return The matching value for this Attribute
*/
protected String getStereotypePropertyAttribute(String attr) {
+ // CSS can match property level
if (StereotypeDisplayUtils.STEREOTYPE_PROPERTY_NAME.equals(attr)) {
DecorationNode propertyLabel = (DecorationNode) semanticElement;
@@ -177,6 +185,14 @@ public class GMFUMLElementAdapter extends GMFElementAdapter {
String propLabel = prop.getName();
return propLabel;
}
+ // CSS can match Container Name
+ } else if (StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_NAME.equals(attr)) {
+
+ EObject propertyCompartment = ((DecorationNode) semanticElement).eContainer();
+ if (helper.isStereotypeCompartment(propertyCompartment)) {
+
+ return helper.getName((DecorationNode) propertyCompartment);
+ }
}
return "";
@@ -195,7 +211,7 @@ public class GMFUMLElementAdapter extends GMFElementAdapter {
if (StereotypeDisplayUtils.STEREOTYPE_LABEL_NAME.equals(attr)) {
DecorationNode label = (DecorationNode) semanticElement;
- String stereoName = StereotypeDisplayHelper.getName(label);
+ String stereoName = helper.getName(label);
return stereoName;
}
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 ce51e443bd2..aff6bdcc834 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
@@ -15,14 +15,12 @@
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
import java.util.ArrayList;
-import java.util.Iterator;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart;
import org.eclipse.gmf.runtime.notation.BasicCompartment;
@@ -45,9 +43,10 @@ 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.CreateAppliedStereotypeCommentViewCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CustomDurationConstraintEditPart;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.command.CreateAppliedStereotypeCommentViewCommand;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypesCommentEditPart;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypeCommentEditPart;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypesCommentLinkEditPart;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCommentCreationEditPolicy;
import org.eclipse.swt.widgets.Display;
@@ -98,13 +97,13 @@ public class AppliedStereotypeCommentCreationEditPolicyEx extends AppliedStereot
ts.setShowTitle(true);
node.getStyles().add(ts);
node.setElement(null);
- node.setType(AppliedStereotypesCommentEditPart.ID);
+ node.setType(AppliedStereotypeCommentEditPart.ID);
connectCommentNode(owner, node);
EObjectValueStyle eObjectValueStyle = (EObjectValueStyle) node.createStyle(NotationPackage.eINSTANCE.getEObjectValueStyle());
eObjectValueStyle.setEObjectValue(base_element);
- eObjectValueStyle.setName("BASE_ELEMENT");
+ eObjectValueStyle.setName(StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME);
// create the link
Connector edge = NotationFactory.eINSTANCE.createConnector();
@@ -131,7 +130,7 @@ public class AppliedStereotypeCommentCreationEditPolicyEx extends AppliedStereot
edge.setElement(null);
eObjectValueStyle = (EObjectValueStyle) edge.createStyle(NotationPackage.eINSTANCE.getEObjectValueStyle());
eObjectValueStyle.setEObjectValue(base_element);
- eObjectValueStyle.setName("BASE_ELEMENT");
+ eObjectValueStyle.setName(StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME);
// copy EAnnotation
final EAnnotation stereotypeAnnotation = owner.getEAnnotation(UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION);
@@ -155,35 +154,7 @@ public class AppliedStereotypeCommentCreationEditPolicyEx extends AppliedStereot
*/
private void connectCommentNode(View owner, Node commentNode) {
- // in the case of the edge the comment has to be placed into the common parent of each end
- // if(owner instanceof Edge) {
- // View viewSource = ((Edge)owner).getSource();
- // View viewTarget = ((Edge)owner).getSource();
- // //list of source parents
- // ArrayList<View> parentsSource = getParentTree(viewSource);
- // //list of source targets
- // ArrayList<View> parentsTarget = getParentTree(viewTarget);
- // View commonParent = null;
- // int index = 0;
- // //find the common
- // while(commonParent == null && index < parentsSource.size()) {
- // if(parentsTarget.contains(parentsSource.get(index))) {
- // commonParent = parentsSource.get(index);
- // if(!(commonParent instanceof BasicCompartment)) {
- // commonParent = null;
- // }
- // }
- // index++;
- // }
- // // a common has been found
- // if(commonParent != null) {
- // ((Bounds)commentNode.getLayoutConstraint()).setX(100);
- // ((Bounds)commentNode.getLayoutConstraint()).setY(100);
- // ViewUtil.insertChildView(commonParent, commentNode, ViewUtil.APPEND, true);
- // return;
- // }
- // }
- // generic case
+
View econtainer = (View) owner.eContainer();
if (owner instanceof Edge) {
econtainer = (View) ((Edge) owner).getSource().eContainer();
@@ -233,25 +204,29 @@ public class AppliedStereotypeCommentCreationEditPolicyEx extends AppliedStereot
}
}
+
+
@Override
- protected void executeAppliedStereotypeCommentCreation(final EditPart editPart, final TransactionalEditingDomain domain, final EObject semanticElement) {
+ protected void executeAppliedStereotypeCommentCreation(final EObject semanticElement) {
+
+ final TransactionalEditingDomain domain = hostEditPart.getEditingDomain();
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
int x = 200;
int y = 100;
- if (editPart.getModel() instanceof Node) {
- LayoutConstraint constraint = ((Node) editPart.getModel()).getLayoutConstraint();
+ if (hostEditPart.getModel() instanceof Node) {
+ LayoutConstraint constraint = ((Node) hostEditPart.getModel()).getLayoutConstraint();
if (constraint instanceof Bounds) {
x = x + ((Bounds) constraint).getX();
y = ((Bounds) constraint).getY();
}
}
- if (editPart.getModel() instanceof Edge && ((((Edge) editPart.getModel()).getSource()) instanceof Node)) {
+ if (hostEditPart.getModel() instanceof Edge && ((((Edge) hostEditPart.getModel()).getSource()) instanceof Node)) {
- LayoutConstraint constraint = ((Node) ((Edge) editPart.getModel()).getSource()).getLayoutConstraint();
+ LayoutConstraint constraint = ((Node) ((Edge) hostEditPart.getModel()).getSource()).getLayoutConstraint();
if (constraint instanceof Bounds) {
x = x + ((Bounds) constraint).getX();
y = ((Bounds) constraint).getY() - 100;
@@ -259,13 +234,13 @@ public class AppliedStereotypeCommentCreationEditPolicyEx extends AppliedStereot
}
boolean isBorderElement = false;
- if (!(editPart instanceof CustomDurationConstraintEditPart)) {
- if (editPart instanceof BorderedBorderItemEditPart) {
+ if (!(hostEditPart instanceof CustomDurationConstraintEditPart)) {
+ if (hostEditPart instanceof BorderedBorderItemEditPart) {
isBorderElement = true;
}
}
- if (getAppliedStereotypeCommentNode() == null) {
- CreateAppliedStereotypeCommentViewCommandEx command = new CreateAppliedStereotypeCommentViewCommandEx(domain, (View) editPart.getModel(), x, y, semanticElement, isBorderElement);
+ if (helper.getStereotypeComment((View) getHost().getModel()) == null) {
+ CreateAppliedStereotypeCommentViewCommandEx command = new CreateAppliedStereotypeCommentViewCommandEx(domain, (View) hostEditPart.getModel(), x, y, semanticElement, isBorderElement);
// use to avoid to put it in the command stack
try {
GMFUnsafe.write(domain, command);
@@ -278,35 +253,4 @@ public class AppliedStereotypeCommentCreationEditPolicyEx extends AppliedStereot
});
}
- @Override
- protected Node getAppliedStereotypeCommentNode() {
- Node node = super.getAppliedStereotypeCommentNode();
- if (node != null) {
- return node;
- }
- View view = (View) getHost().getModel();
- View semanticView = view;
- while (semanticView != null && !(semanticView instanceof Shape || semanticView instanceof Edge)) {
- semanticView = (View) semanticView.eContainer();
- }
- if (semanticView == null) {
- return null;
- }
- Edge appliedStereotypeLink = null;
- // look for all links with the id AppliedStereotypesCommentLinkEditPart.ID
- @SuppressWarnings("unchecked")
- Iterator<Edge> edgeIterator = semanticView.getSourceEdges().iterator();
- while (edgeIterator.hasNext()) {
- Edge edge = edgeIterator.next();
- if (edge.getType().equals(AppliedStereotypesCommentLinkEditPart.ID)) {
- appliedStereotypeLink = edge;
- }
-
- }
- if (appliedStereotypeLink == null) {
- return null;
- }
- return (Node) appliedStereotypeLink.getTarget();
-
- }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionCompartmentXYLayoutEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionCompartmentXYLayoutEditPolicy.java
index 442a930457d..93d8180351a 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionCompartmentXYLayoutEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionCompartmentXYLayoutEditPolicy.java
@@ -86,7 +86,7 @@ import org.eclipse.papyrus.uml.diagram.sequence.util.LifelineMessageCreateHelper
import org.eclipse.papyrus.uml.diagram.sequence.util.LifelineResizeHelper;
import org.eclipse.papyrus.uml.diagram.sequence.util.OperandBoundsComputeHelper;
import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceUtil;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypesCommentEditPart;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypeCommentEditPart;
import org.eclipse.uml2.uml.CombinedFragment;
import org.eclipse.uml2.uml.ExecutionSpecification;
import org.eclipse.uml2.uml.Interaction;
@@ -694,7 +694,7 @@ public class InteractionCompartmentXYLayoutEditPolicy extends XYLayoutEditPolicy
if(request instanceof ChangeBoundsRequest) {
List<?> editParts = ((ChangeBoundsRequest)request).getEditParts();
if(editParts.size() == 1) {
- if (editParts.get(0) instanceof AppliedStereotypesCommentEditPart) {
+ if (editParts.get(0) instanceof AppliedStereotypeCommentEditPart) {
// Allow to move-in AppliedStereotypeCommentEditPart
return super.getAddCommand(request);
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionFragmentsCreationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionFragmentsCreationEditPolicy.java
index 32cbca1b17a..9a252d7a85c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionFragmentsCreationEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionFragmentsCreationEditPolicy.java
@@ -21,7 +21,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.PapyrusCreationEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.util.FragmentsOrdererHelper;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypesCommentEditPart;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypeCommentEditPart;
/**
* Ordering fragments after creation.
@@ -57,7 +57,7 @@ public class InteractionFragmentsCreationEditPolicy extends PapyrusCreationEditP
*/
@Override
protected ICommand getReparentViewCommand(IGraphicalEditPart gep) {
- if (gep instanceof AppliedStereotypesCommentEditPart) {
+ if (gep instanceof AppliedStereotypeCommentEditPart) {
return UnexecutableCommand.INSTANCE;
}
return super.getReparentViewCommand(gep);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandAppliedStereotypeLabelDisplayEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandAppliedStereotypeLabelDisplayEditPolicy.java
index e337f44943f..668b75d3fc6 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandAppliedStereotypeLabelDisplayEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandAppliedStereotypeLabelDisplayEditPolicy.java
@@ -16,20 +16,19 @@ package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeNamedElementFigure;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure;
-import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CustomInteractionOperandEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandGuardEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandGuardEditPart.GuardFigure;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCompartmentEditPolicy;
import org.eclipse.swt.graphics.Image;
/**
* @author Jin Liu (jin.liu@soyatec.com)
*/
-public class InteractionOperandAppliedStereotypeLabelDisplayEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy {
+public class InteractionOperandAppliedStereotypeLabelDisplayEditPolicy extends AppliedStereotypeCompartmentEditPolicy {
@Override
protected void refreshStereotypeDisplay() {
@@ -43,7 +42,7 @@ public class InteractionOperandAppliedStereotypeLabelDisplayEditPolicy extends A
}
GuardFigure figure = ((InteractionOperandGuardEditPart) guard).getPrimaryFigure();
// calculate text and icon to display
- final String stereotypesToDisplay = StereotypeDisplayHelper.getStereotypeTextToDisplay((View) getHost().getModel());
+ final String stereotypesToDisplay = helper.getStereotypeTextToDisplay((View) getHost().getModel());
// computes the icon to be displayed
final Image imageToDisplay = stereotypeIconToDisplay();
@@ -54,7 +53,7 @@ public class InteractionOperandAppliedStereotypeLabelDisplayEditPolicy extends A
if (figure instanceof IPapyrusNodeUMLElementFigure) {
((IPapyrusNodeUMLElementFigure) figure).setStereotypeDisplay(tag + (stereotypesToDisplay == null ? "" : stereotypesToDisplay), imageToDisplay);
if (figure instanceof IPapyrusNodeNamedElementFigure) {
- refreshAppliedStereotypesProperties((IPapyrusNodeNamedElementFigure) figure);
+ refreshAppliedStereotypesPropertiesInBrace(figure);
}
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/LifelineAppliedStereotypeNodeLabelDisplayEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/LifelineAppliedStereotypeNodeLabelDisplayEditPolicy.java
index 9112bc1d41b..ca60bb99f83 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/LifelineAppliedStereotypeNodeLabelDisplayEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/LifelineAppliedStereotypeNodeLabelDisplayEditPolicy.java
@@ -13,8 +13,8 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
-import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CustomLifelineEditPart;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeLabelEditPolicy;
/**
* This policy is used to automatically move a lifeline when a stereotype is changed.
@@ -23,14 +23,14 @@ import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CustomLifelineEditPar
* @author mvelten
*
*/
-public class LifelineAppliedStereotypeNodeLabelDisplayEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy {
+public class LifelineAppliedStereotypeNodeLabelDisplayEditPolicy extends AppliedStereotypeLabelEditPolicy {
/**
* {@inheritDoc}
*/
@Override
- public void refreshDisplay() {
- super.refreshDisplay();
+ public void refreshStereotypeDisplay() {
+ super.refreshStereotypeDisplay();
if (getHost() instanceof CustomLifelineEditPart) {
((CustomLifelineEditPart) getHost()).updateLifelinePosition();
}
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 23e337b723b..1f463e97171 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,5 @@
Manifest-Version: 1.0
-Export-Package: org.eclipse.papyrus.uml.diagram.stereotype.edition.command,
- org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart,
+Export-Package: org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart,
org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies
Require-Bundle: org.eclipse.gmf.runtime.diagram.ui,
org.eclipse.papyrus.uml.diagram.common;bundle-version="1.1.0",
@@ -14,7 +13,8 @@ Require-Bundle: org.eclipse.gmf.runtime.diagram.ui,
org.eclipse.papyrus.infra.core.log;bundle-version="1.1.0",
org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.1.0",
org.eclipse.papyrus.extensionpoints.editors;bundle-version="1.1.0",
- org.eclipse.papyrus.uml.profile;bundle-version="1.1.0"
+ org.eclipse.papyrus.uml.profile;bundle-version="1.1.0",
+ org.eclipse.gmf.runtime.notation
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.1.0.qualifier
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/plugin.xml
index 5ff00a3067c..5331d355cfe 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/plugin.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/plugin.xml
@@ -20,7 +20,7 @@
<object
class="org.eclipse.gmf.runtime.notation.Node(org.eclipse.gmf.runtime.notation)"
id="StereotypePropertiesEditPartProvider">
- <method name="getType()" value="StereotypeCompartment,StereotypeProperty,AppliedStereotypesComment,AppliedStereotypesCommentLink"/>
+ <method name="getType()" value="StereotypeComment,StereotypeCompartment,StereotypeProperty,StereotypeCommentLink"/>
</object>
</editpartProvider>
</extension>
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypesCommentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeCommentEditPart.java
index f1e9df0a5fa..7fd701acc26 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypesCommentEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeCommentEditPart.java
@@ -41,9 +41,9 @@ import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedSt
*
*/
-public class AppliedStereotypesCommentEditPart extends NodeEditPart implements IGraphicalEditPart, IPrimaryEditPart {
+public class AppliedStereotypeCommentEditPart extends NodeEditPart implements IGraphicalEditPart, IPrimaryEditPart {
- public AppliedStereotypesCommentEditPart(View view) {
+ public AppliedStereotypeCommentEditPart(View view) {
super(view);
}
@@ -144,6 +144,8 @@ public class AppliedStereotypesCommentEditPart extends NodeEditPart implements I
return nodeShape; // use nodeShape itself as contentPane
}
+
+
/**
* @generated
*/
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeCompartmentEditPart.java
index 8fe929bba42..18c32c0cd37 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeCompartmentEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeCompartmentEditPart.java
@@ -9,6 +9,7 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 460356 : Refactor Stereotype Display
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart;
@@ -31,7 +32,7 @@ import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ResizeableListCompartmentEditPart;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.PasteEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.figure.node.AppliedStereotypeCompartmentFigure;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypePropertiesEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.util.UMLUtil;
@@ -43,6 +44,8 @@ public class AppliedStereotypeCompartmentEditPart extends ResizeableListCompartm
public static String ID = "AppliedStereotypeCompartment";
+ private static final String NO_STEREOTYPE_COMPARTMENT = "Bad compartement stereotype";
+
public AppliedStereotypeCompartmentEditPart(View view) {
super(view);
}
@@ -52,20 +55,30 @@ public class AppliedStereotypeCompartmentEditPart extends ResizeableListCompartm
return false;
}
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.editpart.ResizeableListCompartmentEditPart#refreshBounds()
+ *
+ */
+ @Override
+ protected void refreshBounds() {
+ // nothingToDo
+ }
+
@Override
public String getCompartmentName() {
- Stereotype stereotype = UMLUtil.getStereotype(this.resolveSemanticElement());
+ Stereotype stereotype = UMLUtil.getStereotype(resolveSemanticElement());
if (stereotype != null) {
- return "" + String.valueOf("\u00AB") + stereotype.getName() + String.valueOf("\u00BB");
+ return (StereotypeDisplayUtils.BRACE_LEFT + stereotype.getName() + StereotypeDisplayUtils.BRACE_RIGHT);
}
- return "bad compartement stereotype";
+ return NO_STEREOTYPE_COMPARTMENT;
}
+
/**
- * this method has bee rewritten in order to add its wn figure to ensure to mange it
- * in papyrus Figure.
+ * this method has be rewritten in order to add its own figure to ensure to manage it
+ * in Papyrus Figure.
*
* Adds a constrained flow layout algorithm to the content pane of compartment figure
*
@@ -74,14 +87,17 @@ public class AppliedStereotypeCompartmentEditPart extends ResizeableListCompartm
@Override
public IFigure createFigure() {
ResizableCompartmentFigure rcf;
- if (getParent() == getTopGraphicEditPart()) {
- // replace ResizableCompartmentFigure by it own figure in order to manage it.
+
+
+ // If the EditPart is the direct Children
+ if ((getParent() == getTopGraphicEditPart())) {
+ // replace ResizableCompartmentFigure by its own figure in order to manage it.
rcf = new AppliedStereotypeCompartmentFigure(getCompartmentName(), getMapMode());
} else {
rcf = new NestedResizableCompartmentFigure(getMapMode());
-
}
- if (this.getParent() instanceof AppliedStereotypesCommentEditPart) {
+
+ if (getParent() instanceof AppliedStereotypeCommentEditPart) {
rcf.setBorder(null);
if (rcf.getTextPane().getChildren().size() > 0 && rcf.getTextPane().getChildren().get(0) instanceof WrappingLabel) {
WrappingLabel label = (WrappingLabel) rcf.getTextPane().getChildren().get(0);
@@ -111,7 +127,6 @@ public class AppliedStereotypeCompartmentEditPart extends ResizeableListCompartm
installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
installEditPolicy(PasteEditPolicy.PASTE_ROLE, new PasteEditPolicy());
- installEditPolicy(AppliedStereotypePropertiesEditPolicy.APPLIED_STEREOTYPE_VISIBILITY_COMPARTMENT, new AppliedStereotypePropertiesEditPolicy());
}
@@ -147,10 +162,6 @@ public class AppliedStereotypeCompartmentEditPart extends ResizeableListCompartm
}
}
- @Override
- protected void refreshBounds() {
- }
-
/**
*
* @see org.eclipse.papyrus.infra.gmfdiag.common.editpart.ResizeableListCompartmentEditPart#refreshVisuals()
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeMultilinePropertyEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeMultilinePropertyEditPart.java
index 707baebf755..68d9c8c48dc 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeMultilinePropertyEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeMultilinePropertyEditPart.java
@@ -161,6 +161,7 @@ public class AppliedStereotypeMultilinePropertyEditPart extends CompartmentEditP
* set the text if not
*/
protected void setLabelTextHelper(IFigure figure, String text) {
+
if (figure instanceof FlowPage) {
// remove all children from page.
((FlowPage) figure).removeAll();
@@ -923,7 +924,8 @@ public class AppliedStereotypeMultilinePropertyEditPart extends CompartmentEditP
* @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getAdapter(java.lang.Class)
*
* @param key
- * @return
+ * Class for which the adapter is required
+ * @return the adapter Option according to the key class.
*/
@Override
public Object getAdapter(Class key) {
@@ -940,7 +942,7 @@ public class AppliedStereotypeMultilinePropertyEditPart extends CompartmentEditP
/**
- * locator for the multiline Cell
+ * Locator for the multiline Cell
*
*/
static public class MultilineCellEditorLocator implements CellEditorLocator {
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/AppliedStereotypeCommentCreationEditPolicy.java
index 71e87e81ec2..095da1025af 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/AppliedStereotypeCommentCreationEditPolicy.java
@@ -15,205 +15,233 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.BasicCompartment;
import org.eclipse.gmf.runtime.notation.Bounds;
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.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.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.command.CreateAppliedStereotypeCommentViewCommand;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypesCommentLinkEditPart;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.CreateAppliedStereotypeCommentContentCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.CreateAppliedStereotypeCommentViewCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeLocationEnum;
import org.eclipse.papyrus.uml.tools.listeners.StereotypeElementListener.StereotypeExtensionNotification;
-import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.Element;
/**
* This editpolicy has in charge to :
* - create or destroy the appliedStereotypesCommentEditpart
* - adapt the information about stereotype display into appliedstereotypeCommentEditPart
- * by using eannotation existing mechanism
+ * by using NamedStyle mechanism into Notation model
+ *
*
*/
public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy {
/** constant for this edit policy role */
- public final static String APPLIED_STEREOTYPE_COMMENT = "Applied_Stereotype_Comment";
+ public final static String APPLIED_STEREOTYPE_COMMENT = "AppliedStereotypeComment";// $NON-NLS-1$
+ protected GraphicalEditPart hostEditPart;
+ private Node node;
+ private Node comment;
/**
- * This method has in charge to refresh the presence of the view that represent the comment
+ * Map between Stereotype Name and StereotypeLabel displayed
*/
- protected void updateAppliedStereotypeCommentShape() {
- String stereotypeLocalizationToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesLocalization((View) getHost().getModel());
- String stereotypePropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay((View) getHost().getModel());
- // look for the AppliedStereotypesCommentEditPart
- if (getAppliedStereotypeCommentNode() == null && (!stereotypePropertiesToDisplay.trim().equals(""))) {
- // test if stereotype has to be display as a comment
- if (stereotypeLocalizationToDisplay.equals(UMLVisualInformationPapyrusConstant.STEREOTYPE_COMMENT_LOCATION)) {
+ private Map<EObject, BasicCompartment> stereotypeCommentMap = new HashMap<EObject, BasicCompartment>();
- if (getHost() instanceof ConnectionEditPart) {
- executeAppliedStereotypeCommentCreation(getHost(), ((ConnectionEditPart) getHost()).getEditingDomain(), ((ConnectionEditPart) getHost()).resolveSemanticElement());
- }
- if (getHost() instanceof GraphicalEditPart) {
- executeAppliedStereotypeCommentCreation(getHost(), ((GraphicalEditPart) getHost()).getEditingDomain(), ((GraphicalEditPart) getHost()).resolveSemanticElement());
- }
- }
- }
- // test if the comment has to be removed
- if (getAppliedStereotypeCommentNode() != null) {
- View commentNode = getAppliedStereotypeCommentNode();
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy#activate()
+ *
+ */
+ @Override
+ public void activate() {
+ super.activate();
+ if (getHost() instanceof GraphicalEditPart) {
+ hostEditPart = (GraphicalEditPart) getHost();
+ node = getNotationNode();
- // 1. the display is not comment
- if (!stereotypeLocalizationToDisplay.equals(UMLVisualInformationPapyrusConstant.STEREOTYPE_COMMENT_LOCATION)) {
- final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(commentNode);
- executeAppliedStereotypeCommentDeletion(domain, commentNode);
- }
+ }
+
+ // if stereotype has been applied, compartment has to be created
+ Element umlElement = getUMLElement();
+ // umlElement may be null if the semantic element has been deleted and the view hasn't been cleaned
+ if (umlElement != null) {
+ Iterator<EObject> iterator = umlElement.getStereotypeApplications().iterator();
+ while (iterator.hasNext()) {
+ final EObject appliedstereotype = iterator.next();
+ createAppliedStereotypeCompartmentComment(appliedstereotype);
- // the result of properties to display is null so no compartment will be created
- String todisplay = StereotypeUtil.getPropertiesValues(stereotypePropertiesToDisplay, getUMLElement());
- if ("".equals(todisplay.trim())) {
- final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(commentNode);
- executeAppliedStereotypeCommentDeletion(domain, commentNode);
}
}
-
}
/**
- * return the number of visible compartment that represent a stereotype
*
- * @param view
- * the container view
- * @param eobject
- * the eobject that represent the container
- * @return the number of visible stereotype compartment
+ * {@inheritedDoc}
*/
- protected int getvisisbleAppliedStereotypeCompartment(View view, EObject eobject) {
- int nbVisibleCompartment = 0;
- @SuppressWarnings("unchecked")
- Iterator<View> iteratorView = view.getChildren().iterator();
- while (iteratorView.hasNext()) {
- View subview = iteratorView.next();
- if (subview.getElement() != null && !subview.getElement().equals(eobject)) {
- nbVisibleCompartment++;
- }
+ @Override
+ public void notifyChanged(Notification notification) {
+
+ final int eventType = notification.getEventType();
+
+ if (eventType == StereotypeExtensionNotification.STEREOTYPE_APPLIED_TO_ELEMENT) {
+ super.notifyChanged(notification);
+
+ getDiagramEventBroker().addNotificationListener((EObject) notification.getNewValue(), this);
+ createAppliedStereotypeCompartmentComment((EObject) notification.getNewValue());
+
+
+ } else if (eventType == StereotypeExtensionNotification.STEREOTYPE_UNAPPLIED_FROM_ELEMENT) {
+ // super.notifyChanged(notification);
+ getDiagramEventBroker().removeNotificationListener((EObject) notification.getOldValue(), this);
+ removeAppliedStereotypeCompartmentComment((EObject) notification.getOldValue());
+
+
+
}
- return nbVisibleCompartment;
+
}
/**
- * this method is use to copy all eAnnotation from the view to the comment in order to display properties of stereotype
+ * @return the stereotypeCommentMap
*/
- protected void delegateEAnnotationInCommentShape() {
- final Node appliedStereotypeComment = getAppliedStereotypeCommentNode();
-
- if (appliedStereotypeComment != null) {
- View originView = getView();
- final EAnnotation stereotypeAnnotation = originView.getEAnnotation(UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION);
-
- final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(originView);
- final RecordingCommand cmd = new RecordingCommand(domain, "EannotationDelegation") {
-
- @Override
- protected void doExecute() {
- EAnnotation stereotypeAnnotationCopy = EcoreUtil.copy(stereotypeAnnotation);
- appliedStereotypeComment.getEAnnotations().clear();
- appliedStereotypeComment.getEAnnotations().add(stereotypeAnnotationCopy);
- RecordingCommand cmd = AppliedStereotypeHelper.getSetAppliedStereotypePropertiesLocalizationCommand(domain, appliedStereotypeComment, UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION);
- cmd.execute();
- String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(getView());
- cmd = AppliedStereotypeHelper.getRemoveAppliedStereotypeCommand(domain, appliedStereotypeComment, AppliedStereotypeHelper.getStereotypesToDisplay(appliedStereotypeComment), presentationKind);
- cmd.execute();
- }
- };
+ public Map<EObject, BasicCompartment> getStereotypeCommentMap() {
+ return stereotypeCommentMap;
+ }
- Display.getCurrent().syncExec(new Runnable() {
- public void run() {
- // use to avoid to put it in the command stack
- try {
- GMFUnsafe.write(domain, cmd);
- } catch (Exception e) {
- Activator.log.error(e);
+ /**
+ * This method creates a node for the compartment of stereotype if it does not exist.
+ *
+ * @param stereotypeApplication
+ * the stereotype application
+ */
+ protected void createAppliedStereotypeCompartmentComment(final EObject stereotypeApplication) {
+
+ Node compartment = helper.getStereotypeCompartment(node, stereotypeApplication);
+ if (compartment != null) {
+ // If the node should be displayed in a Compartment or Brace Comment then create the Comment and its content
+ if (!helper.isEmpty(compartment, StereotypeLocationEnum.IN_COMMENT_BRACE)
+ || (!helper.isEmpty(compartment, StereotypeLocationEnum.IN_COMMENT_COMPARTMENT))) {
+
+ if (helper.getStereotypeComment(node) == null) {
+ // if Comment doesn't exist => Create it and copy the structure from the host
+
+ if (getHost() instanceof ConnectionEditPart) {
+ executeAppliedStereotypeCommentCreation(((ConnectionEditPart) getHost()).resolveSemanticElement());
+ }
+ if (getHost() instanceof GraphicalEditPart) {
+ executeAppliedStereotypeCommentCreation(((GraphicalEditPart) getHost()).resolveSemanticElement());
}
+
}
- });
+
+ executeAppliedStereotypeCommentContent(compartment, stereotypeApplication);
+ }
}
}
/**
- * return the comment nodes that represent stereotype properties
- *
- * @return may be null if nothing is founded
+ * Remove the Compartment into the Comment associated to the stereotypeApplication
+ *
+ * @param stereotypeApplication
+ * the stereotypeApplication associated to the compartment to be deleted
*/
- protected Node getAppliedStereotypeCommentNode() {
- View SemanticView = (View) getHost().getModel();
-
- Edge appliedStereotypeLink = null;
- // look for all links with the id AppliedStereotypesCommentLinkEditPart.ID
- @SuppressWarnings("unchecked")
- Iterator<Edge> edgeIterator = SemanticView.getSourceEdges().iterator();
- while (edgeIterator.hasNext()) {
- Edge edge = edgeIterator.next();
- if (edge.getType().equals(AppliedStereotypesCommentLinkEditPart.ID)) {
- appliedStereotypeLink = edge;
- }
-
+ protected void removeAppliedStereotypeCompartmentComment(EObject stereotypeApplication) {
+ // Remove the Label node
+ BasicCompartment compartment = getStereotypeCommentMap().get(stereotypeApplication);
+ if ((compartment != null) && (TransactionUtil.getEditingDomain(compartment) != null)) {
+ executeAppliedStereotypeCompartmentRemove(hostEditPart, compartment);
+ // Delete entry from the Map
+ deleteInCommentMap(stereotypeApplication);
}
- if (appliedStereotypeLink == null) {
- return null;
+ }
+
+ /**
+ * Add the compartment into the Comment Edit Part
+ *
+ * @param stereotypeApplication
+ * The Stereotype Application associated to the new Compartment
+ */
+ protected void executeAppliedStereotypeCommentContent(Node compartment, EObject stereotypeApplication) {
+ comment = helper.getStereotypeComment(node);
+ if (comment != null) {
+ executeAppliedStereotypeCommentContentCreationCommand(compartment);
+
+ // Store entry in the Map
+ storeInCommentMap(stereotypeApplication, comment);
}
- return (Node) appliedStereotypeLink.getTarget();
+ }
+
+ /**
+ * Create the Comment content based on the original model content
+ *
+ * @param compartment
+ * The original compartment on which is based the Comment compartment to be added into the Comment model
+ */
+ protected void executeAppliedStereotypeCommentContentCreationCommand(Node compartment) {
+ final RecordingCommand cmd = new CreateAppliedStereotypeCommentContentCommand("Applied Stereotype Delegation", comment, hostEditPart, compartment);
+ final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(getView());
+ Display.getCurrent().syncExec(new Runnable() {
+ public void run() {
+ // use to avoid to put it in the command stack
+ try {
+ GMFUnsafe.write(domain, cmd);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
}
/**
- * the goal of this method is to execute the a command to create a notation node for applied stereotype
- * as "Comment" shape
+ * The goal of this method is to execute the a command to create a notation node for applied stereotype
+ * as "Comment" shape.
*
- * @param editPart
- * the semantic Editpart
* @param appliedstereotype
* the stereotype application
*/
- protected void executeAppliedStereotypeCommentCreation(final EditPart editPart, final TransactionalEditingDomain domain, final EObject semanticElement) {
+ protected void executeAppliedStereotypeCommentCreation(final EObject node) {
+
+ final TransactionalEditingDomain domain = hostEditPart.getEditingDomain();
Display.getCurrent().syncExec(new Runnable() {
public void run() {
int x = 200;
int y = 100;
- if (editPart.getModel() instanceof Node) {
- LayoutConstraint constraint = ((Node) editPart.getModel()).getLayoutConstraint();
+ if (hostEditPart.getModel() instanceof Node) {
+ LayoutConstraint constraint = ((Node) hostEditPart.getModel()).getLayoutConstraint();
if (constraint instanceof Bounds) {
x = x + ((Bounds) constraint).getX();
y = ((Bounds) constraint).getY();
}
}
- if (editPart.getModel() instanceof Edge && ((((Edge) editPart.getModel()).getSource()) instanceof Node)) {
+ if (hostEditPart.getModel() instanceof Edge && ((((Edge) hostEditPart.getModel()).getSource()) instanceof Node)) {
- LayoutConstraint constraint = ((Node) ((Edge) editPart.getModel()).getSource()).getLayoutConstraint();
+ LayoutConstraint constraint = ((Node) ((Edge) hostEditPart.getModel()).getSource()).getLayoutConstraint();
if (constraint instanceof Bounds) {
x = x + ((Bounds) constraint).getX();
y = ((Bounds) constraint).getY() - 100;
@@ -221,11 +249,11 @@ public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotyp
}
boolean isBorderElement = false;
- if (editPart instanceof BorderedBorderItemEditPart) {
+ if (hostEditPart instanceof BorderedBorderItemEditPart) {
isBorderElement = true;
}
- if (getAppliedStereotypeCommentNode() == null) {
- CreateAppliedStereotypeCommentViewCommand command = new CreateAppliedStereotypeCommentViewCommand(domain, (View) editPart.getModel(), x, y, semanticElement, isBorderElement);
+ if (helper.getStereotypeComment((View) getHost().getModel()) == null) {
+ CreateAppliedStereotypeCommentViewCommand command = new CreateAppliedStereotypeCommentViewCommand(domain, (View) hostEditPart.getModel(), x, y, node, isBorderElement);
// use to avoid to put it in the command stack
try {
GMFUnsafe.write(domain, command);
@@ -239,7 +267,7 @@ public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotyp
}
/**
- * method in oder to delete the comment
+ * In Charge to delete the Comment Node.
*
* @param domain
* the transactional editing domain
@@ -251,7 +279,7 @@ public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotyp
Display.getCurrent().syncExec(new Runnable() {
public void run() {
- // because it is asynchrone the comment node maybe become s null
+ // because it is asynchrony the comment node maybe become s null
if (commentNode != null && TransactionUtil.getEditingDomain(commentNode) != null) {
DeleteCommand command = new DeleteCommand(commentNode);
// use to avoid to put it in the command stack
@@ -265,42 +293,123 @@ public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotyp
});
}
+
+
/**
+ * This method has in charge to refresh the presence of the view that represent the comment
+ */
+ protected void updateAppliedStereotypeCommentShape() {
+
+
+ // look for the AppliedStereotypesCommentEditPart
+ Node commentNode = helper.getStereotypeComment(node);
+
+ if (helper.hasStereotypeCompartment(node)) {
+
+ // if Comment doesn't exist => Create it and copy the structure from the host
+ if (commentNode == null) {
+
+ if (getHost() instanceof ConnectionEditPart) {
+ executeAppliedStereotypeCommentCreation(((ConnectionEditPart) getHost()).resolveSemanticElement());
+ }
+ if (getHost() instanceof GraphicalEditPart) {
+ executeAppliedStereotypeCommentCreation(((GraphicalEditPart) getHost()).resolveSemanticElement());
+ }
+ }
+
+ } else {
+ // If the host doesn't have compartment remove the Comment if any
+ if (commentNode != null) {
+ final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(commentNode);
+ executeAppliedStereotypeCommentDeletion(domain, commentNode);
+ }
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy#refreshStereotypeDisplay()
*
- * {@inheritedDoc}
*/
@Override
- public void notifyChanged(Notification notification) {
- // change the label of the figure managed by the host edit part (managed
- // by the parent edit
- // part in general...)
- // it must be changed only if:
- // - the annotation corresponding to the display of the stereotype
- // changes
- // - the stereotype application list has changed
- final int eventType = notification.getEventType();
- if (eventType == StereotypeExtensionNotification.STEREOTYPE_APPLIED_TO_ELEMENT) {
- // a stereotype was applied to the notifier
- // then a new listener should be added to the stereotype application
- getDiagramEventBroker().addNotificationListener((EObject) notification.getNewValue(), this);
- // TODO To be deleted when Bug 455311 fixed: Commented to put the SterotypeDisplay by NamedStyle
- // createAppliedStereotypeCompartment((EObject)notification.getNewValue());
- } else if (eventType == StereotypeExtensionNotification.STEREOTYPE_UNAPPLIED_FROM_ELEMENT) {
- getDiagramEventBroker().removeNotificationListener((EObject) notification.getOldValue(), this);
- cleanStereotypeDisplayInEAnnotation();
- updateAppliedStereotypeCommentShape();
+ protected void refreshStereotypeDisplay() {
+ refreshComment();
+ }
+
+ /**
+ * Refresh The Comment Figure. Delete if empty.
+ */
+ protected void refreshComment() {
+
+ // Refresh to create Comment if CSS Change
+ if (node != null) {
+ if (node.getElement() instanceof Element) {
+ Element elt = (Element) node.getElement();
+ EList<EObject> appliedStereotypes = elt.getStereotypeApplications();
+ for (EObject obj : appliedStereotypes) {
+ getDiagramEventBroker().addNotificationListener(obj, this);
+ createAppliedStereotypeCompartmentComment(obj);
+ }
+ }
}
+ // Delete Comment if empty
+ comment = helper.getStereotypeComment(node);
+ if (comment != null) {
+ if (helper.isCommentEmpty(comment)) {
+ // Delete the Comment Node
+ executeAppliedStereotypeCommentDeletion(hostEditPart.getEditingDomain(), comment);
+ }
+ }
+
+
}
/**
- * {@inheritDoc}
+ * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy#storeInMap(org.eclipse.emf.ecore.EObject, org.eclipse.gmf.runtime.notation.View)
+ *
+ * @param stereotypeApplication
+ * The Application Of the stereotype to be stored
+ * @param node
+ * the Comment Node which contains the Applied Stereotype Compartments
*/
- @Override
- public void refreshDisplay() {
- // do nothing
- // refreshStereotypeDisplay();
+
+ protected void storeInCommentMap(EObject stereotypeApplication, View node) {
+
+ if (stereotypeApplication != null && node != null) {
+ BasicCompartment compartment = helper.getStereotypeCompartment(node, stereotypeApplication);
+ getStereotypeCommentMap().put(stereotypeApplication, compartment);
+
+
+ }
+
}
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy#deleteInMap(org.eclipse.emf.ecore.EObject)
+ *
+ * @param stereotypeApplication
+ */
+
+ protected void deleteInCommentMap(EObject stereotypeApplication) {
+ getStereotypeCommentMap().remove(stereotypeApplication);
+ }
+
+ /**
+ * Get the Node (notation) corresponding to the Host editpart
+ */
+ protected Node getNotationNode() {
+ Node node = null;
+
+ if (hostEditPart != null) {
+ View view = hostEditPart.getNotationView();
+ if (view instanceof Node) {
+ node = (Node) view;
+ }
+ }
+ return node;
+ }
+
+
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentEditPolicy.java
index 06681777577..aca154fd354 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentEditPolicy.java
@@ -16,438 +16,108 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies;
-import java.util.Iterator;
-
import org.eclipse.draw2d.IFigure;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.BasicCompartment;
-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.gmfdiag.common.editpart.IPapyrusEditPart;
-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;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure;
-import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure;
-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.command.CreateAppliedStereotypePropertyViewCommand;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.command.CreateAppliedStereotypeViewCommand;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.command.CreateStereotypeLabelCommand;
-import org.eclipse.papyrus.uml.tools.listeners.StereotypeElementListener.StereotypeExtensionNotification;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Extension;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.util.UMLUtil;
/**
* this edit policy can be apply only on {@link IPapyrusEditPart} in order to
* access to primary figure. the primary figure has to be a {@link IPapyrusNodeUMLElementFigure}
+ *
*/
-public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy {
- private GraphicalEditPart editPart;
+public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy {
+ /** constant for this edit policy role */
+ public final static String STEREOTYPE_LABEL_POLICY = "AppliedStereotypeCompartmentEditPolicy"; //$NON-NLS-1$
/**
* Creates a new AppliedStereotype display edit policy
*/
public AppliedStereotypeCompartmentEditPolicy() {
super();
-
- }
-
- @Override
- public void activate() {
- super.activate();
- if (getHost() instanceof GraphicalEditPart) {
- editPart = (GraphicalEditPart) getHost();
- }
- // if stereotype has been applied, compartment has to be created
- Element umlElement = getUMLElement();
- // umlElement may be null if the semantic element has been deleted and the view hasn't been cleaned
- if (umlElement != null) {
- Iterator<EObject> iterator = umlElement.getStereotypeApplications().iterator();
- while (iterator.hasNext()) {
- final EObject appliedstereotype = iterator.next();
- createAppliedStereotypeLabel(appliedstereotype);
- }
- }
}
/**
+ * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy#refreshStereotypeDisplay()
*
- * {@inheritedDoc}
*/
@Override
- public void notifyChanged(Notification notification) {
- // change the label of the figure managed by the host edit part (managed
- // by the parent edit part in general...)
- // it must be changed only if:
- // - the annotation corresponding to the display of the stereotype
- // changes
- // - the stereotype application list has changed
- final int eventType = notification.getEventType();
-
- if (eventType == StereotypeExtensionNotification.STEREOTYPE_APPLIED_TO_ELEMENT) {
- // a stereotype was applied to the notifier
- // then a new listener should be added to the stereotype application
-
- getDiagramEventBroker().addNotificationListener((EObject) notification.getNewValue(), this);
-
- createAppliedStereotypeLabel((EObject) notification.getNewValue());
- createAppliedStereotypeCompartment((EObject) notification.getNewValue());
- createAppliedStereotypeProperty((EObject) notification.getNewValue());
-
- // Store entry in the Map
- storeInMap((EObject) notification.getNewValue(), ((GraphicalEditPart) getHost()).getNotationView());
-
-
- } else if (eventType == StereotypeExtensionNotification.STEREOTYPE_UNAPPLIED_FROM_ELEMENT) {
- getDiagramEventBroker().removeNotificationListener((EObject) notification.getOldValue(), this);
-
- removeAppliedStereotypeLabel((EObject) notification.getOldValue());
- removeAppliedStereotypeCompartment((EObject) notification.getOldValue());
-
- // delete entry in the Map
- deleteInMap((EObject) notification.getOldValue());
-
+ protected void refreshStereotypeDisplay() {
+ if (getHost() instanceof IPapyrusEditPart) {
+ IFigure figure = ((IPapyrusEditPart) getHost()).getPrimaryShape();
+ // Refresh Properties in braces
+ refreshAppliedStereotypesPropertiesInBrace((IPapyrusNodeUMLElementFigure) figure);
}
-
}
- /**
- * the goal of this method is to execute the a command to create a notation node for a compartment of stereotype
- *
- * @param editPart
- * the editPart owner of the new compartment
- * @param appliedstereotype
- * the stereotype application
- */
- protected void executeAppliedStereotypeCompartmentCreation(final GraphicalEditPart editPart, final EObject stereotypeApplication) {
- try {
- editPart.getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- Display.getCurrent().syncExec(new Runnable() {
-
- public void run() {
- CreateAppliedStereotypeViewCommand command = new CreateAppliedStereotypeViewCommand(editPart.getEditingDomain(), editPart.getNotationView(), stereotypeApplication);
-
- // use to avoid to put it in the command stack
- try {
- GMFUnsafe.write(editPart.getEditingDomain(), command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- });
-
- }
- });
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
-
- /**
- * The goal of this method is to execute the a command to create a notation node for a stereotype Label.
- *
- * @param editPart
- * the editPart owner of the new compartment
- * @param appliedstereotype
- * the stereotype application
- */
- protected void executeStereotypeLabelCreation(final GraphicalEditPart editPart, final EObject appliedstereotype, final boolean isVisible) {
- try {
- editPart.getEditingDomain().runExclusive(new Runnable() {
- public void run() {
- Display.getCurrent().syncExec(new Runnable() {
-
- public void run() {
-
- CreateStereotypeLabelCommand command = new CreateStereotypeLabelCommand(editPart.getEditingDomain(), editPart.getNotationView(), appliedstereotype, isVisible);
- // use to avoid to put it in the command stack
- try {
- GMFUnsafe.write(editPart.getEditingDomain(), command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- });
-
- }
- });
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
-
- /**
- * this method is used to create a notation node for the property of the stereotype
- *
- * @param editPart
- * the editPart container
- * @param compartment
- * @param stereotypeApplication
- * @param stereotype
- * the stereotype associated to compartment node
- */
- protected void executeAppliedStereotypePropertyViewCreation(final GraphicalEditPart editPart, final Node compartment, final Property stereotypeProperty, final EObject stereotypeApplication) {
- try {
- editPart.getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- Display.getCurrent().syncExec(new Runnable() {
-
- public void run() {
-
- // use to avoid to put it in the command stack
- CreateAppliedStereotypePropertyViewCommand command = new CreateAppliedStereotypePropertyViewCommand(editPart.getEditingDomain(), compartment, stereotypeProperty);
- try {
- GMFUnsafe.write(editPart.getEditingDomain(), command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- });
- }
- });
-
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
-
-
- /**
- * Execute the command to remove the Stereotype.
- *
- * @param editPart
- * Edit Part on which the command is executed
- * @param label
- * DecorationNode of the Stereotype Label that has to be removed
- */
- protected void executeStereotypeLabelRemove(final GraphicalEditPart editPart, final View label) {
- try {
-
- editPart.getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- DeleteCommand command = new DeleteCommand(label);
- // use to avoid to put it in the command stack
- try {
- GMFUnsafe.write(editPart.getEditingDomain(), command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- });
-
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
/**
- * Execute the command to remove the Stereotype Compartment with Properties.
+ * Refreshes the stereotypes properties displayed above name of the element
+ * in this edit part.
*
- * @param editPart
- * Edit Part on which the command is executed
- * @param label
- * DecorationNode of the Stereotype Label that has to be removed
+ * @param stereotypesPropertiesToDisplay
*/
- protected void executeStereotypeCompartmentRemove(final GraphicalEditPart editPart, final View compartment) {
- try {
-
- editPart.getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- DeleteCommand command = new DeleteCommand(compartment);
- // use to avoid to put it in the command stack
- try {
- GMFUnsafe.write(editPart.getEditingDomain(), command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- });
-
- } catch (Exception e) {
- Activator.log.error(e);
+ protected void refreshAppliedStereotypesPropertiesInBrace(IPapyrusNodeUMLElementFigure figure) {
+ String toDisplayInBrace = helper.getStereotypePropertiesInBrace(((GraphicalEditPart) getHost()).getNotationView());
+ // if the string is not empty, then, the figure has to display it. Else,
+ // it displays nothing
+ if (!"".equals(toDisplayInBrace)) {
+ // it has to be displayed in braces, so compute the string to
+ // display
+ figure.setStereotypePropertiesInBrace(toDisplayInBrace);
+ } else {
+ figure.setStereotypePropertiesInBrace(null);
}
}
/**
- * This method creates a node for the compartment of stereotype if it does not exist.
+ * Returns the uml element controlled by the host edit part
*
- * @param stereotypeApplication
- * the stereotype application
+ * @return the uml element controlled by the host edit part
*/
- protected void createAppliedStereotypeLabel(final EObject stereotypeApplication) {
+ @Override
+ protected Element getUMLElement() {
+ Element element = null;
- IFigure figure;
- if (editPart instanceof IPapyrusEditPart) {
- figure = ((IPapyrusEditPart) editPart).getPrimaryShape();
- final View node = editPart.getNotationView();
- // create only if the Label doesn't exist yet
- if (!StereotypeDisplayHelper.isLabelExist(node, stereotypeApplication)) {
- // Create the Decoration Node
- executeStereotypeLabelCreation(editPart, stereotypeApplication, StereotypeDisplayUtils.DEFAULT_VISIBILITY_VALUE);
- // Update the Figure accordingly
- updateLabelText(figure, node);
+ View view = getView();
+ if (view != null) {
+ EObject container = view.eContainer();
+ if (container instanceof View) {
+ element = (Element) ((View) container).getElement();
}
}
+ return element;
}
-
/**
- * This method creates a node for the compartment of stereotype if it does not exist.
*
- * @param stereotypeApplication
- * the stereotype application
- */
- protected void createAppliedStereotypeCompartment(final EObject stereotypeApplication) {
- final View node = editPart.getNotationView();
- // doesn't exist already
- if (!StereotypeDisplayHelper.isCompartmentExist(node, stereotypeApplication)) {
- // Create Compartment
- executeAppliedStereotypeCompartmentCreation(editPart, stereotypeApplication);
- }
- }
-
-
- /**
- * In charge of property view creation
- *
- * @param eObject
- * The Edit Part of which the Properties should be created
- */
- protected void createAppliedStereotypeProperty(EObject stereotypeApplication) {
-
- Node compartment = StereotypeDisplayHelper.getStereotypeCompartment(editPart.getNotationView(), stereotypeApplication);
- if (compartment != null) {
- Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
- if (stereotype != null) {
- EList<Property> properties = stereotype.allAttributes();
- for (Property property : properties) {
- // if stereotype is null all property of stereotype has to be removed!
- if (property != null && !property.getName().startsWith(Extension.METACLASS_ROLE_PREFIX)) {
- // go through each stereotype property
- executeAppliedStereotypePropertyViewCreation(editPart, compartment, property, stereotypeApplication);
-
- }
- }
- }
- }
- }
-
-
- /**
- * this method suppress the sub-nodes that references the stereotype application
- * it cleans also all sub-nodes with the type ApplicationStereotype that not references an application of stereotypes
- * (this is the case when a stereotype has been unapplied without suppress the compartment.
+ * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AbstractAppliedStereotypeDisplayEditPolicy#getView()
*
- * @param stereotypeApplication
+ * @return
*/
- protected void removeAppliedStereotypeCompartment(final EObject stereotypeApplication) {
-
- GraphicalEditPart editPart = (GraphicalEditPart) getHost();
-
- // Remove the Label node
- BasicCompartment compartment = stereotypePropertyMap.get(stereotypeApplication);
- executeStereotypeCompartmentRemove(editPart, compartment);
-
- }
-
-
-
- /**
- * Remove the StereotypeLabel from an element from it's stereotype application.
- *
- * @param stereotypeApplication
- * Associated Stereotype application to remove
- */
- protected void removeAppliedStereotypeLabel(EObject stereotypeApplication) {
- if (stereotypeApplication == null) {
- return;
- }
-
- if (getHost() instanceof GraphicalEditPart) {
-
- final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
- final View node = editPart.getNotationView();
+ @Override
+ protected View getView() {
+ View view = null;
- // Remove the Label node
- DecorationNode label = stereotypeMap.get(stereotypeApplication);
- executeStereotypeLabelRemove(editPart, label);
+ Object model = getHost().getModel();
+ if (model instanceof View) {
- // Update the Label displayed accordingly
- if (editPart instanceof IPapyrusEditPart) {
- IFigure figure = ((IPapyrusEditPart) editPart).getPrimaryShape();
- updateLabelText(figure, node);
+ EObject container = ((View) model).eContainer();
+ if (container instanceof View) {
+ view = (View) container;
}
}
+ return view;
}
- /**
- * Remove the stereotype entry from the Map
- *
- * @param stereotypeApplication
- * The Stereotype Application reference to delete
- */
- protected void deleteInMap(EObject stereotypeApplication) {
- stereotypeMap.remove(stereotypeApplication);
- stereotypePropertyMap.remove(stereotypeApplication);
- }
-
- /**
- * Store the entry (stereotypeApplication, StereotypeLabel)
- *
- * @param stereotypeApplication
- * The Stereotype Application instance to store
- * @param node
- * The parent view (i.e: CSSShapeImpl)
- */
- protected void storeInMap(EObject stereotypeApplication, View node) {
-
- // String stereoQN = UMLUtil.getStereotype(stereotypeApplication).getQualifiedName();
- if (stereotypeApplication != null && node != null) {
-
- DecorationNode label = StereotypeDisplayHelper.getStereotypeLabel(node, stereotypeApplication);
- stereotypeMap.put(stereotypeApplication, label);
-
- BasicCompartment compartment = StereotypeDisplayHelper.getStereotypeCompartment(node, stereotypeApplication);
- stereotypePropertyMap.put(stereotypeApplication, compartment);
- }
- }
-
- /**
- * Method to set the Figure Label with the new modification.
- *
- * @param figure
- * Figure on which the update has to be done
- * @param node
- * Node view of the element required to retrieve the stereotype label
- *
- */
- protected void updateLabelText(IFigure figure, View node) {
- // Update Figure Label
- if (figure instanceof NodeNamedElementFigure) {
-
- String textToDisplay = StereotypeDisplayHelper.getStereotypeTextToDisplay(node);
- ((NodeNamedElementFigure) figure).setStereotypes(textToDisplay);
- }
- }
}
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 b62165b9b75..9e2c0ad84ed 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
@@ -9,13 +9,17 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 460356 : Refactor Stereotype Display
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.notation.EObjectValueStyle;
import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
import org.eclipse.uml2.uml.Element;
@@ -38,10 +42,31 @@ public class AppliedStereotypeCompartmentForCommentShapeEditPolicy extends Appli
if ((Element) getView().getElement() != null) {
return (Element) getView().getElement();
}
- if (getView().getNamedStyle(NotationPackage.eINSTANCE.getEObjectValueStyle(), "BASE_ELEMENT") != null) {
- EObjectValueStyle eObjectValueStyle = (EObjectValueStyle) getView().getNamedStyle(NotationPackage.eINSTANCE.getEObjectValueStyle(), "BASE_ELEMENT");
+ if (getView().getNamedStyle(NotationPackage.eINSTANCE.getEObjectValueStyle(), StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME) != null) {
+ EObjectValueStyle eObjectValueStyle = (EObjectValueStyle) getView().getNamedStyle(NotationPackage.eINSTANCE.getEObjectValueStyle(), StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME);
return (Element) eObjectValueStyle.getEObjectValue();
}
return null;
}
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeCompartmentEditPolicy#refreshAppliedStereotypesPropertiesInBrace(org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure)
+ *
+ * @param figure
+ */
+ @Override
+ protected void refreshAppliedStereotypesPropertiesInBrace(IPapyrusNodeUMLElementFigure figure) {
+
+ String toDisplayInBrace = helper.getStereotypePropertiesInBrace(((GraphicalEditPart) getHost()).getNotationView());
+ // if the string is not empty, then, the figure has to display it. Else,
+ // it displays nothing
+ if (!"".equals(toDisplayInBrace)) {
+ // it has to be displayed in braces, so compute the string to
+ // display
+ figure.setStereotypePropertiesInBrace(toDisplayInBrace);
+ } else {
+ figure.setStereotypePropertiesInBrace(null);
+ }
+
+ }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeLabelEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeLabelEditPolicy.java
new file mode 100644
index 00000000000..ac73c609ed4
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeLabelEditPolicy.java
@@ -0,0 +1,112 @@
+/*****************************************************************************
+ * 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:
+ * CEA LIST - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 460356 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
+import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeNamedElementFigure;
+import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Céline JANSSENS
+ * This Policy is in charge of create and delete the applied Stereotype Label Node into the Notation model
+ */
+public class AppliedStereotypeLabelEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy {
+
+ /** constant for this edit policy role */
+ public final static String STEREOTYPE_LABEL_POLICY = "AppliedStereotypeLabelEditPolicy"; //$NON-NLS-1$
+
+ private GraphicalEditPart hostEditPart = null;
+
+ /**
+ * Creates a new AppliedStereotype display edit policy
+ */
+ public AppliedStereotypeLabelEditPolicy() {
+ super();
+
+ }
+
+
+ @Override
+ public void activate() {
+ super.activate();
+ if (getHost() instanceof GraphicalEditPart) {
+ hostEditPart = (GraphicalEditPart) getHost();
+ }
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy#refreshStereotypeDisplay()
+ *
+ */
+ @Override
+ protected void refreshStereotypeDisplay() {
+ refreshStereotypeLabelDisplay();
+
+
+ }
+
+ protected void refreshStereotypeLabelDisplay() {
+ if (getHost() instanceof IPapyrusEditPart) {
+ IFigure figure = ((IPapyrusEditPart) getHost()).getPrimaryShape();
+
+ // calculate text and icon to display
+ final String stereotypesToDisplay = helper.getStereotypeTextToDisplay((View) getHost().getModel());
+ // computes the icon to be displayed
+ final Image imageToDisplay = stereotypeIconToDisplay();
+
+ // if the string is not empty, then, the figure has to display it.
+ // Else, it displays nothing
+ if (figure instanceof IPapyrusNodeUMLElementFigure) {
+
+ // Refresh Stereotype Label
+ // Stereotype should be passed as "" if null, in order to avoid "null" string.
+ ((IPapyrusNodeUMLElementFigure) figure).setStereotypeDisplay(tag + (stereotypesToDisplay == null ? "" : stereotypesToDisplay), imageToDisplay);
+
+ // Refresh Stereotype Label
+ if (figure instanceof IPapyrusNodeNamedElementFigure) {
+ refreshAppliedStereotypesLabel((IPapyrusNodeUMLElementFigure) figure);
+ }
+ }
+ }
+
+ }
+
+
+ /**
+ * Refreshes the displayed stereotypes properties for this edit part.
+ */
+ protected void refreshAppliedStereotypesLabel(IPapyrusNodeUMLElementFigure figure) {
+ // If node has a Label
+ if (figure instanceof IPapyrusNodeNamedElementFigure) {
+
+ // Refresh Label
+ boolean displayStereotypes = NotationUtils.getBooleanValue(getView(), NamedElementEditPart.DISPLAY_STEREOTYPES, true);
+ if (!displayStereotypes) {
+ ((IPapyrusNodeNamedElementFigure) figure).removeStereotypeLabel();
+ } else {
+ ((IPapyrusNodeNamedElementFigure) figure).restoreStereotypeLabel();
+ }
+ }
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypePropertiesEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypePropertiesEditPolicy.java
index dfcde33fb8d..8f80ab528c5 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypePropertiesEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypePropertiesEditPolicy.java
@@ -16,68 +16,14 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy;
-import org.eclipse.uml2.uml.Element;
/**
* This editPolicy is used to add dynamically labels of stereotypes into nodes in the context of AppliedStereorypeCompartmentEditpart
+ *
+ * @deprecated. Use {@link AppliedStereotypeCompartmentEditPolicy} instead.
*/
public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy {
- public static String APPLIED_STEREOTYPE_VISIBILITY_COMPARTMENT = "AppliedStereotypeVisibilityEditPolicy";
-
- /**
- * Creates a new AppliedStereotype display edit policy
- */
- public AppliedStereotypePropertiesEditPolicy() {
- super();
- }
-
- /**
- * Returns the uml element controlled by the host edit part
- *
- * @return the uml element controlled by the host edit part
- */
- @Override
- protected Element getUMLElement() {
- Element element = null;
-
- View view = getView();
- if (view != null) {
-
- EObject container = view.eContainer();
- if (container instanceof View) {
- element = (Element) ((View) container).getElement();
- }
- }
-
- return element;
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AbstractAppliedStereotypeDisplayEditPolicy#getView()
- *
- * @return
- */
- @Override
- protected View getView() {
- View view = null;
-
- Object model = getHost().getModel();
- if (model instanceof View) {
-
- EObject container = ((View) model).eContainer();
- if (container instanceof View) {
- view = (View) container;
- }
- }
- return view;
- }
-
-
}
-
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 58700ac0e0f..932cd380114 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
@@ -23,10 +23,10 @@ import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPolicies
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart;
-import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy;
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.AppliedStereotypeCompartmentEditPolicy;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies.AppliedStereotypeLabelEditPolicy;
import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
/**
@@ -51,7 +51,9 @@ public class CustomEditPolicyProvider extends AbstractProvider implements IEditP
}
if (editPart instanceof NamedElementEditPart) {
- editPart.installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeCompartmentEditPolicy());
+ editPart.installEditPolicy(AppliedStereotypeCompartmentEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeCompartmentEditPolicy());
+ editPart.installEditPolicy(AppliedStereotypeLabelEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeLabelEditPolicy());
+
}
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/StereotypePropertiesEditPartProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/StereotypePropertiesEditPartProvider.java
index 68d685f59ff..eb3fe9c8d7f 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/StereotypePropertiesEditPartProvider.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/StereotypePropertiesEditPartProvider.java
@@ -27,7 +27,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.providers.RestrictedAbstractEdit
import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypeCompartmentEditPart;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypeMultilinePropertyEditPart;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypesCommentEditPart;
+import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypeCommentEditPart;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypesCommentLinkEditPart;
@@ -45,8 +45,8 @@ public class StereotypePropertiesEditPartProvider extends RestrictedAbstractEdit
nodeMap.put(StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_TYPE, AppliedStereotypeCompartmentEditPart.class);
nodeMap.put(StereotypeDisplayUtils.STEREOTYPE_PROPERTY_TYPE, AppliedStereotypeMultilinePropertyEditPart.class);
- nodeMap.put(AppliedStereotypesCommentEditPart.ID, AppliedStereotypesCommentEditPart.class);
- edgeMap.put(AppliedStereotypesCommentLinkEditPart.ID, AppliedStereotypesCommentLinkEditPart.class);
+ nodeMap.put(StereotypeDisplayUtils.STEREOTYPE_COMMENT_TYPE, AppliedStereotypeCommentEditPart.class);
+ edgeMap.put(StereotypeDisplayUtils.STEREOTYPE_COMMENT_LINK_TYPE, AppliedStereotypesCommentLinkEditPart.class);
}

Back to the top