Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFanch BONNABESSE2016-06-29 09:22:45 +0000
committervincent lorenzo2016-10-06 12:01:23 +0000
commitc9fe1f3aca27974c66c4818306cf9ab104ebe45a (patch)
tree32e0fe093c2f2a34fbe74f387835bbcb03e89ca7
parent07bf14e9ab0f7c6f3a9b5eac16f5460e1560233a (diff)
downloadorg.eclipse.papyrus-c9fe1f3aca27974c66c4818306cf9ab104ebe45a.tar.gz
org.eclipse.papyrus-c9fe1f3aca27974c66c4818306cf9ab104ebe45a.tar.xz
org.eclipse.papyrus-c9fe1f3aca27974c66c4818306cf9ab104ebe45a.zip
Bug 494758: [Diagram] Dialog to Create or Display exiting links doesn't
work for reflexive Association https://bugs.eclipse.org/bugs/show_bug.cgi?id=494758 This gerrit depends on the gerrit review 75464. Change-Id: I0f6998e8e7dc956ed18f8614e86f6b41cde993ff Signed-off-by: Fanch BONNABESSE <fanch.bonnabesse@all4tec.net>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java71
1 files changed, 61 insertions, 10 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java
index a14409097a2..1be2d92764c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java
@@ -214,20 +214,46 @@ public class CreateOrShowExistingElementHelper {
if (UMLPackage.eINSTANCE.getAssociation().equals(wantedEClass)) {
for (final Element current : ((Element) request.getContainer()).getOwnedElements()) {
if (hasWantedType(current, wantedElementType)) {
- final Collection<?> sources = this.linkMappingHelper.getSource(current);
- final Collection<?> targets = this.linkMappingHelper.getTarget(current);
- if (sources.contains(request.getSource()) && targets.contains(request.getTarget())) {
+ List<?> sources = new ArrayList<>(this.linkMappingHelper.getSource(current));
+ List<?> targets = new ArrayList<>(this.linkMappingHelper.getTarget(current));
+
+ EObject sourceRequest = request.getSource();
+ EObject targetRequest = request.getTarget();
+
+ if (sources.contains(sourceRequest) && targets.contains(targetRequest)) {
boolean identicalAssociation = true;
- final Iterator<Property> iterator = ((Association) current).getMemberEnds().iterator();
- while (iterator.hasNext() && identicalAssociation) {
- final Property property = iterator.next();
- final boolean source = request.getSource().equals(property.getType());
+ // Check if association is reflexive
+ if (sourceRequest.equals(targetRequest)) {
+ identicalAssociation = false;
+ Property firstEnd = AssociationUtil.getSourceFirstEnd((Association) current);
+ Property secondEnd = AssociationUtil.getTargetSecondEnd((Association) current);
+ // Compare memebers ends of the current association
+ if (null != firstEnd && null != secondEnd) {
+ if (firstEnd.getType().equals(secondEnd.getType())) {
+ // Check with the firstEnd = source and the secondEnd = target
+ boolean checkSourceAndTarget = checkReflexiveAssociation(request, firstEnd, secondEnd);
+ // If it's not identical, check firstEnd = target and secondEnd = source.
+ if (!checkSourceAndTarget) {
+ checkSourceAndTarget = checkReflexiveAssociation(request, secondEnd, firstEnd);
+ }
+ if (checkSourceAndTarget) {
+ identicalAssociation = true;
+ }
+ }
+ }
+ } else {
+ final Iterator<Property> iterator = ((Association) current).getMemberEnds().iterator();
+
+ while (iterator.hasNext() && identicalAssociation) {
+ final Property property = iterator.next();
+ final boolean isSource = sourceRequest.equals(property.getType());
- boolean expectedNavigable = getExpectedNavigable(source, request);
+ boolean expectedNavigable = getExpectedNavigable(isSource, request);
- if (!AssociationUtil.isIdenticalProperties(expectedNavigable, AggregationKind.NONE_LITERAL, property)) {
- identicalAssociation = false;
+ if (!AssociationUtil.isIdenticalProperties(expectedNavigable, AggregationKind.NONE_LITERAL, property)) {
+ identicalAssociation = false;
+ }
}
}
@@ -266,6 +292,31 @@ public class CreateOrShowExistingElementHelper {
}
/**
+ * Compare two memberEnds of a reflexive association.
+ *
+ * @param request
+ * The CreateRelationshipRequest.
+ * @param firstProperty
+ * The first property of the current association.
+ * @param secondProperty
+ * The second property of the current association.
+ * @return
+ */
+ private boolean checkReflexiveAssociation(CreateRelationshipRequest request, Property firstProperty, Property secondProperty) {
+ boolean expectedNavigable = getExpectedNavigable(true, request);
+ if (!AssociationUtil.isIdenticalProperties(expectedNavigable, AggregationKind.NONE_LITERAL, firstProperty)) {
+ return false;
+ }
+
+ expectedNavigable = getExpectedNavigable(false, request);
+ if (!AssociationUtil.isIdenticalProperties(expectedNavigable, AggregationKind.NONE_LITERAL, secondProperty)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
*
* Returns the open link dialog.
*

Back to the top