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 69c559860c9735aedbe07560ebc97c95a4e8609c..7ecb8ecb3abcb8097589bfb6a4ff7db77c95f80a 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 @@ -15,6 +15,7 @@ import org.eclipse.gef.commands.Command; import org.eclipse.gef.ui.actions.Clipboard; import de.bmotionstudio.gef.editor.AttributeConstants; +import de.bmotionstudio.gef.editor.model.BConnection; import de.bmotionstudio.gef.editor.model.BControl; import de.bmotionstudio.gef.editor.model.Visualization; @@ -27,6 +28,8 @@ public class PasteCommand extends Command { private List<BControl> parentControls = new ArrayList<BControl>(); + private List<ConnectionCreateCommand> connectionCreateCmds = new ArrayList<ConnectionCreateCommand>(); + @Override public boolean canExecute() { cHelper = (CopyPasteHelper) Clipboard.getDefault().getContents(); @@ -69,7 +72,6 @@ public class PasteCommand extends Command { BControl control = (BControl) it.next(); control.setParent(parent); try { - BControl clone = (BControl) control.clone(); clone.setParent(parent); int x = Integer.valueOf(Integer.valueOf(clone @@ -84,6 +86,26 @@ public class PasteCommand extends Command { + cHelper.getDistance()); list.put(control, clone); cHelper.setDistance(cHelper.getDistance() + 10); + + // Clone connections + for (BConnection c : control.getSourceConnections()) { + BConnection cb = (BConnection) c.clone(); + cb.setSource(clone); + ConnectionCreateCommand connectionCreateCommand = new ConnectionCreateCommand( + clone); + connectionCreateCommand.setConnection(cb); + connectionCreateCmds.add(connectionCreateCommand); + } + + for (BConnection c : control.getTargetConnections()) { + BConnection cb = (BConnection) c.clone(); + cb.setTarget(clone); + ConnectionCreateCommand connectionCreateCommand = new ConnectionCreateCommand( + cb.getSource()); + connectionCreateCommand.setConnection(cb); + connectionCreateCmds.add(connectionCreateCommand); + } + } catch (CloneNotSupportedException e) { e.printStackTrace(); } @@ -101,6 +123,8 @@ public class PasteCommand extends Command { BControl control = it.next(); if (isPastableControl(control)) { control.getParent().addChild(control); + for (ConnectionCreateCommand cmd : connectionCreateCmds) + cmd.redo(); } } } @@ -117,6 +141,8 @@ public class PasteCommand extends Command { BControl bcontrol = it.next(); if (isPastableControl(bcontrol)) { bcontrol.getParent().removeChild(bcontrol); + for (ConnectionCreateCommand cmd : connectionCreateCmds) + cmd.undo(); } } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BConnection.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BConnection.java index 30427a0361ca0baa0cd1c29c7b9a38b230b3bb1e..e984e672fb7d2ed620d4211823c0a1a00f908cf8 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BConnection.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BConnection.java @@ -8,6 +8,7 @@ package de.bmotionstudio.gef.editor.model; import org.eclipse.swt.graphics.RGB; +import de.bmotionstudio.gef.editor.attribute.AbstractAttribute; import de.bmotionstudio.gef.editor.attribute.BAttributeConnection; import de.bmotionstudio.gef.editor.attribute.BAttributeConnectionSourceDecoration; import de.bmotionstudio.gef.editor.attribute.BAttributeConnectionTargetDecoration; @@ -21,11 +22,11 @@ public class BConnection extends BControl { public static String TYPE = "de.bmotionstudio.gef.editor.connection"; /** True, if the connection is attached to its endpoints. */ - private boolean isConnected; + protected boolean isConnected; /** Connection's source endpoint. */ - private BControl source; + protected BControl source; /** Connection's target endpoint. */ - private BControl target; + protected BControl target; /** * Create a (solid) connection between two distinct shapes. @@ -122,6 +123,7 @@ public class BConnection extends BControl { protected void initAttributes() { BAttributeConnection aConnection = new BAttributeConnection(null); + aConnection.setGroup(AbstractAttribute.ROOT); initAttribute(aConnection); BAttributeLineWidth aLineWidth = new BAttributeLineWidth(1); @@ -154,4 +156,11 @@ public class BConnection extends BControl { } + @Override + public BControl clone() throws CloneNotSupportedException { + BConnection clonedControl = (BConnection) super.clone(); + clonedControl.isConnected = false; + return clonedControl; + } + } \ No newline at end of file diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java index b30279045306fc5718669306c8d2044712238383..90b285c2e60c3c8bdca1f5a28599b6e1ea576e86 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/BControl.java @@ -647,30 +647,35 @@ public abstract class BControl implements IAdaptable, Cloneable { clonedControl.listeners = new PropertyChangeSupport(clonedControl); clonedControl.observerListener = new ArrayList<IObserverListener>(); + clonedControl.sourceConnections = new ArrayList<BConnection>(); + clonedControl.targetConnections = new ArrayList<BConnection>(); clonedControl.setParent(getParent()); + // Clone attributes Map<String, AbstractAttribute> newProperties = new HashMap<String, AbstractAttribute>(); for (Entry<String, AbstractAttribute> e : getAttributes().entrySet()) { AbstractAttribute idAtr = e.getValue().clone(); newProperties.put(e.getKey(), idAtr); } - clonedControl.setAttributes(newProperties); clonedControl.setAttributeValue(AttributeConstants.ATTRIBUTE_ID, getVisualization().getMaxIDString(type)); + // Clone children clonedControl.setChildrenArray(new BControlList()); Iterator<BControl> it = getChildrenArray().iterator(); while (it.hasNext()) { clonedControl.addChild(((BControl) it.next()).clone()); } + // Clone observer clonedControl.setObserverMap(new HashMap<String, Observer>()); for (Observer observer : observers.values()) { clonedControl.addObserver(observer.clone()); } + // Clone events clonedControl.setEventMap(new HashMap<String, SchedulerEvent>()); for (Map.Entry<String, SchedulerEvent> e : events.entrySet()) { clonedControl.addEvent(e.getKey(), e.getValue().clone()); 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 8902014ee985724dce5735b94516b9483808da8e..76572aa8d7e3ed9d17ea22b44068332fb696749f 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 @@ -14,7 +14,6 @@ import org.eclipse.draw2d.PositionConstants; import de.be4.classicalb.core.parser.exceptions.BException; import de.bmotionstudio.gef.editor.Animation; -import de.bmotionstudio.gef.editor.AttributeConstants; import de.bmotionstudio.gef.editor.ButtonGroupHelper; import de.bmotionstudio.gef.editor.IAddErrorListener; import de.bmotionstudio.gef.editor.scheduler.PredicateOperation; @@ -186,13 +185,18 @@ public class Visualization extends BControl { private List<String> getAllBControlNames(List<BControl> children) { List<String> list = new ArrayList<String>(); - for (BControl bcontrol : children) { - list.add(bcontrol - .getAttributeValue(AttributeConstants.ATTRIBUTE_ID) - .toString()); - if (bcontrol.getChildrenArray().size() > 0) { - list.addAll(getAllBControlNames(bcontrol.getChildrenArray())); - } + for (BControl control : children) { + list.add(control.getID()); + // Check children + List<BControl> subchildren = control.getChildrenArray(); + if (children.size() > 0) + list.addAll(getAllBControlNames(subchildren)); + // Check connections + List<BControl> connections = new ArrayList<BControl>(); + connections.addAll(control.getSourceConnections()); + connections.addAll(control.getTargetConnections()); + if (connections.size() > 0) + list.addAll(getAllBControlNames(connections)); } return list; } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java index ca5ce02f916c365d1da51e8d4f4f9ac2c01f8409..6adcbe067053f1a1f209c8e7887019dec0cbef8f 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BControlTreeEditPart.java @@ -61,13 +61,15 @@ public class BControlTreeEditPart extends BMSAbstractTreeEditPart implements List<BConnection> sourceConnections = control .getSourceConnections(); for (BConnection con : sourceConnections) { - if (con.showInOutlineView()) + if (con.showInOutlineView() + && !toShowElements.contains(con)) toShowElements.add(con); } List<BConnection> targetConnections = control .getTargetConnections(); for (BConnection con : targetConnections) { - if (con.showInOutlineView()) + if (con.showInOutlineView() + && !toShowElements.contains(con)) toShowElements.add(con); } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java index 47916113359feda9cbaa575bd12303819941b43f..7744514400fbe32a45c0e522d0a84166d8804f3b 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/part/BMSTreeEditPartFactory.java @@ -22,7 +22,6 @@ public class BMSTreeEditPartFactory implements EditPartFactory { public EditPart createEditPart(EditPart context, Object model) { - BMSAbstractTreeEditPart part = null; if (model instanceof Visualization) {