Search in sources :

Example 1 with DeleteNestedConnectionsCommand

use of com.archimatetool.editor.diagram.commands.DeleteNestedConnectionsCommand in project archi by archimatetool.

the class ArchimateContainerLayoutPolicy method getAddCommand.

// Over-ride this method to add a sub-command for nested connections
@Override
protected Command getAddCommand(Request generic) {
    Object parent = getHost().getModel();
    ChangeBoundsRequest request = (ChangeBoundsRequest) generic;
    CompoundCommand command = new CompoundCommand();
    // Add relations/connections between parent and child if Prefs set and if parent is an Archimate object
    boolean doAddNestedConnections = ConnectionPreferences.createRelationWhenMovingElement() && parent instanceof IDiagramModelArchimateObject;
    List<IDiagramModelArchimateObject> childObjectsForNewConnections = new ArrayList<IDiagramModelArchimateObject>();
    // Delete connections between parent and child if Prefs set and if parent is an Archimate object
    boolean doDeleteNestedConnections = ConnectionPreferences.useNestedConnections();
    List<IDiagramModelArchimateObject> childObjectsForDeletedConnections = new ArrayList<IDiagramModelArchimateObject>();
    for (Object editPart : request.getEditParts()) {
        GraphicalEditPart child = (GraphicalEditPart) editPart;
        AddObjectCommand addCommand = createAddCommand(request, child, translateToModelConstraint(getConstraintFor(request, child)));
        command.add(addCommand);
        // If we use nested connections, and child is an Archimate diagram object add it to the list
        if (doAddNestedConnections && addCommand.child instanceof IDiagramModelArchimateObject) {
            childObjectsForNewConnections.add((IDiagramModelArchimateObject) addCommand.child);
        }
        // If we need to delete some nested connections
        if (doDeleteNestedConnections && addCommand.child instanceof IDiagramModelArchimateObject) {
            childObjectsForDeletedConnections.add((IDiagramModelArchimateObject) addCommand.child);
        }
    }
    // We have some child objects for deletion connections
    if (!childObjectsForDeletedConnections.isEmpty()) {
        Command cmd = new DeleteNestedConnectionsCommand((IDiagramModelArchimateObject) parent, childObjectsForDeletedConnections);
        command.add(cmd);
    }
    // We have some child objects so add the sub command
    if (!childObjectsForNewConnections.isEmpty()) {
        Command cmd = new CreateNestedArchimateConnectionsWithDialogCommand((IDiagramModelArchimateObject) parent, childObjectsForNewConnections);
        command.add(cmd);
    }
    return command.unwrap();
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) CreateNestedArchimateConnectionsWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand) Command(org.eclipse.gef.commands.Command) CreateNestedArchimateConnectionsWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) DeleteNestedConnectionsCommand(com.archimatetool.editor.diagram.commands.DeleteNestedConnectionsCommand) ArrayList(java.util.ArrayList) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) DeleteNestedConnectionsCommand(com.archimatetool.editor.diagram.commands.DeleteNestedConnectionsCommand) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

CreateNestedArchimateConnectionsWithDialogCommand (com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand)1 DeleteNestedConnectionsCommand (com.archimatetool.editor.diagram.commands.DeleteNestedConnectionsCommand)1 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)1 ArrayList (java.util.ArrayList)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 Command (org.eclipse.gef.commands.Command)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)1