Search in sources :

Example 21 with IDiagramModelArchimateConnection

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

the class DuplicateCommandHandlerTests method testDuplicateDiagramModel.

@Test
public void testDuplicateDiagramModel() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    IDiagramModel dm = model.getDefaultDiagramModel();
    IArchimateElement actor = IArchimateFactory.eINSTANCE.createBusinessActor();
    IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(actor);
    dmo1.setName("dm");
    dm.getChildren().add(dmo1);
    IArchimateElement role = IArchimateFactory.eINSTANCE.createBusinessRole();
    IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(role);
    dm.getChildren().add(dmo2);
    IArchimateRelationship relation = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
    relation.setSource(actor);
    relation.setTarget(role);
    IDiagramModelArchimateConnection dmc1 = tm.createDiagramModelArchimateConnectionAndAddToModel(relation);
    dmc1.connect(dmo1, dmo2);
    DuplicateCommandHandler handler = new DuplicateCommandHandler(new Object[] { dm });
    handler.duplicate();
    assertEquals(2, model.getDiagramModels().size());
    IDiagramModel dmCopy = model.getDiagramModels().get(1);
    assertNotSame(dm, dmCopy);
    assertEquals(dm.getName() + " (copy)", dmCopy.getName());
    assertNotEquals(dmCopy.getId(), dm.getId());
    EList<IDiagramModelObject> children = dmCopy.getChildren();
    assertEquals(2, children.size());
    IDiagramModelArchimateObject dmo1Copy = (IDiagramModelArchimateObject) children.get(0);
    IDiagramModelArchimateObject dmo2Copy = (IDiagramModelArchimateObject) children.get(1);
    assertNotSame(dmo1, dmo1Copy);
    assertNotSame(dmo2, dmo2Copy);
    assertNotEquals(dmo1.getId(), dmo1Copy.getId());
    assertNotEquals(dmo2.getId(), dmo2Copy.getId());
    assertSame(actor, dmo1Copy.getArchimateConcept());
    assertSame(role, dmo2Copy.getArchimateConcept());
    assertSame(actor.getId(), dmo1Copy.getArchimateConcept().getId());
    assertSame(role.getId(), dmo2Copy.getArchimateConcept().getId());
    EList<IDiagramModelConnection> connections = dmo1Copy.getSourceConnections();
    assertEquals(1, connections.size());
    IDiagramModelArchimateConnection dmc1Copy = (IDiagramModelArchimateConnection) connections.get(0);
    assertNotSame(dmc1, dmc1Copy);
    assertNotEquals(dmc1.getId(), dmc1Copy.getId());
    assertSame(relation, dmc1Copy.getArchimateConcept());
    assertSame(relation.getId(), dmc1Copy.getArchimateConcept().getId());
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 22 with IDiagramModelArchimateConnection

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

the class ArchimateTestModel method createDiagramModelArchimateConnectionAndAddToModel.

/**
 * Create a DiagramModelArchimateConnection and add an Archimate relationship to it.
 * The relationship will be added to its default container folder in the model
 */
public IDiagramModelArchimateConnection createDiagramModelArchimateConnectionAndAddToModel(IArchimateRelationship relationship) {
    IDiagramModelArchimateConnection conn = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    conn.setArchimateRelationship(relationship);
    if (relationship.eContainer() == null) {
        model.getArchimateModel().getDefaultFolderForObject(relationship).getElements().add(relationship);
    }
    return conn;
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection)

Example 23 with IDiagramModelArchimateConnection

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

the class AbstractIssueTypeTests method testGetAdapter_ObjectIsAssignableFrom_Relation.

@Test
public void testGetAdapter_ObjectIsAssignableFrom_Relation() {
    IAggregationRelationship relation = IArchimateFactory.eINSTANCE.createAggregationRelationship();
    IDiagramModelArchimateConnection dmc = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    dmc.setArchimateConcept(relation);
    issueType.setObject(dmc);
    assertSame(relation, issueType.getAdapter(IArchimateConcept.class));
    assertSame(relation, issueType.getAdapter(IArchimateRelationship.class));
    assertNull(issueType.getAdapter(IArchimateElement.class));
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IAggregationRelationship(com.archimatetool.model.IAggregationRelationship) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) Test(org.junit.Test)

Example 24 with IDiagramModelArchimateConnection

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

the class DeleteFromModelAction method run.

@Override
public void run() {
    List<?> selection = getSelectedObjects();
    Set<IArchimateConcept> archimateConcepts = new HashSet<IArchimateConcept>();
    // Gather referenced model concepts
    for (Object object : selection) {
        if (object instanceof EditPart) {
            Object model = ((EditPart) object).getModel();
            if (model instanceof IDiagramModelArchimateObject) {
                IArchimateElement element = ((IDiagramModelArchimateObject) model).getArchimateElement();
                archimateConcepts.add(element);
                // Element's relationships
                for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(element)) {
                    archimateConcepts.add(relation);
                    // Relation's relationships
                    for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
                        archimateConcepts.add(r);
                    }
                }
            } else if (model instanceof IDiagramModelArchimateConnection) {
                IArchimateRelationship relation = ((IDiagramModelArchimateConnection) model).getArchimateRelationship();
                archimateConcepts.add(relation);
                // Relation's relationships
                for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
                    archimateConcepts.add(r);
                }
            }
        }
    }
    // Check whether any of these concepts are referenced in other diagrams
    if (hasMoreThanOneReference(archimateConcepts)) {
        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) {
            // Element
            Command cmd = new DeleteArchimateElementCommand((IArchimateElement) archimateConcept);
            compoundCommand.add(cmd);
            // Diagram Model Objects
            for (IDiagramModelObject dmo : ((IArchimateElement) archimateConcept).getReferencingDiagramObjects()) {
                cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand(dmo);
                compoundCommand.add(cmd);
            }
        } else if (archimateConcept instanceof IArchimateRelationship) {
            // Relationship
            Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) archimateConcept);
            compoundCommand.add(cmd);
            // Diagram Model Connections
            for (IDiagramModelArchimateConnection dmc : ((IArchimateRelationship) archimateConcept).getReferencingDiagramConnections()) {
                cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(dmc);
                compoundCommand.add(cmd);
            }
        }
    }
    BusyIndicator.showWhile(null, new Runnable() {

        @Override
        public void run() {
            execute(compoundCommand);
        }
    });
}
Also used : NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) EditPart(org.eclipse.gef.EditPart) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) Command(org.eclipse.gef.commands.Command) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) 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) HashSet(java.util.HashSet)

Example 25 with IDiagramModelArchimateConnection

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

the class ViewImporter method createConnections.

/**
 * Create and add new diagram connections
 * Do this in two passes in case there are connection -> connections
 */
private void createConnections() throws ImportException {
    Hashtable<IDiagramModelConnection, IDiagramModelConnection> connections = new Hashtable<>();
    // Create new connections. They will be cached in ModelImporter
    for (Iterator<EObject> iter = importedView.eAllContents(); iter.hasNext(); ) {
        EObject importedObject = iter.next();
        if (importedObject instanceof IDiagramModelConnection) {
            connections.put((IDiagramModelConnection) importedObject, cloneObject((IDiagramModelConnection) importedObject));
        }
    }
    // Now connect the source and target ends
    for (Entry<IDiagramModelConnection, IDiagramModelConnection> entry : connections.entrySet()) {
        IDiagramModelConnection importedConnection = entry.getKey();
        IDiagramModelConnection targetConnection = entry.getValue();
        IConnectable targetSource = findObjectInTargetModel(importedConnection.getSource());
        if (targetSource == null) {
            // $NON-NLS-1$
            throw new ImportException("Could not find source component: " + importedConnection.getSource().getId());
        }
        IConnectable targetTarget = findObjectInTargetModel(importedConnection.getTarget());
        if (targetTarget == null) {
            // $NON-NLS-1$
            throw new ImportException("Could not find target component: " + importedConnection.getTarget().getId());
        }
        // It's an Archimate connection
        if (targetConnection instanceof IDiagramModelArchimateConnection) {
            // Set the connections's relationship first before connecting source and target otherwise we end up with duplicate relationships
            setArchimateConcept((IDiagramModelArchimateConnection) importedConnection, (IDiagramModelArchimateConnection) targetConnection);
            // Need a Command for this
            addCommand(new ArchimateConnectionCommand((IDiagramModelArchimateConnection) targetConnection, targetSource, targetTarget));
        } else // Other connection
        {
            targetConnection.connect(targetSource, targetTarget);
        }
    }
}
Also used : IConnectable(com.archimatetool.model.IConnectable) Hashtable(java.util.Hashtable) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection)

Aggregations

IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)59 Test (org.junit.Test)31 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)29 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)27 IArchimateElement (com.archimatetool.model.IArchimateElement)20 IDiagramModel (com.archimatetool.model.IDiagramModel)10 IArchimateConcept (com.archimatetool.model.IArchimateConcept)9 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)9 IArchimateModel (com.archimatetool.model.IArchimateModel)8 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)8 ArrayList (java.util.ArrayList)8 EObject (org.eclipse.emf.ecore.EObject)8 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)7 IAssignmentRelationship (com.archimatetool.model.IAssignmentRelationship)6 IConnectable (com.archimatetool.model.IConnectable)6 Command (org.eclipse.gef.commands.Command)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)6 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)5 EClass (org.eclipse.emf.ecore.EClass)4 NoteEditPart (com.archimatetool.editor.diagram.editparts.diagram.NoteEditPart)3