Search in sources :

Example 1 with DeleteArchimateRelationshipCommand

use of com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand in project archi by archimatetool.

the class DeleteFromModelAction method run.

@Override
public void run() {
    List<?> selection = getSelectedObjects();
    List<IArchimateConcept> archimateConcepts = new ArrayList<IArchimateConcept>();
    List<IDiagramModelComponent> diagramObjects = new ArrayList<IDiagramModelComponent>();
    // Gather Model elements, relations
    for (Object object : selection) {
        if (object instanceof EditPart) {
            Object model = ((EditPart) object).getModel();
            if (model instanceof IDiagramModelArchimateObject) {
                IArchimateElement element = ((IDiagramModelArchimateObject) model).getArchimateElement();
                if (!archimateConcepts.contains(element)) {
                    archimateConcepts.add(element);
                }
                // Element's relationships
                for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(element)) {
                    if (!archimateConcepts.contains(relation)) {
                        archimateConcepts.add(relation);
                    }
                    // Relation's relationships
                    for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
                        if (!archimateConcepts.contains(r)) {
                            archimateConcepts.add(r);
                        }
                    }
                }
            } else if (model instanceof IDiagramModelArchimateConnection) {
                IArchimateRelationship relation = ((IDiagramModelArchimateConnection) model).getArchimateRelationship();
                if (!archimateConcepts.contains(relation)) {
                    archimateConcepts.add(relation);
                }
                // Relation's relationships
                for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
                    if (!archimateConcepts.contains(r)) {
                        archimateConcepts.add(r);
                    }
                }
            }
        }
    }
    // Gather referenced diagram objects
    for (IArchimateConcept archimateConcept : archimateConcepts) {
        for (IDiagramModel diagramModel : archimateConcept.getArchimateModel().getDiagramModels()) {
            for (IDiagramModelComponent dc : DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, archimateConcept)) {
                diagramObjects.add(dc);
            }
        }
    }
    // Check whether any of these concepts are referenced in other diagrams
    if (hasMoreThanOneReference(archimateConcepts, diagramObjects)) {
        if (!MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.DeleteFromModelAction_0, Messages.DeleteFromModelAction_1 + // $NON-NLS-1$
        "\n\n" + Messages.DeleteFromModelAction_2)) {
            return;
        }
    }
    // Create commands
    CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(TEXT);
    for (IArchimateConcept archimateConcept : archimateConcepts) {
        if (archimateConcept instanceof IArchimateElement) {
            Command cmd = new DeleteArchimateElementCommand((IArchimateElement) archimateConcept);
            compoundCommand.add(cmd);
        } else if (archimateConcept instanceof IArchimateRelationship) {
            Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) archimateConcept);
            compoundCommand.add(cmd);
        }
    }
    for (IDiagramModelComponent dc : diagramObjects) {
        if (dc instanceof IDiagramModelObject) {
            Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) dc);
            compoundCommand.add(cmd);
        } else if (dc instanceof IDiagramModelConnection) {
            Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand((IDiagramModelConnection) dc);
            compoundCommand.add(cmd);
        }
    }
    execute(compoundCommand);
}
Also used : NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList) EditPart(org.eclipse.gef.EditPart) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IDiagramModel(com.archimatetool.model.IDiagramModel) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) Command(org.eclipse.gef.commands.Command) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 2 with DeleteArchimateRelationshipCommand

use of com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand in project archi by archimatetool.

the class DeleteCommandHandler method createCommands.

/**
 * Create the Delete Commands
 */
private void createCommands() {
    /*
         *  We need to ensure that the Delete Diagram Model Commands are called first in order to close
         *  any open diagram editors before removing their models from parent folders.
         */
    for (Object object : fElementsToDelete) {
        if (object instanceof IDiagramModel) {
            CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
            if (compoundCommand != null) {
                Command cmd = new DeleteDiagramModelCommand((IDiagramModel) object);
                compoundCommand.add(cmd);
            } else {
                // $NON-NLS-1$
                System.err.println("Could not get CompoundCommand in " + getClass());
            }
        }
    }
    /*
         * Then the other types
         */
    for (Object object : fElementsToDelete) {
        if (object instanceof IDiagramModel) {
            // already done
            continue;
        }
        CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
        if (compoundCommand == null) {
            // sanity check
            // $NON-NLS-1$
            System.err.println("Could not get CompoundCommand in " + getClass());
            continue;
        }
        if (object instanceof IFolder) {
            Command cmd = new DeleteFolderCommand((IFolder) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IArchimateElement) {
            Command cmd = new DeleteArchimateElementCommand((IArchimateElement) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IArchimateRelationship) {
            Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IDiagramModelObject) {
            Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IDiagramModelConnection) {
            Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand((IDiagramModelConnection) object);
            compoundCommand.add(cmd);
        }
    }
}
Also used : DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) DeleteFolderCommand(com.archimatetool.editor.model.commands.DeleteFolderCommand) IDiagramModel(com.archimatetool.model.IDiagramModel) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) DeleteDiagramModelCommand(com.archimatetool.editor.model.commands.DeleteDiagramModelCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) DeleteFolderCommand(com.archimatetool.editor.model.commands.DeleteFolderCommand) Command(org.eclipse.gef.commands.Command) DeleteDiagramModelCommand(com.archimatetool.editor.model.commands.DeleteDiagramModelCommand) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) EObject(org.eclipse.emf.ecore.EObject) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IFolder(com.archimatetool.model.IFolder)

Aggregations

DeleteArchimateElementCommand (com.archimatetool.editor.model.commands.DeleteArchimateElementCommand)2 DeleteArchimateRelationshipCommand (com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand)2 IArchimateElement (com.archimatetool.model.IArchimateElement)2 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)2 IDiagramModel (com.archimatetool.model.IDiagramModel)2 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)2 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 DeleteDiagramModelCommand (com.archimatetool.editor.model.commands.DeleteDiagramModelCommand)1 DeleteFolderCommand (com.archimatetool.editor.model.commands.DeleteFolderCommand)1 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)1 IArchimateConcept (com.archimatetool.model.IArchimateConcept)1 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)1 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)1 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)1 IFolder (com.archimatetool.model.IFolder)1 ArrayList (java.util.ArrayList)1 EObject (org.eclipse.emf.ecore.EObject)1 EditPart (org.eclipse.gef.EditPart)1