Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCéline Janssens2015-02-11 12:24:43 -0500
committerCéline Janssens2015-05-06 09:09:51 -0400
commit2b11ad8627ef5d58a2ff5a90e7a577b192a75f9c (patch)
tree1ae44d2033407c1291ab18e71ff82dab1aa91316
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>
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/helper/CSSDOMSemanticElementHelper.java14
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/MaskLabelHelper.java5
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/model/NotationUtils.java32
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/utils/DeleteActionUtil.java7
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.requirement/src/org/eclipse/papyrus/sysml/diagram/requirement/edit/policy/CustomAppliedStereotypeLabelDisplayEditPolicy.java41
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.activity/custom-src/org/eclipse/papyrus/uml/diagram/activity/edit/policies/AcceptTimeEventActionStereotypeExternalNodeEditPolicy.java4
-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
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.css/META-INF/MANIFEST.MF3
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.css/src/org/eclipse/papyrus/uml/diagram/css/dom/GMFUMLElementAdapter.java96
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/AppliedStereotypeExternalNodeLabelEditPolicy.java4
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/InteractionOperandAppliedStereotypeLabelDisplayEditPolicy.java6
-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/command/CreateAppliedStereotypePropertyViewCommand.java38
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypeViewCommand.java47
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateStereotypeLabelCommand.java93
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeMultilinePropertyEditPart.java1935
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypePropertyEditPart.java1899
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCommentCreationEditPolicy.java19
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentEditPolicy.java437
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypePropertiesEditPolicy.java216
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/provider/StereotypePropertiesEditPartProvider.java7
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositeforview/AppliedStereotypeCompositeWithView.java8
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/AppliedStereotypeCompositeOnModel.java1365
31 files changed, 3844 insertions, 3291 deletions
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 8a94f25a010..756c26990e0 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
@@ -43,6 +43,7 @@ public class CSSDOMSemanticElementHelper {
* @return
*/
public static EObject findSemanticElement(EObject notationElement) {
+
if (notationElement == null) {
return null;
}
@@ -86,13 +87,13 @@ public class CSSDOMSemanticElementHelper {
/*
* Remove the warning to avoid flooding the error log.
- *
+ *
* This may happen in the following cases:
- *
+ *
* - The element is at the root of the Notation model and is not a Diagram (Which may happen in corrupted models,
* or (maybe) non-Papyrus notation models, but shouldn't have a major impact)
* - The element is contained in an EMF ChangeDescription (e.g. Create + Undo creation)
- *
+ *
* See Bug 430534
*/
// Activator.log.warn("Cannot find a valid source for " + notationElement);
@@ -169,6 +170,13 @@ 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/helper/MaskLabelHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/MaskLabelHelper.java
index 94ccfbcd55d..a4b53b02d0a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/MaskLabelHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/MaskLabelHelper.java
@@ -15,6 +15,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.notation.NamedStyle;
@@ -23,6 +24,7 @@ import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStringStyleObservableList;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
public class MaskLabelHelper {
@@ -35,7 +37,8 @@ public class MaskLabelHelper {
* @return
*/
public static Collection<String> getMaskValues(View view) {
- if (view.getNamedStyle(NotationPackage.eINSTANCE.getStringListValueStyle(), VisualInformationPapyrusConstants.CUSTOM_MASK_LABEL) != null) {
+ EList<String> maskLabel = NotationUtils.getStringListValue(view, VisualInformationPapyrusConstants.CUSTOM_MASK_LABEL, null);
+ if (maskLabel != null) {
CustomStringStyleObservableList values = new CustomStringStyleObservableList(view, EMFHelper.resolveEditingDomain(view), VisualInformationPapyrusConstants.CUSTOM_MASK_LABEL);
Set<String> result = new HashSet<String>(values);
values.dispose();
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 a4d154a4641..6fd7c06a7df 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
@@ -275,6 +275,7 @@ public class NotationUtils {
NamedStyle style;
if (intValueStyle != null) {
+
style = view.getNamedStyle(intValueStyle, property);
if (style instanceof IntValueStyle) {
value = ((IntValueStyle) style).getIntValue();
@@ -359,7 +360,7 @@ public class NotationUtils {
int i = 0;
value = new int[valueList.size()];
// Convert list in int array
- for (Iterator iterator = valueList.iterator(); iterator.hasNext();) {
+ for (Iterator<?> iterator = valueList.iterator(); iterator.hasNext();) {
String string = (String) iterator.next();
value[i++] = Integer.parseInt(string);
}
@@ -367,4 +368,33 @@ public class NotationUtils {
}
return value;
}
+
+
+ /**
+ * Get the list as a String list
+ *
+ * @param view
+ * model
+ * @param property
+ * property name
+ * @param defaultStringList
+ * default value if empty
+ * @return List of String
+ *
+ */
+ public static EList<String> getStringListValue(View view, String property, EList<String> defaultStringList) {
+ EList<String> value = defaultStringList;
+ if (view != null && property != null && property != "") {
+ EClass stringValueStyle = NotationPackage.eINSTANCE.getStringListValueStyle();
+ if (stringValueStyle != null) {
+ NamedStyle style;
+ style = view.getNamedStyle(stringValueStyle, property);
+ if (style instanceof StringListValueStyle) {
+ // Get the string list
+ value = ((StringListValueStyle) style).getStringListValue();
+ }
+ }
+ }
+ return value;
+ }
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/utils/DeleteActionUtil.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/utils/DeleteActionUtil.java
index 49cd13a51aa..8097c935269 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/utils/DeleteActionUtil.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/utils/DeleteActionUtil.java
@@ -215,7 +215,12 @@ public final class DeleteActionUtil {
*/
public static boolean isCanonicalView(IGraphicalEditPart editpart) {
View view = editpart.getAdapter(View.class);
- return view != null || view.getElement() != null || !(view.getElement() instanceof View);
+ boolean canonicalView = true;
+ if (view != null) {
+ canonicalView = !(view.getElement() instanceof View);
+ }
+ return canonicalView;
+
}
/**
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.requirement/src/org/eclipse/papyrus/sysml/diagram/requirement/edit/policy/CustomAppliedStereotypeLabelDisplayEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.requirement/src/org/eclipse/papyrus/sysml/diagram/requirement/edit/policy/CustomAppliedStereotypeLabelDisplayEditPolicy.java
index 30e91c16bf2..91e7fbb4378 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.requirement/src/org/eclipse/papyrus/sysml/diagram/requirement/edit/policy/CustomAppliedStereotypeLabelDisplayEditPolicy.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.requirement/src/org/eclipse/papyrus/sysml/diagram/requirement/edit/policy/CustomAppliedStereotypeLabelDisplayEditPolicy.java
@@ -14,16 +14,7 @@
package org.eclipse.papyrus.sysml.diagram.requirement.edit.policy;
-import java.util.Iterator;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.notation.View;
-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.uml2.uml.Element;
-import org.eclipse.uml2.uml.Stereotype;
/**
* Edit policy responsible of the display of stereotypes. It does not rely
@@ -35,38 +26,6 @@ import org.eclipse.uml2.uml.Stereotype;
*/
public class CustomAppliedStereotypeLabelDisplayEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy {
- @Override
- public String stereotypesOnlyToDisplay() {
- Object hostModel = getHost().getModel();
- String result = ""; //$NON-NLS-1$
- View view = (View) hostModel;
- EObject viewElement = view.getElement();
- Element element = (Element) viewElement;
- Iterator<Stereotype> listStereotype = element.getAppliedStereotypes().iterator();
- StringBuffer buffer = new StringBuffer();
- while (listStereotype.hasNext()) {
- Stereotype stereotypec = listStereotype.next();
- String stereotype_string = stereotypec.getQualifiedName();
- buffer.append(stereotype_string);
- if (listStereotype.hasNext()) {
- buffer.append(","); //$NON-NLS-1$
- }
- }
- result = buffer.toString();
-
- if (result.length() != 0) {
- String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(view);
-
- // vertical representation
- if (UMLVisualInformationPapyrusConstant.STEREOTYPE_TEXT_VERTICAL_PRESENTATION.equals(stereotypespresentationKind)) {
- return Activator.ST_LEFT + stereotypesToDisplay(Activator.ST_RIGHT + "\n" + Activator.ST_LEFT, result, "") + Activator.ST_RIGHT;
- } else {// horizontal representation
- return Activator.ST_LEFT + stereotypesToDisplay(", ", result, "") + Activator.ST_RIGHT;
- }
- }
-
- return result;
- }
@Override
public void activate() {
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 3a4097b4cbe..81e99146695 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
@@ -103,9 +103,9 @@ public class AcceptTimeEventActionStereotypeExternalNodeEditPolicy extends Appli
String stereotypesToDisplayWithQN = AppliedStereotypeHelper.getStereotypesQNToDisplay(parentView);
if (UMLVisualInformationPapyrusConstant.STEREOTYPE_TEXT_VERTICAL_PRESENTATION.equals(stereotypespresentationKind)) {
- display += stereotypesAndPropertiesToDisplay("\n", stereotypesToDisplay, stereotypesToDisplayWithQN, stereotypesPropertiesToDisplay);
+ display += stereotypesAndPropertiesToDisplay("\n", stereotypesToDisplay, stereotypesPropertiesToDisplay);
} else {
- final String st = stereotypesToDisplay(", ", stereotypesToDisplay, stereotypesToDisplayWithQN);
+ final String st = stereotypesToDisplay();
if (st != null && !st.equals("")) {
display += Activator.ST_LEFT + st + Activator.ST_RIGHT;
}
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");
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.css/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.css/META-INF/MANIFEST.MF
index 5aeb8007446..20f02fb62fa 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.css/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.css/META-INF/MANIFEST.MF
@@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.databinding;bundle-version="1.4.1",
org.eclipse.papyrus.infra.tools;bundle-version="1.1.0",
org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.1.0",
- org.eclipse.papyrus.infra.emf;bundle-version="1.1.0"
+ org.eclipse.papyrus.infra.emf;bundle-version="1.1.0",
+ org.eclipse.papyrus.uml.diagram.common;bundle-version="1.1.0"
Bundle-Vendor: Eclipse Modeling Project
Bundle-ActivationPolicy: lazy
Bundle-Version: 1.1.0.qualifier
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 73d2e0f07c9..e3f90044eb0 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
@@ -17,12 +17,17 @@ import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
+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.css.dom.GMFElementAdapter;
import org.eclipse.papyrus.infra.gmfdiag.css.engine.ExtendedCSSEngine;
import org.eclipse.papyrus.infra.tools.util.ListHelper;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Stereotype;
/**
@@ -56,14 +61,43 @@ public class GMFUMLElementAdapter extends GMFElementAdapter {
*/
@Override
protected String doGetAttribute(String attr) {
- // Semantic properties
String parentValue = super.doGetAttribute(attr);
if (parentValue != null) {
return parentValue;
}
+
+ // get stereotype Label attribute
+ if (StereotypeDisplayHelper.isStereotypeLabel(semanticElement)) {
+ String value = getStereotypeLabelAttribute(attr);
+ if (value != null && !value.isEmpty()) {
+ return value;
+ }
+ }
+
+ // get stereotype Compartment attribute
+ if (StereotypeDisplayHelper.isStereotypeCompartment(semanticElement)) {
+ String value = getStereotypeCompartmentAttribute(attr);
+ if (value != null && !value.isEmpty()) {
+ return value;
+ }
+ }
+
+ // get stereotype Property attribute
+ if (StereotypeDisplayHelper.isStereotypeProperty(semanticElement)) {
+
+ String value = getStereotypePropertyAttribute(attr);
+ if (value != null && !value.isEmpty()) {
+ return value;
+ }
+ }
+
+
if (semanticElement instanceof Element) {
+
// Applied stereotypes
Element currentElement = (Element) semanticElement;
+
+ // Get applied STereotypes Attributes
if (APPLIED_STEREOTYPES_PROPERTY.equals(attr)) {
List<String> appliedStereotypes = new LinkedList<String>();
for (Stereotype stereotype : currentElement.getAppliedStereotypes()) {
@@ -110,6 +144,66 @@ public class GMFUMLElementAdapter extends GMFElementAdapter {
return null;
}
+ /**
+ * Retrieve the Matching String Value for the StereotypeCompartment Element
+ *
+ * @param attr
+ * Attribute of the String to match with
+ * @return The matching value for this Attribute
+ */
+ protected String getStereotypeCompartmentAttribute(String attr) {
+ if (StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_NAME.equals(attr)) {
+
+ BasicCompartment propertyCompartment = (BasicCompartment) semanticElement;
+ return StereotypeDisplayHelper.getName(propertyCompartment);
+
+ }
+ return "";
+ }
+
+ /**
+ * Retrieve the Matching String Value for the StereotypeCompartment Element
+ *
+ * @param attr
+ * Attribute of the String to match with
+ * @return The matching value for this Attribute
+ */
+ protected String getStereotypePropertyAttribute(String attr) {
+ if (StereotypeDisplayUtils.STEREOTYPE_PROPERTY_NAME.equals(attr)) {
+
+ DecorationNode propertyLabel = (DecorationNode) semanticElement;
+ if (propertyLabel.getElement() instanceof Property) {
+ Property prop = (Property) propertyLabel.getElement();
+ String propLabel = prop.getName();
+ return propLabel;
+ }
+
+ }
+ return "";
+
+ }
+
+ /**
+ * Get the matching Value of the Attribute
+ *
+ * @param attr
+ * Attribute of the String to match with
+ * @return The matching value for this Attribute
+ */
+ protected String getStereotypeLabelAttribute(String attr) {
+
+ if (StereotypeDisplayUtils.STEREOTYPE_LABEL_NAME.equals(attr)) {
+ DecorationNode label = (DecorationNode) semanticElement;
+
+ String stereoName = StereotypeDisplayHelper.getName(label);
+ return stereoName;
+
+ }
+ return null;
+ }
+
+
+
@Override
protected String getCSSValue(EStructuralFeature feature, Object value) {
if (feature instanceof EReference && value instanceof NamedElement) {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/AppliedStereotypeExternalNodeLabelEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/AppliedStereotypeExternalNodeLabelEditPolicy.java
index 04b85552c61..ef6f66fba1b 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/AppliedStereotypeExternalNodeLabelEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/edit/policies/AppliedStereotypeExternalNodeLabelEditPolicy.java
@@ -119,9 +119,9 @@ public class AppliedStereotypeExternalNodeLabelEditPolicy extends AppliedStereot
}
// 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;
+ return Activator.ST_LEFT + stereotypesToDisplay() + Activator.ST_RIGHT;
} else {// horizontal representation
- return Activator.ST_LEFT + stereotypesToDisplay(", ", stereotypesToDisplay, stereotypesToDisplayWithQN) + Activator.ST_RIGHT;
+ return Activator.ST_LEFT + stereotypesToDisplay() + Activator.ST_RIGHT;
}
}
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 8e1ec789590..e337f44943f 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
@@ -15,9 +15,11 @@ 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;
@@ -41,7 +43,7 @@ public class InteractionOperandAppliedStereotypeLabelDisplayEditPolicy extends A
}
GuardFigure figure = ((InteractionOperandGuardEditPart) guard).getPrimaryFigure();
// 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();
@@ -50,7 +52,7 @@ public class InteractionOperandAppliedStereotypeLabelDisplayEditPolicy extends A
// nothing
// if (stereotypesToDisplay != "" || imageToDisplay != null) {
if (figure instanceof IPapyrusNodeUMLElementFigure) {
- ((IPapyrusNodeUMLElementFigure) figure).setStereotypeDisplay(tag + ("".equals(stereotypesOnlyToDisplay()) ? stereotypesToDisplay : stereotypesToDisplay), imageToDisplay);
+ ((IPapyrusNodeUMLElementFigure) figure).setStereotypeDisplay(tag + (stereotypesToDisplay == null ? "" : stereotypesToDisplay), imageToDisplay);
if (figure instanceof IPapyrusNodeNamedElementFigure) {
refreshAppliedStereotypesProperties((IPapyrusNodeNamedElementFigure) figure);
}
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 da422aeaec1..5ff00a3067c 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="AppliedStereotypeCompartment,AppliedStereotypeProperty,AppliedStereotypesComment,AppliedStereotypesCommentLink"/>
+ <method name="getType()" value="StereotypeCompartment,StereotypeProperty,AppliedStereotypesComment,AppliedStereotypesCommentLink"/>
</object>
</editpartProvider>
</extension>
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.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypePropertyViewCommand.java
index 37a1f0760bb..efcf2d74c4d 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.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypePropertyViewCommand.java
@@ -9,18 +9,23 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotypes Display
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.stereotype.edition.command;
+import org.eclipse.emf.ecore.EObject;
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.notation.Node;
+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.stereotype.edition.editpart.AppliedStereotypePropertyEditPart;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils;
+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;
/**
* the goal of this command is to create a basic compartment in the notation that represent a compartment of stereotypes
@@ -32,27 +37,38 @@ public class CreateAppliedStereotypePropertyViewCommand extends RecordingCommand
protected Property property;
- public CreateAppliedStereotypePropertyViewCommand(TransactionalEditingDomain domain, View owner, Property property) {
+ protected EObject stereotypeApplication;
+
+ protected Element element;
+
+ public CreateAppliedStereotypePropertyViewCommand(TransactionalEditingDomain domain, View owner, Property property, EObject stereotypeApplication) {
super(domain, "CreateStereotypePropertyView");
this.owner = owner;
this.property = property;
-
+ this.stereotypeApplication = stereotypeApplication;
+ this.element = UMLUtil.getBaseElement(stereotypeApplication);
}
@SuppressWarnings("unchecked")
@Override
public void doExecute() {
- Node node = NotationFactory.eINSTANCE.createShape();
- node.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
- node.setType(AppliedStereotypePropertyEditPart.ID);
- ViewUtil.insertChildView(owner, node, -1, false);
- node.setElement(property);
- node.setMutable(true);
+ // Create Stereotype Property into Notation Structure
+ // Init
+ Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
+ String propertyName = property.getName();
+ Object value = element.getValue(stereotype, propertyName);
+ // Create Label
+ DecorationNode propertyLabel = NotationFactory.eINSTANCE.createDecorationNode();
+ propertyLabel.setType(StereotypeDisplayUtils.STEREOTYPE_PROPERTY_TYPE);
+ propertyLabel.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
+ propertyLabel.setElement(property);
+ // Add the new Label to it's owner Object
+ ViewUtil.insertChildView(owner, propertyLabel, ViewUtil.APPEND, true);
+ propertyLabel.setMutable(true);
}
-
}
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.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypeViewCommand.java
index fdaa9ea7a3f..1d77bb12c31 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.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateAppliedStereotypeViewCommand.java
@@ -19,9 +19,13 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.notation.Node;
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.stereotype.edition.editpart.AppliedStereotypeCompartmentEditPart;
+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;
/**
* the goal of this command is to create a basic compartment in the notation that represent a compartment of stereotypes
@@ -29,42 +33,63 @@ import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereo
*/
public class CreateAppliedStereotypeViewCommand extends RecordingCommand {
- protected View owner;
+ protected View node;
- protected EObject StereotypeApplication;
+ protected EObject stereotypeApplication;
protected boolean displayit = false;
+ protected Node parent;
+
/**
*
* Constructor.
*
* @param domain
- * @param owner
+ * @param node
+ * The EditPart view of the Compartment
* @param StereotypeApplication
* @param displayit
*/
- public CreateAppliedStereotypeViewCommand(TransactionalEditingDomain domain, View owner, EObject StereotypeApplication, boolean displayit) {
+ public CreateAppliedStereotypeViewCommand(TransactionalEditingDomain domain, View node, EObject stereotypeApplication, boolean displayit) {
super(domain, "CreateStereotypeCompartment");
- this.owner = owner;
- this.StereotypeApplication = StereotypeApplication;
+ this.node = node;
+ this.stereotypeApplication = stereotypeApplication;
this.displayit = displayit;
+ parent = StereotypeDisplayHelper.getStereotypeLabel(node, stereotypeApplication);
}
@SuppressWarnings("unchecked")
@Override
public void doExecute() {
+
+
+ Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
+
+ // Create the Graphical Compartment
Node compartment = NotationFactory.eINSTANCE.createBasicCompartment();
- compartment.setVisible(displayit);
+ compartment.setVisible(true);
compartment.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
+
+ // Create Title Style
TitleStyle ts = NotationFactory.eINSTANCE.createTitleStyle();
ts.setShowTitle(true);
compartment.getStyles().add(ts);
- compartment.setElement(StereotypeApplication);
- compartment.setType(AppliedStereotypeCompartmentEditPart.ID);
- ViewUtil.insertChildView(owner, compartment, ViewUtil.APPEND, false);
+
+ // Create Stereotype Name Style
+ StringValueStyle stereotypeNameStyle = NotationFactory.eINSTANCE.createStringValueStyle();
+ stereotypeNameStyle.setName(StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_NAME);
+ stereotypeNameStyle.setStringValue(stereotype.getQualifiedName());
+ compartment.getStyles().add(stereotypeNameStyle);
+
+ // Complete the creation
+ compartment.setElement(stereotypeApplication);
+ compartment.setType(StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_TYPE);
+ ViewUtil.insertChildView(node, compartment, ViewUtil.APPEND, true);
compartment.setMutable(true);
+
}
+
}
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.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateStereotypeLabelCommand.java
new file mode 100644
index 00000000000..e2892072532
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/command/CreateStereotypeLabelCommand.java
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * 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.stereotype.edition.command;
+
+import org.eclipse.emf.ecore.EObject;
+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.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;
+
+/**
+ * @author Céline JANSSENS
+ *
+ */
+public class CreateStereotypeLabelCommand extends RecordingCommand {
+
+ private static final String STEREOTYPE_LABEL_COMMAND_NAME = "Stereotype Label Creation Command";
+
+
+ protected View owner;
+
+ protected EObject stereoApplication;
+
+ protected boolean isVisible;
+
+ protected Element element;
+
+ /**
+ * Constructor.
+ *
+ * @param domain
+ * Transactional domain
+ * @param owner
+ * Owner of the Label Created
+ * @param stereoApplication
+ * Stereotype application which the Label will be based on
+ * @param isVisible
+ * if the Label is Visible when created
+ */
+ public CreateStereotypeLabelCommand(TransactionalEditingDomain domain, View owner, EObject stereoApplication, boolean isVisible) {
+ super(domain, STEREOTYPE_LABEL_COMMAND_NAME);
+ this.owner = owner;
+ this.stereoApplication = stereoApplication;
+ this.isVisible = isVisible;
+ }
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ *
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void doExecute() {
+
+ Stereotype stereotype = UMLUtil.getStereotype(stereoApplication);
+ // Create Label
+ DecorationNode label = NotationFactory.eINSTANCE.createDecorationNode();
+ label.setType(StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE);
+ label.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
+ label.setElement(stereoApplication);
+
+ // Create Stereotype Name Style
+ StringValueStyle stereotypeNameStyle = NotationFactory.eINSTANCE.createStringValueStyle();
+ stereotypeNameStyle.setName(StereotypeDisplayUtils.STEREOTYPE_LABEL_NAME);
+ stereotypeNameStyle.setStringValue(stereotype.getQualifiedName());
+ label.getStyles().add(stereotypeNameStyle);
+
+ // Add the new Label to it's owner Object
+ ViewUtil.insertChildView(owner, label, ViewUtil.APPEND, true);
+ label.setMutable(true);
+
+
+ }
+}
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 e853b43fc03..bb074503a4e 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
@@ -1,963 +1,972 @@
-/*****************************************************************************
- * Copyright (c) 2010 Atos Origin.
- *
- *
- * 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:
- * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.draw2d.text.FlowPage;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.AccessibleEditPart;
-import org.eclipse.gef.EditPolicy;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.requests.DirectEditRequest;
-import org.eclipse.gef.tools.CellEditorLocator;
-import org.eclipse.gef.tools.DirectEditManager;
-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.ParserOptions;
-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.CompartmentEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
-import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
-import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
-import org.eclipse.gmf.runtime.draw2d.ui.text.TextFlowEx;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
-import org.eclipse.gmf.runtime.notation.FontStyle;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ICellEditorValidator;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.extensionpoints.editors.Activator;
-import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration;
-import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration;
-import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
-import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration;
-import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog;
-import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog;
-import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper;
-import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil;
-import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
-import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
-import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;
-import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager;
-import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypePropertyDirectEditPolicy;
-import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition;
-import org.eclipse.papyrus.uml.diagram.common.editpolicies.UMLTextSelectionEditPolicy;
-import org.eclipse.papyrus.uml.diagram.common.figure.node.EditingFlowPage;
-import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure;
-import org.eclipse.papyrus.uml.diagram.common.figure.node.IMultilineEditableFigure;
-import org.eclipse.papyrus.uml.diagram.common.parser.StereotypePropertyParser;
-import org.eclipse.papyrus.uml.profile.structure.AppliedStereotypeProperty;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.accessibility.AccessibleEvent;
-import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.util.UMLUtil;
-
-/**
- * the goal of this editpart is to edit a property of an application of the stereotype into a text area
- *
- */
-public class AppliedStereotypeMultilinePropertyEditPart extends CompartmentEditPart implements ITextAwareEditPart, NotificationListener, IPapyrusListener, IControlParserForDirectEdit {
-
- public static final String ID = "AppliedStereotypeProperty"; //$NON-NLS-1$
-
- private DirectEditManager manager;
-
- private IParser parser;
-
- private List<?> parserElements;
-
- private String defaultText;
-
- /**
- * direct edition mode (default, undefined, registered editor, etc.)
- *
- */
- protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR;
-
- /**
- * configuration from a registered edit dialog
- *
- */
- protected IDirectEditorConfiguration configuration;
-
- /**
- *
- * Constructor.
- *
- * @param view
- */
- public AppliedStereotypeMultilinePropertyEditPart(View view) {
- super(view);
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart#createDefaultEditPolicies()
- *
- */
- @Override
- protected void createDefaultEditPolicies() {
- super.createDefaultEditPolicies();
- installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy());
- installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new AppliedStereotypePropertyDirectEditPolicy());
- // installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UseCaseDiagramEditPart.NodeLabelDragPolicy());
- }
-
-
-
- /**
- * get the text from the figure
- *
- * @param figure
- * @return the text from the figure
- */
- protected String getLabelTextHelper(IFigure figure) {
- // the figure is an ILabel Figure
- if (figure instanceof ILabelFigure) {
- return ((ILabelFigure) figure).getText();
- }
- return "";
- }
-
- /**
- * set the text inot the
- */
- protected void setLabelTextHelper(IFigure figure, String text) {
- if (figure instanceof FlowPage) {
- // remove all children from page.
- ((FlowPage) figure).removeAll();
-
-
- // generates new ones
- generateBlockForText(text, ((FlowPage) figure));
- }
- }
-
- /**
- * Generates block list for the given text, and adds it to the root flow
- * page
- *
- * @param text
- * the string to display
- */
- protected void generateBlockForText(String text, FlowPage page) {
- // return only one text flow with the content of the text
- TextFlowEx textFlow = new TextFlowEx(text);
- page.add(textFlow);
- }
-
- /**
- * return icon from the figure
- *
- * @param figure
- * @return the icon
- */
- protected Image getLabelIconHelper(IFigure figure) {
- if (figure instanceof ILabelFigure) {
- return ((ILabelFigure) figure).getIcon();
- }
- return null;
- }
-
- /**
- * set the icon inot the figure
- */
- protected void setLabelIconHelper(IFigure figure, Image icon) {
- if (figure instanceof ILabelFigure) {
- ((ILabelFigure) figure).setIcon(icon);
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getModelChildren()
- *
- */
- @Override
- protected List getModelChildren() {
- return Collections.EMPTY_LIST;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getChildBySemanticHint(java.lang.String)
- *
- */
- @Override
- public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
- return null;
- }
-
- /**
- * the element that will display in the text area
- *
- * @return
- */
- protected EObject getParserElement() {
- return resolveSemanticElement();
- }
-
- /**
- * get the icon to display
- */
- protected Image getLabelIcon() {
- return null;
- }
-
- /**
- *
- * @return the text to display in the label
- */
- protected String getLabelText() {
- String text = null;
- EObject parserElement = getParserElement();
- if (parserElement != null && getParser() != null) {
- text = getParser().getPrintString(new SemanticAdapter(this.resolveSemanticElement(), getNotationView()), getParserOptions().intValue());
- }
- if (text == null || text.length() == 0) {
- text = defaultText;
- }
- return text;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#setLabelText(java.lang.String)
- *
- */
-
- public void setLabelText(String text) {
- setLabelTextHelper(getFigure(), text);
- Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
- if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
- ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
- }
- Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
- if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) {
- ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback();
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getEditText()
- *
- */
- public String getEditText() {
- if (getParserElement() == null || getParser() == null) {
- return ""; //$NON-NLS-1$
- }
-
- // return getParser().getEditString(new SemanticAdapter((EObject) this.getAdapter(AppliedStereotypeProperty.class), getNotationView()), getParserOptions().intValue());
- return getParser().getEditString(new SemanticAdapter(resolveSemanticElement(), getNotationView()), getParserOptions().intValue());
- }
-
- /**
- *
- * @return true if this edit part is editable, it depends of the attribue derived of the property
- */
- protected boolean isEditable() {
- if (!(((Property) resolveSemanticElement()).isDerived())) {
- return getParser() != null;
- } else {
- return false;
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getEditTextValidator()
- *
- */
- public ICellEditorValidator getEditTextValidator() {
- return new ICellEditorValidator() {
-
- public String isValid(final Object value) {
- if (value instanceof String) {
- final EObject element = getParserElement();
- final IParser parser = getParser();
- try {
- IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
-
- public void run() {
- setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
- }
- });
- return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage();
- } catch (InterruptedException ie) {
- ie.printStackTrace();
- }
- }
-
- // shouldn't get here
- return null;
- }
- };
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getCompletionProcessor()
- *
- */
- public IContentAssistProcessor getCompletionProcessor() {
- if (getParserElement() == null || getParser() == null) {
- return null;
- }
- return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getParserOptions()
- *
- */
- public ParserOptions getParserOptions() {
- return ParserOptions.NONE;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getParser()
- */
- public IParser getParser() {
- if (parser == null) {
- parser = new StereotypePropertyParser();
- }
- return parser;
- }
-
- /**
- *
- * @return the manager to edit the label
- */
- protected DirectEditManager getManager() {
- if (manager == null) {
- setManager(new MultilineLabelDirectEditManager(this, MultilineLabelDirectEditManager.getTextCellEditorClass(this), new MultilineCellEditorLocator((IMultilineEditableFigure) getFigure())));
- }
- return manager;
- }
-
- /**
- * set a manager to edit the label
- */
- protected void setManager(DirectEditManager manager) {
- this.manager = manager;
- }
-
- /**
- * do the edition
- */
- protected void performDirectEdit() {
- BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
-
- public void run() {
- getManager().show();
- }
- });
- }
-
- /**
- * Do the edition
- *
- * @param eventLocation
- */
- protected void performDirectEdit(Point eventLocation) {
- if (getManager() instanceof TextDirectEditManager) {
- ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
- }
- }
-
- /**
- * Do the edition
- *
- * @param initialCharacter
- */
- private void performDirectEdit(char initialCharacter) {
- if (getManager() instanceof TextDirectEditManager) {
- ((TextDirectEditManager) getManager()).show(initialCharacter);
- } else {
- performDirectEdit();
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#performDirectEditRequest(org.eclipse.gef.Request)
- *
- */
- @Override
- protected void performDirectEditRequest(Request request) {
-
- final Request theRequest = request;
-
- if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) {
- directEditionMode = getDirectEditionType();
- }
- switch (directEditionMode) {
- case IDirectEdition.NO_DIRECT_EDITION:
- // no direct edition mode => does nothing
- return;
- case IDirectEdition.EXTENDED_DIRECT_EDITOR:
- updateExtendedEditorConfiguration();
- if (configuration == null || configuration.getLanguage() == null) {
- performDefaultDirectEditorEdit(theRequest);
- } else {
- configuration.preEditAction(getAdapter(AppliedStereotypeProperty.class));
- Dialog dialog = null;
- if (configuration instanceof ICustomDirectEditorConfiguration) {
- setManager(((ICustomDirectEditorConfiguration) configuration)
- .createDirectEditManager(this));
- initializeDirectEditManager(theRequest);
- return;
- } else if (configuration instanceof IPopupEditorConfiguration) {
- IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this);
- if (helper != null) {
- helper.showEditor();
- }
- return;
- } else if (configuration instanceof IAdvancedEditorConfiguration) {
- dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()));
- } else if (configuration instanceof IDirectEditorConfiguration) {
- dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), configuration);
- } else {
- return;
- }
- final Dialog finalDialog = dialog;
-
- if (Window.OK == dialog.open()) {
- TransactionalEditingDomain domain = getEditingDomain();
- RecordingCommand command = new RecordingCommand(domain, "Edit Label") {
-
- @Override
- protected void doExecute() {
- configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue());
-
- }
- };
- domain.getCommandStack().execute(command);
- }
- }
- break;
- case IDirectEdition.DEFAULT_DIRECT_EDITOR:
-
- // initialize the direct edit manager
- try {
- getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- if (isActive() && isEditable()) {
- if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
- Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
- performDirectEdit(initialChar.charValue());
- } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
- DirectEditRequest editRequest = (DirectEditRequest) theRequest;
- performDirectEdit(editRequest.getLocation());
- } else {
- performDirectEdit();
- }
- }
- }
- });
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- break;
- default:
- break;
- }
- }
-
- public void setParser(IParser parser) {
- this.parser = parser;
- }
-
- /**
- */
- protected void initializeDirectEditManager(final Request request) {
- // initialize the direct edit manager
- try {
- getEditingDomain().runExclusive(new Runnable() {
- public void run() {
- if (isActive() && isEditable()) {
- if (request
- .getExtendedData()
- .get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
- Character initialChar = (Character) request
- .getExtendedData()
- .get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
- performDirectEdit(initialChar.charValue());
- } else if ((request instanceof DirectEditRequest)
- && (getEditText().equals(getLabelText()))) {
- DirectEditRequest editRequest = (DirectEditRequest) request;
- performDirectEdit(editRequest.getLocation());
- } else {
- performDirectEdit();
- }
- }
- }
- });
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#refreshVisuals()
- *
- */
- @Override
- protected void refreshVisuals() {
- super.refreshVisuals();
- refreshLabel();
- refreshFont();
- refreshFontColor();
- refreshUnderline();
- refreshStrikeThrough();
- }
-
- /**
- * refresh the label
- */
- protected void refreshLabel() {
- EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
- if (maskLabelPolicy == null) {
- setLabelTextHelper(getFigure(), getLabelText());
- }
- Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
- if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
- ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
- }
- Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
- if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) {
- ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback();
- }
- }
-
- /**
- * refresh the underline for the label
- */
- protected void refreshUnderline() {
- @SuppressWarnings("unused")
- FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
- // cannot be done in the text area
- }
-
- /**
- * refresh the strike for the label
- */
- protected void refreshStrikeThrough() {
- @SuppressWarnings("unused")
- FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
- // cannot be done in the text area
- }
-
- /**
- * refresh font
- */
- @Override
- protected void refreshFont() {
- FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
- if (style != null) {
- FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
- setFont(fontData);
- }
- }
-
- /**
- * change the color
- */
- @Override
- protected void setFontColor(Color color) {
- getFigure().setForegroundColor(color);
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#addSemanticListeners()
- *
- */
- @Override
- protected void addSemanticListeners() {
- if (getParser() instanceof ISemanticParser) {
-
- EObject element = resolveSemanticElement();
- parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
- for (int i = 0; i < parserElements.size(); i++) {
- addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
- }
- } else {
- super.addSemanticListeners();
- }
- }
-
-
- /**
- * Gets the diagram event broker from the editing domain.
- *
- * @return the diagram event broker
- */
- protected DiagramEventBroker getDiagramEventBroker() {
- TransactionalEditingDomain theEditingDomain = getEditingDomain();
- if (theEditingDomain != null) {
- return DiagramEventBroker.getInstance(theEditingDomain);
- }
- return null;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#removeSemanticListeners()
- *
- */
- @Override
- protected void removeSemanticListeners() {
- if (parserElements != null) {
- for (int i = 0; i < parserElements.size(); i++) {
- removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
- }
- } else {
- super.removeSemanticListeners();
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getAccessibleEditPart()
- *
- */
- @Override
- protected AccessibleEditPart getAccessibleEditPart() {
- if (accessibleEP == null) {
- accessibleEP = new AccessibleGraphicalEditPart() {
-
- @Override
- public void getName(AccessibleEvent e) {
- e.result = getLabelTextHelper(getFigure());
- }
- };
- }
- return accessibleEP;
- }
-
- /**
- *
- * @return the view for the font style
- */
- private View getFontStyleOwnerView() {
- return (View) getModel();
- }
-
- /**
- * Returns the kind of associated editor for direct edition.
- *
- * @return an <code>int</code> corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition
- */
- public int getDirectEditionType() {
- if (checkExtendedEditor()) {
- initExtendedEditorConfiguration();
- return IDirectEdition.EXTENDED_DIRECT_EDITOR;
- }
- if (checkDefaultEdition()) {
- return IDirectEdition.DEFAULT_DIRECT_EDITOR;
- }
-
- // not a named element. no specific editor => do nothing
- return IDirectEdition.NO_DIRECT_EDITION;
- }
-
- /**
- * Checks if an extended editor is present.
- *
- * @return <code>true</code> if an extended editor is present.
- */
- protected boolean checkExtendedEditor() {
- if (resolveSemanticElement() != null) {
- return DirectEditorsUtil.hasSpecificEditorConfiguration(getAdapter(AppliedStereotypeProperty.class), this);
- }
- return false;
- }
-
- /**
- * Checks if a default direct edition is available
- *
- * @return <code>true</code> if a default direct edition is available
- */
- protected boolean checkDefaultEdition() {
- return (getParser() != null);
- }
-
- /**
- * Initializes the extended editor configuration
- *
- */
- protected void initExtendedEditorConfiguration() {
- if (configuration == null) {
- final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + AppliedStereotypeProperty.class.getName());
- Object resolveSemanticElement = getAdapter(AppliedStereotypeProperty.class);
- if (languagePreferred != null && !languagePreferred.equals("")) {
- configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement, this);
- } else {
- configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement, this);
- }
- }
- }
-
- /**
- * Updates the preference configuration
- *
- */
- protected void updateExtendedEditorConfiguration() {
- String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + AppliedStereotypeProperty.class.getName());
- if (languagePreferred != null && !languagePreferred.equals("") && languagePreferred != configuration.getLanguage()) {
- configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, getAdapter(AppliedStereotypeProperty.class), this);
- } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) {
- configuration = null;
- }
- }
-
- /**
- * Performs the direct edit usually used by GMF editors.
- *
- * @param theRequest
- * the direct edit request that starts the direct edit system
- */
- protected void performDefaultDirectEditorEdit(final Request theRequest) {
- // initialize the direct edit manager
- try {
- getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- if (isActive() && isEditable()) {
- if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
- Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
- performDirectEdit(initialChar.charValue());
- } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
- DirectEditRequest editRequest = (DirectEditRequest) theRequest;
- performDirectEdit(editRequest.getLocation());
- } else {
- performDirectEdit();
- }
- }
- }
- });
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#addNotationalListeners()
- *
- */
- @Override
- protected void addNotationalListeners() {
- super.addNotationalListeners();
- addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#removeNotationalListeners()
- *
- */
- @Override
- protected void removeNotationalListeners() {
- super.removeNotationalListeners();
- removeListenerFilter("PrimaryView"); //$NON-NLS-1$
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#handleNotificationEvent(org.eclipse.emf.common.notify.Notification)
- *
- */
- @Override
- protected void handleNotificationEvent(Notification event) {
- refreshLabel();
- Object feature = event.getFeature();
- if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
- Integer c = (Integer) event.getNewValue();
- setFontColor(DiagramColorRegistry.getInstance().getColor(c));
- } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
- refreshUnderline();
- } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
- refreshStrikeThrough();
- } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature)
- || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
- refreshFont();
- } else {
- if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
- refreshLabel();
- }
- if (getParser() instanceof ISemanticParser) {
- ISemanticParser modelParser = (ISemanticParser) getParser();
- if (modelParser.areSemanticElementsAffected(null, event)) {
- removeSemanticListeners();
- if (resolveSemanticElement() != null) {
- addSemanticListeners();
- }
- refreshLabel();
- }
- }
- }
-
- super.handleNotificationEvent(event);
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#createFigure()
- *
- */
- @Override
- protected IFigure createFigure() {
- return new EditingFlowPage();
- }
-
- /**
- *
- */
- private static final String ADD_PARENT_MODEL = "AddParentModel";
-
- protected EObject stereotypeApplication;
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#activate()
- *
- */
- @Override
- public void activate() {
- // before to be suppressed by its owner, the associate EObject can be UNSET, so refresh is prevented
- if (((View) getNotationView().eContainer() != null) && ((View) getNotationView().eContainer()).getElement() != null) {
- super.activate();
- addOwnerElementListeners();
- stereotypeApplication = ((View) getNotationView().eContainer()).getElement();
- final Element umlElement = UMLUtil.getBaseElement(stereotypeApplication);
- getDiagramEventBroker().addNotificationListener(stereotypeApplication, this);
- getDiagramEventBroker().addNotificationListener(umlElement, this);
- }
- }
-
- /**
- *
- */
- protected void addOwnerElementListeners() {
- addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel()));
-
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#deactivate()
- *
- */
- @Override
- public void deactivate() {
- removeOwnerElementListeners();
- super.deactivate();
- if (stereotypeApplication != null) {
- final Element umlElement = UMLUtil.getBaseElement(stereotypeApplication);
- getDiagramEventBroker().removeNotificationListener(stereotypeApplication, this);
- getDiagramEventBroker().removeNotificationListener(umlElement, this);
- }
- }
-
- /**
- *
- */
- protected void removeOwnerElementListeners() {
- removeListenerFilter(ADD_PARENT_MODEL);
-
- }
-
- /**
- * It has been overload in order to be display in the property view
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getAdapter(java.lang.Class)
- *
- * @param key
- * @return
- */
- @Override
- public Object getAdapter(Class key) {
- if (key == AppliedStereotypeProperty.class) {
- return new AppliedStereotypeProperty(((View) getNotationView().eContainer()).getElement(), (Property) resolveSemanticElement());
- }
- return null;
- }
-
- /**
- * locator for the multiline Cell
- *
- */
- static public class MultilineCellEditorLocator implements CellEditorLocator {
-
- private IMultilineEditableFigure multilineEditableFigure;
-
- public MultilineCellEditorLocator(IMultilineEditableFigure figure) {
- this.multilineEditableFigure = figure;
- }
-
- public IMultilineEditableFigure getMultilineEditableFigure() {
- return multilineEditableFigure;
- }
-
- public void relocate(CellEditor celleditor) {
- Text text = (Text) celleditor.getControl();
- Rectangle rect = getMultilineEditableFigure().getBounds().getCopy();
- rect.x = getMultilineEditableFigure().getEditionLocation().x;
- rect.y = getMultilineEditableFigure().getEditionLocation().y;
- getMultilineEditableFigure().translateToAbsolute(rect);
- if (getMultilineEditableFigure().getText().length() > 0) {
- rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT)));
- }
- if (!rect.equals(new Rectangle(text.getBounds()))) {
- text.setBounds(rect.x, rect.y, rect.width, rect.height);
- }
- }
-
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotypes Display
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.draw2d.text.FlowPage;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.RunnableWithResult;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.AccessibleEditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.requests.DirectEditRequest;
+import org.eclipse.gef.tools.CellEditorLocator;
+import org.eclipse.gef.tools.DirectEditManager;
+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.ParserOptions;
+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.CompartmentEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
+import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
+import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
+import org.eclipse.gmf.runtime.draw2d.ui.text.TextFlowEx;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
+import org.eclipse.gmf.runtime.notation.FontStyle;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ICellEditorValidator;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.extensionpoints.editors.Activator;
+import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration;
+import org.eclipse.papyrus.extensionpoints.editors.configuration.ICustomDirectEditorConfiguration;
+import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
+import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration;
+import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog;
+import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog;
+import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper;
+import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil;
+import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
+import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IControlParserForDirectEdit;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;
+import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypePropertyDirectEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.UMLTextSelectionEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.figure.node.EditingFlowPage;
+import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure;
+import org.eclipse.papyrus.uml.diagram.common.figure.node.IMultilineEditableFigure;
+import org.eclipse.papyrus.uml.diagram.common.parser.StereotypePropertyParser;
+import org.eclipse.papyrus.uml.profile.structure.AppliedStereotypeProperty;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.accessibility.AccessibleEvent;
+import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+/**
+ * the goal of this editpart is to edit a property of an application of the stereotype into a text area
+ *
+ */
+public class AppliedStereotypeMultilinePropertyEditPart extends CompartmentEditPart implements ITextAwareEditPart, NotificationListener, IPapyrusListener, IControlParserForDirectEdit {
+
+ public static final String ID = "Applied_Stereotype_Property"; //$NON-NLS-1$
+
+ private DirectEditManager manager;
+
+ private IParser parser;
+
+ private List<?> parserElements;
+
+ private String defaultText;
+
+ /**
+ * direct edition mode (default, undefined, registered editor, etc.)
+ *
+ */
+ protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR;
+
+ /**
+ * configuration from a registered edit dialog
+ *
+ */
+ protected IDirectEditorConfiguration configuration;
+
+ /**
+ * Constructor.
+ *
+ * @param view
+ */
+ public AppliedStereotypeMultilinePropertyEditPart(View view) {
+ super(view);
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart#createDefaultEditPolicies()
+ *
+ */
+ @Override
+ protected void createDefaultEditPolicies() {
+ super.createDefaultEditPolicies();
+ installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new UMLTextSelectionEditPolicy());
+ installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new AppliedStereotypePropertyDirectEditPolicy());
+ // installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UseCaseDiagramEditPart.NodeLabelDragPolicy());
+ }
+
+
+
+ /**
+ * get the text from the figure
+ *
+ * @param figure
+ * @return the text from the figure
+ */
+ protected String getLabelTextHelper(IFigure figure) {
+ // the figure is an ILabel Figure
+ if (figure instanceof ILabelFigure) {
+ return ((ILabelFigure) figure).getText();
+ }
+ return "";
+ }
+
+ /**
+ * set the text if not
+ */
+ protected void setLabelTextHelper(IFigure figure, String text) {
+ if (figure instanceof FlowPage) {
+ // remove all children from page.
+ ((FlowPage) figure).removeAll();
+
+
+ // generates new ones
+ generateBlockForText(text, ((FlowPage) figure));
+ }
+ }
+
+ /**
+ * Generates block list for the given text, and adds it to the root flow
+ * page
+ *
+ * @param text
+ * the string to display
+ */
+ protected void generateBlockForText(String text, FlowPage page) {
+ // return only one text flow with the content of the text
+ TextFlowEx textFlow = new TextFlowEx(text);
+ page.add(textFlow);
+ }
+
+ /**
+ * return icon from the figure
+ *
+ * @param figure
+ * @return the icon
+ */
+ protected Image getLabelIconHelper(IFigure figure) {
+ if (figure instanceof ILabelFigure) {
+ return ((ILabelFigure) figure).getIcon();
+ }
+ return null;
+ }
+
+ /**
+ * set the icon inot the figure
+ */
+ protected void setLabelIconHelper(IFigure figure, Image icon) {
+ if (figure instanceof ILabelFigure) {
+ ((ILabelFigure) figure).setIcon(icon);
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getModelChildren()
+ *
+ */
+ @Override
+ protected List getModelChildren() {
+ return Collections.EMPTY_LIST;
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getChildBySemanticHint(java.lang.String)
+ *
+ */
+ @Override
+ public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
+ return null;
+ }
+
+ /**
+ * the element that will display in the text area
+ *
+ * @return
+ */
+ protected EObject getParserElement() {
+ return resolveSemanticElement();
+ }
+
+ /**
+ * get the icon to display
+ */
+ protected Image getLabelIcon() {
+ return null;
+ }
+
+ /**
+ *
+ * @return the text to display in the label
+ */
+ protected String getLabelText() {
+ String text = null;
+ EObject parserElement = getParserElement();
+ if (parserElement != null && getParser() != null) {
+
+ EObject element = this.resolveSemanticElement();
+ SemanticAdapter sAdapter = new SemanticAdapter(element, getNotationView());
+
+ text = getParser().getPrintString(sAdapter, getParserOptions().intValue());
+ }
+ if (text == null || text.length() == 0) {
+ text = defaultText;
+ }
+ return text;
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#setLabelText(java.lang.String)
+ *
+ */
+
+ public void setLabelText(String text) {
+ setLabelTextHelper(getFigure(), text);
+ Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
+ if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
+ ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
+ }
+ Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
+ if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) {
+ ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getEditText()
+ *
+ */
+ public String getEditText() {
+ if (getParserElement() == null || getParser() == null) {
+ return ""; //$NON-NLS-1$
+ }
+
+ // return getParser().getEditString(new SemanticAdapter((EObject) this.getAdapter(AppliedStereotypeProperty.class), getNotationView()), getParserOptions().intValue());
+ return getParser().getEditString(new SemanticAdapter(resolveSemanticElement(), getNotationView()), getParserOptions().intValue());
+ }
+
+ /**
+ *
+ * @return true if this edit part is editable, it depends of the attribute derived of the property
+ */
+ protected boolean isEditable() {
+ if (!(((Property) resolveSemanticElement()).isDerived())) {
+ return getParser() != null;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getEditTextValidator()
+ *
+ */
+ public ICellEditorValidator getEditTextValidator() {
+ return new ICellEditorValidator() {
+
+ public String isValid(final Object value) {
+ if (value instanceof String) {
+ final EObject element = getParserElement();
+ final IParser parser = getParser();
+ try {
+ IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
+
+ public void run() {
+ setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
+ }
+ });
+ return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage();
+ } catch (InterruptedException ie) {
+ ie.printStackTrace();
+ }
+ }
+
+ // shouldn't get here
+ return null;
+ }
+ };
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getCompletionProcessor()
+ *
+ */
+ public IContentAssistProcessor getCompletionProcessor() {
+ if (getParserElement() == null || getParser() == null) {
+ return null;
+ }
+ return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getParserOptions()
+ *
+ */
+ public ParserOptions getParserOptions() {
+ return ParserOptions.NONE;
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getParser()
+ */
+ public IParser getParser() {
+ if (parser == null) {
+ parser = new StereotypePropertyParser();
+ }
+ return parser;
+ }
+
+ /**
+ *
+ * @return the manager to edit the label
+ */
+ protected DirectEditManager getManager() {
+ if (manager == null) {
+ setManager(new MultilineLabelDirectEditManager(this, MultilineLabelDirectEditManager.getTextCellEditorClass(this), new MultilineCellEditorLocator((IMultilineEditableFigure) getFigure())));
+ }
+ return manager;
+ }
+
+ /**
+ * set a manager to edit the label
+ */
+ protected void setManager(DirectEditManager manager) {
+ this.manager = manager;
+ }
+
+ /**
+ * do the edition
+ */
+ protected void performDirectEdit() {
+ BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
+
+ public void run() {
+ getManager().show();
+ }
+ });
+ }
+
+ /**
+ * Do the edition
+ *
+ * @param eventLocation
+ */
+ protected void performDirectEdit(Point eventLocation) {
+ if (getManager() instanceof TextDirectEditManager) {
+ ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
+ }
+ }
+
+ /**
+ * Do the edition
+ *
+ * @param initialCharacter
+ */
+ private void performDirectEdit(char initialCharacter) {
+ if (getManager() instanceof TextDirectEditManager) {
+ ((TextDirectEditManager) getManager()).show(initialCharacter);
+ } else {
+ performDirectEdit();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#performDirectEditRequest(org.eclipse.gef.Request)
+ *
+ */
+ @Override
+ protected void performDirectEditRequest(Request request) {
+
+ final Request theRequest = request;
+
+ if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) {
+ directEditionMode = getDirectEditionType();
+ }
+ switch (directEditionMode) {
+ case IDirectEdition.NO_DIRECT_EDITION:
+ // no direct edition mode => does nothing
+ return;
+ case IDirectEdition.EXTENDED_DIRECT_EDITOR:
+ updateExtendedEditorConfiguration();
+ if (configuration == null || configuration.getLanguage() == null) {
+ performDefaultDirectEditorEdit(theRequest);
+ } else {
+ configuration.preEditAction(getAdapter(AppliedStereotypeProperty.class));
+ Dialog dialog = null;
+ if (configuration instanceof ICustomDirectEditorConfiguration) {
+ setManager(((ICustomDirectEditorConfiguration) configuration)
+ .createDirectEditManager(this));
+ initializeDirectEditManager(theRequest);
+ return;
+ } else if (configuration instanceof IPopupEditorConfiguration) {
+ IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this);
+ if (helper != null) {
+ helper.showEditor();
+ }
+ return;
+ } else if (configuration instanceof IAdvancedEditorConfiguration) {
+ dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()));
+ } else if (configuration instanceof IDirectEditorConfiguration) {
+ dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), configuration);
+ } else {
+ return;
+ }
+ final Dialog finalDialog = dialog;
+
+ if (Window.OK == dialog.open()) {
+ TransactionalEditingDomain domain = getEditingDomain();
+ RecordingCommand command = new RecordingCommand(domain, "Edit Label") {
+
+ @Override
+ protected void doExecute() {
+ configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue());
+
+ }
+ };
+ domain.getCommandStack().execute(command);
+ }
+ }
+ break;
+ case IDirectEdition.DEFAULT_DIRECT_EDITOR:
+
+ // initialize the direct edit manager
+ try {
+ getEditingDomain().runExclusive(new Runnable() {
+
+ public void run() {
+ if (isActive() && isEditable()) {
+ if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
+ Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
+ performDirectEdit(initialChar.charValue());
+ } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
+ DirectEditRequest editRequest = (DirectEditRequest) theRequest;
+ performDirectEdit(editRequest.getLocation());
+ } else {
+ performDirectEdit();
+ }
+ }
+ }
+ });
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void setParser(IParser parser) {
+ this.parser = parser;
+ }
+
+ /**
+ */
+ protected void initializeDirectEditManager(final Request request) {
+ // initialize the direct edit manager
+ try {
+ getEditingDomain().runExclusive(new Runnable() {
+ public void run() {
+ if (isActive() && isEditable()) {
+ if (request
+ .getExtendedData()
+ .get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
+ Character initialChar = (Character) request
+ .getExtendedData()
+ .get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
+ performDirectEdit(initialChar.charValue());
+ } else if ((request instanceof DirectEditRequest)
+ && (getEditText().equals(getLabelText()))) {
+ DirectEditRequest editRequest = (DirectEditRequest) request;
+ performDirectEdit(editRequest.getLocation());
+ } else {
+ performDirectEdit();
+ }
+ }
+ }
+ });
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#refreshVisuals()
+ *
+ */
+ @Override
+ protected void refreshVisuals() {
+ super.refreshVisuals();
+ refreshLabel();
+ refreshFont();
+ refreshFontColor();
+ refreshUnderline();
+ refreshStrikeThrough();
+ }
+
+ /**
+ * refresh the label
+ */
+ protected void refreshLabel() {
+ EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
+ if (maskLabelPolicy == null) {
+ setLabelTextHelper(getFigure(), getLabelText());
+ }
+ Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
+ if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
+ ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
+ }
+ Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
+ if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) {
+ ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback();
+ }
+ }
+
+ /**
+ * refresh the underline for the label
+ */
+ protected void refreshUnderline() {
+ @SuppressWarnings("unused")
+ FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
+ // cannot be done in the text area
+ }
+
+ /**
+ * refresh the strike for the label
+ */
+ protected void refreshStrikeThrough() {
+ @SuppressWarnings("unused")
+ FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
+ // cannot be done in the text area
+ }
+
+ /**
+ * refresh font
+ */
+ @Override
+ protected void refreshFont() {
+ FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
+ if (style != null) {
+ FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
+ setFont(fontData);
+ }
+ }
+
+ /**
+ * change the color
+ */
+ @Override
+ protected void setFontColor(Color color) {
+ getFigure().setForegroundColor(color);
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#addSemanticListeners()
+ *
+ */
+ @Override
+ protected void addSemanticListeners() {
+ if (getParser() instanceof ISemanticParser) {
+
+ EObject element = resolveSemanticElement();
+ parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
+ for (int i = 0; i < parserElements.size(); i++) {
+ addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
+ }
+ } else {
+ super.addSemanticListeners();
+ }
+ }
+
+
+ /**
+ * Gets the diagram event broker from the editing domain.
+ *
+ * @return the diagram event broker
+ */
+ protected DiagramEventBroker getDiagramEventBroker() {
+ TransactionalEditingDomain theEditingDomain = getEditingDomain();
+ if (theEditingDomain != null) {
+ return DiagramEventBroker.getInstance(theEditingDomain);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#removeSemanticListeners()
+ *
+ */
+ @Override
+ protected void removeSemanticListeners() {
+ if (parserElements != null) {
+ for (int i = 0; i < parserElements.size(); i++) {
+ removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
+ }
+ } else {
+ super.removeSemanticListeners();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getAccessibleEditPart()
+ *
+ */
+ @Override
+ protected AccessibleEditPart getAccessibleEditPart() {
+ if (accessibleEP == null) {
+ accessibleEP = new AccessibleGraphicalEditPart() {
+
+ @Override
+ public void getName(AccessibleEvent e) {
+ e.result = getLabelTextHelper(getFigure());
+ }
+ };
+ }
+ return accessibleEP;
+ }
+
+ /**
+ *
+ * @return the view for the font style
+ */
+ private View getFontStyleOwnerView() {
+ return (View) getModel();
+ }
+
+ /**
+ * Returns the kind of associated editor for direct edition.
+ *
+ * @return an <code>int</code> corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition
+ */
+ public int getDirectEditionType() {
+ if (checkExtendedEditor()) {
+ initExtendedEditorConfiguration();
+ return IDirectEdition.EXTENDED_DIRECT_EDITOR;
+ }
+ if (checkDefaultEdition()) {
+ return IDirectEdition.DEFAULT_DIRECT_EDITOR;
+ }
+
+ // not a named element. no specific editor => do nothing
+ return IDirectEdition.NO_DIRECT_EDITION;
+ }
+
+ /**
+ * Checks if an extended editor is present.
+ *
+ * @return <code>true</code> if an extended editor is present.
+ */
+ protected boolean checkExtendedEditor() {
+ if (resolveSemanticElement() != null) {
+ return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName());
+ }
+ return false;
+ }
+
+ /**
+ * Checks if a default direct edition is available
+ *
+ * @return <code>true</code> if a default direct edition is available
+ */
+ protected boolean checkDefaultEdition() {
+ return (getParser() != null);
+ }
+
+ /**
+ * Initializes the extended editor configuration
+ *
+ */
+ protected void initExtendedEditorConfiguration() {
+ if (configuration == null) {
+ final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + AppliedStereotypeProperty.class.getName());
+ if (languagePreferred != null && !languagePreferred.equals("")) {
+ configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, AppliedStereotypeProperty.class.getName());
+ } else {
+ configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, AppliedStereotypeProperty.class.getName());
+ }
+ }
+ }
+
+ /**
+ * Updates the preference configuration
+ *
+ */
+ protected void updateExtendedEditorConfiguration() {
+ String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + AppliedStereotypeProperty.class.getName());
+ if (languagePreferred != null && !languagePreferred.equals("") && languagePreferred != configuration.getLanguage()) {
+ configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, AppliedStereotypeProperty.class.getName());
+ } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) {
+ configuration = null;
+ }
+ }
+
+ /**
+ * Performs the direct edit usually used by GMF editors.
+ *
+ * @param theRequest
+ * the direct edit request that starts the direct edit system
+ */
+ protected void performDefaultDirectEditorEdit(final Request theRequest) {
+ // initialize the direct edit manager
+ try {
+ getEditingDomain().runExclusive(new Runnable() {
+
+ public void run() {
+ if (isActive() && isEditable()) {
+ if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
+ Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
+ performDirectEdit(initialChar.charValue());
+ } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
+ DirectEditRequest editRequest = (DirectEditRequest) theRequest;
+ performDirectEdit(editRequest.getLocation());
+ } else {
+ performDirectEdit();
+ }
+ }
+ }
+ });
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#addNotationalListeners()
+ *
+ */
+ @Override
+ protected void addNotationalListeners() {
+ super.addNotationalListeners();
+ addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#removeNotationalListeners()
+ *
+ */
+ @Override
+ protected void removeNotationalListeners() {
+ super.removeNotationalListeners();
+ removeListenerFilter("PrimaryView"); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#handleNotificationEvent(org.eclipse.emf.common.notify.Notification)
+ *
+ */
+ @Override
+ protected void handleNotificationEvent(Notification event) {
+ refreshLabel();
+ Object feature = event.getFeature();
+ if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
+ Integer c = (Integer) event.getNewValue();
+ setFontColor(DiagramColorRegistry.getInstance().getColor(c));
+ } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
+ refreshUnderline();
+ } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
+ refreshStrikeThrough();
+ } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature)
+ || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
+ refreshFont();
+ } else {
+ if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
+ refreshLabel();
+ }
+ if (getParser() instanceof ISemanticParser) {
+ ISemanticParser modelParser = (ISemanticParser) getParser();
+ if (modelParser.areSemanticElementsAffected(null, event)) {
+ removeSemanticListeners();
+ if (resolveSemanticElement() != null) {
+ addSemanticListeners();
+ }
+ refreshLabel();
+ }
+ }
+ }
+
+ super.handleNotificationEvent(event);
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#createFigure()
+ *
+ */
+ @Override
+ protected IFigure createFigure() {
+ return new EditingFlowPage();
+ }
+
+ /**
+ *
+ */
+ private static final String ADD_PARENT_MODEL = "AddParentModel";
+
+ protected EObject stereotypeApplication;
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#activate()
+ *
+ */
+ @Override
+ public void activate() {
+ // before to be suppressed by its owner, the associate EObject can be UNSET, so refresh is prevented
+ if (((View) getNotationView().eContainer() != null) && ((View) getNotationView().eContainer()).getElement() != null) {
+ super.activate();
+ addOwnerElementListeners();
+ stereotypeApplication = ((View) getNotationView().eContainer()).getElement();
+ final Element umlElement = UMLUtil.getBaseElement(stereotypeApplication);
+ getDiagramEventBroker().addNotificationListener(stereotypeApplication, this);
+ getDiagramEventBroker().addNotificationListener(umlElement, this);
+ }
+ }
+
+ /**
+ *
+ */
+ protected void addOwnerElementListeners() {
+ addListenerFilter(ADD_PARENT_MODEL, this, ((View) getParent().getModel()));
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#deactivate()
+ *
+ */
+ @Override
+ public void deactivate() {
+ removeOwnerElementListeners();
+ super.deactivate();
+ if (stereotypeApplication != null) {
+ final Element umlElement = UMLUtil.getBaseElement(stereotypeApplication);
+ getDiagramEventBroker().removeNotificationListener(stereotypeApplication, this);
+ getDiagramEventBroker().removeNotificationListener(umlElement, this);
+ }
+ }
+
+ /**
+ *
+ */
+ protected void removeOwnerElementListeners() {
+ removeListenerFilter(ADD_PARENT_MODEL);
+
+ }
+
+ /**
+ * It has been overload in order to be display in the property view
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getAdapter(java.lang.Class)
+ *
+ * @param key
+ * @return
+ */
+ @Override
+ public Object getAdapter(Class key) {
+ if (key == AppliedStereotypeProperty.class) {
+ return new AppliedStereotypeProperty(((View) getNotationView().eContainer()).getElement(), (Property) resolveSemanticElement());
+ } else if (key == View.class) {
+ View view = this.getNotationView();
+ return view;
+ }
+
+ return null;
+ }
+
+
+
+ /**
+ * locator for the multiline Cell
+ *
+ */
+ static public class MultilineCellEditorLocator implements CellEditorLocator {
+
+ private IMultilineEditableFigure multilineEditableFigure;
+
+ public MultilineCellEditorLocator(IMultilineEditableFigure figure) {
+ this.multilineEditableFigure = figure;
+ }
+
+ public IMultilineEditableFigure getMultilineEditableFigure() {
+ return multilineEditableFigure;
+ }
+
+ public void relocate(CellEditor celleditor) {
+ Text text = (Text) celleditor.getControl();
+ Rectangle rect = getMultilineEditableFigure().getBounds().getCopy();
+ rect.x = getMultilineEditableFigure().getEditionLocation().x;
+ rect.y = getMultilineEditableFigure().getEditionLocation().y;
+ getMultilineEditableFigure().translateToAbsolute(rect);
+ if (getMultilineEditableFigure().getText().length() > 0) {
+ rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT)));
+ }
+ if (!rect.equals(new Rectangle(text.getBounds()))) {
+ text.setBounds(rect.x, rect.y, rect.width, rect.height);
+ }
+ }
+
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypePropertyEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypePropertyEditPart.java
index 7ec3110235e..3e42abcd013 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypePropertyEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypePropertyEditPart.java
@@ -1,950 +1,949 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- */
-package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.draw2d.FigureUtilities;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.Label;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.AccessibleEditPart;
-import org.eclipse.gef.DragTracker;
-import org.eclipse.gef.EditPolicy;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.requests.DirectEditRequest;
-import org.eclipse.gef.requests.SelectionRequest;
-import org.eclipse.gef.tools.CellEditorLocator;
-import org.eclipse.gef.tools.DirectEditManager;
-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.ParserOptions;
-import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
-import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
-import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
-import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
-import org.eclipse.gmf.runtime.notation.FontStyle;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ICellEditorValidator;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.extensionpoints.editors.Activator;
-import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration;
-import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
-import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration;
-import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog;
-import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog;
-import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper;
-import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil;
-import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
-import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;
-import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager;
-import org.eclipse.papyrus.uml.diagram.common.editparts.UMLCompartmentEditPart;
-import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition;
-import org.eclipse.papyrus.uml.diagram.common.editpolicies.UMLTextNonResizableEditPolicy;
-import org.eclipse.papyrus.uml.diagram.common.editpolicies.UMLTextSelectionEditPolicy;
-import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure;
-import org.eclipse.papyrus.uml.diagram.common.parser.StereotypePropertyParser;
-import org.eclipse.papyrus.uml.profile.structure.AppliedStereotypeProperty;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.accessibility.AccessibleEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.util.UMLUtil;
-
-
-/**
- * the goal of this editpart is to display property of stereotype in on line
- *
- */
-public class AppliedStereotypePropertyEditPart extends UMLCompartmentEditPart implements ITextAwareEditPart, IPrimaryEditPart {
-
-
- public static final String ID = "AppliedStereotypeProperty";
-
- private DirectEditManager manager;
-
- private IParser parser;
-
- private List<?> parserElements;
-
- protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR;
-
- protected IDirectEditorConfiguration configuration;
-
- public AppliedStereotypePropertyEditPart(View view) {
- super(view);
- }
-
-
- /**
- * Gets the diagram event broker from the editing domain.
- *
- * @return the diagram event broker
- */
- protected DiagramEventBroker getDiagramEventBroker() {
- TransactionalEditingDomain theEditingDomain = getEditingDomain();
- if (theEditingDomain != null) {
- return DiagramEventBroker.getInstance(theEditingDomain);
- }
- return null;
- }
-
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#activate()
- *
- */
- @Override
- public void activate() {
- super.activate();
- // add listeners of listen modification on application of stereotypes
- EObject stereotypeApplication = ((View) getNotationView().eContainer()).getElement();
- final Element umlElement = UMLUtil.getBaseElement(stereotypeApplication);
- getDiagramEventBroker().addNotificationListener(stereotypeApplication, this);
- getDiagramEventBroker().addNotificationListener(umlElement, this);
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#deactivate()
- *
- */
- @Override
- public void deactivate() {
- super.deactivate();
- // remove Listeners
- EObject stereotypeApplication = ((View) getNotationView().eContainer()).getElement();
- final Element umlElement = UMLUtil.getBaseElement(stereotypeApplication);
- getDiagramEventBroker().removeNotificationListener(stereotypeApplication, this);
- getDiagramEventBroker().removeNotificationListener(umlElement, this);
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart#getDragTracker(org.eclipse.gef.Request)
- *
- */
- @Override
- public DragTracker getDragTracker(Request request) {
- if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
- return null;
- }
- return new DragEditPartsTrackerEx(this);
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.editparts.UMLCompartmentEditPart#createDefaultEditPolicies()
- *
- */
- @Override
- protected void createDefaultEditPolicies() {
- super.createDefaultEditPolicies();
- // installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PropertyForClassItemSemanticEditPolicy());
- installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
- installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
- installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
- }
-
-
- /**
- * get the text from the figure
- *
- * @param figure
- * @return
- */
- protected String getLabelTextHelper(IFigure figure) {
- if (figure instanceof WrappingLabel) {
- return ((WrappingLabel) figure).getText();
- } else if (figure instanceof ILabelFigure) {
- return ((ILabelFigure) figure).getText();
- } else {
- return ((Label) figure).getText();
- }
- }
-
- /**
- * set the text into the figure
- *
- * @param figure
- * @param text
- */
- protected void setLabelTextHelper(IFigure figure, String text) {
- if (figure instanceof WrappingLabel) {
- ((WrappingLabel) figure).setText(text);
- } else if (figure instanceof ILabelFigure) {
- ((ILabelFigure) figure).setText(text);
- } else {
- ((Label) figure).setText(text);
- }
- }
-
- /**
- * get the icon from the figure
- *
- * @param figure
- * the figure
- * @return the icon
- */
- protected Image getLabelIconHelper(IFigure figure) {
- if (figure instanceof WrappingLabel) {
- return ((WrappingLabel) figure).getIcon();
- } else if (figure instanceof ILabelFigure) {
- return ((ILabelFigure) figure).getIcon();
- } else {
- return ((Label) figure).getIcon();
- }
- }
-
- /**
- * set the icon into the figure
- *
- * @param figure
- * get the figure
- * @param icon
- */
- protected void setLabelIconHelper(IFigure figure, Image icon) {
- if (figure instanceof WrappingLabel) {
- ((WrappingLabel) figure).setIcon(icon);
- } else if (figure instanceof ILabelFigure) {
- ((ILabelFigure) figure).setIcon(icon);
- } else {
- ((Label) figure).setIcon(icon);
- }
- }
-
- public void setLabel(IFigure figure) {
- unregisterVisuals();
- setFigure(figure);
- registerVisuals();
- refreshVisuals();
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getModelChildren()
- *
- */
- @Override
- @SuppressWarnings("rawtypes")
- protected List getModelChildren() {
- return Collections.EMPTY_LIST;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getChildBySemanticHint(java.lang.String)
- *
- */
- @Override
- public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
- return null;
- }
-
- /**
- *
- * @return the element that will be edited
- */
- protected EObject getParserElement() {
- return resolveSemanticElement();
- }
-
- /**
- *
- * @return null for the icon of the label
- */
- protected Image getLabelIcon() {
- return null;
- }
-
- /**
- *
- * @return a string that is the presentation of the element into the label
- */
- protected String getLabelText() {
- String text = null;
- EObject parserElement = getParserElement();
- if (parserElement != null && getParser() != null) {
- text = getParser().getPrintString(new SemanticAdapter(this.resolveSemanticElement(), getNotationView()), getParserOptions().intValue());
- }
- if (text == null || text.length() == 0) {
- text = "SterotypeProperty";
- }
- return text;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#setLabelText(java.lang.String)
- *
- */
- public void setLabelText(String text) {
- setLabelTextHelper(getFigure(), text);
- Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
- if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
- ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
- }
- Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
- if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) {
- ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback();
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getEditText()
- *
- */
- public String getEditText() {
- if (getParserElement() == null || getParser() == null) {
- return ""; //$NON-NLS-1$
- }
- return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
- }
-
- /**
- *
- * @return the label is editable
- */
- protected boolean isEditable() {
- if (!(((Property) resolveSemanticElement()).isDerived())) {
- return getParser() != null;
- } else {
- return false;
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getEditTextValidator()
- *
- */
- public ICellEditorValidator getEditTextValidator() {
- return new ICellEditorValidator() {
-
- public String isValid(final Object value) {
- if (value instanceof String) {
- final EObject element = getParserElement();
- final IParser parser = getParser();
- try {
- @SuppressWarnings("rawtypes")
- IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
-
- @SuppressWarnings("unchecked")
- public void run() {
- setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
- }
- });
- return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage();
- } catch (InterruptedException ie) {
- ie.printStackTrace();
- }
- }
-
- // shouldn't get here
- return null;
- }
- };
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getCompletionProcessor()
- *
- */
- public IContentAssistProcessor getCompletionProcessor() {
- if (getParserElement() == null || getParser() == null) {
- return null;
- }
- return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getParserOptions()
- *
- */
- public ParserOptions getParserOptions() {
- return ParserOptions.NONE;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getParser()
- *
- */
- public IParser getParser() {
- if (parser == null) {
- parser = new StereotypePropertyParser();
- }
- return parser;
- }
-
- /**
- * get the manager in charge of the edition
- *
- * @return the directEditManager
- */
- protected DirectEditManager getManager() {
- if (manager == null) {
- setManager(new MultilineLabelDirectEditManager(this, MultilineLabelDirectEditManager.getTextCellEditorClass(this), getTextCellEditorLocator(this)));
- }
- return manager;
- }
-
-
- public static CellEditorLocator getTextCellEditorLocator(ITextAwareEditPart source) {
- if (source.getFigure() instanceof WrappingLabel) {
- return new TextCellEditorLocator((WrappingLabel) source.getFigure());
- }
- return null;
-
- }
-
- /**
- * set the manager in charge of the edition
- *
- * @param manager
- */
- protected void setManager(DirectEditManager manager) {
- this.manager = manager;
- }
-
- /**
- * perform the edtion of the label
- */
- protected void performDirectEdit() {
- getManager().show();
- }
-
- /**
- * perform the edtion of the label
- *
- * @param eventLocation
- */
- protected void performDirectEdit(Point eventLocation) {
- if (getManager() instanceof TextDirectEditManager) {
- ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
- }
- }
-
- /**
- * perform the edition
- */
- private void performDirectEdit(char initialCharacter) {
- if (getManager() instanceof TextDirectEditManager) {
- ((TextDirectEditManager) getManager()).show(initialCharacter);
- } else {
- performDirectEdit();
- }
- }
-
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#performDirectEditRequest(org.eclipse.gef.Request)
- */
- @Override
- protected void performDirectEditRequest(Request request) {
-
- final Request theRequest = request;
-
- if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) {
- directEditionMode = getDirectEditionType();
- }
- switch (directEditionMode) {
- case IDirectEdition.NO_DIRECT_EDITION:
- // no direct edition mode => does nothing
- return;
- case IDirectEdition.EXTENDED_DIRECT_EDITOR:
- updateExtendedEditorConfiguration();
- if (configuration == null || configuration.getLanguage() == null) {
- performDefaultDirectEditorEdit(theRequest);
- } else {
- configuration.preEditAction(resolveSemanticElement());
- Dialog dialog = null;
- if (configuration instanceof IPopupEditorConfiguration) {
- IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this);
- helper.showEditor();
- return;
- } else if (configuration instanceof IAdvancedEditorConfiguration) {
- dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()));
- } else if (configuration instanceof IDirectEditorConfiguration) {
- dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), configuration);
- } else {
- return;
- }
- final Dialog finalDialog = dialog;
-
- if (Window.OK == dialog.open()) {
- TransactionalEditingDomain domain = getEditingDomain();
- RecordingCommand command = new RecordingCommand(domain, "Edit Label") {
-
- @Override
- protected void doExecute() {
- configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue());
-
- }
- };
- domain.getCommandStack().execute(command);
- }
- }
- break;
- case IDirectEdition.DEFAULT_DIRECT_EDITOR:
-
- // initialize the direct edit manager
- try {
- getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- if (isActive() && isEditable()) {
- if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
- Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
- performDirectEdit(initialChar.charValue());
- } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
- DirectEditRequest editRequest = (DirectEditRequest) theRequest;
- performDirectEdit(editRequest.getLocation());
- } else {
- performDirectEdit();
- }
- }
- }
- });
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- break;
- default:
- break;
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#refreshVisuals()
- *
- */
- @Override
- protected void refreshVisuals() {
- super.refreshVisuals();
- refreshLabel();
- refreshFont();
- refreshFontColor();
- refreshUnderline();
- refreshStrikeThrough();
- }
-
- /**
- * refresh the associated label by taking in account the semantic
- */
- protected void refreshLabel() {
- EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
- if (maskLabelPolicy == null) {
- setLabelTextHelper(getFigure(), getLabelText());
- setLabelIconHelper(getFigure(), getLabelIcon());
- }
- Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
- if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
- ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
- }
- Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
- if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) {
- ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback();
- }
- }
-
-
- /**
- * specific refresh for the underline
- */
- protected void refreshUnderline() {
- FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
- if (style != null && getFigure() instanceof WrappingLabel) {
- ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline());
- }
- }
-
- /**
- * specific refresh strick for the label
- */
- protected void refreshStrikeThrough() {
- FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
- if (style != null && getFigure() instanceof WrappingLabel) {
- ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#refreshFont()
- *
- */
- @Override
- protected void refreshFont() {
- FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
- if (style != null) {
- FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
- setFont(fontData);
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#setFontColor(org.eclipse.swt.graphics.Color)
- *
- */
- @Override
- protected void setFontColor(Color color) {
- getFigure().setForegroundColor(color);
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#addSemanticListeners()
- *
- */
- @Override
- protected void addSemanticListeners() {
- if (getParser() instanceof ISemanticParser) {
- // listen stereotype application
- EObject StereotypeApplication = ((View) getNotationView().eContainer()).getElement();
- addListenerFilter("SemanticModelForStereotypeApplication", this, StereotypeApplication); //$NON-NLS-1$
- EObject element = resolveSemanticElement();
- parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
- for (int i = 0; i < parserElements.size(); i++) {
- addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
- }
- } else {
- super.addSemanticListeners();
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#removeSemanticListeners()
- *
- */
- @Override
- protected void removeSemanticListeners() {
- // remove listener on the stereotype application
- removeListenerFilter("SemanticModelForStereotypeApplication"); //$NON-NLS-1$
- if (parserElements != null) {
- for (int i = 0; i < parserElements.size(); i++) {
- removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
- }
- } else {
- super.removeSemanticListeners();
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getAccessibleEditPart()
- *
- */
- @Override
- protected AccessibleEditPart getAccessibleEditPart() {
- if (accessibleEP == null) {
- accessibleEP = new AccessibleGraphicalEditPart() {
-
- @Override
- public void getName(AccessibleEvent e) {
- e.result = getLabelTextHelper(getFigure());
- }
- };
- }
- return accessibleEP;
- }
-
- private View getFontStyleOwnerView() {
- return (View) getModel();
- }
-
- /**
- * Returns the kind of associated editor for direct edition.
- *
- * @return an <code>int</code> corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition
- */
- public int getDirectEditionType() {
- if (checkExtendedEditor()) {
- initExtendedEditorConfiguration();
- return IDirectEdition.EXTENDED_DIRECT_EDITOR;
- }
- if (checkDefaultEdition()) {
- return IDirectEdition.DEFAULT_DIRECT_EDITOR;
- }
-
- // not a named element. no specific editor => do nothing
- return IDirectEdition.NO_DIRECT_EDITION;
- }
-
- /**
- * Checks if an extended editor is present.
- *
- * @return <code>true</code> if an extended editor is present.
- */
- protected boolean checkExtendedEditor() {
- if (resolveSemanticElement() != null) {
- return DirectEditorsUtil.hasSpecificEditorConfiguration(getAdapter(AppliedStereotypeProperty.class), this);
- }
- return false;
- }
-
- /**
- * Checks if a default direct edition is available
- *
- * @return <code>true</code> if a default direct edition is available
- */
- protected boolean checkDefaultEdition() {
- return (getParser() != null);
- }
-
- /**
- * Initializes the extended editor configuration
- *
- */
- protected void initExtendedEditorConfiguration() {
- if (configuration == null) {
- Object semanticElement = getAdapter(AppliedStereotypeProperty.class);
- final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + semanticElement);
- if (languagePreferred != null && !languagePreferred.equals("")) {
- configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, semanticElement, this);
- } else {
- configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, semanticElement, this);
- }
- }
- }
-
- /**
- * Updates the preference configuration
- *
- */
- protected void updateExtendedEditorConfiguration() {
- String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
- if (languagePreferred != null && !languagePreferred.equals("") && languagePreferred != configuration.getLanguage()) {
- configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, getAdapter(AppliedStereotypeProperty.class), this);
- } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) {
- configuration = null;
- }
- }
-
- /**
- * Performs the direct edit usually used by GMF editors.
- *
- * @param theRequest
- * the direct edit request that starts the direct edit system
- */
- protected void performDefaultDirectEditorEdit(final Request theRequest) {
- // initialize the direct edit manager
- try {
- getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- if (isActive() && isEditable()) {
- if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
- Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
- performDirectEdit(initialChar.charValue());
- } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
- DirectEditRequest editRequest = (DirectEditRequest) theRequest;
- performDirectEdit(editRequest.getLocation());
- } else {
- performDirectEdit();
- }
- }
- }
- });
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#addNotationalListeners()
- *
- */
- @Override
- protected void addNotationalListeners() {
- super.addNotationalListeners();
- addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#removeNotationalListeners()
- *
- */
- @Override
- protected void removeNotationalListeners() {
- super.removeNotationalListeners();
- removeListenerFilter("PrimaryView"); //$NON-NLS-1$
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#handleNotificationEvent(org.eclipse.emf.common.notify.Notification)
- *
- */
- @Override
- protected void handleNotificationEvent(Notification event) {
- Object feature = event.getFeature();
- if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
- Integer c = (Integer) event.getNewValue();
- setFontColor(DiagramColorRegistry.getInstance().getColor(c));
- } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
- refreshUnderline();
- } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
- refreshStrikeThrough();
- } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature)
- || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
- refreshFont();
- } else {
- if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
- refreshLabel();
- }
- if (getParser() instanceof ISemanticParser) {
- ISemanticParser modelParser = (ISemanticParser) getParser();
- if (modelParser.areSemanticElementsAffected(null, event)) {
- removeSemanticListeners();
- if (resolveSemanticElement() != null) {
- addSemanticListeners();
- }
- refreshLabel();
- }
- }
- }
- super.handleNotificationEvent(event);
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#createFigure()
- *
- */
- @Override
- protected IFigure createFigure() {
- return new PropertyFigureDescriptor();
- }
-
- /**
- * this method has been overloaded in order to be able to display it into the proeprtyView
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getAdapter(java.lang.Class)
- *
- */
- @Override
- public Object getAdapter(Class key) {
- if (key == AppliedStereotypeProperty.class) {
- return new AppliedStereotypeProperty(((View) getNotationView().eContainer()).getElement(), (Property) resolveSemanticElement());
- }
- return null;
- // return super.getAdapter(key);
- }
-
- /**
- * @generated
- */
- static private class TextCellEditorLocator implements CellEditorLocator {
-
- /**
- * @generated
- */
- private WrappingLabel wrapLabel;
-
- /**
- * @generated
- */
- public TextCellEditorLocator(WrappingLabel wrapLabel) {
- this.wrapLabel = wrapLabel;
- }
-
- /**
- * @generated
- */
- public WrappingLabel getWrapLabel() {
- return wrapLabel;
- }
-
- /**
- * @generated
- */
- public void relocate(CellEditor celleditor) {
- Text text = (Text) celleditor.getControl();
- Rectangle rect = getWrapLabel().getTextBounds().getCopy();
- getWrapLabel().translateToAbsolute(rect);
- if (!text.getFont().isDisposed()) {
- if (getWrapLabel().isTextWrapOn() && getWrapLabel().getText().length() > 0) {
- rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT)));
- } else {
- int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
- rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
- }
- }
- if (!rect.equals(new Rectangle(text.getBounds()))) {
- text.setBounds(rect.x, rect.y, rect.width, rect.height);
- }
- }
- }
-
-
- /**
- * the figure associated to this editpart
- *
- */
- public class PropertyFigureDescriptor extends WrappingLabel {
-
- /**
- * @generated
- */
- public PropertyFigureDescriptor() {
- this.setText("");
-
- this.setFont(THIS_FONT);
-
- }
-
- }
-
- static final Font THIS_FONT = new Font(Display.getCurrent(), "Arial", 10, SWT.NORMAL);
-
-}
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ */
+package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.draw2d.FigureUtilities;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.RunnableWithResult;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.AccessibleEditPart;
+import org.eclipse.gef.DragTracker;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.requests.DirectEditRequest;
+import org.eclipse.gef.requests.SelectionRequest;
+import org.eclipse.gef.tools.CellEditorLocator;
+import org.eclipse.gef.tools.DirectEditManager;
+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.ParserOptions;
+import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ListItemComponentEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
+import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
+import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
+import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
+import org.eclipse.gmf.runtime.notation.FontStyle;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ICellEditorValidator;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.extensionpoints.editors.Activator;
+import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration;
+import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
+import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration;
+import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog;
+import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog;
+import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper;
+import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil;
+import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;
+import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager;
+import org.eclipse.papyrus.uml.diagram.common.editparts.UMLCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.UMLTextNonResizableEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.UMLTextSelectionEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure;
+import org.eclipse.papyrus.uml.diagram.common.parser.StereotypePropertyParser;
+import org.eclipse.papyrus.uml.profile.structure.AppliedStereotypeProperty;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.accessibility.AccessibleEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+
+/**
+ * the goal of this editpart is to display property of stereotype in on line
+ *
+ */
+public class AppliedStereotypePropertyEditPart extends UMLCompartmentEditPart implements ITextAwareEditPart, IPrimaryEditPart {
+
+
+ public static final String ID = "AppliedStereotypeProperty";
+
+ private DirectEditManager manager;
+
+ private IParser parser;
+
+ private List<?> parserElements;
+
+ protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR;
+
+ protected IDirectEditorConfiguration configuration;
+
+ public AppliedStereotypePropertyEditPart(View view) {
+ super(view);
+ }
+
+
+ /**
+ * Gets the diagram event broker from the editing domain.
+ *
+ * @return the diagram event broker
+ */
+ protected DiagramEventBroker getDiagramEventBroker() {
+ TransactionalEditingDomain theEditingDomain = getEditingDomain();
+ if (theEditingDomain != null) {
+ return DiagramEventBroker.getInstance(theEditingDomain);
+ }
+ return null;
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#activate()
+ *
+ */
+ @Override
+ public void activate() {
+ super.activate();
+ // add listeners of listen modification on application of stereotypes
+ EObject stereotypeApplication = ((View) getNotationView().eContainer()).getElement();
+ final Element umlElement = UMLUtil.getBaseElement(stereotypeApplication);
+ getDiagramEventBroker().addNotificationListener(stereotypeApplication, this);
+ getDiagramEventBroker().addNotificationListener(umlElement, this);
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#deactivate()
+ *
+ */
+ @Override
+ public void deactivate() {
+ super.deactivate();
+ // remove Listeners
+ EObject stereotypeApplication = ((View) getNotationView().eContainer()).getElement();
+ final Element umlElement = UMLUtil.getBaseElement(stereotypeApplication);
+ getDiagramEventBroker().removeNotificationListener(stereotypeApplication, this);
+ getDiagramEventBroker().removeNotificationListener(umlElement, this);
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart#getDragTracker(org.eclipse.gef.Request)
+ *
+ */
+ @Override
+ public DragTracker getDragTracker(Request request) {
+ if (request instanceof SelectionRequest && ((SelectionRequest) request).getLastButtonPressed() == 3) {
+ return null;
+ }
+ return new DragEditPartsTrackerEx(this);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.diagram.common.editparts.UMLCompartmentEditPart#createDefaultEditPolicies()
+ *
+ */
+ @Override
+ protected void createDefaultEditPolicies() {
+ super.createDefaultEditPolicies();
+ // installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PropertyForClassItemSemanticEditPolicy());
+ installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new UMLTextNonResizableEditPolicy());
+ installEditPolicy(EditPolicy.COMPONENT_ROLE, new ListItemComponentEditPolicy());
+ installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
+ }
+
+
+ /**
+ * get the text from the figure
+ *
+ * @param figure
+ * @return
+ */
+ protected String getLabelTextHelper(IFigure figure) {
+ if (figure instanceof WrappingLabel) {
+ return ((WrappingLabel) figure).getText();
+ } else if (figure instanceof ILabelFigure) {
+ return ((ILabelFigure) figure).getText();
+ } else {
+ return ((Label) figure).getText();
+ }
+ }
+
+ /**
+ * set the text into the figure
+ *
+ * @param figure
+ * @param text
+ */
+ protected void setLabelTextHelper(IFigure figure, String text) {
+ if (figure instanceof WrappingLabel) {
+ ((WrappingLabel) figure).setText(text);
+ } else if (figure instanceof ILabelFigure) {
+ ((ILabelFigure) figure).setText(text);
+ } else {
+ ((Label) figure).setText(text);
+ }
+ }
+
+ /**
+ * get the icon from the figure
+ *
+ * @param figure
+ * the figure
+ * @return the icon
+ */
+ protected Image getLabelIconHelper(IFigure figure) {
+ if (figure instanceof WrappingLabel) {
+ return ((WrappingLabel) figure).getIcon();
+ } else if (figure instanceof ILabelFigure) {
+ return ((ILabelFigure) figure).getIcon();
+ } else {
+ return ((Label) figure).getIcon();
+ }
+ }
+
+ /**
+ * set the icon into the figure
+ *
+ * @param figure
+ * get the figure
+ * @param icon
+ */
+ protected void setLabelIconHelper(IFigure figure, Image icon) {
+ if (figure instanceof WrappingLabel) {
+ ((WrappingLabel) figure).setIcon(icon);
+ } else if (figure instanceof ILabelFigure) {
+ ((ILabelFigure) figure).setIcon(icon);
+ } else {
+ ((Label) figure).setIcon(icon);
+ }
+ }
+
+ public void setLabel(IFigure figure) {
+ unregisterVisuals();
+ setFigure(figure);
+ registerVisuals();
+ refreshVisuals();
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getModelChildren()
+ *
+ */
+ @Override
+ @SuppressWarnings("rawtypes")
+ protected List getModelChildren() {
+ return Collections.EMPTY_LIST;
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getChildBySemanticHint(java.lang.String)
+ *
+ */
+ @Override
+ public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
+ return null;
+ }
+
+ /**
+ *
+ * @return the element that will be edited
+ */
+ protected EObject getParserElement() {
+ return resolveSemanticElement();
+ }
+
+ /**
+ *
+ * @return null for the icon of the label
+ */
+ protected Image getLabelIcon() {
+ return null;
+ }
+
+ /**
+ *
+ * @return a string that is the presentation of the element into the label
+ */
+ protected String getLabelText() {
+ String text = null;
+ EObject parserElement = getParserElement();
+ if (parserElement != null && getParser() != null) {
+ text = getParser().getPrintString(new SemanticAdapter(this.resolveSemanticElement(), getNotationView()), getParserOptions().intValue());
+ }
+ if (text == null || text.length() == 0) {
+ text = "SterotypeProperty";
+ }
+ return text;
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#setLabelText(java.lang.String)
+ *
+ */
+ public void setLabelText(String text) {
+ setLabelTextHelper(getFigure(), text);
+ Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
+ if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
+ ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
+ }
+ Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
+ if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) {
+ ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getEditText()
+ *
+ */
+ public String getEditText() {
+ if (getParserElement() == null || getParser() == null) {
+ return ""; //$NON-NLS-1$
+ }
+ return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
+ }
+
+ /**
+ *
+ * @return the label is editable
+ */
+ protected boolean isEditable() {
+ if (!(((Property) resolveSemanticElement()).isDerived())) {
+ return getParser() != null;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getEditTextValidator()
+ *
+ */
+ public ICellEditorValidator getEditTextValidator() {
+ return new ICellEditorValidator() {
+
+ public String isValid(final Object value) {
+ if (value instanceof String) {
+ final EObject element = getParserElement();
+ final IParser parser = getParser();
+ try {
+ @SuppressWarnings("rawtypes")
+ IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
+
+ @SuppressWarnings("unchecked")
+ public void run() {
+ setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
+ }
+ });
+ return valid.getCode() == IParserEditStatus.EDITABLE ? null : valid.getMessage();
+ } catch (InterruptedException ie) {
+ ie.printStackTrace();
+ }
+ }
+
+ // shouldn't get here
+ return null;
+ }
+ };
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getCompletionProcessor()
+ *
+ */
+ public IContentAssistProcessor getCompletionProcessor() {
+ if (getParserElement() == null || getParser() == null) {
+ return null;
+ }
+ return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getParserOptions()
+ *
+ */
+ public ParserOptions getParserOptions() {
+ return ParserOptions.NONE;
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart#getParser()
+ *
+ */
+ public IParser getParser() {
+ if (parser == null) {
+ parser = new StereotypePropertyParser();
+ }
+ return parser;
+ }
+
+ /**
+ * get the manager in charge of the edition
+ *
+ * @return the directEditManager
+ */
+ protected DirectEditManager getManager() {
+ if (manager == null) {
+ setManager(new MultilineLabelDirectEditManager(this, MultilineLabelDirectEditManager.getTextCellEditorClass(this), getTextCellEditorLocator(this)));
+ }
+ return manager;
+ }
+
+
+ public static CellEditorLocator getTextCellEditorLocator(ITextAwareEditPart source) {
+ if (source.getFigure() instanceof WrappingLabel) {
+ return new TextCellEditorLocator((WrappingLabel) source.getFigure());
+ }
+ return null;
+
+ }
+
+ /**
+ * set the manager in charge of the edition
+ *
+ * @param manager
+ */
+ protected void setManager(DirectEditManager manager) {
+ this.manager = manager;
+ }
+
+ /**
+ * perform the edtion of the label
+ */
+ protected void performDirectEdit() {
+ getManager().show();
+ }
+
+ /**
+ * perform the edtion of the label
+ *
+ * @param eventLocation
+ */
+ protected void performDirectEdit(Point eventLocation) {
+ if (getManager() instanceof TextDirectEditManager) {
+ ((TextDirectEditManager) getManager()).show(eventLocation.getSWTPoint());
+ }
+ }
+
+ /**
+ * perform the edition
+ */
+ private void performDirectEdit(char initialCharacter) {
+ if (getManager() instanceof TextDirectEditManager) {
+ ((TextDirectEditManager) getManager()).show(initialCharacter);
+ } else {
+ performDirectEdit();
+ }
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#performDirectEditRequest(org.eclipse.gef.Request)
+ */
+ @Override
+ protected void performDirectEditRequest(Request request) {
+
+ final Request theRequest = request;
+
+ if (IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) {
+ directEditionMode = getDirectEditionType();
+ }
+ switch (directEditionMode) {
+ case IDirectEdition.NO_DIRECT_EDITION:
+ // no direct edition mode => does nothing
+ return;
+ case IDirectEdition.EXTENDED_DIRECT_EDITOR:
+ updateExtendedEditorConfiguration();
+ if (configuration == null || configuration.getLanguage() == null) {
+ performDefaultDirectEditorEdit(theRequest);
+ } else {
+ configuration.preEditAction(resolveSemanticElement());
+ Dialog dialog = null;
+ if (configuration instanceof IPopupEditorConfiguration) {
+ IPopupEditorHelper helper = ((IPopupEditorConfiguration) configuration).createPopupEditorHelper(this);
+ helper.showEditor();
+ return;
+ } else if (configuration instanceof IAdvancedEditorConfiguration) {
+ dialog = ((IAdvancedEditorConfiguration) configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()));
+ } else if (configuration instanceof IDirectEditorConfiguration) {
+ dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()), configuration);
+ } else {
+ return;
+ }
+ final Dialog finalDialog = dialog;
+
+ if (Window.OK == dialog.open()) {
+ TransactionalEditingDomain domain = getEditingDomain();
+ RecordingCommand command = new RecordingCommand(domain, "Edit Label") {
+
+ @Override
+ protected void doExecute() {
+ configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog) finalDialog).getValue());
+
+ }
+ };
+ domain.getCommandStack().execute(command);
+ }
+ }
+ break;
+ case IDirectEdition.DEFAULT_DIRECT_EDITOR:
+
+ // initialize the direct edit manager
+ try {
+ getEditingDomain().runExclusive(new Runnable() {
+
+ public void run() {
+ if (isActive() && isEditable()) {
+ if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
+ Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
+ performDirectEdit(initialChar.charValue());
+ } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
+ DirectEditRequest editRequest = (DirectEditRequest) theRequest;
+ performDirectEdit(editRequest.getLocation());
+ } else {
+ performDirectEdit();
+ }
+ }
+ }
+ });
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#refreshVisuals()
+ *
+ */
+ @Override
+ protected void refreshVisuals() {
+ super.refreshVisuals();
+ refreshLabel();
+ refreshFont();
+ refreshFontColor();
+ refreshUnderline();
+ refreshStrikeThrough();
+ }
+
+ /**
+ * refresh the associated label by taking in account the semantic
+ */
+ protected void refreshLabel() {
+ EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
+ if (maskLabelPolicy == null) {
+ setLabelTextHelper(getFigure(), getLabelText());
+ setLabelIconHelper(getFigure(), getLabelIcon());
+ }
+ Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
+ if (pdEditPolicy instanceof UMLTextSelectionEditPolicy) {
+ ((UMLTextSelectionEditPolicy) pdEditPolicy).refreshFeedback();
+ }
+ Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
+ if (sfEditPolicy instanceof UMLTextSelectionEditPolicy) {
+ ((UMLTextSelectionEditPolicy) sfEditPolicy).refreshFeedback();
+ }
+ }
+
+
+ /**
+ * specific refresh for the underline
+ */
+ protected void refreshUnderline() {
+ FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
+ if (style != null && getFigure() instanceof WrappingLabel) {
+ ((WrappingLabel) getFigure()).setTextUnderline(style.isUnderline());
+ }
+ }
+
+ /**
+ * specific refresh strick for the label
+ */
+ protected void refreshStrikeThrough() {
+ FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
+ if (style != null && getFigure() instanceof WrappingLabel) {
+ ((WrappingLabel) getFigure()).setTextStrikeThrough(style.isStrikeThrough());
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#refreshFont()
+ *
+ */
+ @Override
+ protected void refreshFont() {
+ FontStyle style = (FontStyle) getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
+ if (style != null) {
+ FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
+ setFont(fontData);
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#setFontColor(org.eclipse.swt.graphics.Color)
+ *
+ */
+ @Override
+ protected void setFontColor(Color color) {
+ getFigure().setForegroundColor(color);
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#addSemanticListeners()
+ *
+ */
+ @Override
+ protected void addSemanticListeners() {
+ if (getParser() instanceof ISemanticParser) {
+ // listen stereotype application
+ EObject stereotypeApplication = ((View) getNotationView().eContainer()).getElement();
+ addListenerFilter("SemanticModelForStereotypeApplication", this, stereotypeApplication); //$NON-NLS-1$
+ EObject element = resolveSemanticElement();
+ parserElements = ((ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
+ for (int i = 0; i < parserElements.size(); i++) {
+ addListenerFilter("SemanticModel" + i, this, (EObject) parserElements.get(i)); //$NON-NLS-1$
+ }
+ } else {
+ super.addSemanticListeners();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#removeSemanticListeners()
+ *
+ */
+ @Override
+ protected void removeSemanticListeners() {
+ // remove listener on the stereotype application
+ removeListenerFilter("SemanticModelForStereotypeApplication"); //$NON-NLS-1$
+ if (parserElements != null) {
+ for (int i = 0; i < parserElements.size(); i++) {
+ removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
+ }
+ } else {
+ super.removeSemanticListeners();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getAccessibleEditPart()
+ *
+ */
+ @Override
+ protected AccessibleEditPart getAccessibleEditPart() {
+ if (accessibleEP == null) {
+ accessibleEP = new AccessibleGraphicalEditPart() {
+
+ @Override
+ public void getName(AccessibleEvent e) {
+ e.result = getLabelTextHelper(getFigure());
+ }
+ };
+ }
+ return accessibleEP;
+ }
+
+ private View getFontStyleOwnerView() {
+ return (View) getModel();
+ }
+
+ /**
+ * Returns the kind of associated editor for direct edition.
+ *
+ * @return an <code>int</code> corresponding to the kind of direct editor, @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition
+ */
+ public int getDirectEditionType() {
+ if (checkExtendedEditor()) {
+ initExtendedEditorConfiguration();
+ return IDirectEdition.EXTENDED_DIRECT_EDITOR;
+ }
+ if (checkDefaultEdition()) {
+ return IDirectEdition.DEFAULT_DIRECT_EDITOR;
+ }
+
+ // not a named element. no specific editor => do nothing
+ return IDirectEdition.NO_DIRECT_EDITION;
+ }
+
+ /**
+ * Checks if an extended editor is present.
+ *
+ * @return <code>true</code> if an extended editor is present.
+ */
+ protected boolean checkExtendedEditor() {
+ if (resolveSemanticElement() != null) {
+ return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName());
+ }
+ return false;
+ }
+
+ /**
+ * Checks if a default direct edition is available
+ *
+ * @return <code>true</code> if a default direct edition is available
+ */
+ protected boolean checkDefaultEdition() {
+ return (getParser() != null);
+ }
+
+ /**
+ * Initializes the extended editor configuration
+ *
+ */
+ protected void initExtendedEditorConfiguration() {
+ if (configuration == null) {
+ final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
+ if (languagePreferred != null && !languagePreferred.equals("")) {
+ configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
+ } else {
+ configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName());
+ }
+ }
+ }
+
+ /**
+ * Updates the preference configuration
+ *
+ */
+ protected void updateExtendedEditorConfiguration() {
+ String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
+ if (languagePreferred != null && !languagePreferred.equals("") && languagePreferred != configuration.getLanguage()) {
+ configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
+ } else if (IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) {
+ configuration = null;
+ }
+ }
+
+ /**
+ * Performs the direct edit usually used by GMF editors.
+ *
+ * @param theRequest
+ * the direct edit request that starts the direct edit system
+ */
+ protected void performDefaultDirectEditorEdit(final Request theRequest) {
+ // initialize the direct edit manager
+ try {
+ getEditingDomain().runExclusive(new Runnable() {
+
+ public void run() {
+ if (isActive() && isEditable()) {
+ if (theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
+ Character initialChar = (Character) theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
+ performDirectEdit(initialChar.charValue());
+ } else if ((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
+ DirectEditRequest editRequest = (DirectEditRequest) theRequest;
+ performDirectEdit(editRequest.getLocation());
+ } else {
+ performDirectEdit();
+ }
+ }
+ }
+ });
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#addNotationalListeners()
+ *
+ */
+ @Override
+ protected void addNotationalListeners() {
+ super.addNotationalListeners();
+ addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#removeNotationalListeners()
+ *
+ */
+ @Override
+ protected void removeNotationalListeners() {
+ super.removeNotationalListeners();
+ removeListenerFilter("PrimaryView"); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#handleNotificationEvent(org.eclipse.emf.common.notify.Notification)
+ *
+ */
+ @Override
+ protected void handleNotificationEvent(Notification event) {
+ Object feature = event.getFeature();
+ if (NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
+ Integer c = (Integer) event.getNewValue();
+ setFontColor(DiagramColorRegistry.getInstance().getColor(c));
+ } else if (NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
+ refreshUnderline();
+ } else if (NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
+ refreshStrikeThrough();
+ } else if (NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature)
+ || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
+ refreshFont();
+ } else {
+ if (getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
+ refreshLabel();
+ }
+ if (getParser() instanceof ISemanticParser) {
+ ISemanticParser modelParser = (ISemanticParser) getParser();
+ if (modelParser.areSemanticElementsAffected(null, event)) {
+ removeSemanticListeners();
+ if (resolveSemanticElement() != null) {
+ addSemanticListeners();
+ }
+ refreshLabel();
+ }
+ }
+ }
+ super.handleNotificationEvent(event);
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#createFigure()
+ *
+ */
+ @Override
+ protected IFigure createFigure() {
+ return new PropertyFigureDescriptor();
+ }
+
+ /**
+ * this method has been overloaded in order to be able to display it into the proeprtyView
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#getAdapter(java.lang.Class)
+ *
+ */
+ @Override
+ public Object getAdapter(Class key) {
+ if (key == AppliedStereotypeProperty.class) {
+ return new AppliedStereotypeProperty(((View) getNotationView().eContainer()).getElement(), (Property) resolveSemanticElement());
+ }
+ return null;
+ // return super.getAdapter(key);
+ }
+
+ /**
+ * @generated
+ */
+ static private class TextCellEditorLocator implements CellEditorLocator {
+
+ /**
+ * @generated
+ */
+ private WrappingLabel wrapLabel;
+
+ /**
+ * @generated
+ */
+ public TextCellEditorLocator(WrappingLabel wrapLabel) {
+ this.wrapLabel = wrapLabel;
+ }
+
+ /**
+ * @generated
+ */
+ public WrappingLabel getWrapLabel() {
+ return wrapLabel;
+ }
+
+ /**
+ * @generated
+ */
+ public void relocate(CellEditor celleditor) {
+ Text text = (Text) celleditor.getControl();
+ Rectangle rect = getWrapLabel().getTextBounds().getCopy();
+ getWrapLabel().translateToAbsolute(rect);
+ if (!text.getFont().isDisposed()) {
+ if (getWrapLabel().isTextWrapOn() && getWrapLabel().getText().length() > 0) {
+ rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT)));
+ } else {
+ int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
+ rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
+ }
+ }
+ if (!rect.equals(new Rectangle(text.getBounds()))) {
+ text.setBounds(rect.x, rect.y, rect.width, rect.height);
+ }
+ }
+ }
+
+
+ /**
+ * the figure associated to this editpart
+ *
+ */
+ public class PropertyFigureDescriptor extends WrappingLabel {
+
+ /**
+ * @generated
+ */
+ public PropertyFigureDescriptor() {
+ this.setText("");
+
+ this.setFont(THIS_FONT);
+
+ }
+
+ }
+
+ static final Font THIS_FONT = new Font(Display.getCurrent(), "Arial", 10, SWT.NORMAL);
+
+}
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 5c7e587c4bb..71e87e81ec2 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
@@ -283,6 +283,7 @@ public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotyp
// 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);
@@ -290,23 +291,7 @@ public class AppliedStereotypeCommentCreationEditPolicy extends AppliedStereotyp
updateAppliedStereotypeCommentShape();
}
- // if element that has changed is a stereotype => refresh the label.
- if (notification.getNotifier() instanceof View && (notification.getEventType() == Notification.ADD) && (notification.getNewValue() instanceof EAnnotation)) {
- if (UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION == ((EAnnotation) notification.getNewValue()).getSource()) {
- // stereotype annotation has changed => refresh label display
- updateAppliedStereotypeCommentShape();
- delegateEAnnotationInCommentShape();
- // refreshDisplay();
- }
- }
- // if element that has changed is a stereotype => refresh the label.
- if (notification.getNotifier() instanceof EAnnotation && (notification.getEventType() == Notification.ADD)) {
- if (UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION == ((EAnnotation) notification.getNotifier()).getSource()) {
- // stereotype annotation has changed => refresh label display
- updateAppliedStereotypeCommentShape();
- delegateEAnnotationInCommentShape();
- }
- }
+
}
/**
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 6ff3958e082..8dfd9336a86 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
@@ -11,6 +11,7 @@
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 323802
* Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.fr - Bug 393532
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotypes Display
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies;
@@ -20,15 +21,14 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.StringTokenizer;
+import org.eclipse.draw2d.IFigure;
import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.impl.DynamicEObjectImpl;
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.Node;
+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.editpart.IPapyrusEditPart;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe;
import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
@@ -36,13 +36,15 @@ import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusCons
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.CreateAppliedStereotypeViewCommand;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypeCompartmentEditPart;
+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.Stereotype;
-import org.eclipse.uml2.uml.util.UMLUtil;
/**
* this edit policy can be apply only on {@link IPapyrusEditPart} in order to
@@ -57,8 +59,6 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod
super();
}
-
-
@Override
public void activate() {
super.activate();
@@ -70,67 +70,57 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod
Iterator<EObject> iterator = umlElement.getStereotypeApplications().iterator();
while (iterator.hasNext()) {
final EObject appliedstereotype = iterator.next();
- createAppliedStereotypeCompartment(appliedstereotype);
+ createAppliedStereotypeLabel(appliedstereotype);
}
}
}
/**
- * this method has in charge to calculate if a compartment must be displayed.
- * To know that it computes if a property of stereotype is displayed into it.
*
- * @param applicationOfStereotype
- * the eobject that represent the stereotype application
- * @return true if the compartment display a property of sterotype
+ * {@inheritedDoc}
*/
- protected boolean hasToDisplayCompartment(EObject applicationOfStereotype) {
- String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay((View) getHost().getModel());
- String stereotypesLocalizationToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesLocalization((View) getHost().getModel());
- if (!(stereotypesLocalizationToDisplay.equals(UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION))) {
- return false;
- }
- HashSet<org.eclipse.uml2.uml.Stereotype> stereoSet = new HashSet<org.eclipse.uml2.uml.Stereotype>();
- ArrayList<String> stPropList = new ArrayList<String>();
+ @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();
- // fill our data structure in order to generate the string
- StringTokenizer propStringTokenizer = new StringTokenizer(stereotypesPropertiesToDisplay, ",");
- while (propStringTokenizer.hasMoreElements()) {
- // extract property to display
- String propertyQN = propStringTokenizer.nextToken();
- // stereotype
- String stereotypeQN = propertyQN.substring(0, propertyQN.indexOf("."));
+ 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);
- Stereotype stereotype = hostSemanticElement.getAppliedStereotype(stereotypeQN);
+ createAppliedStereotypeLabel((EObject) notification.getNewValue());
+ // Store entry in the Map
+ storeInMap((EObject) notification.getNewValue(), ((GraphicalEditPart) getHost()).getNotationView());
- if (stereotype != null) {
- stereoSet.add(stereotype);
- }
- stPropList.add(propertyQN);
- }
+ } 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());
- // Display each stereotype
- Iterator<org.eclipse.uml2.uml.Stereotype> stereoIter = stereoSet.iterator();
- while (stereoIter.hasNext()) {
- Stereotype stereotype = stereoIter.next();
- if (stereotype != null) {
- if (applicationOfStereotype.equals(hostSemanticElement.getStereotypeApplication(stereotype))) {
- return true;
- }
- }
}
- return false;
+
}
+
/**
* 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
+ * the editPart owner of the new compartment
* @param appliedstereotype
* the stereotype application
*/
- protected void executeAppliedStereotypeCompatmentCreation(final GraphicalEditPart editPart, final EObject appliedstereotype) {
+ protected void executeAppliedStereotypeCompartmentCreation(final GraphicalEditPart editPart, final EObject stereotypeApplication) {
try {
editPart.getEditingDomain().runExclusive(new Runnable() {
@@ -138,7 +128,8 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod
Display.getCurrent().syncExec(new Runnable() {
public void run() {
- CreateAppliedStereotypeViewCommand command = new CreateAppliedStereotypeViewCommand(editPart.getEditingDomain(), editPart.getNotationView(), appliedstereotype, hasToDisplayCompartment(appliedstereotype));
+ CreateAppliedStereotypeViewCommand command = new CreateAppliedStereotypeViewCommand(editPart.getEditingDomain(), editPart.getNotationView(), stereotypeApplication, hasToDisplayCompartment(stereotypeApplication));
+
// use to avoid to put it in the command stack
try {
GMFUnsafe.write(editPart.getEditingDomain(), command);
@@ -156,117 +147,131 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod
}
/**
+ * The goal of this method is to execute the a command to create a notation node for a stereotype Label.
*
- * {@inheritedDoc}
+ * @param editPart
+ * the editPart owner of the new compartment
+ * @param appliedstereotype
+ * the stereotype application
*/
- @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);
- createAppliedStereotypeCompartment((EObject) notification.getNewValue());
- } else if (eventType == StereotypeExtensionNotification.STEREOTYPE_UNAPPLIED_FROM_ELEMENT) {
- getDiagramEventBroker().removeNotificationListener((EObject) notification.getOldValue(), this);
- cleanStereotypeDisplayInEAnnotation();
- removeAppliedStereotypeCompartment((EObject) notification.getNewValue());
+ 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() {
- }
- // if element that has changed is a stereotype => refresh the label.
- if (notification.getNotifier() instanceof Node && (notification.getEventType() == Notification.ADD) && (notification.getNewValue() instanceof EAnnotation)) {
- if (UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION == ((EAnnotation) notification.getNewValue()).getSource()) {
- // stereotype annotation has changed => refresh label display
- refreshDisplay();
- }
- }
- // if element that has changed is a stereotype => refresh the label.
- if (notification.getNotifier() instanceof EAnnotation && (notification.getEventType() == Notification.ADD)) {
- if (UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION == ((EAnnotation) notification.getNotifier()).getSource()) {
- // stereotype annotation has changed => refresh label display
- refreshDisplay();
- }
+ 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 creates a node for the compartment of stereotype if it does not exist.
- *
- * @param stereotypeApplication
- * the stereotype application
+ * 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
*/
- public void createAppliedStereotypeCompartment(final EObject stereotypeApplication) {
- final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
- final View node = editPart.getNotationView();
- // llok for the coressponded node for the stereotype application
- View correspondedAppliedStereotype = getCoresspondedStereotypeApplication(stereotypeApplication, node);
- // it does not exist
- if (correspondedAppliedStereotype == null) {
- executeAppliedStereotypeCompatmentCreation(editPart, stereotypeApplication);
+ 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);
}
}
/**
- * the goal of this method is to execute the a command to create a notation node for a compartment of stereotype
- *
+ * Execute the command to remove the Stereotype Compartment with Properties.
+ *
* @param editPart
- * the editpart owner of the new compartment
- * @param appliedstereotype
- * the stereotype application
+ * Edit Part on which the command is executed
+ * @param label
+ * DecorationNode of the Stereotype Label that has to be removed
*/
- protected void setVisivility(final View view, final boolean isVisible) {
+ protected void executeStereotypeCompartmentRemove(final GraphicalEditPart editPart, final View compartment) {
try {
- final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
+
editPart.getEditingDomain().runExclusive(new Runnable() {
public void run() {
- SetNodeVisibilityCommand setCommand = new SetNodeVisibilityCommand(editPart.getEditingDomain(), view, isVisible);
+ DeleteCommand command = new DeleteCommand(compartment);
// use to avoid to put it in the command stack
try {
- GMFUnsafe.write(editPart.getEditingDomain(), setCommand);
+ 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 return the node that references the stereotype application
+ * this method creates a node for the compartment of stereotype if it does not exist.
*
* @param stereotypeApplication
- * the application of the sterotype
- * @param node
- * the notation node where we look for all subnodes
- * @return the corresponded node or null
+ * the stereotype application
*/
- protected View getCoresspondedStereotypeApplication(final EObject stereotypeApplication, final View node) {
- View correspondedAppliedStereotype = null;
- int i = 0;
- // wee look for through all sub nodes
- while (correspondedAppliedStereotype == null && i < node.getChildren().size()) {
- if ((node.getChildren().get(i)) instanceof Node) {
- if (stereotypeApplication.equals(((Node) (node.getChildren().get(i))).getElement())) {
- correspondedAppliedStereotype = ((Node) (node.getChildren().get(i)));
+ public void createAppliedStereotypeLabel(final EObject stereotypeApplication) {
+
+ if (getHost() instanceof GraphicalEditPart) {
+ final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
+
+ 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);
+
+ // Create Compartment
+ executeAppliedStereotypeCompartmentCreation(editPart, stereotypeApplication);
+
}
}
- i++;
}
- return correspondedAppliedStereotype;
}
+
+
/**
* 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
@@ -275,56 +280,73 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod
* @param stereotypeApplication
*/
public void removeAppliedStereotypeCompartment(final EObject stereotypeApplication) {
+
+ GraphicalEditPart editPart = (GraphicalEditPart) getHost();
+
+ // Remove the Label node
+ BasicCompartment compartment = stereotypePropertyMap.get(stereotypeApplication);
+ executeStereotypeCompartmentRemove(editPart, compartment);
+
+ refreshDisplay();
+
+ }
+
+ /**
+ * 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;
}
- final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
- final View node = editPart.getNotationView();
- try {
- int i = 0;
- // we go through all sub nodes
- while (i < node.getChildren().size()) {
- if ((node.getChildren().get(i)) instanceof Node) {
- final Node currentNode = (Node) (node.getChildren().get(i));
- // it references the stereotype application?
- if (stereotypeApplication.equals(currentNode.getElement())) {
- // yes, Execution of the Deletion command
- editPart.getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- DeleteCommand command = new DeleteCommand(currentNode);
- // use to avoid to put it in the command stack
- try {
- GMFUnsafe.write(editPart.getEditingDomain(), command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- });
- }
- // the sub nodes has the type appliedStereotypeCompartment but does not references a application of stereotype
- if ((currentNode.getType().equals(AppliedStereotypeCompartmentEditPart.ID)) && (!(currentNode.getElement() instanceof DynamicEObjectImpl))) {
- // yes, Execution of the Deletion command
- editPart.getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- if (currentNode != null && editPart.getEditingDomain() != null) {
- DeleteCommand command = new DeleteCommand(editPart.getEditingDomain(), currentNode);
- // use to avoid to put it in the command stack
- try {
- GMFUnsafe.write(editPart.getEditingDomain(), command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- }
- });
- }
- }
- i++;
+
+ if (getHost() instanceof GraphicalEditPart) {
+
+ final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
+ final View node = editPart.getNotationView();
+
+ // Remove the Label node
+ DecorationNode label = stereotypeMap.get(stereotypeApplication);
+ executeStereotypeLabelRemove(editPart, label);
+
+ // Update the Label displayed accordingly
+ if (editPart instanceof IPapyrusEditPart) {
+ IFigure figure = ((IPapyrusEditPart) editPart).getPrimaryShape();
+ updateLabelText(figure, node);
}
- } catch (Exception e) {
- Activator.log.error(e);
+ }
+ }
+
+ /**
+ * Remove the stereotype entry from the Map
+ *
+ * @param stereotypeApplication
+ * @param node
+ */
+ protected void deleteInMap(EObject stereotypeApplication) {
+ stereotypeMap.remove(stereotypeApplication);
+ stereotypePropertyMap.remove(stereotypeApplication);
+
+ }
+
+ /**
+ * Store the entry (stereotypeApplication, StereotypeLabel)
+ *
+ * @param stereotypeApplication
+ * @param node
+ */
+ 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);
}
}
@@ -333,27 +355,74 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod
*/
@Override
protected void refreshAppliedStereotypesPropertiesInCompartment(String stereotypesPropertiesToDisplay, IPapyrusNodeUMLElementFigure figure) {
- final boolean displayInCompartment = AppliedStereotypeHelper.hasAppliedStereotypesPropertiesToDisplay((View) getHost().getModel(), UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION);
- // if the string is not empty, then, the figure has to display it. Else,
- // it displays nothing
- final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
- final View node = editPart.getNotationView();
- int i = 0;
- // we go through all sub nodes
- while (i < node.getChildren().size()) {
- if ((node.getChildren().get(i)) instanceof Node) {
- final Node currentNode = (Node) (node.getChildren().get(i));
- if (currentNode.getType().equals(AppliedStereotypeCompartmentEditPart.ID)) {
- EObject stereotypeApplication = currentNode.getElement();
- Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
- if (stereotype != null && stereotypesPropertiesToDisplay.contains(stereotype.getQualifiedName())) {
- setVisivility(currentNode, displayInCompartment);
- } else {
- setVisivility(currentNode, currentNode.isVisible());
- }
+ // Do Nothing
+ // TODO Check if required into Parent
+ }
+
+ /**
+ * this method has in charge to calculate if a compartment must be displayed.
+ * To know that it computes if a property of stereotype is displayed into it.
+ *
+ * @param applicationOfStereotype
+ * the eObject that represent the stereotype application
+ * @return true if the compartment display a property of stereotype
+ */
+ protected boolean hasToDisplayCompartment(EObject applicationOfStereotype) {
+ String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay((View) getHost().getModel());
+ String stereotypesLocalizationToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesLocalization((View) getHost().getModel());
+ if (!(stereotypesLocalizationToDisplay.equals(UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION))) {
+ return false;
+ }
+ HashSet<org.eclipse.uml2.uml.Stereotype> stereoSet = new HashSet<org.eclipse.uml2.uml.Stereotype>();
+ ArrayList<String> stPropList = new ArrayList<String>();
+
+ // fill our data structure in order to generate the string
+ StringTokenizer propStringTokenizer = new StringTokenizer(stereotypesPropertiesToDisplay, ",");
+ while (propStringTokenizer.hasMoreElements()) {
+ // extract property to display
+ String propertyQN = propStringTokenizer.nextToken();
+ // stereotype
+ String stereotypeQN = propertyQN.substring(0, propertyQN.indexOf("."));
+
+ Stereotype stereotype = hostSemanticElement.getAppliedStereotype(stereotypeQN);
+
+ if (stereotype != null) {
+ stereoSet.add(stereotype);
+ }
+
+ stPropList.add(propertyQN);
+ }
+
+ // Display each stereotype
+ Iterator<org.eclipse.uml2.uml.Stereotype> stereoIter = stereoSet.iterator();
+ while (stereoIter.hasNext()) {
+ Stereotype stereotype = stereoIter.next();
+ if (stereotype != null) {
+ if (applicationOfStereotype.equals(hostSemanticElement.getStereotypeApplication(stereotype))) {
+ return true;
}
}
- i++;
+ }
+ return false;
+ }
+
+ /**
+ * Method to set the Figure Label with the new modification.
+ *
+ * @author Céline JANSSENS
+ * @param figure
+ * Figure on which the update has to be done
+ * @param node
+ * Node view of the element required to retrieve the stereotype label
+ *
+ */
+ public 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/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 71eeacbc70b..12e05e01a16 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
@@ -11,36 +11,33 @@
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 323802
* Gabriel Pascual (ALL4TEC) - Bug 441195
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotypes Display
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies;
-import java.util.StringTokenizer;
-
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.transaction.RecordingCommand;
-import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
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.common.stereotype.StereotypeDisplayUtils;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.command.CreateAppliedStereotypePropertyViewCommand;
-import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypePropertyEditPart;
-import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.swt.widgets.Display;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Extension;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.util.UMLUtil;
/**
- * This editpolicy is used to add dynamically labels of stereotypes into nodes int the context of AppliedStereorypeCompartmentEditpart
+ * This editPolicy is used to add dynamically labels of stereotypes into nodes in the context of AppliedStereorypeCompartmentEditpart
*/
public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy {
@@ -102,14 +99,11 @@ public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNode
*
* @param editPart
* the editpart container
- * @param stereotypesPropertiesToDisplay
- * list of applied stereotype properties to display
- * @param node
- * the comaprtment node that contains all properties
+ * @param stereotypeApplication
* @param stereotype
* the stereotype associated to compartment node
*/
- protected void executeAppliedStereotypePropertytCreation(final GraphicalEditPart editPart, final String stereotypesPropertiesToDisplay, final View node, final Stereotype stereotype) {
+ protected void executeAppliedStereotypePropertyViewCreation(final GraphicalEditPart editPart, final Property stereotypeProperty, final EObject stereotypeApplication) {
try {
editPart.getEditingDomain().runExclusive(new Runnable() {
@@ -118,45 +112,12 @@ public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNode
public void run() {
- StringTokenizer propStringTokenizer = new StringTokenizer(stereotypesPropertiesToDisplay, ",");
- while (propStringTokenizer.hasMoreElements()) {
- // extract property to display
- String propertyQN = propStringTokenizer.nextToken();
- // get a property that is interesting for us
- if (propertyQN.startsWith(stereotype.getQualifiedName())) {
-
- String propertyName = propertyQN.substring(propertyQN.lastIndexOf(".") + 1);
- Property stereotypeProperty = StereotypeUtil.getPropertyByName(stereotype, propertyName);
-
- if (stereotypeProperty == null) {
- return;
- }
-
- Node sterotypePropertyNode = null;
- int i = 0;
- // we go through all sub nodes to get sub node that is link to this property
- while (i < node.getChildren().size() && sterotypePropertyNode == null) {
- if ((node.getChildren().get(i)) instanceof Node) {
- final Node currentNode = (Node) (node.getChildren().get(i));
- if (AppliedStereotypePropertyEditPart.ID.equals(currentNode.getType())) {
- if (stereotypeProperty.equals(currentNode.getElement())) {
- sterotypePropertyNode = currentNode;
- }
- }
- }
- i++;
- }
-
- if (sterotypePropertyNode == null) {
- // use to avoid to put it in the command stack
- CreateAppliedStereotypePropertyViewCommand command = new CreateAppliedStereotypePropertyViewCommand(editPart.getEditingDomain(), editPart.getNotationView(), stereotypeProperty);
- try {
- GMFUnsafe.write(editPart.getEditingDomain(), command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- }
+ // use to avoid to put it in the command stack
+ CreateAppliedStereotypePropertyViewCommand command = new CreateAppliedStereotypePropertyViewCommand(editPart.getEditingDomain(), editPart.getNotationView(), stereotypeProperty, stereotypeApplication);
+ try {
+ GMFUnsafe.write(editPart.getEditingDomain(), command);
+ } catch (Exception e) {
+ Activator.log.error(e);
}
}
});
@@ -174,17 +135,33 @@ public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNode
*/
@Override
public void notifyChanged(Notification notification) {
- // refresh obly when the EAnnotation about stereotype is added or remove
+ // refresh only when the EAnnotation about stereotype is added or remove
// to update only property of stereotype application
+ final int eventType = notification.getEventType();
+ final Object newValue = notification.getNewValue();
+ final Object notifier = notification.getNotifier();
+ final Object oldValue = notification.getOldValue();
+
+ if (eventType == Notification.ADD && newValue instanceof Node) {
+ if (((Node) newValue).getType().equals(StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_TYPE)) {
+ if (notifier instanceof Node) {
+
+ // a stereotype was applied to the notifier
+ // then a new listener should be added to the stereotype application
+ getDiagramEventBroker().addNotificationListener((EObject) notification.getNewValue(), this);
+ createAppliedStereotypeProperty((Node) newValue);
+ }
+ }
+ } else if (eventType == Notification.REMOVE && oldValue instanceof Node) {
+ if (((Node) oldValue).getType().equals(StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_TYPE)) {
+ if (notifier instanceof Node) {
+ getDiagramEventBroker().removeNotificationListener((EObject) notification.getOldValue(), this);
- // if element that has changed is a stereotype => refresh the label.
- if (notification.getNotifier() instanceof Node && (notification.getEventType() == Notification.ADD) && (notification.getNewValue() instanceof EAnnotation)) {
- if (UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION == ((EAnnotation) notification.getNewValue()).getSource()) {
- // stereotype annotation has changed => refresh label display
- refreshDisplay();
+ }
}
}
+
}
@@ -220,111 +197,48 @@ public class AppliedStereotypePropertiesEditPolicy extends AppliedStereotypeNode
protected void refreshStereotypeDisplay() {
}
-
/**
- * Refreshes the stereotype application property
+ * In charge of property view creation
+ *
+ * @param eObject
+ * The Edit Part of which the Properties should be created
*/
- @Override
- public void refreshDisplay() {
- if (((View) getHost().getModel()).eContainer() != null) {
- String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay((View) ((View) getHost().getModel()).eContainer());
- final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
- final View node = editPart.getNotationView();
-
- // 1. Manage adding of application stereotype properties
- EObject stereotypeApplication = editPart.resolveSemanticElement();
- Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
- // if stereotype is null all property of stereotype has to be removed!
- if (stereotype != null) {
- // go through each stereotype property
- executeAppliedStereotypePropertytCreation(editPart, stereotypesPropertiesToDisplay, node, stereotype);
-
- // Manage removing of Stereotype application properties
- manageRemovingPropertiesNodes(stereotypesPropertiesToDisplay, editPart, node, stereotype);
-
-
- } else {
- try {
- editPart.getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- Display.getCurrent().syncExec(new Runnable() {
-
- public void run() {
- DeleteCommand command = new DeleteCommand((View) getHost().getModel());
- // use to avoid to put it in the command stack
- try {
- GMFUnsafe.write(editPart.getEditingDomain(), command);
- } catch (Exception e) {
- System.err.println(e);
- }
+ public void createAppliedStereotypeProperty(Node compartment) {
+ if (compartment != null) {
+ if (getHost() instanceof GraphicalEditPart) {
+ GraphicalEditPart editPart = (GraphicalEditPart) getHost();
+ View view = editPart.getNotationView();
+ if (view != null) {
+ EObject stereotypeApplication = compartment.getElement();
+ EObject element = view.getElement();
+ 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
+ if (element.equals(stereotypeApplication)) {
+ executeAppliedStereotypePropertyViewCreation(editPart, property, stereotypeApplication);
}
-
- });
+ }
}
- });
- } catch (Exception e) {
- System.err.println(e);
+ }
}
-
}
}
}
-
-
/**
- * this method is used to remove nodes of property that are not in a given list
- *
- * @param stereotypesPropertiesToDisplay
- * a list of qualified name of properties
- * @param editPart
- * the graphical editpart that is the container
- * @param node
- * the notation node that is the container
- * @param stereotype
- * the stereotype that is display in this container
+ * Refreshes the stereotype application property
*/
- protected void manageRemovingPropertiesNodes(String stereotypesPropertiesToDisplay, final GraphicalEditPart editPart, final View node, Stereotype stereotype) {
- int i = 0;
- while (i < node.getChildren().size()) {
- if ((node.getChildren().get(i)) instanceof Node) {
- final Node currentNode = (Node) (node.getChildren().get(i));
- if (currentNode.getType().equals(AppliedStereotypePropertyEditPart.ID)) {
- Property property = (Property) currentNode.getElement();
- final String propertyQN = stereotype.getQualifiedName() + "." + property.getName();
- if (!stereotypesPropertiesToDisplay.contains(propertyQN)) {
- try {
- // yes, Execution of the Deletion command
- editPart.getEditingDomain().runExclusive(new Runnable() {
-
- public void run() {
- Display.getCurrent().syncExec(new Runnable() {
-
- public void run() {
- if (currentNode.eContainer() != null) {
-
- DeleteCommand command = new DeleteCommand(currentNode);
- // use to avoid to put it in the command stack
- try {
- GMFUnsafe.write(editPart.getEditingDomain(), command);
- } catch (Exception e) {
- System.err.println(e);
- }
- }
-
- }
- });
- }
- });
- } catch (Exception e) {
- System.err.println(e);
- }
- }
+ @Override
+ public void refreshDisplay() {
+ if (((View) getHost().getModel()).eContainer() != null) {
+
+ final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
- }
- }
- i++;
}
}
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 e5e81abb81a..68d685f59ff 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
@@ -9,6 +9,7 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotypes Display
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.stereotype.edition.provider;
@@ -23,9 +24,9 @@ import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.providers.RestrictedAbstractEditPartProvider;
+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.AppliedStereotypePropertyEditPart;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypesCommentEditPart;
import org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart.AppliedStereotypesCommentLinkEditPart;
@@ -42,8 +43,8 @@ public class StereotypePropertiesEditPartProvider extends RestrictedAbstractEdit
public StereotypePropertiesEditPartProvider() {
super();
- nodeMap.put(AppliedStereotypeCompartmentEditPart.ID, AppliedStereotypeCompartmentEditPart.class);
- nodeMap.put(AppliedStereotypePropertyEditPart.ID, AppliedStereotypeMultilinePropertyEditPart.class);
+ 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);
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositeforview/AppliedStereotypeCompositeWithView.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositeforview/AppliedStereotypeCompositeWithView.java
index d9c5dea6d80..13ca8bb5f42 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositeforview/AppliedStereotypeCompositeWithView.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositeforview/AppliedStereotypeCompositeWithView.java
@@ -158,10 +158,9 @@ public class AppliedStereotypeCompositeWithView extends org.eclipse.papyrus.uml.
* @return
*/
@Override
- protected Command getApplyStereotypeCommmand(Element elt, Stereotype st, TransactionalEditingDomain domain) {
- CompoundCommand compoundCommand = new CompoundCommand("ApplyStereotypeCommand");
-
- Command parentCommmand = super.getApplyStereotypeCommmand(elt, st, domain);
+ protected Command getApplyStereotypeCommand(Element elt, Stereotype st, TransactionalEditingDomain domain) {
+ CompoundCommand compoundCommand = new CompoundCommand("Apply Stereotype Command");
+ Command parentCommmand = super.getApplyStereotypeCommand(elt, st, domain);
compoundCommand.append(parentCommmand);
// Fix regression / Bug 431258
@@ -169,7 +168,6 @@ public class AppliedStereotypeCompositeWithView extends org.eclipse.papyrus.uml.
if (diagramElement != null) {
String presentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(diagramElement);
RecordingCommand command = AppliedStereotypeHelper.getAddAppliedStereotypeCommand(domain, diagramElement, st.getQualifiedName(), presentationKind);
-
compoundCommand.append(command);
}
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/AppliedStereotypeCompositeOnModel.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/AppliedStereotypeCompositeOnModel.java
index 1609d4d64cf..a7142d3ad72 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/AppliedStereotypeCompositeOnModel.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/AppliedStereotypeCompositeOnModel.java
@@ -1,683 +1,682 @@
-/*****************************************************************************
- * Copyright (c) 2008, 2014 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:
- * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
- * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
- * Christian W. Damus (CEA) - bug 323802
- * Christian W. Damus (CEA) - bug 448139
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.properties.profile.ui.compositesformodel;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.impl.NotificationImpl;
-import org.eclipse.emf.common.util.BasicEList;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.papyrus.uml.profile.Activator;
-import org.eclipse.papyrus.uml.profile.preference.ProfilePreferenceConstants;
-import org.eclipse.papyrus.uml.profile.tree.ProfileElementContentProvider;
-import org.eclipse.papyrus.uml.profile.tree.ProfileElementLabelProvider;
-import org.eclipse.papyrus.uml.profile.tree.ProfileElementTreeViewerFilter;
-import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypePropertyTreeObject;
-import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypeTreeObject;
-import org.eclipse.papyrus.uml.profile.tree.objects.StereotypedElementTreeObject;
-import org.eclipse.papyrus.uml.profile.tree.objects.TreeObject;
-import org.eclipse.papyrus.uml.profile.utils.Util;
-import org.eclipse.papyrus.uml.properties.profile.ui.dialogs.ChooseSetStereotypeDialog;
-import org.eclipse.papyrus.uml.properties.profile.ui.panels.AppliedStereotypePanel;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Stereotype;
-
-// TODO: Auto-generated Javadoc
-/**
- * This composite is used to display applied stereotype in the model. It allows applying or desapply a stereotype
- */
-public class AppliedStereotypeCompositeOnModel extends DecoratedTreeComposite implements ISelectionChangedListener {
-
- /**
- * Gets the domain.
- *
- * @return the domain
- */
- public TransactionalEditingDomain getEditingDomain(Element context) {
- try {
- return ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain(context);
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- return null;
- }
- }
-
- /** The panel that display applied stereotypes. */
- private AppliedStereotypePanel appliedStereotypePanel;
-
- /** The label. */
- protected CLabel label;
-
- /**
- * The default constructor.
- *
- * @param parent
- * the parent Composite for this panel
- */
- public AppliedStereotypeCompositeOnModel(AppliedStereotypePanel parent) {
- super(parent, SWT.NONE, "Applied stereotypes", true);
-
- appliedStereotypePanel = parent;
- }
-
- /**
- * create a composite applied stereotype on model.
- *
- * @param parent
- * the parent composite
- */
- public AppliedStereotypeCompositeOnModel(Composite parent) {
- super(parent, SWT.NONE, "Applied stereotypes", true);
- }
-
- /**
- * apply a stereotype on current selected element.
- */
- protected void addAppliedStereotype() {
-
- // Open stereotype selection (may add or remove)
- ChooseSetStereotypeDialog dialog = new ChooseSetStereotypeDialog(this.getShell(), getElement());
- int result = dialog.open();
-
- if (result == Window.OK) {
- // Retrieve selected element
- Element element = getElement();
-
- // compare the 2 lists (present list and future list
- EList<Stereotype> oldStereotypeList = element.getAppliedStereotypes();
- ArrayList<Stereotype> newStereotypeList = dialog.getSelectedElements();
-
- // Keep newStereotype order (will be used at the end of the method)
- EList<Stereotype> newOrderList = new BasicEList<Stereotype>();
- newOrderList.addAll(newStereotypeList);
-
- // If the 2 lists differ, apply the new list of stereotypes
- if (!(newStereotypeList.equals(oldStereotypeList))) {
-
- // Parse old list :
- // if stereotype is in the new list : it is already applied
- // --> don't unapply it
- // --> remove it from new list
- Iterator<Stereotype> it = oldStereotypeList.iterator();
- while (it.hasNext()) {
- Stereotype currentStOld = it.next();
- if (newStereotypeList.contains(currentStOld)) {
- newStereotypeList.remove(currentStOld);
- } else {
- unapplyStereotype(element, currentStOld);
- }
- }
-
- // Already applied stereotype should have been removed
- // apply others
- Iterator<Stereotype> newApplyStereotypes = newStereotypeList.iterator();
- while (newApplyStereotypes.hasNext()) {
- Stereotype currentStereotype = newApplyStereotypes.next();
- applyStereotype(element, currentStereotype);
- }
-
- // Update Stereotype order
- // this.reorderStereotypeApplications(element, newOrderList);
-
- // checkSelection(null);
- selectionChanged(null);
-
- if (appliedStereotypePanel != null) {
- appliedStereotypePanel.refresh();
- }
- }
- }
-
- }
-
- /**
- * Button action : open a selection dialog box that allow the user to choose stereotypes to apply (or unapply).
- */
- @Override
- public void addButtonPressed() {
- addAppliedStereotype();
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public Composite createContent(Composite parent, TabbedPropertySheetWidgetFactory factory) {
- super.createContent(parent, factory);
- createStereotypesTree();
-
- removeButton.setToolTipText("Remove stereotype");
- addButton.setToolTipText("Apply stereotype");
-
- return this;
- }
-
- /**
- * Creates the stereotypes tree.
- *
- * @return the tree of applied stereotypes and properties
- */
- private void createStereotypesTree() {
- // Tree viewer shows applied stereotypes
- treeViewer.setContentProvider(new ProfileElementContentProvider());
- treeViewer.setLabelProvider(new ProfileElementLabelProvider());
- treeViewer.addFilter(new ProfileElementTreeViewerFilter());
- treeViewer.addSelectionChangedListener(this);
- }
-
- /**
- * Button action : modify display order of stereotypes (selected elements are pushed down in the list).
- */
- @Override
- public void downButtonPressed() {
- int nbrOfSelection = getTree().getSelectionCount();
- if (nbrOfSelection < 1) {
- return;
- }
-
- TreeItem[] items = getTree().getSelection();
- int indexLast = getTree().indexOf(items[items.length - 1]);
- if (indexLast + 1 >= getElement().getAppliedStereotypes().size()) {
- // do nothing
- return;
- }
-
- for (int i = 0; i < nbrOfSelection; i++) {
- TreeItem item = items[nbrOfSelection - 1 - i];
- if (item.getData() instanceof AppliedStereotypeTreeObject) {
- AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
- EList stereotypes = new BasicEList();
- stereotypes.addAll(element.getAppliedStereotypes());
-
- int index = stereotypes.indexOf(sTO.getStereotype());
- if ((index == -1) || (index >= stereotypes.size() - 1)) {
- // Not found of already on top...
- return;
- }
-
- stereotypes.move(index + 1, sTO.getStereotype());
- this.reorderStereotypeApplications(element, stereotypes);
- }
- }
- }
-
- /**
- * Edits the item.
- *
- * @param item
- * the item
- */
- @Override
- public void editItem(TreeItem item) {
- // do nothing
- }
-
- /**
- * Gets the selected.
- *
- * @return Returns the selected element.
- */
- public Element getSelected() {
- return appliedStereotypePanel.getSelected();
- }
-
- /**
- * Gets the tree.
- *
- * @return the tree
- */
- public Tree getTree() {
- return treeViewer.getTree();
- }
-
- /**
- * Checks if is in stereotype display.
- *
- * @param st
- * the stereotype
- *
- * @return true, if checks if is in stereotype display
- */
- protected Boolean isInStereotypeDisplay(Stereotype st) {
- return false;
- }
-
- /**
- * Redraw the treeViewer while preserving selections and non-collapsed tree elements
- * It is not sufficient to redraw only selected elements as an optimization, since
- * derived stereotype attributes (that are not selected) might change in response to
- * changing other attributes.
- *
- * @param propertyView
- */
- public void refreshTreeViewer() {
- treeViewer.refresh();
- }
-
- /**
- * Refresh the content of applied the applied stereotype tree.
- */
- @Override
- public void refresh() {
- super.refresh();
-
- if (treeViewer.getTree() != null && !(treeViewer.getTree().isDisposed())) {
- if (element != null) {
- // Preserve selection
- final ISelection selection = treeViewer.getSelection();
- try {
- treeViewer.setInput(new StereotypedElementTreeObject(element));
- } finally {
- treeViewer.setSelection(selection);
- }
- } else {
- treeViewer.setInput(null);
- }
- StereotypedElementTreeObject rTO = (StereotypedElementTreeObject) treeViewer.getInput();
- if (rTO == null) {
- return;
- }
-
- boolean isEditable = isEditable();
-
- // If the property is Multivalued show Up - Down
- if ((rTO.getChildren() != null) && (rTO.getChildren().length > 1)) {
- upButton.setEnabled(isEditable);
- downButton.setEnabled(isEditable);
- } else {
- upButton.setEnabled(false);
- downButton.setEnabled(false);
- }
-
- if ((rTO.getChildren() != null) && (rTO.getChildren().length == 0)) {
- removeButton.setEnabled(false);
- } else {
- removeButton.setEnabled(isEditable);
- }
- }
- }
-
- /**
- * Button action : unapply the stereotypes selected by the user in the stereotype tree.
- */
- @Override
- public void removeButtonPressed() {
- unapplyStereotype();
- }
-
- /**
- * Selection changed.
- *
- * @param event
- * the event
- */
- public void selectionChanged(SelectionChangedEvent event) {
- if (appliedStereotypePanel != null) {
- if (event == null) {
- appliedStereotypePanel.setSelectedProperty(null);
- return;
- }
-
- IStructuredSelection structSelection = (IStructuredSelection) event.getSelection();
- Object selection = structSelection.getFirstElement();
- if (selection instanceof AppliedStereotypePropertyTreeObject) {
- appliedStereotypePanel.setSelectedProperty((AppliedStereotypePropertyTreeObject) selection);
- } else {
- appliedStereotypePanel.setSelectedProperty(null);
- }
-
- }
- }
-
- /**
- * Sets the input.
- *
- * @param element
- * the element
- */
- public void setInput(StereotypedElementTreeObject element) {
- // Preserve selection
- final ISelection selection = treeViewer.getSelection();
- try {
- treeViewer.setInput(element);
- } finally {
- treeViewer.setSelection(selection);
- }
- if (Activator.getDefault().getPreferenceStore().getBoolean(ProfilePreferenceConstants.EXPAND_STEREOTYPES_TREE)) {
- treeViewer.expandAll();
- }
- }
-
- /**
- * unapply stereotype on current selected element.
- */
- protected void unapplyStereotype() {
- int nbrOfSelection = getTree().getSelectionCount();
- if (nbrOfSelection == 0) {
- return;
- }
-
- for (int i = 0; i < nbrOfSelection; i++) {
- TreeItem item = getTree().getSelection()[i];
- if (item.getData() instanceof AppliedStereotypeTreeObject) {
- AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
- unapplyStereotype(element, sTO.getStereotype());
- sTO.removeMe();
- }
- }
- if (appliedStereotypePanel != null) {
- appliedStereotypePanel.refresh();
- } else {
- refresh();
- }
- }
-
- /**
- * Button action : modify display order of stereotypes (selected elements are pushed up in the list).
- */
- @Override
- public void upButtonPressed() {
- int nbrOfSelection = getTree().getSelectionCount();
- if (nbrOfSelection < 1) {
- return;
- }
-
- TreeItem[] items = getTree().getSelection();
- int indexFirst = getTree().indexOf(items[0]);
- if (indexFirst == 0) {
- // do nothing
- return;
- }
-
- for (int i = 0; i < nbrOfSelection; i++) {
- TreeItem item = items[i];
- if (item.getData() instanceof AppliedStereotypeTreeObject) {
- AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
- EList stereotypes = new BasicEList();
- stereotypes.addAll(element.getAppliedStereotypes());
-
- int index = stereotypes.indexOf(sTO.getStereotype());
- if (index < 1) {
- return;
- }
-
- stereotypes.move(index - 1, sTO.getStereotype());
- this.reorderStereotypeApplications(element, stereotypes);
- }
- }
- if (appliedStereotypePanel != null) {
- appliedStereotypePanel.refresh();
- } else {
- refresh();
- }
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.properties.profile.ui.compositesformodel.DecoratedTreeComposite#keepSelection(org.eclipse.jface.viewers.ISelection)
- *
- * @param pSelection
- */
- @Override
- public void keepSelection(ISelection pSelection) {
- getDisplay().asyncExec(new SelectionKeeper(pSelection));
- }
-
- /**
- * Apply stereotype.
- *
- * @param elt
- * the elt
- * @param st
- * the st
- */
- public void applyStereotype(final Element elt, final Stereotype st) {
- try {
- final TransactionalEditingDomain domain = getEditingDomain(elt);
- domain.runExclusive(new Runnable() {
-
- public void run() {
-
- Display.getCurrent().asyncExec(new Runnable() {
-
- public void run() {
- domain.getCommandStack().execute(getApplyStereotypeCommmand(elt, st, domain));
- }
- });
- }
- });
-
- } catch (Exception e) {
- Activator.log.error(e);
- }
-
- }
-
- /**
- * Unapply stereotype.
- *
- * @param elt
- * the uml element
- * @param st
- * the stereotype to unapply
- */
- protected void unapplyStereotype(final Element elt, final Stereotype st) {
- // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline)
- try {
- final TransactionalEditingDomain domain = getEditingDomain(elt);
- domain.runExclusive(new Runnable() {
-
- public void run() {
-
- Display.getCurrent().asyncExec(new Runnable() {
-
- public void run() {
- domain.getCommandStack().execute(getUnapplyStereotypeCommand(elt, st, domain));
- }
- });
- }
- });
-
- } catch (Exception e) {
- Activator.log.error(e);
- }
-
- }
-
- /**
- * change the order of applied stereotype
- *
- * @param element
- * the UML element where stereotypes are applied
- * @param stereotypes
- * the lis of applied stereotypes with the wanted order
- */
- public void reorderStereotypeApplications(final Element element, final EList stereotypes) {
- try {
- final TransactionalEditingDomain domain = getEditingDomain(element);
- domain.runExclusive(new Runnable() {
-
- public void run() {
-
- Display.getCurrent().asyncExec(new Runnable() {
-
- public void run() {
- domain.getCommandStack().execute(new RecordingCommand(domain) {
-
- @Override
- protected void doExecute() {
- Util.reorderStereotypeApplications(element, stereotypes);
- refresh();
- }
- });
- }
- });
- }
- });
-
- } catch (Exception e) {
- Activator.log.error(e);
- }
-
- }
-
- /**
- *
- * @author gpascual
- *
- */
- private class SelectionKeeper implements Runnable {
-
- /** Selection to keep. */
- ISelection selection = null;
-
- /**
- *
- * Constructor.
- *
- */
- public SelectionKeeper(ISelection selection) {
- this.selection = selection;
- }
-
- public void run() {
- Object[] vSelectedElements = extractSelectedElements(selection);
- Object[] vCorrespondingElements = getCorrespondingElements(vSelectedElements);
- ISelection vSelection = new StructuredSelection(vCorrespondingElements);
- treeViewer.setSelection(vSelection);
-
- }
-
-
-
-
-
- private Object[] getCorrespondingElements(Object[] vSelectedElements) {
- StereotypedElementTreeObject vStereotypesTree = (StereotypedElementTreeObject) treeViewer.getInput();
- List<Object> vReturn = new ArrayList<Object>();
- for (Object vStereotype : vSelectedElements) {
- if (vStereotype instanceof AppliedStereotypeTreeObject) {
- AppliedStereotypeTreeObject vTreeObject = findAppliedStereotypeInTree(((AppliedStereotypeTreeObject) vStereotype).getStereotype(), vStereotypesTree);
- vReturn.add(vTreeObject);
- }
- }
-
- return vReturn.toArray();
- }
-
- private AppliedStereotypeTreeObject findAppliedStereotypeInTree(Stereotype stereotype, StereotypedElementTreeObject vStereotypesTree) {
- AppliedStereotypeTreeObject vAppliedStereotypeObject = null;
-
- for (TreeObject vChild : vStereotypesTree.getChildren()) {
- if (vChild instanceof AppliedStereotypeTreeObject) {
- if (stereotype.equals(((AppliedStereotypeTreeObject) vChild).getStereotype())) {
- vAppliedStereotypeObject = (AppliedStereotypeTreeObject) vChild;
- }
- }
- }
-
- return vAppliedStereotypeObject;
-
- }
-
- private Object[] extractSelectedElements(ISelection pSelection) {
- List<Object> vObjectsList = new ArrayList<Object>();
- if (pSelection instanceof IStructuredSelection) {
- vObjectsList.addAll(Arrays.asList(((IStructuredSelection) pSelection).toArray()));
- }
- return vObjectsList.toArray();
- }
- }
-
- /**
- * Create command to execute during apply stereotype action.
- *
- * @param elt
- * Element where stereotype was applied
- * @param st
- * Stereotype to apply on element
- *
- * @param domain
- * Transaction domain to execute command
- * @return Command to execute to apply stereotype on element
- */
- protected Command getApplyStereotypeCommmand(final Element elt, final Stereotype st, final TransactionalEditingDomain domain) {
- return new RecordingCommand(domain) {
-
- /**
- * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
- */
- @Override
- protected void doExecute() {
- elt.applyStereotype(st);
- elt.eNotify(new NotificationImpl(Notification.SET, true, true, true));
- refresh();
- }
- };
- }
-
- /**
- * Create command execute during unapply stereotype action.
- *
- * @param elt
- * element where stereotype was unapplied
- * @param st
- * Stereotype to unapply on element
- * @param domain
- * Transaction domain to execute command
- * @return Command to execute to unapply stereotype on element
- */
- protected Command getUnapplyStereotypeCommand(final Element elt, final Stereotype st, final TransactionalEditingDomain domain) {
- return new RecordingCommand(domain) {
-
- /**
- * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
- */
- @Override
- protected void doExecute() {
- elt.unapplyStereotype(st);
- elt.eNotify(new NotificationImpl(Notification.SET, true, true, true));
- refresh();
- }
- };
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2008, 2014 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:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ * Christian W. Damus (CEA) - bug 323802
+ * Christian W. Damus (CEA) - bug 448139
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.properties.profile.ui.compositesformodel;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.impl.NotificationImpl;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.uml.profile.Activator;
+import org.eclipse.papyrus.uml.profile.preference.ProfilePreferenceConstants;
+import org.eclipse.papyrus.uml.profile.tree.ProfileElementContentProvider;
+import org.eclipse.papyrus.uml.profile.tree.ProfileElementLabelProvider;
+import org.eclipse.papyrus.uml.profile.tree.ProfileElementTreeViewerFilter;
+import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypePropertyTreeObject;
+import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypeTreeObject;
+import org.eclipse.papyrus.uml.profile.tree.objects.StereotypedElementTreeObject;
+import org.eclipse.papyrus.uml.profile.tree.objects.TreeObject;
+import org.eclipse.papyrus.uml.profile.utils.Util;
+import org.eclipse.papyrus.uml.properties.profile.ui.dialogs.ChooseSetStereotypeDialog;
+import org.eclipse.papyrus.uml.properties.profile.ui.panels.AppliedStereotypePanel;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+
+// TODO: Auto-generated Javadoc
+/**
+ * This composite is used to display applied stereotype in the model. It allows applying or desapply a stereotype
+ */
+public class AppliedStereotypeCompositeOnModel extends DecoratedTreeComposite implements ISelectionChangedListener {
+
+ /**
+ * Gets the domain.
+ *
+ * @return the domain
+ */
+ public TransactionalEditingDomain getEditingDomain(Element context) {
+ try {
+ return ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain(context);
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ return null;
+ }
+ }
+
+ /** The panel that display applied stereotypes. */
+ private AppliedStereotypePanel appliedStereotypePanel;
+
+ /** The label. */
+ protected CLabel label;
+
+ /**
+ * The default constructor.
+ *
+ * @param parent
+ * the parent Composite for this panel
+ */
+ public AppliedStereotypeCompositeOnModel(AppliedStereotypePanel parent) {
+ super(parent, SWT.NONE, "Applied stereotypes", true);
+
+ appliedStereotypePanel = parent;
+ }
+
+ /**
+ * create a composite applied stereotype on model.
+ *
+ * @param parent
+ * the parent composite
+ */
+ public AppliedStereotypeCompositeOnModel(Composite parent) {
+ super(parent, SWT.NONE, "Applied stereotypes", true);
+ }
+
+ /**
+ * apply a stereotype on current selected element.
+ */
+ protected void addAppliedStereotype() {
+
+ // Open stereotype selection (may add or remove)
+ ChooseSetStereotypeDialog dialog = new ChooseSetStereotypeDialog(this.getShell(), getElement());
+ int result = dialog.open();
+
+ if (result == Window.OK) {
+ // Retrieve selected element
+ Element element = getElement();
+
+ // compare the 2 lists (present list and future list
+ EList<Stereotype> oldStereotypeList = element.getAppliedStereotypes();
+ ArrayList<Stereotype> newStereotypeList = dialog.getSelectedElements();
+
+ // Keep newStereotype order (will be used at the end of the method)
+ EList<Stereotype> newOrderList = new BasicEList<Stereotype>();
+ newOrderList.addAll(newStereotypeList);
+
+ // If the 2 lists differ, apply the new list of stereotypes
+ if (!(newStereotypeList.equals(oldStereotypeList))) {
+
+ // Parse old list :
+ // if stereotype is in the new list : it is already applied
+ // --> don't unapply it
+ // --> remove it from new list
+ Iterator<Stereotype> it = oldStereotypeList.iterator();
+ while (it.hasNext()) {
+ Stereotype currentStOld = it.next();
+ if (newStereotypeList.contains(currentStOld)) {
+ newStereotypeList.remove(currentStOld);
+ } else {
+ unapplyStereotype(element, currentStOld);
+ }
+ }
+
+ // Already applied stereotype should have been removed
+ // apply others
+ Iterator<Stereotype> newApplyStereotypes = newStereotypeList.iterator();
+ while (newApplyStereotypes.hasNext()) {
+ Stereotype currentStereotype = newApplyStereotypes.next();
+ applyStereotype(element, currentStereotype);
+ }
+
+ // Update Stereotype order
+ // this.reorderStereotypeApplications(element, newOrderList);
+
+ // checkSelection(null);
+ selectionChanged(null);
+
+ if (appliedStereotypePanel != null) {
+ appliedStereotypePanel.refresh();
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Button action : open a selection dialog box that allow the user to choose stereotypes to apply (or unapply).
+ */
+ @Override
+ public void addButtonPressed() {
+ addAppliedStereotype();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Composite createContent(Composite parent, TabbedPropertySheetWidgetFactory factory) {
+ super.createContent(parent, factory);
+ createStereotypesTree();
+
+ removeButton.setToolTipText("Remove stereotype");
+ addButton.setToolTipText("Apply stereotype");
+
+ return this;
+ }
+
+ /**
+ * Creates the stereotypes tree.
+ *
+ * @return the tree of applied stereotypes and properties
+ */
+ private void createStereotypesTree() {
+ // Tree viewer shows applied stereotypes
+ treeViewer.setContentProvider(new ProfileElementContentProvider());
+ treeViewer.setLabelProvider(new ProfileElementLabelProvider());
+ treeViewer.addFilter(new ProfileElementTreeViewerFilter());
+ treeViewer.addSelectionChangedListener(this);
+ }
+
+ /**
+ * Button action : modify display order of stereotypes (selected elements are pushed down in the list).
+ */
+ @Override
+ public void downButtonPressed() {
+ int nbrOfSelection = getTree().getSelectionCount();
+ if (nbrOfSelection < 1) {
+ return;
+ }
+
+ TreeItem[] items = getTree().getSelection();
+ int indexLast = getTree().indexOf(items[items.length - 1]);
+ if (indexLast + 1 >= getElement().getAppliedStereotypes().size()) {
+ // do nothing
+ return;
+ }
+
+ for (int i = 0; i < nbrOfSelection; i++) {
+ TreeItem item = items[nbrOfSelection - 1 - i];
+ if (item.getData() instanceof AppliedStereotypeTreeObject) {
+ AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
+ EList stereotypes = new BasicEList();
+ stereotypes.addAll(element.getAppliedStereotypes());
+
+ int index = stereotypes.indexOf(sTO.getStereotype());
+ if ((index == -1) || (index >= stereotypes.size() - 1)) {
+ // Not found of already on top...
+ return;
+ }
+
+ stereotypes.move(index + 1, sTO.getStereotype());
+ this.reorderStereotypeApplications(element, stereotypes);
+ }
+ }
+ }
+
+ /**
+ * Edits the item.
+ *
+ * @param item
+ * the item
+ */
+ @Override
+ public void editItem(TreeItem item) {
+ // do nothing
+ }
+
+ /**
+ * Gets the selected.
+ *
+ * @return Returns the selected element.
+ */
+ public Element getSelected() {
+ return appliedStereotypePanel.getSelected();
+ }
+
+ /**
+ * Gets the tree.
+ *
+ * @return the tree
+ */
+ public Tree getTree() {
+ return treeViewer.getTree();
+ }
+
+ /**
+ * Checks if is in stereotype display.
+ *
+ * @param st
+ * the stereotype
+ *
+ * @return true, if checks if is in stereotype display
+ */
+ protected Boolean isInStereotypeDisplay(Stereotype st) {
+ return false;
+ }
+
+ /**
+ * Redraw the treeViewer while preserving selections and non-collapsed tree elements
+ * It is not sufficient to redraw only selected elements as an optimization, since
+ * derived stereotype attributes (that are not selected) might change in response to
+ * changing other attributes.
+ *
+ * @param propertyView
+ */
+ public void refreshTreeViewer() {
+ treeViewer.refresh();
+ }
+
+ /**
+ * Refresh the content of applied the applied stereotype tree.
+ */
+ @Override
+ public void refresh() {
+ super.refresh();
+
+ if (treeViewer.getTree() != null && !(treeViewer.getTree().isDisposed())) {
+ if (element != null) {
+ // Preserve selection
+ final ISelection selection = treeViewer.getSelection();
+ try {
+ treeViewer.setInput(new StereotypedElementTreeObject(element));
+ } finally {
+ treeViewer.setSelection(selection);
+ }
+ } else {
+ treeViewer.setInput(null);
+ }
+ StereotypedElementTreeObject rTO = (StereotypedElementTreeObject) treeViewer.getInput();
+ if (rTO == null) {
+ return;
+ }
+
+ boolean isEditable = isEditable();
+
+ // If the property is Multivalued show Up - Down
+ if ((rTO.getChildren() != null) && (rTO.getChildren().length > 1)) {
+ upButton.setEnabled(isEditable);
+ downButton.setEnabled(isEditable);
+ } else {
+ upButton.setEnabled(false);
+ downButton.setEnabled(false);
+ }
+
+ if ((rTO.getChildren() != null) && (rTO.getChildren().length == 0)) {
+ removeButton.setEnabled(false);
+ } else {
+ removeButton.setEnabled(isEditable);
+ }
+ }
+ }
+
+ /**
+ * Button action : unapply the stereotypes selected by the user in the stereotype tree.
+ */
+ @Override
+ public void removeButtonPressed() {
+ unapplyStereotype();
+ }
+
+ /**
+ * Selection changed.
+ *
+ * @param event
+ * the event
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (appliedStereotypePanel != null) {
+ if (event == null) {
+ appliedStereotypePanel.setSelectedProperty(null);
+ return;
+ }
+
+ IStructuredSelection structSelection = (IStructuredSelection) event.getSelection();
+ Object selection = structSelection.getFirstElement();
+ if (selection instanceof AppliedStereotypePropertyTreeObject) {
+ appliedStereotypePanel.setSelectedProperty((AppliedStereotypePropertyTreeObject) selection);
+ } else {
+ appliedStereotypePanel.setSelectedProperty(null);
+ }
+
+ }
+ }
+
+ /**
+ * Sets the input.
+ *
+ * @param element
+ * the element
+ */
+ public void setInput(StereotypedElementTreeObject element) {
+ // Preserve selection
+ final ISelection selection = treeViewer.getSelection();
+ try {
+ treeViewer.setInput(element);
+ } finally {
+ treeViewer.setSelection(selection);
+ }
+ if (Activator.getDefault().getPreferenceStore().getBoolean(ProfilePreferenceConstants.EXPAND_STEREOTYPES_TREE)) {
+ treeViewer.expandAll();
+ }
+ }
+
+ /**
+ * unapply stereotype on current selected element.
+ */
+ protected void unapplyStereotype() {
+ int nbrOfSelection = getTree().getSelectionCount();
+ if (nbrOfSelection == 0) {
+ return;
+ }
+
+ for (int i = 0; i < nbrOfSelection; i++) {
+ TreeItem item = getTree().getSelection()[i];
+ if (item.getData() instanceof AppliedStereotypeTreeObject) {
+ AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
+ unapplyStereotype(element, sTO.getStereotype());
+ sTO.removeMe();
+ }
+ }
+ if (appliedStereotypePanel != null) {
+ appliedStereotypePanel.refresh();
+ } else {
+ refresh();
+ }
+ }
+
+ /**
+ * Button action : modify display order of stereotypes (selected elements are pushed up in the list).
+ */
+ @Override
+ public void upButtonPressed() {
+ int nbrOfSelection = getTree().getSelectionCount();
+ if (nbrOfSelection < 1) {
+ return;
+ }
+
+ TreeItem[] items = getTree().getSelection();
+ int indexFirst = getTree().indexOf(items[0]);
+ if (indexFirst == 0) {
+ // do nothing
+ return;
+ }
+
+ for (int i = 0; i < nbrOfSelection; i++) {
+ TreeItem item = items[i];
+ if (item.getData() instanceof AppliedStereotypeTreeObject) {
+ AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
+ EList stereotypes = new BasicEList();
+ stereotypes.addAll(element.getAppliedStereotypes());
+
+ int index = stereotypes.indexOf(sTO.getStereotype());
+ if (index < 1) {
+ return;
+ }
+
+ stereotypes.move(index - 1, sTO.getStereotype());
+ this.reorderStereotypeApplications(element, stereotypes);
+ }
+ }
+ if (appliedStereotypePanel != null) {
+ appliedStereotypePanel.refresh();
+ } else {
+ refresh();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.properties.profile.ui.compositesformodel.DecoratedTreeComposite#keepSelection(org.eclipse.jface.viewers.ISelection)
+ *
+ * @param pSelection
+ */
+ @Override
+ public void keepSelection(ISelection pSelection) {
+ getDisplay().asyncExec(new SelectionKeeper(pSelection));
+ }
+
+ /**
+ * Apply stereotype.
+ *
+ * @param elt
+ * the elt
+ * @param st
+ * the st
+ */
+ public void applyStereotype(final Element elt, final Stereotype st) {
+ try {
+ final TransactionalEditingDomain domain = getEditingDomain(elt);
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ domain.getCommandStack().execute(getApplyStereotypeCommand(elt, st, domain));
+ }
+ });
+ }
+ });
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ }
+
+ /**
+ * Unapply stereotype.
+ *
+ * @param elt
+ * the uml element
+ * @param st
+ * the stereotype to unapply
+ */
+ protected void unapplyStereotype(final Element elt, final Stereotype st) {
+ // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline)
+ try {
+ final TransactionalEditingDomain domain = getEditingDomain(elt);
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ domain.getCommandStack().execute(getUnapplyStereotypeCommand(elt, st, domain));
+ }
+ });
+ }
+ });
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ }
+
+ /**
+ * change the order of applied stereotype
+ *
+ * @param element
+ * the UML element where stereotypes are applied
+ * @param stereotypes
+ * the lis of applied stereotypes with the wanted order
+ */
+ public void reorderStereotypeApplications(final Element element, final EList stereotypes) {
+ try {
+ final TransactionalEditingDomain domain = getEditingDomain(element);
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ domain.getCommandStack().execute(new RecordingCommand(domain) {
+
+ @Override
+ protected void doExecute() {
+ Util.reorderStereotypeApplications(element, stereotypes);
+ refresh();
+ }
+ });
+ }
+ });
+ }
+ });
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ }
+
+ /**
+ *
+ * @author gpascual
+ *
+ */
+ private class SelectionKeeper implements Runnable {
+
+ /** Selection to keep. */
+ ISelection selection = null;
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public SelectionKeeper(ISelection selection) {
+ this.selection = selection;
+ }
+
+ public void run() {
+ Object[] vSelectedElements = extractSelectedElements(selection);
+ Object[] vCorrespondingElements = getCorrespondingElements(vSelectedElements);
+ ISelection vSelection = new StructuredSelection(vCorrespondingElements);
+ treeViewer.setSelection(vSelection);
+
+ }
+
+
+
+
+
+ private Object[] getCorrespondingElements(Object[] vSelectedElements) {
+ StereotypedElementTreeObject vStereotypesTree = (StereotypedElementTreeObject) treeViewer.getInput();
+ List<Object> vReturn = new ArrayList<Object>();
+ for (Object vStereotype : vSelectedElements) {
+ if (vStereotype instanceof AppliedStereotypeTreeObject) {
+ AppliedStereotypeTreeObject vTreeObject = findAppliedStereotypeInTree(((AppliedStereotypeTreeObject) vStereotype).getStereotype(), vStereotypesTree);
+ vReturn.add(vTreeObject);
+ }
+ }
+
+ return vReturn.toArray();
+ }
+
+ private AppliedStereotypeTreeObject findAppliedStereotypeInTree(Stereotype stereotype, StereotypedElementTreeObject vStereotypesTree) {
+ AppliedStereotypeTreeObject vAppliedStereotypeObject = null;
+
+ for (TreeObject vChild : vStereotypesTree.getChildren()) {
+ if (vChild instanceof AppliedStereotypeTreeObject) {
+ if (stereotype.equals(((AppliedStereotypeTreeObject) vChild).getStereotype())) {
+ vAppliedStereotypeObject = (AppliedStereotypeTreeObject) vChild;
+ }
+ }
+ }
+
+ return vAppliedStereotypeObject;
+
+ }
+
+ private Object[] extractSelectedElements(ISelection pSelection) {
+ List<Object> vObjectsList = new ArrayList<Object>();
+ if (pSelection instanceof IStructuredSelection) {
+ vObjectsList.addAll(Arrays.asList(((IStructuredSelection) pSelection).toArray()));
+ }
+ return vObjectsList.toArray();
+ }
+ }
+
+ /**
+ * Create command to execute during apply stereotype action.
+ *
+ * @param elt
+ * Element where stereotype was applied
+ * @param st
+ * Stereotype to apply on element
+ *
+ * @param domain
+ * Transaction domain to execute command
+ * @return Command to execute to apply stereotype on element
+ */
+ protected Command getApplyStereotypeCommand(final Element elt, final Stereotype st, final TransactionalEditingDomain domain) {
+ return new RecordingCommand(domain) {
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ */
+ @Override
+ protected void doExecute() {
+ elt.applyStereotype(st);
+ refresh();
+ }
+ };
+ }
+
+ /**
+ * Create command execute during unapply stereotype action.
+ *
+ * @param elt
+ * element where stereotype was unapplied
+ * @param st
+ * Stereotype to unapply on element
+ * @param domain
+ * Transaction domain to execute command
+ * @return Command to execute to unapply stereotype on element
+ */
+ protected Command getUnapplyStereotypeCommand(final Element elt, final Stereotype st, final TransactionalEditingDomain domain) {
+ return new RecordingCommand(domain) {
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ */
+ @Override
+ protected void doExecute() {
+ elt.unapplyStereotype(st);
+ elt.eNotify(new NotificationImpl(Notification.SET, true, true, true));
+ refresh();
+ }
+ };
+ }
+
+
+}

Back to the top