Search in sources :

Example 1 with IDiagramModelComponent

use of com.archimatetool.model.IDiagramModelComponent in project archi by archimatetool.

the class DeleteCommandHandler method getElementsToDelete.

/**
 * Create the list of objects to delete and check
 * @return
 */
private void getElementsToDelete() {
    // Actual elements to delete
    fElementsToDelete = new ArrayList<Object>();
    // First, gather up the list of Archimate objects to be deleted...
    for (Object object : fSelectedObjects) {
        if (canDelete(object)) {
            addToList(object, fElementsToDelete);
            addFolderChildElements(object);
            addElementRelationships(object);
        }
    }
    // Gather referenced diagram objects to be deleted checking that the parent diagram model is not also selected to be deleted
    for (Object object : new ArrayList<>(fElementsToDelete)) {
        // Archimate Components
        if (object instanceof IArchimateConcept) {
            IArchimateConcept archimateConcept = (IArchimateConcept) object;
            for (IDiagramModel diagramModel : archimateConcept.getArchimateModel().getDiagramModels()) {
                // Check diagram model is not selected to be deleted - no point in deleting any of its children
                if (!fElementsToDelete.contains(diagramModel)) {
                    for (IDiagramModelComponent dc : DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, archimateConcept)) {
                        addToList(dc, fElementsToDelete);
                    }
                }
            }
        }
        // Diagram Models and their references
        if (object instanceof IDiagramModel) {
            IDiagramModel diagramModelDeleted = (IDiagramModel) object;
            for (IDiagramModel diagramModel : diagramModelDeleted.getArchimateModel().getDiagramModels()) {
                // is there one?
                List<IDiagramModelReference> list = DiagramModelUtils.findDiagramModelReferences(diagramModel, diagramModelDeleted);
                fElementsToDelete.addAll(list);
            }
        }
    }
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) IDiagramModel(com.archimatetool.model.IDiagramModel) IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) ArrayList(java.util.ArrayList) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) EObject(org.eclipse.emf.ecore.EObject)

Example 2 with IDiagramModelComponent

use of com.archimatetool.model.IDiagramModelComponent in project archi by archimatetool.

the class ValidatorView method selectObjects.

void selectObjects(IStructuredSelection selection) {
    if (selection != null) {
        List<IArchimateConcept> treeList = new ArrayList<IArchimateConcept>();
        List<IDiagramModel> viewList = new ArrayList<IDiagramModel>();
        List<IDiagramModelComponent> viewComponentList = new ArrayList<IDiagramModelComponent>();
        for (Object o : selection.toArray()) {
            if (o instanceof IIssue) {
                IIssue issue = (IIssue) o;
                if (issue.getObject() instanceof IArchimateConcept) {
                    treeList.add((IArchimateConcept) issue.getObject());
                } else if (issue.getObject() instanceof IDiagramModel) {
                    viewList.add((IDiagramModel) issue.getObject());
                } else if (issue.getObject() instanceof IDiagramModelComponent) {
                    viewList.add(((IDiagramModelComponent) issue.getObject()).getDiagramModel());
                    viewComponentList.add(((IDiagramModelComponent) issue.getObject()));
                }
            }
        }
        if (!treeList.isEmpty()) {
            ITreeModelView view = (ITreeModelView) ViewManager.showViewPart(ITreeModelView.ID, false);
            if (view != null) {
                view.getViewer().setSelection(new StructuredSelection(treeList), true);
            }
        }
        if (!viewList.isEmpty()) {
            for (IDiagramModel dm : viewList) {
                IDiagramModelEditor editor = EditorManager.openDiagramEditor(dm);
                if (editor instanceof IArchimateDiagramEditor) {
                    ((IArchimateDiagramEditor) editor).selectObjects(viewComponentList.toArray());
                }
            }
        }
    }
}
Also used : ITreeModelView(com.archimatetool.editor.views.tree.ITreeModelView) IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IDiagramModelEditor(com.archimatetool.editor.diagram.IDiagramModelEditor) IArchimateDiagramEditor(com.archimatetool.editor.diagram.IArchimateDiagramEditor) IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IIssue(com.archimatetool.hammer.validation.issues.IIssue)

Example 3 with IDiagramModelComponent

use of com.archimatetool.model.IDiagramModelComponent in project archi by archimatetool.

the class DiagramModelComponentTests method testGetCopy.

@Test
public void testGetCopy() {
    component.setName("name");
    IDiagramModelComponent copy = (IDiagramModelComponent) component.getCopy();
    assertNotSame(component, copy);
    assertNull(copy.getId());
    assertEquals(component.getName(), copy.getName());
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) Test(org.junit.Test)

Example 4 with IDiagramModelComponent

use of com.archimatetool.model.IDiagramModelComponent 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 5 with IDiagramModelComponent

use of com.archimatetool.model.IDiagramModelComponent in project archi by archimatetool.

the class CopySnapshotTests method testCopiedObjectsHaveIdentifiersAndParents.

private void testCopiedObjectsHaveIdentifiersAndParents(IDiagramModel newTargetDiagramModel) {
    List<IDiagramModelComponent> selected = new ArrayList<IDiagramModelComponent>();
    selected.addAll(getAllDiagramComponents(sourceDiagramModel));
    CopySnapshot snapshot = new CopySnapshot(selected);
    Command cmd = snapshot.getPasteCommand(newTargetDiagramModel, mock(GraphicalViewer.class), null, false);
    cmd.execute();
    for (TreeIterator<EObject> iter = newTargetDiagramModel.eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        assertNotNull(eObject.eContainer());
        if (eObject instanceof IIdentifier) {
            assertNotNull(((IIdentifier) eObject).getId());
        }
        if (eObject instanceof IDiagramModelArchimateComponent) {
            assertNotNull(((IDiagramModelArchimateComponent) eObject).getArchimateConcept());
            assertNotNull(((IDiagramModelArchimateComponent) eObject).getArchimateConcept().eContainer());
        }
    }
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) GraphicalViewer(org.eclipse.gef.GraphicalViewer) IIdentifier(com.archimatetool.model.IIdentifier) Command(org.eclipse.gef.commands.Command) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent)

Aggregations

IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)18 ArrayList (java.util.ArrayList)13 Command (org.eclipse.gef.commands.Command)7 Test (org.junit.Test)6 IArchimateConcept (com.archimatetool.model.IArchimateConcept)5 IDiagramModel (com.archimatetool.model.IDiagramModel)5 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)5 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)5 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)4 EObject (org.eclipse.emf.ecore.EObject)4 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)3 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)3 EditPart (org.eclipse.gef.EditPart)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)2 IArchimateElement (com.archimatetool.model.IArchimateElement)2 IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)2 Point (org.eclipse.draw2d.geometry.Point)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IArchimateDiagramEditor (com.archimatetool.editor.diagram.IArchimateDiagramEditor)1