Skip to content
Snippets Groups Projects
Commit 800c9ee2 authored by Lukas Ladenberger's avatar Lukas Ladenberger
Browse files

fixed PROBPLUGIN-39

parent 9d8095cf
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
}
}
......
......@@ -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
......@@ -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());
......
......@@ -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;
}
......
......@@ -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);
}
}
......
......@@ -22,7 +22,6 @@ public class BMSTreeEditPartFactory implements EditPartFactory {
public EditPart createEditPart(EditPart context, Object model) {
BMSAbstractTreeEditPart part = null;
if (model instanceof Visualization) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment