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.profile
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.profile')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/edit/parts/AbstractAssociationEditPart.java405
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/policies/ProfileDiagramDragDropEditPolicy.java17
2 files changed, 224 insertions, 198 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/edit/parts/AbstractAssociationEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/edit/parts/AbstractAssociationEditPart.java
index f6a57c66e48..89120be3c74 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/edit/parts/AbstractAssociationEditPart.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/edit/parts/AbstractAssociationEditPart.java
@@ -1,186 +1,219 @@
-/*****************************************************************************
- * Copyright (c) 2009 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Adapted code from Class Diagram
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.profile.custom.edit.parts;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-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.profile.custom.figure.AssociationFigure;
-import org.eclipse.uml2.uml.AggregationKind;
-import org.eclipse.uml2.uml.Association;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Property;
-
-/**
- * this a abstract editpart use to add listeners
- */
-public abstract class AbstractAssociationEditPart extends UMLConnectionNodeEditPart {
-
- /** Filter ID for the end source listener */
- protected static final String ASSOCIATION_END_LISTENERS_SOURCE = "AssociationEndListenersSource"; //$NON-NLS-1$
-
- /** Filter ID for the end target listener */
- protected static final String ASSOCIATION_END_LISTENERS_TARGET = "AssociationEndListenersTarget"; //$NON-NLS-1$
-
- /**
- *
- * Constructor.
- *
- * @param view
- * the view
- */
- public AbstractAssociationEditPart(View view) {
- super(view);
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public void activate() {
- super.activate();
- addAssociationEndListeners();
- }
-
- /**
- * this methods add listeners on targets and sources
- */
- protected void addAssociationEndListeners() {
- EObject semanticElement = resolveSemanticElement();
- 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);
-
- addListenerFilter(ASSOCIATION_END_LISTENERS_SOURCE, this, sourceEnd);
- addListenerFilter(ASSOCIATION_END_LISTENERS_TARGET, this, targetEnd);
- }
- }
- }
-
- /**
- *
- * {@inheritDoc}
- */
-
- @Override
- public void deactivate() {
- removeAssociationEndListeners();
- super.deactivate();
- }
-
- /**
- *
- * {@inheritDoc}
- */
-
- @Override
- protected void handleNotificationEvent(Notification event) {
- super.handleNotificationEvent(event);
-
- // set the good ends for the association figure
- if (resolveSemanticElement() != null) {
-
- refreshVisuals();
- }
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- protected void refreshVisuals() {
- if (resolveSemanticElement() != null) {
- if (getSource() == null || getTarget() == null) {
- return;
- }
- 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) {
- Association association = (Association) getUMLElement();
- assert (association.getMemberEnds().size() >= 2);
- if (association.getMemberEnds() != null && association.getMemberEnds().size() >= 2) {
- if (((association.getMemberEnds().get(0))).getType().equals(((GraphicalEditPart) getSource()).resolveSemanticElement())) {
- source = ((association.getMemberEnds().get(0)));
- target = ((association.getMemberEnds().get(1)));
- } else {
- source = ((association.getMemberEnds().get(1)));
- target = ((association.getMemberEnds().get(0)));
- }
- int sourceType = 0;
- int targetType = 0;
- // to display the dot.
- // owned?
- if (!source.getOwner().equals(resolveSemanticElement())) {
- sourceType += AssociationFigure.owned;
- sourceType += AssociationFigure.navigable;
- }
- if (!target.getOwner().equals(resolveSemanticElement())) {
- targetType += AssociationFigure.owned;
- targetType += AssociationFigure.navigable;
- }
- // aggregation? for it the opposite is changed
- if (source.getAggregation() == AggregationKind.SHARED_LITERAL) {
- targetType += AssociationFigure.aggregation;
- }
- if (target.getAggregation() == AggregationKind.SHARED_LITERAL) {
- sourceType += AssociationFigure.aggregation;
- }
- // composite? for it the opposite is changed
- if (source.getAggregation() == AggregationKind.COMPOSITE_LITERAL) {
- targetType += AssociationFigure.composition;
- }
- if (target.getAggregation() == AggregationKind.COMPOSITE_LITERAL) {
- sourceType += AssociationFigure.composition;
- }
-
- // navigable?
- if (association.getNavigableOwnedEnds().contains(source)) {
- sourceType += AssociationFigure.navigable;
- }
- if (association.getNavigableOwnedEnds().contains(target)) {
- targetType += AssociationFigure.navigable;
- }
- if (getPrimaryShape() instanceof AssociationFigure) {
- ((AssociationFigure) getPrimaryShape()).setEnd(sourceType, targetType);
- }
- }
-
- }
-
- }
- super.refreshVisuals();
- }
-
- /**
- * this method is used to remove listener on ends
- */
- protected void removeAssociationEndListeners() {
- removeListenerFilter(ASSOCIATION_END_LISTENERS_SOURCE);
- removeListenerFilter(ASSOCIATION_END_LISTENERS_TARGET);
-
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2009 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Adapted code from Class Diagram
+ * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 493430
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.profile.custom.edit.parts;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+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.util.AssociationUtil;
+import org.eclipse.papyrus.uml.diagram.profile.custom.figure.AssociationFigure;
+import org.eclipse.uml2.uml.AggregationKind;
+import org.eclipse.uml2.uml.Association;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Type;
+
+/**
+ * this a abstract editpart use to add listeners
+ */
+public abstract class AbstractAssociationEditPart extends UMLConnectionNodeEditPart {
+
+ /** Filter ID for the end source listener */
+ protected static final String ASSOCIATION_END_LISTENERS_SOURCE = "AssociationEndListenersSource"; //$NON-NLS-1$
+
+ /** Filter ID for the end target listener */
+ protected static final String ASSOCIATION_END_LISTENERS_TARGET = "AssociationEndListenersTarget"; //$NON-NLS-1$
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param view
+ * the view
+ */
+ public AbstractAssociationEditPart(View view) {
+ super(view);
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void activate() {
+ super.activate();
+ addAssociationEndListeners();
+ }
+
+ /**
+ * this methods add listeners on targets and sources
+ */
+ protected void addAssociationEndListeners() {
+ EObject semanticElement = resolveSemanticElement();
+ if (semanticElement instanceof Association) {
+ Association association = (Association) semanticElement;
+ if (association.getMemberEnds().size() >= 2) {
+ EObject sourceEnd = getSourceProperty(association);
+ EObject targetEnd = getTargetProperty(association);
+
+ addListenerFilter(ASSOCIATION_END_LISTENERS_SOURCE, this, sourceEnd);
+ addListenerFilter(ASSOCIATION_END_LISTENERS_TARGET, this, targetEnd);
+ }
+ }
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+
+ @Override
+ public void deactivate() {
+ removeAssociationEndListeners();
+ super.deactivate();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+
+ @Override
+ protected void handleNotificationEvent(Notification event) {
+ super.handleNotificationEvent(event);
+
+ // set the good ends for the association figure
+ if (resolveSemanticElement() != null) {
+ refreshVisuals();
+ }
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ protected void refreshVisuals() {
+ if (resolveSemanticElement() != null) {
+ if (getSource() == null || getTarget() == null) {
+ return;
+ }
+ if (((GraphicalEditPart) getSource()).resolveSemanticElement() == null || ((GraphicalEditPart) getTarget()).resolveSemanticElement() == null) {
+ return;
+ }
+
+
+ // Get the association
+ if (getUMLElement() instanceof Association) {
+ Association association = (Association) getUMLElement();
+ if (null != association.getMemberEnds() && 2 <= association.getMemberEnds().size()) {
+ Property source = getSourceProperty(association);
+ Property target = getTargetProperty(association);
+
+ if (null == source || null == target) {
+ return;
+ }
+
+ // If
+ 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.
+ // owned?
+ if (!source.getOwner().equals(resolveSemanticElement())) {
+ sourceType += AssociationFigure.owned;
+ sourceType += AssociationFigure.navigable;
+ }
+ if (!target.getOwner().equals(resolveSemanticElement())) {
+ targetType += AssociationFigure.owned;
+ targetType += AssociationFigure.navigable;
+ }
+ // aggregation? for it the opposite is changed
+ if (source.getAggregation() == AggregationKind.SHARED_LITERAL) {
+ targetType += AssociationFigure.aggregation;
+ }
+ if (target.getAggregation() == AggregationKind.SHARED_LITERAL) {
+ sourceType += AssociationFigure.aggregation;
+ }
+ // composite? for it the opposite is changed
+ if (source.getAggregation() == AggregationKind.COMPOSITE_LITERAL) {
+ targetType += AssociationFigure.composition;
+ }
+ if (target.getAggregation() == AggregationKind.COMPOSITE_LITERAL) {
+ sourceType += AssociationFigure.composition;
+ }
+ // navigable?
+ if (association.getNavigableOwnedEnds().contains(source)) {
+ sourceType += AssociationFigure.navigable;
+ }
+ if (association.getNavigableOwnedEnds().contains(target)) {
+ targetType += AssociationFigure.navigable;
+ }
+ if (getPrimaryShape() instanceof AssociationFigure) {
+ ((AssociationFigure) getPrimaryShape()).setEnd(sourceType, targetType);
+ }
+ }
+
+ }
+
+ }
+ super.refreshVisuals();
+ }
+
+ /**
+ * 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.getSourceFirstEnd(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.getTargetSecondEnd(association);
+ }
+
+ /**
+ * this method is used to remove listener on ends
+ */
+ protected void removeAssociationEndListeners() {
+ removeListenerFilter(ASSOCIATION_END_LISTENERS_SOURCE);
+ removeListenerFilter(ASSOCIATION_END_LISTENERS_TARGET);
+
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/policies/ProfileDiagramDragDropEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/policies/ProfileDiagramDragDropEditPolicy.java
index 2380cc47d07..e996ccd20ad 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/policies/ProfileDiagramDragDropEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile/custom-src/org/eclipse/papyrus/uml/diagram/profile/custom/policies/ProfileDiagramDragDropEditPolicy.java
@@ -12,7 +12,7 @@
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Adapted code from the class diagram
* Christian W. Damus - bug 433206
* Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 492893
- *
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.profile.custom.policies;
@@ -58,6 +58,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.commands.CommonDeferredCreateCon
import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramEditPartsUtil;
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.papyrus.uml.diagram.common.util.Util;
import org.eclipse.papyrus.uml.diagram.profile.custom.commands.SetStereotypeVisibleOnMetaclassCommand;
import org.eclipse.papyrus.uml.diagram.profile.custom.helper.MultiAssociationHelper;
@@ -84,7 +85,6 @@ import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.Dependency;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ElementImport;
-import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;
/**
@@ -158,16 +158,9 @@ public class ProfileDiagramDragDropEditPolicy extends CommonDiagramDragDropEditP
protected Command dropAssociation(final DropObjectsRequest dropRequest, final Element semanticLink, final String nodeVISUALID) {
final List<?> endtypes = new ArrayList<>(ProfileLinkMappingHelper.getInstance().getSource(semanticLink));
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