From 1b0f2e3ea2f3df5739527ba01f22b3f6e88f640c Mon Sep 17 00:00:00 2001 From: Lukas Ladenberger <lukas.ladenberger@googlemail.com> Date: Fri, 9 Nov 2012 10:41:33 +0100 Subject: [PATCH] cleanup paste command --- .../gef/editor/command/PasteCommand.java | 71 ++++++------------- 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/PasteCommand.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/PasteCommand.java index 0932a3ed..65f80d35 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/PasteCommand.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/command/PasteCommand.java @@ -93,58 +93,14 @@ public class PasteCommand extends Command { HashMap<BControl, BControl> helpMap = new HashMap<BControl, BControl>(); helpMap.putAll(cHelper.getAlreadyClonedMap()); helpMap.putAll(mappingControl); - Iterator<BControl> it2 = helpMap.keySet().iterator(); while (it2.hasNext()) { BControl control = it2.next(); - // Clone connections - for (BConnection c : control.getSourceConnections()) { - - BConnection newConnection = mappingConnection.get(c); - if (newConnection == null) { - newConnection = (BConnection) c.clone(); - newConnection.disconnect(); - mappingConnection.put(c, newConnection); - } - - BControl s = helpMap.get(newConnection - .getSource()); - if (s == null) - s = newConnection.getSource(); - BControl t = helpMap.get(newConnection - .getTarget()); - if (t == null) - t = newConnection.getTarget(); - - newConnection.setTarget(t); - newConnection.setSource(s); - - } - - for (BConnection c : control.getTargetConnections()) { - - BConnection newConnection = mappingConnection.get(c); - if (newConnection == null) { - newConnection = (BConnection) c.clone(); - newConnection.disconnect(); - mappingConnection.put(c, newConnection); - } - - BControl t = helpMap.get(newConnection - .getTarget()); - if (t == null) - t = newConnection.getTarget(); - BControl s = helpMap.get(newConnection - .getSource()); - if (s == null) - s = newConnection.getSource(); - - newConnection.setTarget(t); - newConnection.setSource(s); - - } - + for (BConnection c : control.getSourceConnections()) + copyPasteConnection(c, helpMap); + for (BConnection c : control.getTargetConnections()) + copyPasteConnection(c, helpMap); } redo(); @@ -157,6 +113,25 @@ public class PasteCommand extends Command { } + private void copyPasteConnection(BConnection c, + HashMap<BControl, BControl> controlMap) + throws CloneNotSupportedException { + BConnection newConnection = mappingConnection.get(c); + if (newConnection == null) { + newConnection = (BConnection) c.clone(); + newConnection.disconnect(); + mappingConnection.put(c, newConnection); + } + BControl t = controlMap.get(newConnection.getTarget()); + if (t == null) + t = newConnection.getTarget(); + BControl s = controlMap.get(newConnection.getSource()); + if (s == null) + s = newConnection.getSource(); + newConnection.setTarget(t); + newConnection.setSource(s); + } + @Override public void redo() { -- GitLab