Bug 482692: [Tooling] Optional Capsule should have hatching Pattern
https://bugs.eclipse.org/bugs/show_bug.cgi?id=482692

- Add Hash Pattern icon
- Define Rule for Hashed Pattern into the CapsuleDiagram.css
- Create a specific Figure for the PorpertyPart in Real Time Context
- Modify Test according to the new figure


Change-Id: I35a02e3ca3fad2da497d3b4c98a6ad8a5820db61
Signed-off-by: Céline Janssens <Celine.Janssens@all4tec.net>
diff --git a/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/utils/CapsulePartUtils.java b/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/utils/CapsulePartUtils.java
index 9f52e29..c8a1355 100644
--- a/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/utils/CapsulePartUtils.java
+++ b/plugins/umlrt/core/org.eclipse.papyrusrt.umlrt.core/src/org/eclipse/papyrusrt/umlrt/core/utils/CapsulePartUtils.java
@@ -8,12 +8,15 @@
  *
  * Contributors:
  *  CEA LIST - Initial API and implementation
+ *  Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Add #getStereotypeApplication()
  *****************************************************************************/
 package org.eclipse.papyrusrt.umlrt.core.utils;
 
 import org.eclipse.papyrusrt.umlrt.core.types.ElementTypeUtils;
 import org.eclipse.papyrusrt.umlrt.core.types.IUMLRTElementTypes;
+import org.eclipse.papyrusrt.umlrt.profile.UMLRealTime.CapsulePart;
 import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.util.UMLUtil;
 
 /**
  * Utility class for capsule parts
@@ -27,8 +30,20 @@
 	 *            the property to check
 	 * @return <code>true</code> if the specified element is a CapsulePart (property typed by a capsule, and stereotyped by <<CapsulePart>>)
 	 */
-	public static boolean isCapsulePart(Property property) {
+	public static boolean isCapsulePart(final Property property) {
 		return ElementTypeUtils.matches(property, IUMLRTElementTypes.CAPSULE_PART_ID);
 	}
 
+	/**
+	 * Get the Stereotype Application of the Capsule Part
+	 * 
+	 * @param property
+	 *            The Capsule Part as a Property
+	 * @return the Capsule Part stereotype application from the UML RT profile application.
+	 */
+	public static CapsulePart getStereotypeApplication(final Property property) {
+		return UMLUtil.getStereotypeApplication(property, CapsulePart.class);
+
+	}
+
 }
diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/css/capsulediagram.css b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/css/capsulediagram.css
index c94798e..2328fba 100644
--- a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/css/capsulediagram.css
+++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/css/capsulediagram.css
@@ -37,8 +37,6 @@
 Port[appliedStereotypes~="UMLRealTime::RTPort"][isConjugated="false"] {
 	gradient: none;
 	fillColor:black;
-	
-	
 }
 
 /* Fill the Port figure  if it is not conjugated */
@@ -46,4 +44,9 @@
 	gradient: none;
 	fillColor:white;
 	
+}
+
+/* Add a Hash pattern for the Capsule Part figure  if it is optional */
+Property[appliedStereotypes~="UMLRealTime::CapsulePart"][lower="0"]{
+    hashPattern:true;
 }
\ No newline at end of file
diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/editparts/RTPropertyPartEditPart.java b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/editparts/RTPropertyPartEditPart.java
index e453153..8638d5d 100644
--- a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/editparts/RTPropertyPartEditPart.java
+++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/editparts/RTPropertyPartEditPart.java
@@ -13,13 +13,16 @@
 

 package org.eclipse.papyrusrt.umlrt.tooling.diagram.common.editparts;

 

+import org.eclipse.draw2d.IFigure;

 import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;

 import org.eclipse.gmf.runtime.notation.View;

+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;

 import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartEditPartCN;

 import org.eclipse.papyrusrt.umlrt.tooling.diagram.common.editparts.providers.RTEditPartProvider;

 import org.eclipse.papyrusrt.umlrt.tooling.diagram.common.editpolicies.CanonicalPortDisplayEditPolicy;

 import org.eclipse.papyrusrt.umlrt.tooling.diagram.common.editpolicies.RTCustomDiagramDragDropEditPolicy;

 import org.eclipse.papyrusrt.umlrt.tooling.diagram.common.editpolicies.RTSideAffixedNodesCreationEditPolicy;

+import org.eclipse.papyrusrt.umlrt.tooling.diagram.common.figures.RTPropertyPartFigure;

 

 /**

  * This Class redefines the PropertyPartEditPartCN for the Real Time Context

@@ -32,18 +35,25 @@
  */

 public class RTPropertyPartEditPart extends PropertyPartEditPartCN {

 

+	/**

+	 * CSS name of Hash pattern property.

+	 */

+	protected static final String HASH_PROPERTY_NAME = "hashPattern";// $NON-NLS-1$

 

 	/**

 	 * Constructor.

 	 *

 	 * @param view

 	 */

-	public RTPropertyPartEditPart(View view) {

+	public RTPropertyPartEditPart(final View view) {

 		super(view);

-

 	}

 

+

+

 	/**

+	 * {@inheritDoc}

+	 * 

 	 * @see org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartEditPartCN#createDefaultEditPolicies()

 	 *

 	 */

@@ -57,4 +67,43 @@
 

 	}

 

+

+	/**

+	 * {@inheritDoc}

+	 * 

+	 * @see org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartEditPartCN#createNodeShape()

+	 *

+	 */

+	@Override

+	protected IFigure createNodeShape() {

+		return primaryShape = new RTPropertyPartFigure();

+	}

+

+	/**

+	 * {@inheritDoc}

+	 * 

+	 * @see org.eclipse.papyrus.uml.diagram.composite.edit.parts.PropertyPartEditPartCN#getPrimaryShape()

+	 */

+	@Override

+	public RTPropertyPartFigure getPrimaryShape() {

+		return (RTPropertyPartFigure) primaryShape;

+	}

+

+	/**

+	 * {@inheritDoc}

+	 * 

+	 * @see org.eclipse.papyrus.uml.diagram.common.editparts.RoundedCompartmentEditPart#refreshVisuals()

+	 *

+	 */

+	@Override

+	protected void refreshVisuals() {

+

+		super.refreshVisuals();

+		boolean isHash = NotationUtils.getBooleanValue(getNotationView(), HASH_PROPERTY_NAME, false);

+

+		getPrimaryShape().setHashed(isHash);

+

+	}

+

+

 }

diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/figures/RTPropertyPartFigure.java b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/figures/RTPropertyPartFigure.java
new file mode 100644
index 0000000..9cdf6b5
--- /dev/null
+++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/figures/RTPropertyPartFigure.java
@@ -0,0 +1,117 @@
+/*****************************************************************************

+ * Copyright (c) 2015 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:

+ *  Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation

+ *****************************************************************************/

+package org.eclipse.papyrusrt.umlrt.tooling.diagram.common.figures;

+

+import org.eclipse.draw2d.Graphics;

+import org.eclipse.draw2d.geometry.Point;

+import org.eclipse.papyrus.uml.diagram.common.Activator;

+import org.eclipse.papyrus.uml.diagram.composite.custom.figures.PropertyPartFigure;

+import org.eclipse.swt.graphics.Image;

+

+/**

+ * Figure for the Property Part in Real Time context (used for the CapsulePart for example)

+ * 

+ * @author Céline JANSSENS

+ *

+ */

+public class RTPropertyPartFigure extends PropertyPartFigure {

+

+	/**

+	 * Path of the hash pattern to use

+	 */

+	private static final String PATTERN_PATH = "/icons/hash_pattern_grey.png";

+

+	/**

+	 * Boolean that test if the figure should be fill with hashed pattern

+	 */

+	private boolean hashed = Boolean.FALSE;

+

+

+

+	/**

+	 * Paint the Hash Figure on the CapsulePart

+	 * 

+	 * @param graphics

+	 *            the graphics of the figure

+	 * @deprecated To implemented into Papyrus RoundedCompartment

+	 */

+	@Deprecated

+	protected void paintHashPattern(final Graphics graphics) {

+

+		if (hashed) {

+

+			Image hashImage = Activator.getPluginIconImage(org.eclipse.papyrusrt.umlrt.tooling.ui.Activator.PLUGIN_ID, PATTERN_PATH);

+

+

+			int imageWidth = hashImage.getBounds().width;

+			int imageHeight = hashImage.getBounds().height;

+

+			int horizontalTimes = (getBounds().width() / imageWidth) + 1;

+			int verticalTimes = (getBounds().height() / imageHeight) + 1;

+

+			Point origin = new Point(getBounds().getLocation());

+

+			for (int verticalTime = 0; verticalTime < verticalTimes; verticalTime++) {

+				for (int horizontalTime = 0; horizontalTime < horizontalTimes; horizontalTime++) {

+					graphics.pushState();

+					graphics.drawImage(hashImage, origin);

+					graphics.popState();

+					origin.translate(imageWidth, 0);

+

+				}

+				origin.setX(getBounds().getLocation().x());

+				origin.translate(0, imageHeight);

+			}

+

+		}

+

+	}

+

+

+	/**

+	 * getter of hashed

+	 * 

+	 * @return hashed boolean value

+	 */

+	public boolean isHashed() {

+		return hashed;

+

+	}

+

+	/**

+	 * Setter of hashed

+	 * 

+	 * @param hashed

+	 *            the value to be set for hashed field

+	 */

+	public void setHashed(final boolean hashed) {

+		this.hashed = hashed;

+	}

+

+

+	/**

+	 * {@inheritDoc}

+	 * 

+	 * @see org.eclipse.papyrus.uml.diagram.common.figure.node.RoundedCompartmentFigure#paintFigure(org.eclipse.draw2d.Graphics)

+	 *

+	 */

+	@Override

+	public void paintFigure(final Graphics graphics) {

+

+		super.paintFigure(graphics);

+

+		paintHashPattern(graphics);

+

+	}

+

+

+}

diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/icons/hash_pattern_grey.png b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/icons/hash_pattern_grey.png
new file mode 100644
index 0000000..086acc5
--- /dev/null
+++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/icons/hash_pattern_grey.png
Binary files differ
diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/modelelement/RTStereotypeModelElement.java b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/modelelement/RTStereotypeModelElement.java
index 1994d52..f6b9061 100644
--- a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/modelelement/RTStereotypeModelElement.java
+++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/modelelement/RTStereotypeModelElement.java
@@ -43,6 +43,14 @@
 import org.eclipse.uml2.uml.Port;
 import org.eclipse.uml2.uml.Stereotype;
 
+/**
+ * Model Element for Real Time Stereotype properties.
+ * Used for RTPort properties like "isWired", "isPublish", "isNotification"
+ * Used for CapsulePart
+ * 
+ * @author Céline JANSSENS
+ *
+ */
 public class RTStereotypeModelElement extends StereotypeModelElement {
 
 	/** label provider for RTPort::Registration kind */
@@ -60,21 +68,23 @@
 		EObject source = getSource();
 		if (source instanceof RTPort) {
 			Port port = ((RTPort) source).getBase_Port();
-			RTPort rtPort = (RTPort) source;
-			if (IRealTimeConstants.KIND.equals(propertyPath)) {
-				editable = true;
-			} else if (UMLRealTimePackage.eINSTANCE.getRTPort_IsNotification().equals(feature)) {
-				editable = port.isBehavior(); // isNotification disabled if !isBehavior
-			} else if (UMLRealTimePackage.eINSTANCE.getRTPort_IsWired().equals(feature)) {
-				editable = port.isBehavior() && !RTPortUtils.isConnected(port) && !RTPortUtils.isLegacySpp(port) && !RTPortUtils.isLegacySap(port); // isWired disabled if connected || !isBehavior || isLegacySpp || isLegacySap
-			} else if (UMLRealTimePackage.eINSTANCE.getRTPort_IsPublish().equals(feature)) {
-				editable = false; // isPublish always disabled
-			} else if (UMLRealTimePackage.eINSTANCE.getRTPort_Registration().equals(feature)) {
-				editable = !rtPort.isWired(); // registration kind disabled if isWired
-			} else if (UMLRealTimePackage.eINSTANCE.getRTPort_RegistrationOverride().equals(feature)) {
-				editable = !rtPort.isWired(); // registration override disabled if isWired
-			} else {
-				editable = super.isFeatureEditable(propertyPath);
+			if (null != port) {
+				RTPort rtPort = (RTPort) source;
+				if (IRealTimeConstants.KIND.equals(propertyPath)) {
+					editable = true;
+				} else if (UMLRealTimePackage.eINSTANCE.getRTPort_IsNotification().equals(feature)) {
+					editable = port.isBehavior(); // isNotification disabled if !isBehavior
+				} else if (UMLRealTimePackage.eINSTANCE.getRTPort_IsWired().equals(feature)) {
+					editable = port.isBehavior() && !RTPortUtils.isConnected(port) && !RTPortUtils.isLegacySpp(port) && !RTPortUtils.isLegacySap(port); // isWired disabled if connected || !isBehavior || isLegacySpp || isLegacySap
+				} else if (UMLRealTimePackage.eINSTANCE.getRTPort_IsPublish().equals(feature)) {
+					editable = false; // isPublish always disabled
+				} else if (UMLRealTimePackage.eINSTANCE.getRTPort_Registration().equals(feature)) {
+					editable = !rtPort.isWired(); // registration kind disabled if isWired
+				} else if (UMLRealTimePackage.eINSTANCE.getRTPort_RegistrationOverride().equals(feature)) {
+					editable = !rtPort.isWired(); // registration override disabled if isWired
+				} else {
+					editable = super.isFeatureEditable(propertyPath);
+				}
 			}
 		} else if (source instanceof CapsulePart) {
 			editable = true;
diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/widgets/CapsulePartKindObservableValue.java b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/widgets/CapsulePartKindObservableValue.java
index 9ea72fa..f1f5731 100644
--- a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/widgets/CapsulePartKindObservableValue.java
+++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.ui/src/org/eclipse/papyrusrt/umlrt/tooling/ui/widgets/CapsulePartKindObservableValue.java
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *  Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ *  
  *****************************************************************************/
 package org.eclipse.papyrusrt.umlrt.tooling.ui.widgets;
 
@@ -16,6 +17,7 @@
 import org.eclipse.core.databinding.observable.value.ValueDiff;
 import org.eclipse.emf.common.command.Command;
 import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.emf.common.notify.Adapter;
 import org.eclipse.emf.common.notify.Notification;
 import org.eclipse.emf.common.notify.impl.AdapterImpl;
 import org.eclipse.emf.ecore.EObject;
@@ -25,9 +27,12 @@
 import org.eclipse.papyrusrt.umlrt.core.utils.CapsulePartKindEnum;
 import org.eclipse.papyrusrt.umlrt.profile.UMLRealTime.CapsulePart;
 import org.eclipse.uml2.uml.AggregationKind;
-import org.eclipse.uml2.uml.MultiplicityElement;
+import org.eclipse.uml2.uml.LiteralInteger;
+import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
 import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.UMLFactory;
 import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.ValueSpecification;
 import org.eclipse.uml2.uml.util.UMLUtil;
 
 /**
@@ -47,8 +52,12 @@
 	/** The aggregation Enum value. */
 	private AggregationKind aggregation;
 
-	/** The multiplicity Element. */
-	private MultiplicityElement multiplicity;
+	/** The aggregation Enum value. */
+	private LiteralInteger lowerValue;
+
+	/** The aggregation Enum value. */
+	private LiteralUnlimitedNatural upperValue;
+
 
 	/**
 	 * Instantiates a new capsule part kind observable value.
@@ -63,16 +72,20 @@
 		super(UMLUtil.getBaseElement(RTApplication), UMLUtil.getBaseElement(RTApplication).eContainingFeature(), domain);
 
 		if (RTApplication instanceof CapsulePart) {
+			setUMLPropertiesValue();
+
 			capsulePartElement = (Property) UMLUtil.getBaseElement(RTApplication);
 
-			capsulePartElement.eAdapters().add(getListener());
-			capsulePartElement.getUpperValue().eAdapters().add(getListener());
-			capsulePartElement.getLowerValue().eAdapters().add(getListener());
+			// add listeners
+			capsulePartElement.eAdapters().add(getAggregationListener());
+			capsulePartElement.eAdapters().add(getMultiplicityListener());
 
-			setUMLPropertiesValue();
+			capsulePartElement.getLowerValue().eAdapters().add(getMultiplicityListener());
+			capsulePartElement.getUpperValue().eAdapters().add(getMultiplicityListener());
+
 		}
-	}
 
+	}
 
 
 	/**
@@ -80,8 +93,10 @@
 	 */
 	protected void setUMLPropertiesValue() {
 		if (capsulePartElement instanceof Property) {
-			multiplicity = capsulePartElement;
+			// Set fields value
 			aggregation = capsulePartElement.getAggregation();
+			lowerValue = (LiteralInteger) capsulePartElement.getLowerValue();
+			upperValue = (LiteralUnlimitedNatural) capsulePartElement.getUpperValue();
 		}
 	}
 
@@ -95,107 +110,98 @@
 		CapsulePartKindEnum kind = null;
 		setUMLPropertiesValue();
 
-		if (multiplicity.getLower() == multiplicity.getUpper()) {
+		// Define what is the kind of the capsulePart based on the multiplicity and the aggregation value
+		if (capsulePartElement.getLower() == capsulePartElement.getUpper()) {
 			kind = CapsulePartKindEnum.FIXED;
-		} else if (multiplicity.getLower() == 0) {
+		} else if (0 == capsulePartElement.getLower()) {
 			if (AggregationKind.COMPOSITE_LITERAL.equals(aggregation)) {
 				kind = CapsulePartKindEnum.OPTIONAL;
 			} else if (AggregationKind.SHARED_LITERAL.equals(aggregation)) {
 				kind = CapsulePartKindEnum.PLUGIN;
 			}
 		}
-
-
 		return kind;
 	}
 
-	/**
-	 * @see org.eclipse.emf.databinding.EObjectObservableValue#getObserved()
-	 *
-	 * @return
-	 */
-	@Override
-	public Object getObserved() {
-		return capsulePartElement;
-	}
 
 
 	/**
-	 * @see org.eclipse.emf.databinding.EObjectObservableValue#getValueType()
-	 *
-	 * @return
-	 */
-	@Override
-	public Object getValueType() {
-		return CapsulePartKindEnum.class;
-	}
-
-	/**
 	 * @see org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableValue#getCommand(java.lang.Object)
 	 *
 	 * @param value
 	 * @return
 	 */
 	@Override
-	public Command getCommand(Object value) {
-		Command command = null;
+	public Command getCommand(final Object value) {
+		setUMLPropertiesValue();
+		// Set the new value based on the kind set
+		LiteralInteger newLowerValue = UMLFactory.eINSTANCE.createLiteralInteger();
+		LiteralUnlimitedNatural newUpperValue = UMLFactory.eINSTANCE.createLiteralUnlimitedNatural();
+		AggregationKind newAggregation = AggregationKind.COMPOSITE_LITERAL;
+		newUpperValue.setValue(upperValue.getValue());
+
+
 		if (value instanceof CapsulePartKindEnum) {
 			// For Each Kind of Capsule Part, set the property accordingly
 			switch ((CapsulePartKindEnum) value) {
 			case FIXED:
-				command = getCommandForCapsulePart(AggregationKind.COMPOSITE_LITERAL, multiplicity.getUpper(), multiplicity.getUpper());
+				newLowerValue.setValue(upperValue.getValue());
+				newAggregation = AggregationKind.COMPOSITE_LITERAL;
 				break;
 			case OPTIONAL:
-				command = getCommandForCapsulePart(AggregationKind.COMPOSITE_LITERAL, 0, multiplicity.getUpper());
+				newLowerValue.setValue(0);
+				newAggregation = AggregationKind.COMPOSITE_LITERAL;
 				break;
 			case PLUGIN:
-				command = getCommandForCapsulePart(AggregationKind.SHARED_LITERAL, 0, multiplicity.getUpper());
+				newLowerValue.setValue(0);
+				newAggregation = AggregationKind.SHARED_LITERAL;
 				break;
-
 			default:
-				// Fixed Capsule Part by Default
-				command = getCommandForCapsulePart(AggregationKind.COMPOSITE_LITERAL, multiplicity.getUpper(), multiplicity.getUpper());
+				lowerValue.setValue(upperValue.getValue());
+				newAggregation = AggregationKind.COMPOSITE_LITERAL;
 				break;
 			}
 		}
+
+
+		Command command = getCommandForCapsulePart(newLowerValue, newAggregation);
+
 		return command;
 	}
 
 	/**
 	 * Gets the command for capsule part.
-	 *
-	 * @param aggregation
-	 *            the aggregation
-	 * @param lower
-	 *            the lower
-	 * @param upper
-	 *            the upper
+	 * 
+	 * @param newLowerValue
+	 * @param newAggregation
+	 * 
 	 * @return the command for capsule part
 	 */
-	protected Command getCommandForCapsulePart(AggregationKind aggregation, int lower, int upper) {
+	protected Command getCommandForCapsulePart(final ValueSpecification newLowerValue, final AggregationKind newAggregation) {
 		CompoundCommand command = new CompoundCommand();
-		command.append(getSetAggregationCommand(aggregation));
-		command.append(getSetMultiplicityCommand(lower, upper));
+
+		command.append(getSetAggregationCommand(newAggregation));
+		command.append(getSetMultiplicityCommand(newLowerValue));
 
 		return command;
 	}
 
 
+
 	/**
 	 * Gets the sets the multiplicity command.
-	 *
-	 * @param lower
-	 *            the lower
-	 * @param upper
-	 *            the upper
+	 * 
+	 * @param newLowerValue
+	 * 
 	 * @return the sets the multiplicity command
 	 */
-	protected Command getSetMultiplicityCommand(final int lower, final int upper) {
+	protected Command getSetMultiplicityCommand(final ValueSpecification newLowerValue) {
+
 		RecordingCommand multiplicityCommand = new RecordingCommand((TransactionalEditingDomain) domain) {
 			@Override
 			protected void doExecute() {
-				capsulePartElement.setLower(lower);
-				capsulePartElement.setUpper(upper);
+				capsulePartElement.setLowerValue(newLowerValue);
+
 			}
 
 			@Override
@@ -213,12 +219,60 @@
 	}
 
 
+
+
 	/**
-	 * Retrieve Listener to put on the Stereotype Application.
-	 *
-	 * @return the listener
+	 * Gets the sets the aggregation command.
+	 * 
+	 * @param newAggregation
+	 * 
+	 * @return the sets the aggregation command
 	 */
-	protected AdapterImpl getListener() {
+	protected Command getSetAggregationCommand(final AggregationKind newAggregation) {
+		RecordingCommand aggregationCommand = new RecordingCommand((TransactionalEditingDomain) domain) {
+			@Override
+			protected void doExecute() {
+				capsulePartElement.setAggregation(newAggregation);
+
+			}
+
+			@Override
+			public boolean canExecute() {
+				return true;
+			}
+
+			@Override
+			public String getLabel() {
+				return LABEL_AGGREGATION;
+			}
+		};
+
+		return aggregationCommand;
+	}
+
+	/**
+	 * @see org.eclipse.emf.databinding.EObjectObservableValue#getObserved()
+	 * 
+	 */
+	@Override
+	public Object getObserved() {
+		return capsulePartElement;
+	}
+
+
+	/**
+	 * @see org.eclipse.emf.databinding.EObjectObservableValue#getValueType()
+	 * 
+	 */
+	@Override
+	public Object getValueType() {
+		return CapsulePartKindEnum.class;
+	}
+
+	/**
+	 * Retrieve the listener for Multiplicity Bounds
+	 */
+	protected Adapter getMultiplicityListener() {
 		return new AdapterImpl() {
 
 			@Override
@@ -227,10 +281,14 @@
 				int type = notification.getEventType();
 				Object feature = notification.getFeature();
 
-				if ((notifier == capsulePartElement) && (type == Notification.SET)) {
-					if (UMLPackage.eINSTANCE.getProperty_Aggregation().equals(feature)) {
-						fireDiff(notification);
-					}
+				if ((notifier == capsulePartElement) && (feature == UMLPackage.eINSTANCE.getMultiplicityElement_LowerValue()) && (type == Notification.SET)) {
+
+					fireDiff(notification);
+
+				} else if ((notifier == capsulePartElement) && (feature == UMLPackage.eINSTANCE.getMultiplicityElement_UpperValue()) && (type == Notification.SET)) {
+
+					fireDiff(notification);
+
 				} else if ((notifier == capsulePartElement.getLowerValue()) && (type == Notification.SET)) {
 
 					fireDiff(notification);
@@ -252,37 +310,52 @@
 				});
 			}
 		};
+
 	}
 
 	/**
-	 * Gets the sets the aggregation command.
-	 *
-	 * @param wishedAggregation
-	 *            the wished aggregation
-	 * @return the sets the aggregation command
+	 * Retrieve the listener for Aggregation
 	 */
-	protected Command getSetAggregationCommand(final AggregationKind wishedAggregation) {
-		RecordingCommand aggregationCommand = new RecordingCommand((TransactionalEditingDomain) domain) {
-			@Override
-			protected void doExecute() {
-				capsulePartElement.setAggregation(wishedAggregation);
-			}
+	protected Adapter getAggregationListener() {
+		return new AdapterImpl() {
 
 			@Override
-			public boolean canExecute() {
-				return true;
+			public void notifyChanged(Notification notification) {
+				Object notifier = notification.getNotifier();
+				int type = notification.getEventType();
+				Object feature = notification.getFeature();
+
+				if ((notifier == capsulePartElement) && (type == Notification.SET)) {
+					if (UMLPackage.eINSTANCE.getProperty_Aggregation().equals(feature)) {
+						fireDiff(notification);
+					}
+				}
 			}
 
-			@Override
-			public String getLabel() {
-				return LABEL_AGGREGATION;
+			private void fireDiff(Notification notification) {
+				final ValueDiff diff = Diffs.createValueDiff(notification.getOldValue(), notification.getNewValue());
+				getRealm().exec(new Runnable() {
+					@Override
+					public void run() {
+						fireValueChange(diff);
+					}
+				});
 			}
 		};
-
-		return aggregationCommand;
 	}
 
 
+	@Override
+	public synchronized void dispose() {
+
+		super.dispose();
+		// Remove the listeners
+		capsulePartElement.eAdapters().remove(getMultiplicityListener());
+		capsulePartElement.eAdapters().remove(getAggregationListener());
+
+		capsulePartElement.getLowerValue().eAdapters().remove(getMultiplicityListener());
+		capsulePartElement.getUpperValue().eAdapters().remove(getMultiplicityListener());
+	}
 
 }
 
diff --git a/releng/rcptt/papyrusrt.rcptt.synchronisation.tests/Synchro_32_SynchronizationOfCapsulePart.test b/releng/rcptt/papyrusrt.rcptt.synchronisation.tests/Synchro_32_SynchronizationOfCapsulePart.test
new file mode 100644
index 0000000..9c83821
--- /dev/null
+++ b/releng/rcptt/papyrusrt.rcptt.synchronisation.tests/Synchro_32_SynchronizationOfCapsulePart.test
@@ -0,0 +1,61 @@
+--- RCPTT testcase ---
+Format-Version: 1.0
+Contexts: _fWASMHyuEeWDurBKKa1KKg
+Element-Name: Synchro_32_SynchronizationOfCapsulePart
+Element-Type: testcase
+Element-Version: 3.0
+External-Reference: 
+Id: _jAkb0JpwEeWSHptStDmSKg
+Runtime-Version: 2.0.1.201508250612
+Save-Time: 12/4/15 11:30 AM
+Testcase-Type: ecl
+
+------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac
+Content-Type: text/ecl
+Entry-Name: .content
+
+// Open Model
+with [get-view "Project Explorer" | get-tree] {
+    select InitialDiagram | double-click
+    select "InitialDiagram/model" | double-click
+}
+
+// Open Diagram and create a New Capsule
+with [get-view "Model Explorer" | get-tree] {
+    get-item "RootElement/«Capsule» Capsule1/Capsule1" | click
+    select "RootElement/«Capsule» Capsule1/Capsule1" | double-click
+    get-item "RootElement/«Capsule» Capsule1/Capsule1" | click
+    get-item RootElement | click
+    select RootElement | get-menu "UMLRealTime/Capsule" | click
+}
+
+// Create A New Capsule Pasrt 
+get-editor "model.di" | get-diagram -index 1 | get-edit-part -name Capsule1 | get-edit-part -name Capsule1 
+    | mouse-move 53 241 -height 250 -width 500
+with [get-view "Model Explorer" | get-tree] {
+    get-item "RootElement/«Capsule» Capsule1" | click
+    select "RootElement/«Capsule» Capsule1" | get-menu "UMLRealTime/CapsulePart" | click
+}
+
+// Select the Capsule for the new Capsule Part
+with [get-window Edit] {
+    get-button "Edit the reference value" | click
+    with [get-window Capsule] {
+        get-editbox -after [get-label "Filter:"] | set-focus
+        get-tree | select "RootElement/«Capsule» Capsule2"
+        get-button OK | click
+    }
+    get-button OK | click
+}
+
+// test that the CapsulePart is present into the Diagram as a RTPropertyEditPart and Named as "# capsule2: Capsule2 [1]"
+get-editor "model.di" | get-diagram -index 1 | get-edit-part -name Capsule1 | mouse-move 633 204 -height 365 -width 647
+with [get-editor "model.di" | get-diagram -index 1 | get-edit-part -name Capsule1 | get-edit-part -name Capsule1] {
+    get-property "getChildren().ClassCompositeCompartmentEditPart[2].getChildren().RTPropertyPartEditPart[0].getClassName()" 
+        | equals "org.eclipse.papyrusrt.umlrt.tooling.diagram.common.editparts.RTPropertyPartEditPart" | verify-true
+    get-property "getChildren().ClassCompositeCompartmentEditPart[2].getChildren().RTPropertyPartEditPart[0].getPrimaryShape().getClassName()" 
+        | equals "org.eclipse.papyrusrt.umlrt.tooling.diagram.common.figures.RTPropertyPartFigure" | verify-true
+    get-property "getChildren().ClassCompositeCompartmentEditPart[2].getChildren().RTPropertyPartEditPart[0].getPrimaryShape().getNameLabel().getText()" 
+        | equals "# capsule2: Capsule2 [1]" | verify-true
+}
+------=_.content-0a7243a0-75d3-3d5f-9791-539de0e5b7ac--