Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineLabelHelper.java')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineLabelHelper.java87
1 files changed, 33 insertions, 54 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineLabelHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineLabelHelper.java
index c0926ed9fa8..d2628591f4e 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineLabelHelper.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineLabelHelper.java
@@ -1,22 +1,31 @@
package org.eclipse.papyrus.uml.diagram.sequence.util;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.helper.StereotypedElementLabelHelper;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineNameEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.preferences.CustomLifelinePreferencePage;
+import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
import org.eclipse.uml2.uml.ConnectableElement;
import org.eclipse.uml2.uml.Lifeline;
import org.eclipse.uml2.uml.Type;
public class LifelineLabelHelper extends StereotypedElementLabelHelper {
+ public static final String SHOW_REPRESENT_NAME = "representsName";
+
+ public static final String SHOW_REPRESENT_TYPE = "representsType";
+
+ public static final String SHOW_UNDEFINED_TYPE = "undefinedType";
+
+ public static final String SHOW_LIFELINE_NAME = "lifelineName";
+
+ public static final Collection<String> DEFAULT_LABEL_DISPLAY = Arrays.asList(SHOW_REPRESENT_NAME, SHOW_REPRESENT_TYPE);
+
/**
* singelton instance
*/
@@ -24,7 +33,7 @@ public class LifelineLabelHelper extends StereotypedElementLabelHelper {
/**
* Returns the singleton instance of this class
- *
+ *
* @return the singleton instance.
*/
public static LifelineLabelHelper getInstance() {
@@ -35,61 +44,34 @@ public class LifelineLabelHelper extends StereotypedElementLabelHelper {
}
/** Map for masks */
- protected final Map<Integer, String> masks = new HashMap<Integer, String>(7);
+ protected final Map<String, String> masks = new HashMap<String, String>();
/**
* Creates a new Operation label helper.
*/
protected LifelineLabelHelper() {
// initialize the map
- masks.put(CustomLifelinePreferencePage.SHOW_REPRESENT_NAME, "Show represent name");
- masks.put(CustomLifelinePreferencePage.SHOW_REPRESENT_TYPE, "Show represent type");
- masks.put(CustomLifelinePreferencePage.SHOW_UNDEFINED_TYPE, "Always show undefined type");
- masks.put(CustomLifelinePreferencePage.SHOW_LIFELINE_NAME, "Always show lifeline name");
- }
-
- /**
- * Returns the mask name given the value of the mask
- *
- * @return the mask name or <code>null</code> if no masks has been found
- */
- public String getMaskLabel(int value) {
- return masks.get(value);
- }
-
- /**
- * Returns the collection of mask names
- *
- * @return the collection of mask names
- */
- public Collection<String> getMaskLabels() {
- return masks.values();
+ masks.put(SHOW_REPRESENT_NAME, "Show represent name");
+ masks.put(SHOW_REPRESENT_TYPE, "Show represent type");
+ masks.put(SHOW_UNDEFINED_TYPE, "Always show undefined type");
+ masks.put(SHOW_LIFELINE_NAME, "Always show lifeline name");
}
/**
* Returns the map of masks used to display
- *
+ *
* @return the map of masks used to display
*/
- public Map<Integer, String> getMasks() {
+ public Map<String, String> getMasks() {
return masks;
}
/**
- * Returns the collection of mask values
- *
- * @return the collection of mask values
- */
- public Set<Integer> getMaskValues() {
- return masks.keySet();
- }
-
- /**
* {@inheritDoc}
*/
@Override
public Lifeline getUMLElement(GraphicalEditPart editPart) {
- return (Lifeline)((View)editPart.getModel()).getElement();
+ return (Lifeline)UMLUtil.resolveUMLElement(editPart);
}
@Override
@@ -97,7 +79,7 @@ public class LifelineLabelHelper extends StereotypedElementLabelHelper {
if(editPart instanceof LifelineNameEditPart) {
editPart = (GraphicalEditPart)editPart.getParent();
}
- int displayValue = CustomLifelinePreferencePage.DEFAULT_LABEL_DISPLAY;
+ Collection<String> displayValue = DEFAULT_LABEL_DISPLAY;
IMaskManagedLabelEditPolicy policy = (IMaskManagedLabelEditPolicy)editPart.getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
if(policy != null) {
displayValue = policy.getCurrentDisplayValue();
@@ -110,11 +92,11 @@ public class LifelineLabelHelper extends StereotypedElementLabelHelper {
private static final String UNDEFINED = "<Undefined>";
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=383722
- private String getCustomLabel(Lifeline lifeline, int displayValue) {
+ private String getCustomLabel(Lifeline lifeline, Collection<String> displayValue) {
StringBuilder sb = new StringBuilder();
appendName(lifeline, displayValue, sb);
- boolean displayType = isCheck(displayValue, CustomLifelinePreferencePage.SHOW_REPRESENT_TYPE);
- if(lifeline.getRepresents() == null || isCheck(displayValue, CustomLifelinePreferencePage.SHOW_LIFELINE_NAME)) {
+ boolean displayType = displayValue.contains(SHOW_REPRESENT_TYPE);
+ if(lifeline.getRepresents() == null || displayValue.contains(LifelineLabelHelper.SHOW_LIFELINE_NAME)) {
displayType = false;
}
if(displayType) {
@@ -124,33 +106,33 @@ public class LifelineLabelHelper extends StereotypedElementLabelHelper {
return sb.toString();
}
- protected void appendName(Lifeline lifeline, int displayValue, StringBuilder sb) {
+ protected void appendName(Lifeline lifeline, Collection<String> displayValue, StringBuilder sb) {
ConnectableElement element = lifeline.getRepresents();
String lifelineName = lifeline.getName();
- if(element == null || isCheck(displayValue, CustomLifelinePreferencePage.SHOW_LIFELINE_NAME)) {
+ if(element == null || displayValue.contains(SHOW_LIFELINE_NAME)) {
appendString(sb, lifelineName, UNAMED);
return;
} else {
// represents is not null
- if(isCheck(displayValue, CustomLifelinePreferencePage.SHOW_REPRESENT_NAME)) {
+ if(displayValue.contains(SHOW_REPRESENT_NAME)) {
appendString(sb, element.getName(), UNAMED);
}
// if neither <1> or <2> are checked, show lifeline name (or <unnamed> when the lifeline has no name)
- else if(!isCheck(displayValue, CustomLifelinePreferencePage.SHOW_REPRESENT_TYPE)) {
+ else if(!displayValue.contains(SHOW_REPRESENT_TYPE)) {
appendString(sb, lifelineName, UNAMED);
}
}
}
- protected void appendType(Lifeline lifeline, int displayValue, StringBuilder sb) {
+ protected void appendType(Lifeline lifeline, Collection<String> displayValue, StringBuilder sb) {
ConnectableElement element = lifeline.getRepresents();
if(element == null) {
return;
}
Type type = element.getType();
- if(isCheck(displayValue, CustomLifelinePreferencePage.SHOW_REPRESENT_TYPE)) {
+ if(displayValue.contains(SHOW_REPRESENT_TYPE)) {
if(type == null) {
- if(isCheck(displayValue, CustomLifelinePreferencePage.SHOW_UNDEFINED_TYPE)) {
+ if(displayValue.contains(SHOW_UNDEFINED_TYPE)) {
sb.append(":").append(UNDEFINED);
}
} else {
@@ -159,10 +141,6 @@ public class LifelineLabelHelper extends StereotypedElementLabelHelper {
}
}
- private static boolean isCheck(int value, int mask) {
- return (value & mask) != 0;
- }
-
private void appendString(StringBuilder sb, String str, String defaultValue) {
if(str != null) {
sb.append(str);
@@ -170,4 +148,5 @@ public class LifelineLabelHelper extends StereotypedElementLabelHelper {
sb.append(defaultValue);
}
}
+
}

Back to the top