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