diff --git a/com.archimatetool.editor/plugin.xml b/com.archimatetool.editor/plugin.xml
index cbfd28d39..048fb7fd6 100644
--- a/com.archimatetool.editor/plugin.xml
+++ b/com.archimatetool.editor/plugin.xml
@@ -958,6 +958,12 @@
id="com.archimatetool.editor.action.deleteFromModel"
name="%command.name.20">
+
+
(container.getChildren(), child));
+
+ // Add child to new parent
+ compoundCommand.add(new AddListMemberCommand<>(parent.getChildren(), child));
+
+ // Adjust x,y position to new parent
+ compoundCommand.add(new ChangePositionCommand(child, dmo.getBounds()));
+ }
+
+ // Delete target container object
+ compoundCommand.add(DiagramCommandFactory.createDeleteDiagramObjectNoChildrenCommand(dmo));
+ }
+ }
+ }
+
+ execute(compoundCommand);
+ }
+
+ private static class ChangePositionCommand extends Command {
+ private IDiagramModelObject dmo;
+ private IBounds oldBounds, newBounds;
+
+ public ChangePositionCommand(IDiagramModelObject dmo, IBounds parentBounds) {
+ this.dmo = dmo;
+ this.oldBounds = dmo.getBounds();
+ newBounds = IArchimateFactory.eINSTANCE.createBounds(oldBounds.getX() + parentBounds.getX(),
+ oldBounds.getY() + parentBounds.getY(), oldBounds.getWidth(), oldBounds.getHeight());
+ }
+
+ @Override
+ public void execute() {
+ dmo.setBounds(newBounds);
+ }
+
+ @Override
+ public void undo() {
+ dmo.setBounds(oldBounds);
+ }
+
+ @Override
+ public void dispose() {
+ dmo = null;
+ oldBounds = null;
+ newBounds = null;
+ }
+ }
+}
diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/DiagramCommandFactory.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/DiagramCommandFactory.java
index 20dc72a67..e944d674f 100644
--- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/DiagramCommandFactory.java
+++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/commands/DiagramCommandFactory.java
@@ -22,23 +22,24 @@
public final class DiagramCommandFactory {
/**
- * @param object
* @return A new Delete Diagram Object Command
*/
public static Command createDeleteDiagramObjectCommand(IDiagramModelObject object) {
CompoundCommand result = new CompoundCommand();
- __addDeleteDiagramObjectCommands(object, result);
+ addDeleteDiagramObjectCommands(object, result, true);
return result.unwrap();
}
/**
- * Recurse and add child delete commands.
- * We have to do this because if the object has children with connections going outside these need explicit Delete Commands too
- * otherwise we end up with trailing connections...
- * @param container
- * @param result
+ * @return A new Delete Diagram Object Command but don't delete child objects
*/
- private static void __addDeleteDiagramObjectCommands(IDiagramModelObject object, CompoundCommand result) {
+ public static Command createDeleteDiagramObjectNoChildrenCommand(IDiagramModelObject object) {
+ CompoundCommand result = new CompoundCommand();
+ addDeleteDiagramObjectCommands(object, result, false);
+ return result.unwrap();
+ }
+
+ private static void addDeleteDiagramObjectCommands(IDiagramModelObject object, CompoundCommand result, boolean recurse) {
result.add(new DeleteDiagramObjectCommand(object));
for(IDiagramModelConnection connection : object.getSourceConnections()) {
@@ -49,9 +50,9 @@ private static void __addDeleteDiagramObjectCommands(IDiagramModelObject object,
result.add(createDeleteDiagramConnectionCommand(connection));
}
- if(object instanceof IDiagramModelContainer) {
- for(IDiagramModelObject child : ((IDiagramModelContainer)object).getChildren()) {
- __addDeleteDiagramObjectCommands(child, result);
+ if(recurse && object instanceof IDiagramModelContainer container) {
+ for(IDiagramModelObject child : container.getChildren()) {
+ addDeleteDiagramObjectCommands(child, result, recurse);
}
}
}
@@ -62,11 +63,11 @@ private static void __addDeleteDiagramObjectCommands(IDiagramModelObject object,
*/
public static Command createDeleteDiagramConnectionCommand(IDiagramModelConnection connection) {
CompoundCommand result = new CompoundCommand();
- __addDeleteDiagramConnectionCommands(connection, result);
+ addDeleteDiagramConnectionCommands(connection, result);
return result.unwrap();
}
- private static void __addDeleteDiagramConnectionCommands(IDiagramModelConnection connection, CompoundCommand result) {
+ private static void addDeleteDiagramConnectionCommands(IDiagramModelConnection connection, CompoundCommand result) {
for(IDiagramModelConnection conn : connection.getSourceConnections()) {
result.add(createDeleteDiagramConnectionCommand(conn));
}