Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFanch BONNABESSE2016-06-17 14:21:53 +0000
committerGerrit Code Review @ Eclipse.org2016-10-06 12:01:01 +0000
commit07bf14e9ab0f7c6f3a9b5eac16f5460e1560233a (patch)
treec3de015c57991748b4dd92646bc79ecb37955269 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus
parentc90b7f35348e7567133c1d67ab16e4913624d7dc (diff)
downloadorg.eclipse.papyrus-07bf14e9ab0f7c6f3a9b5eac16f5460e1560233a.tar.gz
org.eclipse.papyrus-07bf14e9ab0f7c6f3a9b5eac16f5460e1560233a.tar.xz
org.eclipse.papyrus-07bf14e9ab0f7c6f3a9b5eac16f5460e1560233a.zip
Bug 493430: [Class Diagram] Roles inverted when creating a reflexive
association https://bugs.eclipse.org/bugs/show_bug.cgi?id=493430 getSource and getTarget for Association. Cherry pick of 75464. Change-Id: Ic0c9992b12ec14b7ef616c30936bbe0cd337ee73 Signed-off-by: Fanch BONNABESSE <fanch.bonnabesse@all4tec.net>
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/edit/part/AbstractAssociationEditPart.java67
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/helper/AssociationClassHelper.java25
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java15
3 files changed, 68 insertions, 39 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/edit/part/AbstractAssociationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/edit/part/AbstractAssociationEditPart.java
index 3afd8ccccbf..e0426d38aa3 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/edit/part/AbstractAssociationEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/edit/part/AbstractAssociationEditPart.java
@@ -10,6 +10,8 @@
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
* Benoit Maggi (CEA LIST) - Bug 468026
+ * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 493430
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.clazz.custom.edit.part;
@@ -19,9 +21,9 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.common.editparts.UMLConnectionNodeEditPart;
import org.eclipse.papyrus.uml.diagram.common.figure.edge.AssociationFigure;
+import org.eclipse.papyrus.uml.diagram.common.util.AssociationUtil;
import org.eclipse.uml2.uml.AggregationKind;
import org.eclipse.uml2.uml.Association;
-import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;
@@ -56,8 +58,8 @@ public abstract class AbstractAssociationEditPart extends UMLConnectionNodeEditP
if (semanticElement instanceof Association) {
Association association = (Association) semanticElement;
if (association.getMemberEnds().size() >= 2) {
- EObject sourceEnd = association.getMemberEnds().get(0);
- EObject targetEnd = association.getMemberEnds().get(1);
+ EObject sourceEnd = getSourceProperty(association);
+ EObject targetEnd = getTargetProperty(association);
addListenerFilter(ASSOCIATION_END_LISTENERS_SOURCE, this, sourceEnd);
addListenerFilter(ASSOCIATION_END_LISTENERS_TARGET, this, targetEnd);
}
@@ -106,23 +108,30 @@ public abstract class AbstractAssociationEditPart extends UMLConnectionNodeEditP
if (((GraphicalEditPart) getSource()).resolveSemanticElement() == null || ((GraphicalEditPart) getTarget()).resolveSemanticElement() == null) {
return;
}
- Property source = null;
- Property target = null;
- // Get the association
- Element umlElement = getUMLElement();
- if (umlElement instanceof Association) {
+
+ if (getUMLElement() instanceof Association) {
Association association = (Association) getUMLElement();
- assert (association.getMemberEnds().size() >= 2);
- if (association.getMemberEnds() != null && association.getMemberEnds().size() >= 2) {
- Property firstProperty = association.getMemberEnds().get(0);
- Type firstPropertyType = firstProperty.getType();
- if (firstPropertyType!= null && firstPropertyType.equals(((GraphicalEditPart) getSource()).resolveSemanticElement())) {
- source = (firstProperty);
- target = ((association.getMemberEnds().get(1)));
- } else {
- source = ((association.getMemberEnds().get(1)));
- target = (firstProperty);
+ if (null != association.getMemberEnds() && 2 <= association.getMemberEnds().size()) {
+ Property source = getSourceProperty(association);
+ Property target = getTargetProperty(association);
+
+ if (null == source || null == target) {
+ return;
+ }
+
+ if (!source.getType().equals(target.getType())) {
+ Property propertyGet0 = association.getMemberEnds().get(0);
+ Property propertyGet1 = association.getMemberEnds().get(1);
+ Type propertyTypeGet0 = propertyGet0.getType();
+ if (null != propertyTypeGet0 && propertyTypeGet0.equals(((GraphicalEditPart) getSource()).resolveSemanticElement())) {
+ source = propertyGet0;
+ target = propertyGet1;
+ } else {
+ source = propertyGet1;
+ target = propertyGet0;
+ }
}
+
int sourceType = 0;
int targetType = 0;
// to display the dot.
@@ -166,6 +175,28 @@ public abstract class AbstractAssociationEditPart extends UMLConnectionNodeEditP
}
/**
+ * Get the source member end of the Association.
+ *
+ * @param association
+ * The Association.
+ * @return The source member end.
+ */
+ protected Property getSourceProperty(final Association association) {
+ return AssociationUtil.getTargetSecondEnd(association);
+ }
+
+ /**
+ * Get the target member end of the Association.
+ *
+ * @param association
+ * The Association.
+ * @return The target member end.
+ */
+ protected Property getTargetProperty(final Association association) {
+ return AssociationUtil.getSourceFirstEnd(association);
+ }
+
+ /**
* this method is used to remove listener on ends
*/
protected void removeAssociationEndListeners() {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/helper/AssociationClassHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/helper/AssociationClassHelper.java
index 3f3bfdb2686..3fecbe05580 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/helper/AssociationClassHelper.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/helper/AssociationClassHelper.java
@@ -9,6 +9,7 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 493430
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.clazz.custom.helper;
@@ -41,10 +42,11 @@ import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.SemanticAdapter;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.SemanticElementAdapter;
import org.eclipse.papyrus.uml.diagram.clazz.custom.command.AssociationClassViewCreateCommand;
import org.eclipse.papyrus.uml.diagram.clazz.custom.command.CustomDeferredCreateConnectionViewCommand;
import org.eclipse.papyrus.uml.diagram.clazz.providers.UMLElementTypes;
-import org.eclipse.papyrus.infra.gmfdiag.common.adapter.SemanticAdapter;
import org.eclipse.papyrus.uml.diagram.common.helper.ElementHelper;
import org.eclipse.uml2.uml.AssociationClass;
import org.eclipse.uml2.uml.Property;
@@ -85,7 +87,7 @@ public class AssociationClassHelper extends ElementHelper {
public Command dropAssociationClass(AssociationClass associationClass, EditPartViewer viewer, PreferencesHint diagramPreferencesHint, Point location, View containerView) {
CompositeCommand cc = new CompositeCommand("drop");
// 0. Obtain list of property to display
- List<Property> endToDisplay = new ArrayList<Property>(associationClass.getMemberEnds());
+ List<Property> endToDisplay = new ArrayList<>(associationClass.getMemberEnds());
GraphicalEditPart[] endEditPart = new GraphicalEditPart[associationClass.getMemberEnds().size()];
// 2. for each element create a graphical representation of the type and
// finally the branch
@@ -122,32 +124,35 @@ public class AssociationClassHelper extends ElementHelper {
// 3. creation of the dashed line between the associationClass link
// and associationClass Node
// target
+ // The Target Type is contains on the first property.
if (endEditPart[0] == null) {
// creation of the node
ViewDescriptor _descriptor = new ViewDescriptor(new EObjectAdapter(endToDisplay.get(0)), Node.class, null, ViewUtil.APPEND, true, diagramPreferencesHint);
// get the command and execute it.
CreateCommand endNodeCreationCommand = new CreateCommand(getEditingDomain(), _descriptor, containerView);
cc.compose(endNodeCreationCommand);
- setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable) endNodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x, location.y + 100));
+ setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable) endNodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x, location.y - 100));
cc.compose(setBoundsCommand);
- sourceAdapter = (IAdaptable) endNodeCreationCommand.getCommandResult().getReturnValue();
+ targetAdapter = (IAdaptable) endNodeCreationCommand.getCommandResult().getReturnValue();
} else {
- sourceAdapter = new SemanticAdapter(null, endEditPart[0].getModel());
+ targetAdapter = new SemanticAdapter(null, endEditPart[0].getModel());
}
+ // The Source Type is contains on the second property.
if (endEditPart[1] == null) {
// creation of the node
- ViewDescriptor _descriptor = new ViewDescriptor(new EObjectAdapter(endToDisplay.get(2)), Node.class, null, ViewUtil.APPEND, true, diagramPreferencesHint);
+ ViewDescriptor _descriptor = new ViewDescriptor(new EObjectAdapter(endToDisplay.get(1)), Node.class, null, ViewUtil.APPEND, true, diagramPreferencesHint);
// get the command and execute it.
CreateCommand endNodeCreationCommand = new CreateCommand(getEditingDomain(), _descriptor, containerView);
cc.compose(endNodeCreationCommand);
- setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable) endNodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x, location.y - 100));
+ setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable) endNodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x, location.y + 100));
cc.compose(setBoundsCommand);
- targetAdapter = (IAdaptable) endNodeCreationCommand.getCommandResult().getReturnValue();
+ sourceAdapter = (IAdaptable) endNodeCreationCommand.getCommandResult().getReturnValue();
} else {
- targetAdapter = new SemanticAdapter(null, endEditPart[1].getModel());
+ sourceAdapter = new SemanticAdapter(null, endEditPart[1].getModel());
}
// create association link
- ConnectionViewDescriptor viewDescriptor = new ConnectionViewDescriptor(UMLElementTypes.AssociationClass_Edge, ((IHintedType) UMLElementTypes.AssociationClass_Edge).getSemanticHint(), diagramPreferencesHint);
+ SemanticElementAdapter adapter = new SemanticElementAdapter(associationClass, UMLElementTypes.AssociationClass_Edge);
+ ConnectionViewDescriptor viewDescriptor = new ConnectionViewDescriptor(adapter, ((IHintedType) UMLElementTypes.AssociationClass_Edge).getSemanticHint(), diagramPreferencesHint);
// Creation of the associationLink
CustomDeferredCreateConnectionViewCommand associationcClassLinkCommand = new CustomDeferredCreateConnectionViewCommand(getEditingDomain(), ((IHintedType) UMLElementTypes.AssociationClass_Edge).getSemanticHint(), sourceAdapter, targetAdapter, viewer,
diagramPreferencesHint, viewDescriptor, null);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java
index 6f34c0f2bb2..c90a0a70974 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz/custom-src/org/eclipse/papyrus/uml/diagram/clazz/custom/policies/ClassDiagramDragDropEditPolicy.java
@@ -70,6 +70,7 @@ import org.eclipse.papyrus.uml.diagram.clazz.part.UMLVisualIDRegistry;
import org.eclipse.papyrus.uml.diagram.clazz.providers.UMLElementTypes;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.CommonDiagramDragDropEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.strategy.paste.ShowConstraintContextLink;
+import org.eclipse.papyrus.uml.diagram.common.util.AssociationUtil;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.AssociationClass;
import org.eclipse.uml2.uml.Constraint;
@@ -77,7 +78,6 @@ import org.eclipse.uml2.uml.Dependency;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.InstanceSpecification;
import org.eclipse.uml2.uml.PackageableElement;
-import org.eclipse.uml2.uml.Property;
/**
* The Class ClassDiagramDragDropEditPolicy.
@@ -248,16 +248,9 @@ public class ClassDiagramDragDropEditPolicy extends CommonDiagramDragDropEditPol
return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Association"), source, target, AssociationEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink)); //$NON-NLS-1$
}
if (endtypes.size() == 2) {
- Element source = null;
- Element target = null;
- final List<Property> memberEnds = ((Association) semanticLink).getMemberEnds();
- if (memberEnds.get(0).equals(endtypes.get(0))) {
- source = (Element) endtypes.get(0);
- target = (Element) endtypes.get(1);
- } else {
- source = (Element) endtypes.get(1);
- target = (Element) endtypes.get(0);
- }
+ // Source link is based on the target property and the target link is based on the source property
+ Element source = AssociationUtil.getTargetSecondEnd((Association) semanticLink).getType();
+ Element target = AssociationUtil.getSourceFirstEnd((Association) semanticLink).getType();
return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Association"), source, target, AssociationEditPart.VISUAL_ID, dropRequest.getLocation(), semanticLink)); //$NON-NLS-1$
}
if (endtypes.size() > 2) {

Back to the top