Search in sources :

Example 21 with IDiagramModelConnection

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

the class CreateDiagramArchimateConnectionWithDialogCommandTests method testCreationOfConnectionAndRelationship.

@Test
public void testCreationOfConnectionAndRelationship() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(IArchimateFactory.eINSTANCE.createBusinessActor());
    IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(IArchimateFactory.eINSTANCE.createBusinessRole());
    model.getDefaultDiagramModel().getChildren().add(dmo1);
    model.getDefaultDiagramModel().getChildren().add(dmo2);
    cmd.setSource(dmo1);
    cmd.setTarget(dmo2);
    cmd.execute();
    IDiagramModelConnection connection = cmd.fConnection;
    assertTrue(connection instanceof IDiagramModelArchimateConnection);
    assertSame(dmo1, connection.getSource());
    assertSame(dmo2, connection.getTarget());
    IArchimateRelationship relationship = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship();
    assertTrue(relationship instanceof IAssignmentRelationship);
    assertNotNull(relationship.eContainer());
    cmd.undo();
    assertNull(relationship.eContainer());
}
Also used : IAssignmentRelationship(com.archimatetool.model.IAssignmentRelationship) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 22 with IDiagramModelConnection

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

the class ArchimateDiagramEditPartFactoryTests method testLineConnectionEditPart.

@Test
public void testLineConnectionEditPart() {
    IDiagramModelConnection conn = IArchimateFactory.eINSTANCE.createDiagramModelConnection();
    EditPart editPart = editPartFactory.createEditPart(null, conn);
    assertTrue(editPart instanceof DiagramConnectionEditPart);
    assertEquals(conn, editPart.getModel());
}
Also used : IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) GroupEditPart(com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart) NoteEditPart(com.archimatetool.editor.diagram.editparts.diagram.NoteEditPart) EditPart(org.eclipse.gef.EditPart) EmptyEditPart(com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart) Test(org.junit.Test)

Example 23 with IDiagramModelConnection

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

the class CopySnapshot method createSnapshotConnectionsForSelectedComponents.

/*
     * Create copies of connections that have been selected (if source and target also have been selected/mapped)
     */
private void createSnapshotConnectionsForSelectedComponents(List<IDiagramModelComponent> selected) {
    // Create new connection copies for all selected connections, but don't connect them yet
    for (IDiagramModelComponent component : selected) {
        if (component instanceof IDiagramModelConnection) {
            IDiagramModelConnection connection = (IDiagramModelConnection) component;
            // The source and the target object must also be selected
            if (isSelectedConnectionCopyable(connection, selected)) {
                IDiagramModelConnection newConnection = (IDiagramModelConnection) connection.getCopy();
                fOriginalToSnapshotComponentsMapping.put(connection, newConnection);
            }
        }
    }
    // Now connect both ends if both ends are also in the selection/mapping
    for (Entry<IConnectable, IConnectable> entry : fOriginalToSnapshotComponentsMapping.entrySet()) {
        if (entry.getKey() instanceof IDiagramModelConnection) {
            IDiagramModelConnection originalConnection = (IDiagramModelConnection) entry.getKey();
            IConnectable newSource = fOriginalToSnapshotComponentsMapping.get(originalConnection.getSource());
            IConnectable newTarget = fOriginalToSnapshotComponentsMapping.get(originalConnection.getTarget());
            if (newSource != null && newTarget != null) {
                IDiagramModelConnection newConnection = (IDiagramModelConnection) entry.getValue();
                newConnection.connect(newSource, newTarget);
            }
        }
    }
}
Also used : IConnectable(com.archimatetool.model.IConnectable) IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection)

Example 24 with IDiagramModelConnection

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

the class CopySnapshot method createPasteConnections.

private List<IDiagramModelConnection> createPasteConnections() {
    List<IDiagramModelConnection> connections = new ArrayList<IDiagramModelConnection>();
    // Create new connections from basis of snapshot
    for (IConnectable connectable : fOriginalToSnapshotComponentsMapping.values()) {
        if (connectable instanceof IDiagramModelConnection) {
            IDiagramModelConnection snapshotConnection = (IDiagramModelConnection) connectable;
            IDiagramModelConnection newConnection = (IDiagramModelConnection) snapshotConnection.getCopy();
            createID(newConnection);
            connections.add(newConnection);
            // Mapping
            fSnapshotToNewComponentMapping.put(snapshotConnection, newConnection);
            // Re-use original Archimate relationship if required
            if (!fDoCreateNewArchimateComponents && snapshotConnection instanceof IDiagramModelArchimateConnection) {
                IDiagramModelArchimateConnection originalDiagramConnection = (IDiagramModelArchimateConnection) fOriginalToSnapshotComponentsMapping.getKey(snapshotConnection);
                IArchimateRelationship relationship = originalDiagramConnection.getArchimateRelationship();
                ((IDiagramModelArchimateConnection) newConnection).setArchimateRelationship(relationship);
            }
        }
    }
    // Connect them
    for (Entry<IConnectable, IConnectable> entry : fSnapshotToNewComponentMapping.entrySet()) {
        if (entry.getKey() instanceof IDiagramModelConnection) {
            IDiagramModelConnection snapshotConnection = (IDiagramModelConnection) entry.getKey();
            IConnectable newSource = fSnapshotToNewComponentMapping.get(snapshotConnection.getSource());
            IConnectable newTarget = fSnapshotToNewComponentMapping.get(snapshotConnection.getTarget());
            if (newSource != null && newTarget != null) {
                IDiagramModelConnection newConnection = (IDiagramModelConnection) entry.getValue();
                newConnection.connect(newSource, newTarget);
            }
        }
    }
    return connections;
}
Also used : IConnectable(com.archimatetool.model.IConnectable) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) ArrayList(java.util.ArrayList) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship)

Example 25 with IDiagramModelConnection

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

the class CopySnapshot method createAutomaticSnapshotConnections.

/*
     * Create automatic copies of connections (if source and target also have been selected/mapped)
     */
private void createAutomaticSnapshotConnections() {
    List<IDiagramModelConnection> allConnections = new ArrayList<IDiagramModelConnection>();
    // Get all connections from objects
    for (IConnectable connectable : fOriginalToSnapshotComponentsMapping.keySet()) {
        for (IDiagramModelConnection connection : connectable.getSourceConnections()) {
            if (!allConnections.contains(connection)) {
                allConnections.add(connection);
            }
        }
        for (IDiagramModelConnection connection : connectable.getTargetConnections()) {
            if (!allConnections.contains(connection)) {
                allConnections.add(connection);
            }
        }
    }
    // Create copies of ones that have both ends
    for (IDiagramModelConnection connection : allConnections) {
        if (isSelectedConnectionCopyable(connection, allConnections)) {
            IDiagramModelConnection newConnection = (IDiagramModelConnection) connection.getCopy();
            fOriginalToSnapshotComponentsMapping.put(connection, newConnection);
        }
    }
    // Now connect both ends if both ends are also in the mapping
    for (Entry<IConnectable, IConnectable> entry : fOriginalToSnapshotComponentsMapping.entrySet()) {
        if (entry.getKey() instanceof IDiagramModelConnection) {
            IDiagramModelConnection originalConnection = (IDiagramModelConnection) entry.getKey();
            IConnectable newSource = fOriginalToSnapshotComponentsMapping.get(originalConnection.getSource());
            IConnectable newTarget = fOriginalToSnapshotComponentsMapping.get(originalConnection.getTarget());
            if (newSource != null && newTarget != null) {
                IDiagramModelConnection newConnection = (IDiagramModelConnection) entry.getValue();
                newConnection.connect(newSource, newTarget);
            } else {
                // $NON-NLS-1$
                System.err.println("No source or target in CopySnapshot!");
            }
        }
    }
}
Also used : IConnectable(com.archimatetool.model.IConnectable) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) ArrayList(java.util.ArrayList)

Aggregations

IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)34 Test (org.junit.Test)15 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)10 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)7 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)6 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)5 Command (org.eclipse.gef.commands.Command)5 IArchimateElement (com.archimatetool.model.IArchimateElement)4 IConnectable (com.archimatetool.model.IConnectable)4 IDiagramModel (com.archimatetool.model.IDiagramModel)4 EditPart (org.eclipse.gef.EditPart)4 ReconnectDiagramConnectionCommand (com.archimatetool.editor.diagram.commands.ReconnectDiagramConnectionCommand)3 EmptyEditPart (com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart)3 ArrayList (java.util.ArrayList)3 ConnectionTextPositionCommand (com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand)2 LineWidthCommand (com.archimatetool.editor.diagram.commands.LineWidthCommand)2 DiagramConnectionEditPart (com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart)2 DeleteArchimateElementCommand (com.archimatetool.editor.model.commands.DeleteArchimateElementCommand)2 DeleteArchimateRelationshipCommand (com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand)2