-
-
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
6 changed files
with
113 additions
and
13 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
76 changes: 76 additions & 0 deletions
76
...atetool.editor/src/com/archimatetool/editor/diagram/actions/DeleteParentObjectAction.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,76 @@ | ||
/** | ||
* 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.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.IBounds; | ||
import com.archimatetool.model.IDiagramModelContainer; | ||
import com.archimatetool.model.IDiagramModelObject; | ||
|
||
|
||
|
||
/** | ||
* Delete Parent Object and move children to parent | ||
* | ||
* @author Phillip Beauvoir | ||
*/ | ||
public class DeleteParentObjectAction extends SelectionAction { | ||
|
||
public static final String ID = "com.archimatetool.editor.action.deleteParentObject"; //$NON-NLS-1$ | ||
public static final String TEXT = "Delete Parent Object"; | ||
|
||
public DeleteParentObjectAction(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 target && dmo.eContainer() instanceof IDiagramModelContainer parent) { | ||
for(IDiagramModelObject child : target.getChildren()) { | ||
compoundCommand.add(new RemoveListMemberCommand<>(target.getChildren(), child)); | ||
compoundCommand.add(new AddListMemberCommand<>(parent.getChildren(), child)); | ||
|
||
IBounds targetBounds = dmo.getBounds(); | ||
IBounds childBounds = child.getBounds(); | ||
|
||
childBounds.setX(childBounds.getX() + targetBounds.getX()); | ||
childBounds.setY(childBounds.getY() + targetBounds.getY()); | ||
} | ||
|
||
compoundCommand.add(DiagramCommandFactory.createDeleteDiagramObjectNoChildrenCommand(dmo)); | ||
} | ||
} | ||
} | ||
|
||
execute(compoundCommand); | ||
} | ||
} |
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