Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/FloatingLabelEditPart.java173
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/RoundedCompartmentEditPart.java80
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/FloatingLabelEditPolicy.java248
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/FloatingLabelHelper.java325
4 files changed, 706 insertions, 120 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/FloatingLabelEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/FloatingLabelEditPart.java
index 6964c855862..a9a298218df 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/FloatingLabelEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/FloatingLabelEditPart.java
@@ -1,80 +1,93 @@
-/*****************************************************************************
- * Copyright (c) 2010, 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:
- * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.editparts;
-
-import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
-import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * The Class FloatingNameEditPart.
- */
-public class FloatingLabelEditPart extends LabelEditPart {
-
- /** The Constant DISPLAY_FLOATING_NAME. */
- private static final String DISPLAY_FLOATING_LABEL = "displayFloatingLabel";
-
-
- /** The Constant DEFAULT_LABEL_DISPLAYED. */
- private static final boolean DEFAULT_LABEL_DISPLAYED = false;
-
- /**
- * Instantiates a new floating name edit part.
- *
- * @param view
- * the view
- */
- public FloatingLabelEditPart(View view) {
- super(view);
- }
-
- /**
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#refreshVisibility()
- *
- */
- @Override
- protected void refreshVisibility() {
- super.refreshVisibility();
- //get the value of the CSS property
- BooleanValueStyle isLabelDisplayedValue = (BooleanValueStyle)((View)((View)getModel()).eContainer()).getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), getDisplayFloatingLabel());
-
- //if the property exist set the visibility of the floating name
- boolean isLabelDisplayed;
- if(isLabelDisplayedValue == null) {
- isLabelDisplayed = getDefaultLabelDisplayedValue();
- } else {
- isLabelDisplayed = isLabelDisplayedValue.isBooleanValue();
- }
- getFigure().setVisible(isLabelDisplayed);
- }
-
- /**
- * Gets the default label displayed value.
- *
- * @return the default label displayed value
- */
- protected boolean getDefaultLabelDisplayedValue() {
- return DEFAULT_LABEL_DISPLAYED;
- }
-
- /**
- * Gets the display floating label.
- *
- * @return the display floating label
- */
- public static String getDisplayFloatingLabel() {
- return DISPLAY_FLOATING_LABEL;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2010, 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:
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.editparts;
+
+import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
+import org.eclipse.gmf.runtime.notation.BooleanValueStyle;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.FloatingLabelEditPolicy;
+
+/**
+ * The Class FloatingNameEditPart.
+ */
+public class FloatingLabelEditPart extends LabelEditPart {
+
+ /** The Constant DISPLAY_FLOATING_NAME. */
+ private static final String DISPLAY_FLOATING_LABEL = "displayFloatingLabel";
+
+
+ /** The Constant DEFAULT_LABEL_DISPLAYED. */
+ private static final boolean DEFAULT_LABEL_DISPLAYED = false;
+
+ /**
+ * Instantiates a new floating label edit part.
+ *
+ * @param view
+ * the view
+ */
+ public FloatingLabelEditPart(View view) {
+ super(view);
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart#createDefaultEditPolicies()
+ *
+ */
+ @Override
+ protected void createDefaultEditPolicies() {
+ super.createDefaultEditPolicies();
+ // installEditPolicy(org.eclipse.papyrus.uml.diagram.common.editpolicies.ExternalLabelDisplayEditPolicy.EXTERNAL_LABEL_POLICY, new ExternalLabelDisplayEditPolicy());
+ installEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL, new FloatingLabelEditPolicy());
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#refreshVisibility()
+ *
+ */
+ @Override
+ protected void refreshVisibility() {
+ super.refreshVisibility();
+ // get the value of the CSS property
+ BooleanValueStyle isLabelDisplayedValue = (BooleanValueStyle) ((View) ((View) getModel()).eContainer()).getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), getDisplayFloatingLabel());
+
+ // if the property exist set the visibility of the floating label
+ boolean isLabelDisplayed;
+ if (isLabelDisplayedValue == null) {
+ isLabelDisplayed = getDefaultLabelDisplayedValue();
+ } else {
+ isLabelDisplayed = isLabelDisplayedValue.isBooleanValue();
+ }
+ getFigure().setVisible(isLabelDisplayed);
+ }
+
+ /**
+ * Gets the default label displayed value.
+ *
+ * @return the default label displayed value
+ */
+ protected boolean getDefaultLabelDisplayedValue() {
+ return DEFAULT_LABEL_DISPLAYED;
+ }
+
+ /**
+ * Gets the display floating label.
+ *
+ * @return the display floating label
+ */
+ public static String getDisplayFloatingLabel() {
+ return DISPLAY_FLOATING_LABEL;
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/RoundedCompartmentEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/RoundedCompartmentEditPart.java
index a1cccdd79ec..9746921f754 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/RoundedCompartmentEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/RoundedCompartmentEditPart.java
@@ -26,13 +26,13 @@ import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEd
public abstract class RoundedCompartmentEditPart extends NamedElementEditPart {
/** The Constant FLOATING_NAME_OFFSET_HEIGHT. */
- protected static final String FLOATING_NAME_OFFSET_HEIGHT = "floatingNameOffsetHeight";
+ protected static final String FLOATING_LABEL_OFFSET_HEIGHT = "floatingLabelOffsetHeight";
/** The Constant FLOATING_NAME_OFFSET_WIDTH. */
- protected static final String FLOATING_NAME_OFFSET_WIDTH = "floatingNameOffsetWidth";
+ protected static final String FLOATING_LABEL_OFFSET_WIDTH = "floatingLabelOffsetWidth";
/** CSS boolean property controlling whether label should be constrained. */
- public static final String FLOATING_NAME_CONSTRAINED = "isFloatingNameConstrained";
+ public static final String FLOATING_LABEL_CONSTRAINED = "isFloatingLabelConstrained";
/** CSS boolean property controlling whether. */
public static final String RADIUS_WIDTH = "radiusWidth";
@@ -43,11 +43,11 @@ public abstract class RoundedCompartmentEditPart extends NamedElementEditPart {
/** CSS boolean property controlling whether. */
public static final String IS_OVAL = "isOval";
- private static final boolean DEFAULT_IS_FLOATING_NAME_CONSTRAINED = false;
+ private static final boolean DEFAULT_IS_FLOATING_LABEL_CONSTRAINED = false;
- private static final int DEFAULT_FLOATING_NAME_OFFSET_WIDTH = 0;
+ private static final int DEFAULT_FLOATING_LABEL_OFFSET_WIDTH = 0;
- private static final int DEFAULT_FLOATING_NAME_OFFSET_HEIGHT = 0;
+ private static final int DEFAULT_FLOATING_LABEL_OFFSET_HEIGHT = 0;
private static final int DEFAULT_CORNER_WIDTH = 0;
@@ -59,7 +59,7 @@ public abstract class RoundedCompartmentEditPart extends NamedElementEditPart {
* Instantiates a new rounded compartment edit part.
*
* @param view
- * the view
+ * the view
*/
public RoundedCompartmentEditPart(View view) {
super(view);
@@ -69,7 +69,7 @@ public abstract class RoundedCompartmentEditPart extends NamedElementEditPart {
@Override
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
- //Install Edit Policy to Hide/show compartment, in particular for the symbol compartment
+ // Install Edit Policy to Hide/show compartment, in particular for the symbol compartment
installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy());
}
@@ -90,32 +90,32 @@ public abstract class RoundedCompartmentEditPart extends NamedElementEditPart {
* Refresh floating name.
*/
protected void refreshFloatingName() {
- if(getPrimaryShape() instanceof IRoundedRectangleFigure) {
- //The figure
- IRoundedRectangleFigure roundedRectangleFigure = (IRoundedRectangleFigure)getPrimaryShape();
+ if (getPrimaryShape() instanceof IRoundedRectangleFigure) {
+ // The figure
+ IRoundedRectangleFigure roundedRectangleFigure = (IRoundedRectangleFigure) getPrimaryShape();
- //Get CSS value for the name attached properties
- BooleanValueStyle isNameConstrainedValue = (BooleanValueStyle)((View)getModel()).getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), FLOATING_NAME_CONSTRAINED);
+ // Get CSS value for the name attached properties
+ BooleanValueStyle isNameConstrainedValue = (BooleanValueStyle) ((View) getModel()).getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), FLOATING_LABEL_CONSTRAINED);
boolean isNameConstrained;
- //if no css property set to default value
- if(isNameConstrainedValue == null) {
+ // if no css property set to default value
+ if (isNameConstrainedValue == null) {
isNameConstrained = getDefaultIsFloatingNameConstrained();
} else {
isNameConstrained = isNameConstrainedValue.isBooleanValue();
}
- //Set the name attached properties in figure
+ // Set the name attached properties in figure
roundedRectangleFigure.setFloatingNameConstrained(isNameConstrained);
- //get Offset
- //get CSS the value of offset Width
- IntValueStyle offsetWidth = (IntValueStyle)((View)getModel()).getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), FLOATING_NAME_OFFSET_WIDTH);
+ // get Offset
+ // get CSS the value of offset Width
+ IntValueStyle offsetWidth = (IntValueStyle) ((View) getModel()).getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), FLOATING_LABEL_OFFSET_WIDTH);
int width = offsetWidth != null ? offsetWidth.getIntValue() : getDefaultFloatingNameOffsetWidth();
- //get CSS the value of offset Height
- IntValueStyle offsetHeight = (IntValueStyle)((View)getModel()).getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), FLOATING_NAME_OFFSET_HEIGHT);
+ // get CSS the value of offset Height
+ IntValueStyle offsetHeight = (IntValueStyle) ((View) getModel()).getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), FLOATING_LABEL_OFFSET_HEIGHT);
int height = offsetHeight != null ? offsetHeight.getIntValue() : getDefaultFloatingNameOffsetHeight();
- //Set the floating name offset
+ // Set the floating name offset
roundedRectangleFigure.setFloatingNameOffset(new Dimension(width, height));
}
@@ -128,7 +128,7 @@ public abstract class RoundedCompartmentEditPart extends NamedElementEditPart {
* @return the default is name constrained
*/
protected boolean getDefaultIsFloatingNameConstrained() {
- return DEFAULT_IS_FLOATING_NAME_CONSTRAINED;
+ return DEFAULT_IS_FLOATING_LABEL_CONSTRAINED;
}
/**
@@ -137,7 +137,7 @@ public abstract class RoundedCompartmentEditPart extends NamedElementEditPart {
* @return the default floating name offset height
*/
protected int getDefaultFloatingNameOffsetHeight() {
- return DEFAULT_FLOATING_NAME_OFFSET_HEIGHT;
+ return DEFAULT_FLOATING_LABEL_OFFSET_HEIGHT;
}
/**
@@ -146,28 +146,28 @@ public abstract class RoundedCompartmentEditPart extends NamedElementEditPart {
* @return the default floating name offset width
*/
protected int getDefaultFloatingNameOffsetWidth() {
- return DEFAULT_FLOATING_NAME_OFFSET_WIDTH;
+ return DEFAULT_FLOATING_LABEL_OFFSET_WIDTH;
}
/**
* Refresh radius.
*/
protected void refreshRadius() {
- if(getPrimaryShape() instanceof IRoundedRectangleFigure) {
- //The figure
- IRoundedRectangleFigure roundedRectangleFigure = (IRoundedRectangleFigure)getPrimaryShape();
+ if (getPrimaryShape() instanceof IRoundedRectangleFigure) {
+ // The figure
+ IRoundedRectangleFigure roundedRectangleFigure = (IRoundedRectangleFigure) getPrimaryShape();
Dimension radiusDimension = new Dimension();
- //get CSS the value of radius Width
- IntValueStyle radiusWidth = (IntValueStyle)((View)getModel()).getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), RADIUS_WIDTH);
+ // get CSS the value of radius Width
+ IntValueStyle radiusWidth = (IntValueStyle) ((View) getModel()).getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), RADIUS_WIDTH);
radiusDimension.width = radiusWidth != null ? radiusWidth.getIntValue() : getDefaultCornerWidth();
- //get CSS the value of radius Height
- IntValueStyle radiusHeight = (IntValueStyle)((View)getModel()).getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), RADIUS_HEIGHT);
+ // get CSS the value of radius Height
+ IntValueStyle radiusHeight = (IntValueStyle) ((View) getModel()).getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), RADIUS_HEIGHT);
radiusDimension.height = radiusHeight != null ? radiusHeight.getIntValue() : getDefaultCornerHeight();
- //Set the corner dimension
+ // Set the corner dimension
roundedRectangleFigure.setCornerDimensions(radiusDimension);
}
}
@@ -194,18 +194,18 @@ public abstract class RoundedCompartmentEditPart extends NamedElementEditPart {
* Refresh oval.
*/
protected void refreshOval() {
- if(getPrimaryShape() instanceof IRoundedRectangleFigure) {
- //The figure
- IRoundedRectangleFigure roundedRectangleFigure = (IRoundedRectangleFigure)getPrimaryShape();
- //get the CSS value of isOval
- BooleanValueStyle isOvalValue = (BooleanValueStyle)((View)getModel()).getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), IS_OVAL);
+ if (getPrimaryShape() instanceof IRoundedRectangleFigure) {
+ // The figure
+ IRoundedRectangleFigure roundedRectangleFigure = (IRoundedRectangleFigure) getPrimaryShape();
+ // get the CSS value of isOval
+ BooleanValueStyle isOvalValue = (BooleanValueStyle) ((View) getModel()).getNamedStyle(NotationPackage.eINSTANCE.getBooleanValueStyle(), IS_OVAL);
boolean isOval;
- if(isOvalValue == null) {
+ if (isOvalValue == null) {
isOval = getDefaultIsOvalValue();
} else {
isOval = isOvalValue.isBooleanValue();
}
- //Set isOval
+ // Set isOval
roundedRectangleFigure.setOval(isOval);
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/FloatingLabelEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/FloatingLabelEditPolicy.java
new file mode 100644
index 00000000000..86da3847ba3
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/FloatingLabelEditPolicy.java
@@ -0,0 +1,248 @@
+/*****************************************************************************
+ * Copyright (c) 2010, 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:
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.helper.FloatingLabelHelper;
+import org.eclipse.papyrus.uml.tools.utils.ICustomAppearance;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.MultiplicityElement;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Parameter;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.Signal;
+import org.eclipse.uml2.uml.TypedElement;
+import org.eclipse.uml2.uml.UMLPackage;
+
+// TODO: Auto-generated Javadoc
+/**
+ * Specific edit policy for label displaying stereotypes and their properties for edges representing
+ * UML elements.
+ */
+public class FloatingLabelEditPolicy extends AbstractMaskManagedEditPolicy {
+
+ /**
+ * Creates a new PropertyLabelEditPolicy.
+ */
+ public FloatingLabelEditPolicy() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addAdditionalListeners() {
+ super.addAdditionalListeners();
+ NamedElement umlElement = getUMLElement();
+ // check host semantic element is not null
+ if (umlElement == null) {
+ Activator.log.error("No semantic element present when adding listeners in FloatingLabelEditPolicy", null);
+ return;
+ }
+ // adds a listener to the element itself, and to linked elements, like Type
+ if (umlElement instanceof TypedElement) {
+ if (((TypedElement) umlElement).getType() != null) {
+ getDiagramEventBroker().addNotificationListener(((TypedElement) umlElement).getType(), this);
+ }
+ }
+ if (umlElement instanceof MultiplicityElement) {
+ getDiagramEventBroker().addNotificationListener(((MultiplicityElement) umlElement).getUpperValue(), this);
+ getDiagramEventBroker().addNotificationListener(((MultiplicityElement) umlElement).getLowerValue(), this);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Collection<String> getDefaultDisplayValue() {
+ NamedElement umlElement = getUMLElement();
+ if (umlElement != null) {
+
+ /**
+ * default uml operation display.
+ */
+ if (umlElement instanceof Operation) {
+ return ICustomAppearance.DEFAULT_UML_OPERATION;
+ }
+
+ /**
+ * default uml Port ins composite diagrams.
+ */
+ if (umlElement instanceof Port) {
+ return ICustomAppearance.DEFAULT_UML_PORT;
+ }
+
+ /**
+ * default uml Parameter in composite diagrams.
+ */
+ if (umlElement instanceof Parameter) {
+ return ICustomAppearance.DEFAULT_UML_PARAMETER;
+ }
+
+ /**
+ * default uml instancespecification .
+ */
+ if (umlElement instanceof InstanceSpecification) {
+ return ICustomAppearance.DEFAULT_UML_INSTANCESPECIFICATION;
+ }
+
+ /**
+ * default uml Signal .
+ */
+ if (umlElement instanceof Signal) {
+ return Arrays.asList(ICustomAppearance.DISP_NAME, ICustomAppearance.DISP_TYPE);
+ }
+
+ }
+ return ICustomAppearance.DEFAULT_UML_FLOATING_LABEL;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Map<String, String> getMasks() {
+ return FloatingLabelHelper.getInstance().getMasks();
+ }
+
+ /**
+ * {@inheritedDoc}.
+ *
+ * @return the UML element
+ */
+ @Override
+ public NamedElement getUMLElement() {
+ EObject element = super.getUMLElement();
+ if (element instanceof NamedElement) {
+ return (NamedElement) element;
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritedDoc}.
+ *
+ * @param notification
+ * the notification
+ */
+ @Override
+ public void notifyChanged(Notification notification) {
+ super.notifyChanged(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
+ Object object = notification.getNotifier();
+ NamedElement property = getUMLElement();
+ if (object == null || property == null) {
+ return;
+ }
+ if (notification.getFeature().equals(UMLPackage.eINSTANCE.getLiteralInteger_Value())) {
+ refreshDisplay();
+ } else if (notification.getFeature().equals(UMLPackage.eINSTANCE.getLiteralUnlimitedNatural_Value())) {
+ refreshDisplay();
+ }
+ if (object.equals(property)) {
+ notifyNamedElementChanged(property, notification);
+ }
+ if (isMaskManagedAnnotation(object)) {
+ refreshDisplay();
+ }
+ if (isRemovedMaskManagedLabelAnnotation(object, notification)) {
+ refreshDisplay();
+ }
+ }
+
+ /**
+ * notifies that the named element has changed.
+ *
+ * @param namedElement
+ * the property that has changed
+ * @param notification
+ * the notification send when the element has been changed
+ */
+ protected void notifyNamedElementChanged(NamedElement namedElement, Notification notification) {
+ switch (notification.getFeatureID(NamedElement.class)) {
+ case UMLPackage.NAMED_ELEMENT__NAME:
+ refreshDisplay();
+ break;
+ case UMLPackage.NAMED_ELEMENT__VISIBILITY:
+ refreshDisplay();
+ break;
+ default:
+ // does nothing in other cases
+ break;
+ }
+ }
+
+ /**
+ * Returns the view controlled by the host edit part.
+ *
+ * @return the view controlled by the host edit part
+ */
+ @Override
+ protected View getView() {
+ if (getHost().getModel() instanceof View) {
+ if (((View) getHost().getModel()).eContainer() instanceof View) {
+ return (View) ((View) getHost().getModel()).eContainer();
+ }
+ return null;
+ }
+ return null;
+ }
+
+
+ /**
+ * Refreshes the display of the edit part.
+ */
+ @Override
+ public void refreshDisplay() {
+ // calls the helper for this edit Part
+ FloatingLabelHelper.getInstance().refreshEditPartDisplay((GraphicalEditPart) getHost());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void removeAdditionalListeners() {
+ super.removeAdditionalListeners();
+ NamedElement umlElement = getUMLElement();
+ if (umlElement == null) {
+ // check semantic element is not null and this is really an instance of NamedElement
+ return;
+ }
+ // remove listener to the element itself, and to linked elements, like Type
+ if (umlElement instanceof TypedElement) {
+ if (((TypedElement) umlElement).getType() != null) {
+ getDiagramEventBroker().removeNotificationListener(((TypedElement) umlElement).getType(), this);
+ }
+ }
+ if (umlElement instanceof MultiplicityElement) {
+ getDiagramEventBroker().removeNotificationListener(((MultiplicityElement) umlElement).getUpperValue(), this);
+ getDiagramEventBroker().removeNotificationListener(((MultiplicityElement) umlElement).getLowerValue(), this);
+ }
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/FloatingLabelHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/FloatingLabelHelper.java
new file mode 100644
index 00000000000..05014b9ec21
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/FloatingLabelHelper.java
@@ -0,0 +1,325 @@
+/*****************************************************************************
+ * Copyright (c) 2010, 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:
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.helper;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+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.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy;
+import org.eclipse.papyrus.uml.tools.utils.CollaborationUseUtil;
+import org.eclipse.papyrus.uml.tools.utils.ICustomAppearance;
+import org.eclipse.papyrus.uml.tools.utils.InstanceSpecificationUtil;
+import org.eclipse.papyrus.uml.tools.utils.MultiplicityElementUtil;
+import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
+import org.eclipse.papyrus.uml.tools.utils.OperationUtil;
+import org.eclipse.papyrus.uml.tools.utils.ParameterUtil;
+import org.eclipse.papyrus.uml.tools.utils.PortUtil;
+import org.eclipse.papyrus.uml.tools.utils.PropertyUtil;
+import org.eclipse.papyrus.uml.tools.utils.SignalUtil;
+import org.eclipse.papyrus.uml.tools.utils.TypeUtil;
+import org.eclipse.uml2.uml.Association;
+import org.eclipse.uml2.uml.CollaborationUse;
+import org.eclipse.uml2.uml.InstanceSpecification;
+import org.eclipse.uml2.uml.MultiplicityElement;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Parameter;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Signal;
+import org.eclipse.uml2.uml.TemplateParameter;
+import org.eclipse.uml2.uml.TypedElement;
+
+//TODO Check for usefull property to display
+
+/**
+ * Helper for labels displaying {@link NamedElement}.
+ */
+public class FloatingLabelHelper extends StereotypedElementLabelHelper {
+
+ // Einstance
+ /** The label helper. */
+ private static FloatingLabelHelper labelHelper;
+
+ /**
+ * Gets the single instance of FloatingLabelHelper.
+ *
+ * @return single instance of FloatingLabelHelper
+ */
+ public static FloatingLabelHelper getInstance() {
+ if (labelHelper == null) {
+ labelHelper = new FloatingLabelHelper();
+ }
+ return labelHelper;
+ }
+
+ /** Map for masks. */
+ protected final Map<String, String> masks = new HashMap<String, String>();
+
+ /**
+ * Instantiates a new floating label helper.
+ */
+ protected FloatingLabelHelper() {
+ // initialize the map
+
+ /**
+ * Style constant for visibility display in labels.
+ */
+ masks.put(ICustomAppearance.DISP_VISIBILITY, "Visibility");
+
+ /**
+ * Style constant for isDerive display in labels.
+ */
+ masks.put(ICustomAppearance.DISP_DERIVE, "Derived");
+
+ /**
+ * Style constant for name display in labels.
+ */
+ masks.put(ICustomAppearance.DISP_NAME, "Name");
+
+ /**
+ * Style constant for type display in labels.
+ */
+ masks.put(ICustomAppearance.DISP_TYPE, "Type");
+
+ /**
+ * Style constant for multiplicity display in labels.
+ */
+ masks.put(ICustomAppearance.DISP_MULTIPLICITY, "Multiplicity");
+
+ /**
+ * Style constant for default value display in labels.
+ */
+ masks.put(ICustomAppearance.DISP_DEFAULT_VALUE, "Default Value");
+
+ /**
+ * Style constant for modifiers display in labels.
+ */
+ masks.put(ICustomAppearance.DISP_MODIFIERS, "Modifiers");
+
+ /** Style constant for carriage return in labels */
+ masks.put(ICustomAppearance.DISP_MULTI_LINE, "Multiline");
+
+ /** Style constant for operation#parameter direction display in labels */
+ masks.put(ICustomAppearance.DISP_PARAMETER_DIRECTION, "Parameters Direction");
+
+ /** Style constant for direction display in labels */
+ masks.put(ICustomAppearance.DISP_DIRECTION, "Direction");
+
+ /** Style constant for operation#parameter name display in labels */
+ masks.put(ICustomAppearance.DISP_PARAMETER_NAME, "Parameters Name");
+
+ /** Style constant for operation#parameter type display in labels */
+ masks.put(ICustomAppearance.DISP_PARAMETER_TYPE, "Parameters Type");
+
+ /** Style constant for operation#parameter multiplicity display in labels */
+ masks.put(ICustomAppearance.DISP_PARAMETER_MULTIPLICITY, "Parameters Multiplicity");
+
+ /** Style constant for operation#parameter default value display in labels */
+ masks.put(ICustomAppearance.DISP_PARAMETER_DEFAULT, "Parameters Default");
+
+ /** Style constant for operation#parameter modifiers display in labels */
+ masks.put(ICustomAppearance.DISP_PARAMETER_MODIFIERS, "Parameters Modifiers");
+
+ /** Style constant for return type display in labels */
+ masks.put(ICustomAppearance.DISP_RT_TYPE, "returnType");
+
+ /** Style constant for return multiplicity display in labels */
+ masks.put(ICustomAppearance.DISP_RT_MULTIPLICITY, "Return Multiplicity");
+
+ /** Style constant for conjugated labels */
+ masks.put(ICustomAppearance.DISP_CONJUGATED, "Conjugated");
+ }
+
+ /**
+ * Computes the label that should be displayed by the figure managed by this
+ * edit part.
+ *
+ * @param editPart
+ * the edit part that controls the {@link NamedElement} to be
+ * displayed
+ * @return the label corresponding to the specific display of the property
+ * ("default" display given by preferences or specific display given
+ * by eAnnotation).
+ */
+ @Override
+ protected String elementLabel(GraphicalEditPart editPart) {
+ IMaskManagedLabelEditPolicy policy = (IMaskManagedLabelEditPolicy) editPart.getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
+ if (policy == null) {
+ policy = (IMaskManagedLabelEditPolicy) editPart.getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL);
+ }
+
+ Collection<String> displayValue = Collections.emptySet();
+
+ if (policy != null) {
+ displayValue = policy.getCurrentDisplayValue();
+ }
+
+ return parseString(editPart, displayValue);
+ }
+
+ /**
+ * Parses the string.
+ *
+ * @param editPart
+ * the edit part
+ * @param displayValue
+ * the display value
+ * @return the string
+ */
+ protected String parseString(GraphicalEditPart editPart, Collection<String> displayValue) {
+ NamedElement namedElement = getUMLElement(editPart);
+
+ if (namedElement != null) {
+ return getCustomLabel(namedElement, displayValue);
+ }
+
+ return "";
+ }
+
+
+ /**
+ * Returns the map of masks used to display a {@link NamedElement}.
+ *
+ * @return the {@link Map} of masks used to display a {@link NamedElement}
+ */
+ public Map<String, String> getMasks() {
+ return masks;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public NamedElement getUMLElement(GraphicalEditPart editPart) {
+ if (editPart.getModel() instanceof View) {
+ View view = (View) editPart.getModel();
+ if (view.getElement() instanceof NamedElement) {
+ return (NamedElement) view.getElement();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * return the custom label of the property, given UML2 specification and a custom style.
+ *
+ * @param namedElement
+ * the integer representing the style of the label
+ * @param maskValues
+ * the mask values
+ * @return the string corresponding to the label of the property
+ */
+ public static String getCustomLabel(NamedElement namedElement, Collection<String> maskValues) {
+
+ // Use of specific existing custom label
+
+ // use CollaborationUse custom label
+ if (namedElement instanceof CollaborationUse) {
+ return CollaborationUseUtil.getCustomLabel((CollaborationUse) namedElement, maskValues);
+ }
+
+ // use InstanceSpecification custom label
+ if (namedElement instanceof InstanceSpecification) {
+ return InstanceSpecificationUtil.getCustomLabel((InstanceSpecification) namedElement, maskValues);
+ }
+
+ // use Operation custom label
+ if (namedElement instanceof Operation) {
+ return OperationUtil.getCustomLabel((Operation) namedElement, maskValues);
+ }
+
+ // use Parameter custom label
+ if (namedElement instanceof Parameter) {
+ return ParameterUtil.getCustomLabel((Parameter) namedElement, maskValues);
+ }
+
+ // use Signal custom label
+ if (namedElement instanceof Signal) {
+ return SignalUtil.getCustomLabel((Signal) namedElement, maskValues);
+ }
+
+ // use Port custom label
+ if (namedElement instanceof Port) {
+ return PortUtil.getCustomLabel((Port) namedElement, maskValues);
+ }
+
+ // use Property custom label
+ if (namedElement instanceof Property) {
+ return PropertyUtil.getCustomLabel((Property) namedElement, maskValues);
+ }
+ // TODO add others usefull properties
+
+ // default custom label
+ StringBuffer buffer = new StringBuffer();
+
+ // visibility
+ if (maskValues.contains(ICustomAppearance.DISP_VISIBILITY)) {
+ buffer.append(" ");
+ buffer.append(NamedElementUtil.getVisibilityAsSign(namedElement));
+ }
+
+ // derived property for association
+ if (namedElement instanceof Association) {
+ if (maskValues.contains(ICustomAppearance.DISP_DERIVE)) {
+ if (((Association) namedElement).isDerived()) {
+ buffer.append("/");
+ }
+ }
+ }
+ // name
+ if (maskValues.contains(ICustomAppearance.DISP_NAME)) {
+ buffer.append(" ");
+ buffer.append(namedElement.getName());
+ }
+
+ // Type of TypedElement
+ if (namedElement instanceof TypedElement) {
+ if (maskValues.contains(ICustomAppearance.DISP_TYPE)) {
+ // type
+ if (((TypedElement) namedElement).getType() != null) {
+ buffer.append(": " + ((TypedElement) namedElement).getType().getName());
+ } else {
+ buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME);
+ }
+ }
+ }
+
+ // Multiplicity
+ if (namedElement instanceof MultiplicityElement) {
+ if (maskValues.contains(ICustomAppearance.DISP_MULTIPLICITY)) {
+ // multiplicity -> do not display [1]
+ String multiplicity = MultiplicityElementUtil.getMultiplicityAsString((MultiplicityElement) namedElement);
+ buffer.append(multiplicity);
+ }
+ }
+
+ // Template Parameter(not sure of the uml element
+ if (namedElement instanceof TemplateParameter) {
+ if (maskValues.contains(ICustomAppearance.DISP_DEFAULT_VALUE)) {
+ // default value
+ if (((TemplateParameter) namedElement).getDefault() != null) {
+ buffer.append(" = ");
+ buffer.append(((TemplateParameter) namedElement).getDefault());
+ }
+ }
+ }
+
+ return buffer.toString();
+ }
+}

Back to the top