From baec5bd7be3d3bc41c776dc7fde19bfc7a0a6ba5 Mon Sep 17 00:00:00 2001
From: Lukas Ladenberger <lukas.ladenberger@googlemail.com>
Date: Wed, 7 Nov 2012 11:44:50 +0100
Subject: [PATCH] fixed PROBPLUGIN-47

---
 .../editor/BMotionSelectionSynchronizer.java   | 15 ++-------------
 .../gef/editor/BMotionStudioEditorPage.java    |  3 +--
 .../gef/editor/model/Visualization.java        | 18 +++++++++++++-----
 3 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionSelectionSynchronizer.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionSelectionSynchronizer.java
index 2a3753c6..69891a07 100644
--- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionSelectionSynchronizer.java
+++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionSelectionSynchronizer.java
@@ -16,27 +16,16 @@ import de.bmotionstudio.gef.editor.model.BControl;
 
 public class BMotionSelectionSynchronizer extends SelectionSynchronizer {
 
-	private BMotionStudioEditor editor;
-
-	public BMotionSelectionSynchronizer(BMotionStudioEditor editor) {
-		this.editor = editor;
-	}
-
 	protected EditPart convert(EditPartViewer viewer, EditPart part) {
 		EditPart p = super.convert(viewer, part);
 		if (viewer instanceof ScrollingGraphicalViewer
 				|| viewer instanceof TreeViewer) {
 			Object model = part.getModel();
 			if (model instanceof BControl) {
-				BControl control = (BControl) model;
-				String id = control.getID();
-				BControl editControl = editor.getEditPage().getVisualization()
-						.getBControl(id);
-				Object temp = viewer.getEditPartRegistry().get(editControl);
+				Object temp = viewer.getEditPartRegistry().get(model);
 				EditPart newPart = null;
-				if (temp != null) {
+				if (temp != null)
 					newPart = (EditPart) temp;
-				}
 				return newPart;
 			}
 		}
diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditorPage.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditorPage.java
index 4ab8aad0..38ddeb19 100644
--- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditorPage.java
+++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditorPage.java
@@ -645,8 +645,7 @@ public class BMotionStudioEditorPage extends GraphicalEditorWithFlyoutPalette {
 	@Override
 	public SelectionSynchronizer getSelectionSynchronizer() {
 		if (bmotionSelectionSynchronizer == null)
-			bmotionSelectionSynchronizer = new BMotionSelectionSynchronizer(
-					bmotionStudioEditor);
+			bmotionSelectionSynchronizer = new BMotionSelectionSynchronizer();
 		return bmotionSelectionSynchronizer;
 	}
 
diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java
index 76572aa8..1de47b1b 100644
--- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java
+++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Visualization.java
@@ -231,13 +231,21 @@ public class Visualization extends BControl {
 	}
 
 	private BControl getBControl(String ID, List<BControl> children) {
-		for (BControl bcontrol : children) {
-			if (bcontrol.getID().equals(ID)) {
-				return bcontrol;
+		for (BControl control : children) {
+			if (control.getID().equals(ID)) {
+				return control;
+			}
+			for (BConnection c : control.getSourceConnections()) {
+				if (c.getIcon().equals(ID))
+					return c;
+			}
+			for (BConnection c : control.getTargetConnections()) {
+				if (c.getIcon().equals(ID))
+					return c;
 			}
-			if (bcontrol.getChildrenArray().size() > 0) {
+			if (control.getChildrenArray().size() > 0) {
 				BControl childControl = getBControl(ID,
-						bcontrol.getChildrenArray());
+						control.getChildrenArray());
 				if (childControl != null)
 					return childControl;
 			}
-- 
GitLab