Search in sources :

Example 11 with IArchimateConcept

use of com.archimatetool.model.IArchimateConcept 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 12 with IArchimateConcept

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

the class DiagramModelArchimateConnection method reconnect.

@Override
public void reconnect() {
    super.reconnect();
    // Set the source/target in the Archimate model if need be
    if (source instanceof IDiagramModelArchimateComponent && target instanceof IDiagramModelArchimateComponent) {
        IArchimateConcept srcConcept = ((IDiagramModelArchimateComponent) source).getArchimateConcept();
        IArchimateConcept tgtConcept = ((IDiagramModelArchimateComponent) target).getArchimateConcept();
        IArchimateRelationship relationship = getArchimateRelationship();
        if (relationship.getSource() != srcConcept) {
            // optimised
            relationship.setSource(srcConcept);
        }
        if (relationship.getTarget() != tgtConcept) {
            // optimised
            relationship.setTarget(tgtConcept);
        }
    }
}
Also used : IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship)

Example 13 with IArchimateConcept

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

the class ArchimateRelationship method setSource.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public void setSource(IArchimateConcept newSource) {
    IArchimateConcept oldSource = source;
    source = newSource;
    if (oldSource != null) {
        oldSource.getSourceRelationships().remove(this);
    }
    if (newSource != null) {
        newSource.getSourceRelationships().add(this);
    }
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, IArchimatePackage.ARCHIMATE_RELATIONSHIP__SOURCE, oldSource, source));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) IArchimateConcept(com.archimatetool.model.IArchimateConcept)

Example 14 with IArchimateConcept

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

the class CSVExporterTests method testSort.

@Test
public void testSort() {
    IArchimateElement element1 = IArchimateFactory.eINSTANCE.createDevice();
    element1.setName("AA");
    IArchimateElement element2 = IArchimateFactory.eINSTANCE.createBusinessActor();
    element2.setName("ZZ");
    IArchimateElement element3 = IArchimateFactory.eINSTANCE.createBusinessActor();
    element3.setName("AA");
    IArchimateElement element4 = IArchimateFactory.eINSTANCE.createApplicationCollaboration();
    element4.setName("ZZ");
    List<IArchimateConcept> list = new ArrayList<IArchimateConcept>();
    list.add(element1);
    list.add(element2);
    list.add(element3);
    list.add(element4);
    exporter.sort(list);
    assertEquals(element4, list.get(0));
    assertEquals(element3, list.get(1));
    assertEquals(element2, list.get(2));
    assertEquals(element1, list.get(3));
}
Also used : ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateConcept(com.archimatetool.model.IArchimateConcept) Test(org.junit.Test)

Example 15 with IArchimateConcept

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

the class CSVImporterTests method testFindReferencedConcept_IsRelationship.

@Test
public void testFindReferencedConcept_IsRelationship() throws Exception {
    importer.doImport(elements1File);
    IArchimateConcept concept = importer.findReferencedConcept("5854f8a3");
    assertTrue(concept instanceof IArchimateRelationship);
}
Also used : IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) Test(org.junit.Test)

Aggregations

IArchimateConcept (com.archimatetool.model.IArchimateConcept)38 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)14 ArrayList (java.util.ArrayList)9 IDiagramModel (com.archimatetool.model.IDiagramModel)7 EObject (org.eclipse.emf.ecore.EObject)7 IArchimateElement (com.archimatetool.model.IArchimateElement)6 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)6 Test (org.junit.Test)6 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)5 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 IArchimateDiagramEditor (com.archimatetool.editor.diagram.IArchimateDiagramEditor)3 IDiagramModelEditor (com.archimatetool.editor.diagram.IDiagramModelEditor)3 IArchimateModel (com.archimatetool.model.IArchimateModel)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 CSVParseException (com.archimatetool.csv.CSVParseException)2 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)2 IConnectable (com.archimatetool.model.IConnectable)2 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)2 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)2