Bug 376544 - bug in re-connecting a connection with identical start and
end anchor
diff --git a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/DefaultReconnectionFeature.java b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/DefaultReconnectionFeature.java
index 47b4894..9fe186c 100644
--- a/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/DefaultReconnectionFeature.java
+++ b/plugins/org.eclipse.graphiti/src/org/eclipse/graphiti/features/impl/DefaultReconnectionFeature.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2011 SAP AG.
+ * Copyright (c) 2005, 2012 SAP AG.
* 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
@@ -12,6 +12,7 @@
* mgorning - Bug 343983 - Notification for Cancelled Reconnection Events
* mwenz - Bug 364035 - DefaultReconnectionFeature#reconnect should use getNewAnchor(context)
* not context.getNewAnchor()
+ * Henrik Rentz-Reichert - mwenz - Bug 376544 - bug in re-connecting a connection with identical start and end anchor
*
* </copyright>
*
@@ -22,6 +23,7 @@
import org.eclipse.graphiti.features.IReconnectionFeature;
import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.IReconnectionContext;
+import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
import org.eclipse.graphiti.internal.Messages;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.Connection;
@@ -105,10 +107,9 @@
preReconnect(context);
Connection connection = context.getConnection();
- Anchor newAnchor = getNewAnchor(context);
- Anchor oldAnchor = context.getOldAnchor();
+ Anchor newAnchor = context.getNewAnchor();
- if (connection.getStart().equals(oldAnchor)) {
+ if (context.getReconnectType().equals(ReconnectionContext.RECONNECT_SOURCE)) {
connection.setStart(newAnchor);
} else {
connection.setEnd(newAnchor);
diff --git a/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/AllTests.java b/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/AllTests.java
index 485a759..02cea76 100644
--- a/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/AllTests.java
+++ b/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/AllTests.java
@@ -1,7 +1,7 @@
/*******************************************************************************
* <copyright>
*
- * Copyright (c) 2005, 2010 SAP AG.
+ * Copyright (c) 2005, 2012 SAP AG.
* 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
@@ -9,6 +9,7 @@
*
* Contributors:
* SAP AG - initial API, implementation and documentation
+ * Henrik Rentz-Reichert - mwenz - Bug 376544 - bug in re-connecting a connection with identical start and end anchor
*
* </copyright>
*
@@ -20,11 +21,13 @@
import org.eclipse.graphiti.tests.cases.GaServiceTest;
import org.eclipse.graphiti.tests.cases.LinkServiceTest;
import org.eclipse.graphiti.tests.cases.PeServiceTest;
+import org.eclipse.graphiti.tests.cases.ReconnectionTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
-@Suite.SuiteClasses( { DefaultFeaturesTest.class, GaServiceTest.class, LinkServiceTest.class, PeServiceTest.class, CreateServiceTest.class })
+@Suite.SuiteClasses({ DefaultFeaturesTest.class, GaServiceTest.class, LinkServiceTest.class, PeServiceTest.class,
+ CreateServiceTest.class, ReconnectionTest.class })
public class AllTests {
}
diff --git a/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/ReconnectionTest.java b/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/ReconnectionTest.java
new file mode 100644
index 0000000..9c0f54b
--- /dev/null
+++ b/tests/org.eclipse.graphiti.tests/src/org/eclipse/graphiti/tests/cases/ReconnectionTest.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * <copyright>
+ *
+ * Copyright (c) 2012, 2012 SAP AG.
+ * 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:
+ * Henrik Rentz-Reichert - mwenz - Bug 376544 - bug in re-connecting a connection with identical start and end anchor
+ *
+ * </copyright>
+ *
+ *******************************************************************************/
+package org.eclipse.graphiti.tests.cases;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
+import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
+import org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.services.IPeService;
+import org.eclipse.graphiti.tests.reuse.GFAbstractTestCase;
+import org.junit.Test;
+
+public class ReconnectionTest extends GFAbstractTestCase {
+
+ public ReconnectionTest() {
+ super();
+ }
+
+ @Test
+ public void testReconnectLoopToOtherAnchor() throws Exception {
+ IPeService peService = Graphiti.getPeService();
+
+ Shape shape = peService.createShape(null, true);
+ BoxRelativeAnchor anchor1 = peService.createBoxRelativeAnchor(shape);
+ BoxRelativeAnchor anchor2 = peService.createBoxRelativeAnchor(shape);
+ FreeFormConnection connection = peService.createFreeFormConnection(null);
+ connection.setStart(anchor1);
+ connection.setEnd(anchor1);
+
+ ReconnectionContext context = new ReconnectionContext(connection, anchor1, anchor2, null);
+ context.setReconnectType(ReconnectionContext.RECONNECT_TARGET);
+
+ DefaultReconnectionFeature reconnectionFeature = new DefaultReconnectionFeature(null);
+ reconnectionFeature.reconnect(context);
+
+ assertEquals(anchor2, connection.getEnd());
+ }
+}