Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCéline Janssens2015-02-11 17:24:43 +0000
committerCéline Janssens2015-05-06 13:09:51 +0000
commit2b11ad8627ef5d58a2ff5a90e7a577b192a75f9c (patch)
tree1ae44d2033407c1291ab18e71ff82dab1aa91316 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common
parentdf2cb98a440a93cdd0a19a2a49412f3f49e2a60b (diff)
downloadorg.eclipse.papyrus-2b11ad8627ef5d58a2ff5a90e7a577b192a75f9c.tar.gz
org.eclipse.papyrus-2b11ad8627ef5d58a2ff5a90e7a577b192a75f9c.tar.xz
org.eclipse.papyrus-2b11ad8627ef5d58a2ff5a90e7a577b192a75f9c.zip
Bug 455311: [All Diagrams] Applied stereotypes visibility should be
implemented with NamedStyle instead of EAnnotation - Display all the stereotypes thanks to DecorationNode with one Label by stereotype - Hide stereotypes thanks to CSS - Display Qualified Name of some stereotypes thanks to CSS - Display all the properties into the compartment thanks to the DecorationNode into the notation file. - Hide the properties thanks to the CSS - Fix some spelling issues Change-Id: If2bec78b39e031ecc5c3b5b40097ba5104873c1c Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=455311 Signed-off-by: Céline Janssens <Celine.Janssens@all4tec.net>
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF4
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/NamedElementEditPart.java34
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java15
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeExternalNodeEditPolicy.java43
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeLabelDisplayEditPolicy.java179
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeNodeLabelDisplayEditPolicy.java46
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java12
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayHelper.java467
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayUtils.java57
9 files changed, 600 insertions, 257 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
index 957e6b5229b..3cf80e81dba 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
@@ -34,6 +34,7 @@ Export-Package: org.eclipse.papyrus.uml.diagram.common,
org.eclipse.papyrus.uml.diagram.common.service,
org.eclipse.papyrus.uml.diagram.common.service.palette,
org.eclipse.papyrus.uml.diagram.common.sheet,
+ org.eclipse.papyrus.uml.diagram.common.stereotype,
org.eclipse.papyrus.uml.diagram.common.strategy.paste,
org.eclipse.papyrus.uml.diagram.common.ui.dialogs,
org.eclipse.papyrus.uml.diagram.common.ui.helper,
@@ -109,6 +110,5 @@ Bundle-Version: 1.1.0.qualifier
Eclipse-BuddyPolicy: dependent
Bundle-Activator: org.eclipse.papyrus.uml.diagram.common.Activator
Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.common;singleton:
- =true
+Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.common;singleton:=true
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/NamedElementEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/NamedElementEditPart.java
index 9ba52894689..06aef38f56c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/NamedElementEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/NamedElementEditPart.java
@@ -184,6 +184,8 @@ public abstract class NamedElementEditPart extends UMLNodeEditPart implements IU
*/
private void refreshLabelMargin() {
Object model = this.getModel();
+
+
if (model instanceof View) {
int leftMargin = NotationUtils.getIntValue((View) model, LEFT_MARGIN_PROPERTY, getDefaultLeftNameMargin());
int rightMargin = NotationUtils.getIntValue((View) model, RIGHT_MARGIN_PROPERTY, getDefaultRightNameMargin());
@@ -234,34 +236,46 @@ public abstract class NamedElementEditPart extends UMLNodeEditPart implements IU
* Refresh label display.
*/
protected void refreshLabelDisplay() {
+
View view = getNotationView();
+ IPapyrusNodeNamedElementFigure figure = getNodeNamedElementFigure();
+
// SVGNodePlate can be null!
if (svgNodePlate != null) {
if (svgNodePlate.hasLabelBounds()) {
- getNodeNamedElementFigure().getNameLabel().setTextWrap(true);
+ figure.getNameLabel().setTextWrap(true);
}
else {
- getNodeNamedElementFigure().getNameLabel().setTextWrap(false);
+ figure.getNameLabel().setTextWrap(false);
}
}
+ // Get NamedStyle display preferences
BooleanValueStyle displayNameStyle = (BooleanValueStyle) view.getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), NameDisplayEditPolicy.DISPLAY_NAME);
BooleanValueStyle displayStereotypes = (BooleanValueStyle) view.getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), DISPLAY_STEREOTYPES);
BooleanValueStyle displayTags = (BooleanValueStyle) view.getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), DISPLAY_TAGS);
+
+
+ // Manage the display of Name Label
if (displayNameStyle != null && !displayNameStyle.isBooleanValue()) {
- getNodeNamedElementFigure().removeNameLabel();
- getNodeNamedElementFigure().removeStereotypeLabel();
- getNodeNamedElementFigure().removeTaggedLabel();
+ figure.removeNameLabel();
+ figure.removeStereotypeLabel();
+ figure.removeTaggedLabel();
} else {
- getNodeNamedElementFigure().restoreNameLabel();
+ figure.restoreNameLabel();
+
+ // Manage the display of Stereotypes Label
if (displayStereotypes != null && !displayStereotypes.isBooleanValue()) {
- getNodeNamedElementFigure().removeStereotypeLabel();
+ figure.removeStereotypeLabel();
} else {
- getNodeNamedElementFigure().restoreStereotypeLabel();
+ figure.restoreStereotypeLabel();
+
}
+
+ // Manage the display of the Stereotypes Properties Label
if (displayTags != null && !displayTags.isBooleanValue()) {
- getNodeNamedElementFigure().removeTaggedLabel();
+ figure.removeTaggedLabel();
} else {
- getNodeNamedElementFigure().restoreTaggedLabel();
+ figure.restoreTaggedLabel();
}
}
}
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 a380cad16b7..6407015f5e4 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
@@ -31,10 +31,10 @@ import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.RollbackException;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
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.gef.ui.internal.editpolicies.GraphicalEditPolicyEx;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener;
import org.eclipse.papyrus.infra.core.services.ServiceException;
@@ -56,7 +56,7 @@ import com.google.common.collect.Lists;
* Specific edit policy for label displaying stereotypes and their properties
* for representing UML elements.
*/
-public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends GraphicalEditPolicy implements NotificationListener, IPapyrusListener {
+public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends GraphicalEditPolicyEx implements NotificationListener, IPapyrusListener {
/** constant for this edit policy role */
public final static String STEREOTYPE_LABEL_POLICY = "AppliedStereotypeDisplayEditPolicy";
@@ -142,7 +142,7 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic
}
hostSemanticElement = getUMLElement();
// adds a listener on the view and the element controlled by the
- // editpart
+ // editPart
getDiagramEventBroker().addNotificationListener(view, this);
if (hostSemanticElement == null) {
return;
@@ -314,6 +314,15 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic
public abstract void refreshDisplay();
/**
+ * @see org.eclipse.gmf.runtime.gef.ui.internal.editpolicies.GraphicalEditPolicyEx#refresh()
+ * This method must extend GraphicalEditPolicyEx, in order to call the edit policy refresh method when the EditPart is Refreshed
+ */
+ @Override
+ public void refresh() {
+ refreshDisplay();
+ }
+
+ /**
* Parses the string containing the complete definition of properties to be
* displayed, and generates a map.
*
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 78389326dec..450d8e9b934 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
@@ -19,8 +19,8 @@ import org.eclipse.gmf.runtime.notation.View;
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.figure.node.IPapyrusUMLElementFigure;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
/**
@@ -74,7 +74,7 @@ public class AppliedStereotypeExternalNodeEditPolicy extends AppliedStereotypeLa
}
/**
- *
+ * Retrieve the List of the Stereotypes to Display
*
* @return the list of stereotypes to display with properties if there are
* selected to be displayed
@@ -89,46 +89,18 @@ public class AppliedStereotypeExternalNodeEditPolicy extends AppliedStereotypeLa
}
// try to display stereotype properties
- String stereotypespresentationLocation = AppliedStereotypeHelper.getAppliedStereotypesPropertiesLocalization(parentView);
String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay(parentView);
- String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay(parentView);
+ String stereotypesToDisplay = StereotypeDisplayHelper.getStereotypeTextToDisplay(parentView);
String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(parentView);
- // 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_BRACE_LOCATION.equals(stereotypespresentationLocation)) {
- String stereotypesToDisplayWithQN = AppliedStereotypeHelper.getStereotypesQNToDisplay(parentView);
-
- if (UMLVisualInformationPapyrusConstant.STEREOTYPE_TEXT_VERTICAL_PRESENTATION.equals(stereotypespresentationKind)) {
- display += stereotypesAndPropertiesToDisplay("\n", stereotypesToDisplay, stereotypesToDisplayWithQN, stereotypesPropertiesToDisplay);
- } else {
- final String st = stereotypesToDisplay(", ", stereotypesToDisplay, stereotypesToDisplayWithQN);
- 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;
+
+ return stereotypesToDisplay;
}
/**
@@ -141,10 +113,9 @@ public class AppliedStereotypeExternalNodeEditPolicy extends AppliedStereotypeLa
IFigure figure = ((IPapyrusEditPart) getHost()).getPrimaryShape();
if (figure instanceof IPapyrusUMLElementFigure) {// calculate text
- // and icon to
- // display
+ // and icon to display
final String stereotypesToDisplay = stereotypesToDisplay();
- ((IPapyrusUMLElementFigure) figure).setStereotypeDisplay(tag + (stereotypesToDisplay), null);
+ ((IPapyrusUMLElementFigure) figure).setStereotypeDisplay(tag + (stereotypesToDisplay == null ? "" : stereotypesToDisplay), null);
}
}
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 4ec0b7b67eb..ae916874660 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
@@ -13,15 +13,21 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.BasicCompartment;
+import org.eclipse.gmf.runtime.notation.DecorationNode;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.preference.IPreferenceStore;
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.StereotypeDisplayUtils;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.Element;
@@ -44,6 +50,16 @@ public abstract class AppliedStereotypeLabelDisplayEditPolicy extends AbstractAp
public String tag;
/**
+ * Map between Stereotype Name and StereotypeLabel displayed
+ */
+ public Map<EObject, DecorationNode> stereotypeMap = new HashMap<EObject, DecorationNode>();
+
+ /**
+ * Map between Stereotype Name and StereotypeLabel displayed
+ */
+ public Map<EObject, BasicCompartment> stereotypePropertyMap = new HashMap<EObject, BasicCompartment>();
+
+ /**
* Creates a new AppliedStereotypeLabelDisplayEditPolicy, with the specified
* tag for the element.
*
@@ -118,23 +134,19 @@ public abstract class AppliedStereotypeLabelDisplayEditPolicy extends AbstractAp
* @return a string that displays stereotypes (using their simple name or
* their qualified name) and their properties
*/
- public String stereotypesAndPropertiesToDisplay(String separator, String stereotypesToDisplay, String stereotypeWithQualifiedName, String stereotypesPropertiesToDisplay) {
+ public String stereotypesAndPropertiesToDisplay(String separator, String stereotypesToDisplay, String stereotypesPropertiesToDisplay) {
// 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 "";
}
- // retrieve if the name of the stereotype has to put to lower case or
- // not
- String sNameAppearance = store.getString(UMLVisualInformationPapyrusConstant.P_STEREOTYPE_NAME_APPEARANCE);
// changes the string of properties into a map, where the entries of the
- // map are the
- // stereotype qualified name, and the properties to display are the data
+ // map are the stereotype qualified name, and the properties to display are the data
Map<String, List<String>> propertiesToDisplay = parseStereotypeProperties(stereotypesToDisplay, stereotypesPropertiesToDisplay);
- StringTokenizer strQualifiedName = new StringTokenizer(stereotypesToDisplay, ",");
+ StringTokenizer strQualifiedName = new StringTokenizer(stereotypesToDisplay, StereotypeDisplayUtils.STEREOTYPE_LABEL_SEPARATOR);
String out = "";
while (strQualifiedName.hasMoreElements()) {
String currentStereotype = strQualifiedName.nextToken();
@@ -143,37 +155,6 @@ public abstract class AppliedStereotypeLabelDisplayEditPolicy extends AbstractAp
final Element umlElement = getUMLElement();
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 + Activator.ST_LEFT + name + Activator.ST_RIGHT + 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 + Activator.ST_LEFT + name + Activator.ST_RIGHT + separator;
- }
- }
// now should add all properties associated to this stereotype
List<String> properties = propertiesToDisplay.get(stereotype.getQualifiedName());
@@ -195,131 +176,15 @@ public abstract class AppliedStereotypeLabelDisplayEditPolicy extends AbstractAp
}
/**
- * get the list of stereotype to display from the eannotation
+ * Get the list of stereotype to display.
*
* @return the list of stereotypes to display
*/
public String stereotypesToDisplay() {
- // retrieve all stereotypes to be displayed
-
// try to display stereotype properties
- String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay((View) getHost().getModel());
- String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay((View) getHost().getModel());
- String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind((View) getHost().getModel());
-
- // 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 stereotypesToDisplayWithQN = AppliedStereotypeHelper.getStereotypesQNToDisplay(((View) getHost().getModel()));
- String display = "";
- if (UMLVisualInformationPapyrusConstant.STEREOTYPE_TEXT_VERTICAL_PRESENTATION.equals(stereotypespresentationKind)) {
- display += stereotypesAndPropertiesToDisplay("\n", stereotypesToDisplay, stereotypesToDisplayWithQN, stereotypesPropertiesToDisplay);
- } else {
- final String st = stereotypesToDisplay(", ", stereotypesToDisplay, stereotypesToDisplayWithQN);
- 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;
+ String stereotypesToDisplay = StereotypeDisplayHelper.getStereotypeTextToDisplay((View) getHost().getModel());
+ return stereotypesToDisplay;
}
- /**
- * 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(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();
- 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;
- }
}
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 0d03dee3517..00b0be284e7 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
@@ -21,10 +21,10 @@ import org.eclipse.gmf.runtime.notation.View;
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.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.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.swt.graphics.Image;
@@ -51,16 +51,15 @@ public class AppliedStereotypeNodeLabelDisplayEditPolicy extends AppliedStereoty
IFigure figure = ((IPapyrusEditPart) getHost()).getPrimaryShape();
// calculate text and icon to display
- final String stereotypesToDisplay = stereotypesOnlyToDisplay();
+ 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 (stereotypesToDisplay != "" || imageToDisplay != null) {
+ // Else, it displays nothing
if (figure instanceof IPapyrusNodeUMLElementFigure) {
- ((IPapyrusNodeUMLElementFigure) figure).setStereotypeDisplay(tag + (stereotypesOnlyToDisplay().equals("") ? stereotypesToDisplay : stereotypesToDisplay), imageToDisplay);
+ // 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);
@@ -144,39 +143,4 @@ public class AppliedStereotypeNodeLabelDisplayEditPolicy extends AppliedStereoty
}
}
- /**
- * this method is used to display only applied stereotypes
- *
- * @return the string with applied stereotypes. It can return "" if there is
- * no stereotypes to display
- */
- public String stereotypesOnlyToDisplay() {
- // list of stereotypes to display
- String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay((View) getHost().getModel());
- // Kind of the representation
- String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind((View) getHost().getModel());
-
- // check the presentation kind. if only icon => do not display
- // stereotypes
- if (UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION.equals(stereotypespresentationKind)) {
- return ""; // empty string, so stereotype label should not be
- // displayed
- }
-
- // stereotypes with qualified name to display
- String stereotypesToDisplayWithQN = AppliedStereotypeHelper.getStereotypesQNToDisplay(((View) getHost().getModel()));
-
- // the set is empty
- if (stereotypesToDisplayWithQN.length() == 0 && stereotypesToDisplay.length() == 0) {
- return "";
- }
- // vertical representation
- if (UMLVisualInformationPapyrusConstant.STEREOTYPE_TEXT_VERTICAL_PRESENTATION.equals(stereotypespresentationKind)) {
- return Activator.ST_LEFT + stereotypesToDisplay(Activator.ST_RIGHT + "\n" + Activator.ST_LEFT, stereotypesToDisplay, stereotypesToDisplayWithQN) + Activator.ST_RIGHT;
- } else {// horizontal representation
- return Activator.ST_LEFT + stereotypesToDisplay(", ", stereotypesToDisplay, stereotypesToDisplayWithQN) + Activator.ST_RIGHT;
-
- }
- }
-
}
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 76847adcc4f..b3d3b11cae9 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
@@ -32,6 +32,7 @@ import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;
@@ -133,9 +134,6 @@ public class StereotypePropertyParser implements IParser, ISemanticParser {
return UnexecutableCommand.INSTANCE;
}
-
-
-
/**
*
* @see org.eclipse.gmf.runtime.common.ui.services.parser.IParser#getPrintString(org.eclipse.core.runtime.IAdaptable, int)
@@ -150,11 +148,9 @@ public class StereotypePropertyParser implements IParser, ISemanticParser {
if (element instanceof IAdaptable) {
final Property property = ((Property) (EMFHelper.getEObject(element)));
final View view = ((View) element.getAdapter(View.class));
- final EObject stereotypeApplication = ((View) view.eContainer()).getElement();
- final Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
- final Element umlElement = UMLUtil.getBaseElement(stereotypeApplication);
- if (stereotype != null && property != null && umlElement != null) {
- return StereotypeUtil.displayPropertyValue(stereotype, property, umlElement, "");
+
+ if (view != null && property != null) {
+ return StereotypeDisplayHelper.getStereotypePropertyToDisplay(view, property);
}
}
return "<UNDEFINED>";
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
new file mode 100644
index 00000000000..4d209a9372f
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayHelper.java
@@ -0,0 +1,467 @@
+/*****************************************************************************
+ * 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:
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation (Bug 455311)
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotypes Display
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.stereotype;
+
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+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.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.SetNodeVisibilityCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * This Helper contains all the Methods required in the using of Stereotype Display thanks
+ * to the Notation View structure
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class StereotypeDisplayHelper {
+
+ private final static String EMPTY_STRING = "";
+
+ public static String getStereotypeTextToDisplay(View model) {
+ String textToDisplay = null;
+ String finalText = null;
+ Iterator<?> iter = model.getChildren().iterator();
+ Object object;
+ DecorationNode label;
+ while (iter.hasNext()) {
+ object = iter.next();
+ if (object instanceof DecorationNode) {
+ label = (DecorationNode) object;
+
+ if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
+ if (label.isVisible()) {
+ textToDisplay = addStereotypeName(textToDisplay, label, model);
+ }
+ }
+ }
+ }
+
+ if ((textToDisplay != null) && (!EMPTY_STRING.equals(textToDisplay))) {
+ finalText = StereotypeDisplayUtils.BRACE_LEFT + textToDisplay + StereotypeDisplayUtils.BRACE_RIGHT;
+ }
+
+ return finalText;
+
+ }
+
+ /**
+ * Add the Stereotype Name to the text to display.
+ *
+ * @param textToDisplay
+ * The actual string before adding the new Stereotype Name
+ * @param label
+ * The StereotypeLabel of the new stereotype to added
+ * @param model
+ *
+ * @return The String with the new StereotypeName and
+ */
+ protected static String addStereotypeName(String textToDisplay, DecorationNode label, View model) {
+ String newTextToDisplay = textToDisplay;
+ if (!"".equals(newTextToDisplay) && (newTextToDisplay != null)) {
+ newTextToDisplay = (newTextToDisplay + StereotypeDisplayUtils.STEREOTYPE_LABEL_SEPARATOR);
+ }
+
+ String name = StereotypeDisplayHelper.getName(label);
+ String depth = StereotypeDisplayHelper.getDepth(label);
+
+ String nameWithDepth = getStereotypeNameWithDepth(name, depth);
+ newTextToDisplay = ((newTextToDisplay == null ? EMPTY_STRING : newTextToDisplay) + nameWithDepth);
+ return newTextToDisplay;
+ }
+
+ /**
+ * Retrieve the Depth NamedStyle Value of a StereotypeLabel DecorationNode.
+ * The evaluation of the retrieved content is done into method {@link #computeDepthName(int, String) }.
+ *
+ * @param label
+ * StereotypeLabel Node
+ * @return the Depth as a String
+ */
+ public static String getDepth(DecorationNode label) {
+ String depth = EMPTY_STRING;
+ if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
+
+ depth = NotationUtils.getStringValue(label, StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH, StereotypeDisplayUtils.DEFAULT_DEPTH_VALUE);
+
+ }
+ return depth;
+ }
+
+ /**
+ * Retrieve the Stereotype Name with its appropriate depth
+ *
+ * @param text
+ * The full name of the Stereotype (i.e: "SysML::Blocks::Block")
+ * @param depth
+ * 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) {
+
+ if (depth != null && !EMPTY_STRING.equals(depth)) {
+ if (StereotypeDisplayUtils.DEPTH_MIN.equals(depth)) {
+ return getMinimumDepthName(qualifiedName);
+ } else if (StereotypeDisplayUtils.DEPTH_MAX.equals(depth)) {
+ return qualifiedName;
+ } else if (StereotypeDisplayUtils.DEPTH_AUTO.equals(depth)) {
+ // TODO to be computed
+ return qualifiedName;
+ } else {
+ // In case the depth retrieve is a number
+ try {
+ int depthRetrieve = Integer.parseInt(depth);
+ // Case the number is coherent
+
+ if (depthRetrieve > -getMaxDepth(qualifiedName) && depthRetrieve < 0) { // between the minimum and the maximum depth (i.e.:-1)
+ return computeDepthName(depthRetrieve, qualifiedName);
+ } else if (depthRetrieve <= -getMaxDepth(qualifiedName)) { // if smaller than the depth (i.e: -42)
+ return getMinimumDepthName(qualifiedName); // the Last segment is retrieve (i.e: Block)
+ } else if (depthRetrieve == 0) { // mean full name
+ return qualifiedName;
+ } else { // in all other cases , this is the full name which is retrieve
+ return qualifiedName;
+ }
+
+ } catch (NumberFormatException e) {
+ Activator.log.error("Wrong Depth value. Impossible to parse depth : " + depth, e);
+ }
+ }
+ }
+ return qualifiedName;
+ }
+
+ /**
+ * If the retrieve Depth is an appropriate number , compute the Name accordingly.
+ *
+ * @param depthRetrieve
+ * The depth retrieved (should be negative)
+ * @param qualifiedName
+ * The Full Qualified Name
+ * @return the Name computed with the appropriate Depth
+ */
+ protected static String computeDepthName(int depthRetrieve, String qualifiedName) {
+
+ StringBuffer name = new StringBuffer(qualifiedName);
+ try {
+ for (int i = 0; i > depthRetrieve; i--) {
+ int index = name.indexOf(StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR);
+ name = name.delete(0, index + StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR.length());
+ }
+
+ } catch (IndexOutOfBoundsException e) {
+ Activator.log.error(e.getMessage(), e);
+ }
+ return name.toString();
+ }
+
+ /**
+ * Get the last segment of the full qualifiedName.
+ *
+ * @param qualifiedName
+ * The full path name
+ * @return The Last segment of the path.
+ */
+ public static String getMinimumDepthName(String qualifiedName) {
+ String segment = "";
+ StringBuffer name = new StringBuffer(qualifiedName);
+ int index = name.lastIndexOf(StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR);
+ segment = name.substring(index + StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR.length());
+ return segment;
+ }
+
+ /**
+ * Get the number of deepness level. (Ex: SysML::Blocks::Block ==> Returns 3 )
+ *
+ * @param qualifiedName
+ * The full path name
+ * @return Number of deepness level of the full path
+ */
+ protected static int getMaxDepth(String qualifiedName) {
+
+ StringTokenizer tok = new StringTokenizer(qualifiedName, StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR);
+ return tok.countTokens();
+
+ }
+
+ /**
+ * Return the associated DecorationNode of a node from it's qualified name.
+ *
+ * @param node
+ * Container Node of the StereotypeLabel
+ * @param qualifiedName
+ * Qualified Name of the Stereotype associated to this Label
+ * @return associated StereotypeLabel
+ */
+ public static DecorationNode getStereotypeLabel(View node, String qualifiedName) {
+
+ if ((qualifiedName != null) && (qualifiedName != EMPTY_STRING)) {
+ Object obj;
+ Iterator<?> iter = node.getChildren().iterator();
+ while (iter.hasNext()) {
+ obj = iter.next();
+ if (obj instanceof DecorationNode) {
+ DecorationNode label = (DecorationNode) obj;
+ if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
+ if (qualifiedName.equals(getName(label))) {
+ return label;
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Return the associated DecorationNode of a node from it's stereotypeAppplication.
+ *
+ * @param node
+ * Node on which the Stereotype Label is retrieved
+ * @param stereotypeApplication
+ * Stereotype Application of the Label to be retrieved.
+ * @return associated StereotypeLabel
+ */
+ public static DecorationNode getStereotypeLabel(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 DecorationNode) {
+ DecorationNode label = (DecorationNode) obj;
+ if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
+ if (label.getElement().equals(stereotypeApplication)) {
+ return label;
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Return the associated DecorationNode of a node from it's stereotypeAppplication.
+ *
+ * @param node
+ * Node on which the Stereotype Label is retrieved
+ * @param stereotypeApplication
+ * Stereotype Application of the Label to be retrieved.
+ * @return associated StereotypeLabel
+ */
+ public static 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) {
+ BasicCompartment compartment = (BasicCompartment) obj;
+ if (StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_TYPE.equals(compartment.getType())) {
+ if (compartment.getElement().equals(stereotypeApplication)) {
+ return compartment;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Define if the Object is a StereotypeLabel
+ *
+ * @param element
+ * The object on which the test is done
+ *
+ * @return True if the Object is of type "StereotypeLabel"
+ */
+ public static boolean isStereotypeLabel(Object element) {
+ boolean stereotypeLabel = Boolean.FALSE;
+ if (element instanceof DecorationNode) {
+ stereotypeLabel = StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(((DecorationNode) element).getType());
+ }
+ return stereotypeLabel;
+ }
+
+ /**
+ * Define if the Object is a StereotypeCompartment
+ *
+ * @param element
+ * The object on which the test is done
+ * @return True if Object is a StereotypeCompartment
+ */
+ public static boolean isStereotypeCompartment(EObject element) {
+ boolean stereotypeCompartment = Boolean.FALSE;
+ if (element instanceof BasicCompartment) {
+ stereotypeCompartment = StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_TYPE.equals(((DecorationNode) element).getType());
+ }
+ return stereotypeCompartment;
+ }
+
+ /**
+ * Define if the Object is a StereotypeProperty
+ *
+ * @param element
+ * The object on which the test is done
+ *
+ * @return true if Object is a StereotypeProperty Label
+ */
+ public static boolean isStereotypeProperty(Object element) {
+ boolean stereotypeProperty = Boolean.FALSE;
+ if (element instanceof DecorationNode) {
+ stereotypeProperty = StereotypeDisplayUtils.STEREOTYPE_PROPERTY_TYPE.equals(((DecorationNode) element).getType());
+ }
+ return stereotypeProperty;
+ }
+
+ /**
+ * 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_STRING;
+ if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
+ name = NotationUtils.getStringValue(label, StereotypeDisplayUtils.STEREOTYPE_LABEL_NAME, "");
+ }
+ return name;
+ }
+
+ /**
+ * Get the name of the Stereotype Compartment that contains Stereotype Properties (The name is the Qualified Name of the related Stereotype )
+ *
+ * @param compartment
+ * 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_STRING;
+ if (StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_TYPE.equals(compartment.getType())) {
+ name = NotationUtils.getStringValue(compartment, StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_NAME, "");
+ }
+ return name;
+ }
+
+ /**
+ * Define if Label is present into the node
+ *
+ * @param node
+ * View of the node for which the test is done
+ * @param stereotypeApplication
+ * 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) {
+
+ boolean exist = false;
+ Iterator<?> iter = node.getChildren().iterator();
+ while (!exist && iter.hasNext()) {
+ Object obj = iter.next();
+ if (obj instanceof DecorationNode) {
+
+ DecorationNode stereo = (DecorationNode) obj;
+
+ if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(stereo.getType())) {
+ exist = stereo.getElement().equals(stereotypeApplication);
+ }
+ }
+ }
+ return exist;
+ }
+
+
+ /**
+ * Set the visibility of a view
+ *
+ * @param view
+ * The view on which the visibility has to be set
+ * @param isVisible
+ * True to make the Compartment visible
+ */
+ public static void setVisibility(final GraphicalEditPart editPart, final View view, final boolean isVisible) {
+ try {
+
+ editPart.getEditingDomain().runExclusive(new Runnable() {
+
+ @Override
+ public void run() {
+ SetNodeVisibilityCommand setCommand = new SetNodeVisibilityCommand(editPart.getEditingDomain(), view, isVisible);
+ // use to avoid to put it in the command stack
+ try {
+ GMFUnsafe.write(editPart.getEditingDomain(), setCommand);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+ });
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+
+
+ /**
+ * Retrieve the property Text to display into the StereotypeCompartment
+ *
+ * @param view
+ * The StereotypeProperty (DecorationNode)
+ * @param property
+ * 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) {
+ String propertyAndValue = EMPTY_STRING;
+ if (view instanceof DecorationNode) {
+ if (view.getType().equals(StereotypeDisplayUtils.STEREOTYPE_PROPERTY_TYPE)) {
+
+ if (view.isVisible()) {
+
+ final EObject stereotypeApplication = ((View) view.eContainer()).getElement();
+ final Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
+ final Element umlElement = UMLUtil.getBaseElement(stereotypeApplication);
+
+ if (stereotype != null && property != null && umlElement != null) {
+ propertyAndValue = StereotypeUtil.displayPropertyValue(stereotype, property, umlElement, "");
+ }
+ }
+ }
+ }
+ return propertyAndValue;
+
+ }
+
+
+}
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
new file mode 100644
index 00000000000..be1b60f3625
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayUtils.java
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotypes Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype;
+
+/**
+ * This Class regroups the Constants required for the Stereotype Display
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class StereotypeDisplayUtils {
+
+ public static final String STEREOTYPE_LABEL_DEPTH_SEPARATOR = "::";//$NON-NLS-1$
+
+ 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_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$
+ 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$
+
+ 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_STEREOTYPE_PROPERTY_LOCATION = "compartment";//$NON-NLS-1$
+ 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 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");
+
+}

Back to the top