-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete object and move child objects to parent
- Loading branch information
Showing
7 changed files
with
156 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...himatetool.editor/src/com/archimatetool/editor/diagram/actions/DeleteContainerAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* This program and the accompanying materials | ||
* are made available under the terms of the License | ||
* which accompanies this distribution in the file LICENSE.txt | ||
*/ | ||
package com.archimatetool.editor.diagram.actions; | ||
|
||
import org.eclipse.gef.EditPart; | ||
import org.eclipse.gef.commands.Command; | ||
import org.eclipse.gef.commands.CompoundCommand; | ||
import org.eclipse.gef.ui.actions.SelectionAction; | ||
import org.eclipse.ui.IWorkbenchPart; | ||
|
||
import com.archimatetool.editor.diagram.commands.DiagramCommandFactory; | ||
import com.archimatetool.editor.model.commands.AddListMemberCommand; | ||
import com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand; | ||
import com.archimatetool.editor.model.commands.RemoveListMemberCommand; | ||
import com.archimatetool.model.IArchimateFactory; | ||
import com.archimatetool.model.IBounds; | ||
import com.archimatetool.model.IDiagramModelContainer; | ||
import com.archimatetool.model.IDiagramModelObject; | ||
|
||
|
||
|
||
/** | ||
* Delete Container object and move children to parent | ||
* | ||
* @author Phillip Beauvoir | ||
*/ | ||
public class DeleteContainerAction extends SelectionAction { | ||
|
||
public static final String ID = "com.archimatetool.editor.action.deleteContainer"; //$NON-NLS-1$ | ||
public static final String TEXT = "Delete from View and keep children"; | ||
|
||
public DeleteContainerAction(IWorkbenchPart part) { | ||
super(part); | ||
setText(TEXT); | ||
setId(ID); | ||
setActionDefinitionId(ID); // register key binding | ||
} | ||
|
||
@Override | ||
protected boolean calculateEnabled() { | ||
for(Object object : getSelectedObjects()) { | ||
if(object instanceof EditPart editPart && editPart.getModel() instanceof IDiagramModelObject) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(TEXT); | ||
|
||
for(Object object : getSelectedObjects()) { | ||
if(object instanceof EditPart editPart && editPart.getModel() instanceof IDiagramModelObject dmo) { | ||
if(dmo instanceof IDiagramModelContainer container && dmo.eContainer() instanceof IDiagramModelContainer parent) { | ||
// Iterate thru child objects to move them to new parent | ||
for(IDiagramModelObject child : container.getChildren()) { | ||
// Remove child from parent | ||
compoundCommand.add(new RemoveListMemberCommand<>(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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters