Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/figures/StateFigure.java')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/figures/StateFigure.java130
1 files changed, 129 insertions, 1 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/figures/StateFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/figures/StateFigure.java
index 07838b55d7d..6eaf56b04fb 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/figures/StateFigure.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.statemachine/custom-src/org/eclipse/papyrus/uml/diagram/statemachine/custom/figures/StateFigure.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2014 CEA LIST.
+ * Copyright (c) 2014-2017 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,13 +8,16 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Pauline DEVILLE (CEA LIST): Bug 509015 - [StateMachineDiagram] lacks support for UML 2.5 notation of redefinable elements with isLeaf=true
*/
package org.eclipse.papyrus.uml.diagram.statemachine.custom.figures;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.RectangleFigure;
+import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel;
import org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure;
/**
@@ -26,6 +29,16 @@ public class StateFigure extends RoundedCompartmentFigure {
protected boolean isSubmachineState = false;
+ /**
+ * The isLeaf feature of the state
+ */
+ protected boolean isLeafState = false;
+
+ /** The final label. */
+ protected PapyrusWrappingLabel finalLabel;
+
+ private static final String FINAL_LABEL_VALUE = "final";
+
/** The State Compartment */
private final static String STATE_COMPARTMENT = "stateCompartment";
@@ -53,6 +66,7 @@ public class StateFigure extends RoundedCompartmentFigure {
*/
public StateFigure(String tagLabel) {
super(COMPARTMENT, tagLabel);
+ createFinalLabel();
}
public void setSubmachineStateName(String text) {
@@ -64,6 +78,14 @@ public class StateFigure extends RoundedCompartmentFigure {
}
/**
+ * @param isLeafState
+ * the isLeafState to set
+ */
+ public void setIsLeafState(boolean isLeafState) {
+ this.isLeafState = isLeafState;
+ }
+
+ /**
* Get the state compartment figure
*
* @return
@@ -72,4 +94,110 @@ public class StateFigure extends RoundedCompartmentFigure {
return getCompartment(STATE_COMPARTMENT);
}
+ /**
+ * Create the final label in the figure.
+ */
+ protected void createFinalLabel() {
+ finalLabel = new PapyrusWrappingLabel();
+ String textToDisplay = new StringBuffer(CHEVRON).insert(1, FINAL_LABEL_VALUE).toString();
+ finalLabel.setText(textToDisplay);
+ finalLabel.setOpaque(false);
+ finalLabel.setAlignment(namePosition);
+ finalLabel.setForegroundColor(getNameLabel().getForegroundColor());
+ finalLabel.setFont(getNameLabel().getFont());
+ if (isLeafState) {
+ getTagLabelContainer().add(finalLabel, getTagLabelConstraint(), getFinalLabelPosition());
+ }
+ }
+
+ public void restoreFinalLabel() {
+ if (isLeafState && finalLabel != null) {
+ finalLabel.setOpaque(false);
+ finalLabel.setAlignment(namePosition);
+ getFinalLabelContainer().add(finalLabel, getFinalLabelConstraint(), getFinalLabelPosition());
+ } else {
+ removeFinalLabel();
+ }
+ }
+
+ /**
+ * Create a label that contains the stereotype of the element.
+ */
+ protected void removeFinalLabel() {
+ if (finalLabel != null) {
+ if (getFinalLabelContainer().getChildren().contains(finalLabel)) {
+ getFinalLabelContainer().remove(finalLabel);
+ }
+ }
+ }
+
+ /**
+ * @return the position of the label
+ */
+ protected int getFinalLabelPosition() {
+ int position = 0;
+ if (getFinalLabelContainer().equals(getNameLabelContainer())) {
+ // located after name label
+ position = getNameLabelPosition();
+ if (this.nameLabel != null) {
+ position++;
+ }
+ } else if (getFinalLabelContainer().equals(getQualifiedNameLabelContainer())) {
+ // located after qualifed name label
+ position = getQualifiedNameLabelPosition();
+ if (this.qualifiedLabel != null) {
+ position++;
+ }
+ } else if (getFinalLabelContainer().equals(getStereotypePropertiesInBraceLabelContainer())) {
+ // located after stereotype properties in brace label
+ position = getStereotypePropertiesLabelPosition();
+ if (this.stereotypePropertiesInBraceContent != null) {
+ position++;
+ }
+ } else if (getFinalLabelContainer().equals(getStereotypeLabelContainer())) {
+ // located after stereotype label
+ position = getStereotypeLabelPosition();
+ if (this.stereotypesLabel != null) {
+ position++;
+ }
+ } else if (getFinalLabelContainer().equals(getIconLabelContainer())) {
+ // located after icon label
+ position = getIconLabelPosition();
+ if ((this.iconLabel != null) && (this.iconLabel.getIcon() != null)) {
+ position++;
+ }
+ }
+ return position;
+ }
+
+ /**
+ * Get the constraint for adding the final label.
+ *
+ * @return figure containing the final label
+ */
+ protected Object getFinalLabelConstraint() {
+ return getDefaultLabelsConstraint();
+ }
+
+ /**
+ * Get the container for the final label.
+ *
+ * @return figure containing the final label
+ */
+ protected IFigure getFinalLabelContainer() {
+ return getDefaultLabelsContainer();
+ }
+
+ /**
+ * Helper method to calculate the height of name
+ */
+ @Override
+ protected int getNameHeight() {
+ int nameHeight = super.getNameHeight();
+ if (finalLabel != null && getFinalLabelContainer().equals(getNameLabelContainer())) {
+ nameHeight += finalLabel.getPreferredSize().height;
+ }
+ return nameHeight;
+ }
+
}

Back to the top