Search in sources :

Example 51 with IDiagramModelArchimateConnection

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

the class DiagramModelUtils method shouldBeHiddenConnection.

/**
 * @param connection The connection to check
 * @return true if a connection should be hidden when its source (parent) element contains its target (child) element
 */
public static boolean shouldBeHiddenConnection(IDiagramModelArchimateConnection connection) {
    if (!ConnectionPreferences.useNestedConnections()) {
        return false;
    }
    // Only if the connection's source and target are both ArchiMate concepts
    if (!(connection.getSource() instanceof IDiagramModelArchimateComponent) && !(connection.getTarget() instanceof IDiagramModelArchimateComponent)) {
        return false;
    }
    IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent) connection.getSource();
    IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent) connection.getTarget();
    // If the connection's source element contains the target element, or the connection's target element contains the source element
    if (source instanceof IDiagramModelArchimateObject && target instanceof IDiagramModelArchimateObject) {
        if (((IDiagramModelContainer) source).getChildren().contains((IDiagramModelArchimateObject) target) || ((IDiagramModelContainer) target).getChildren().contains((IDiagramModelArchimateObject) source)) {
            // And it's a relationship type we have chosen to hide
            for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
                if (connection.getArchimateRelationship().eClass() == eClass) {
                    return true;
                }
            }
        }
    }
    // If connection's source is an element and target is a connection
    if (source instanceof IDiagramModelArchimateObject && target instanceof IDiagramModelArchimateConnection) {
        IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) source;
        IConnectable connectionSource = ((IDiagramModelArchimateConnection) target).getSource();
        IConnectable connectionTarget = ((IDiagramModelArchimateConnection) target).getTarget();
        if (parent.getChildren().contains(connectionSource) && parent.getChildren().contains(connectionTarget)) {
            // And it's a relationship type we have chosen to hide
            for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
                if (connection.getArchimateRelationship().eClass() == eClass) {
                    return true;
                }
            }
        }
    }
    // TODO: Not sure if this directionality should be allowed
    if (target instanceof IDiagramModelArchimateObject && source instanceof IDiagramModelArchimateConnection) {
        IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) target;
        IConnectable connectionSource = ((IDiagramModelArchimateConnection) source).getSource();
        IConnectable connectionTarget = ((IDiagramModelArchimateConnection) source).getTarget();
        if (parent.getChildren().contains(connectionSource) && parent.getChildren().contains(connectionTarget)) {
            // And it's a relationship type we have chosen to hide
            for (EClass eClass : ConnectionPreferences.getRelationsClassesForHiding()) {
                if (connection.getArchimateRelationship().eClass() == eClass) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IConnectable(com.archimatetool.model.IConnectable) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 52 with IDiagramModelArchimateConnection

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

the class XMLModelImporter method addConnections.

// ======================================= Connections ====================================
private void addConnections(Element viewElement) throws XMLModelParserException {
    class ConnectionInfo {

        IDiagramModelConnection connection;

        Element connectionElement;
    }
    List<ConnectionInfo> connectionInfoList = new ArrayList<>();
    // 1st pass - Create all connections
    for (Element connectionElement : viewElement.getChildren(ELEMENT_CONNECTION, ARCHIMATE3_NAMESPACE)) {
        IDiagramModelConnection connection = null;
        // An ArchiMate relationship connection
        String relationshipRef = connectionElement.getAttributeValue(ATTRIBUTE_RELATIONSHIPREF);
        if (hasValue(relationshipRef)) {
            // Get relationship
            IArchimateConcept concept = fConceptsLookup.get(relationshipRef);
            if (!(concept instanceof IArchimateRelationship)) {
                throw new XMLModelParserException(Messages.XMLModelImporter_7 + relationshipRef);
            }
            // Create new ArchiMate connection with relationship
            connection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection((IArchimateRelationship) concept);
        } else // Create new ordinary connection
        {
            connection = IArchimateFactory.eINSTANCE.createDiagramModelConnection();
        }
        // Add id and add to lookup table
        if (connection != null) {
            // Add Identifier before adding to model
            String identifier = connectionElement.getAttributeValue(ATTRIBUTE_IDENTIFIER);
            connection.setId(identifier);
            // Add to connection list for 2nd pass
            ConnectionInfo cInfo = new ConnectionInfo();
            cInfo.connection = connection;
            cInfo.connectionElement = connectionElement;
            connectionInfoList.add(cInfo);
            // Add to lookup
            fConnectionsNodesLookup.put(connection.getId(), connection);
        }
    }
    // 2nd pass
    for (ConnectionInfo cInfo : connectionInfoList) {
        // Get connection source node/connection
        String sourceRef = cInfo.connectionElement.getAttributeValue(ATTRIBUTE_SOURCE);
        IConnectable connectableSource = fConnectionsNodesLookup.get(sourceRef);
        if (connectableSource == null) {
            throw new XMLModelParserException(Messages.XMLModelImporter_9 + sourceRef);
        }
        // Get connection target node/connection
        String targetRef = cInfo.connectionElement.getAttributeValue(ATTRIBUTE_TARGET);
        IConnectable connectableTarget = fConnectionsNodesLookup.get(targetRef);
        if (connectableTarget == null) {
            throw new XMLModelParserException(Messages.XMLModelImporter_10 + targetRef);
        }
        // If an ArchiMate connection, source and target must be also
        if (cInfo.connection instanceof IDiagramModelArchimateConnection) {
            // Must be ArchiMate type source
            if (!(connectableSource instanceof IDiagramModelArchimateComponent)) {
                throw new XMLModelParserException(Messages.XMLModelImporter_11 + sourceRef);
            }
            // Must be ArchiMate type target
            if (!(connectableTarget instanceof IDiagramModelArchimateComponent)) {
                throw new XMLModelParserException(Messages.XMLModelImporter_12 + targetRef);
            }
        } else // Another connection type
        {
            // Only connect between notes and groups
            if (connectableSource instanceof IDiagramModelArchimateComponent && connectableTarget instanceof IDiagramModelArchimateComponent) {
                continue;
            }
            // Don't connect to other connections
            if (connectableSource instanceof IDiagramModelConnection || connectableTarget instanceof IDiagramModelConnection) {
                continue;
            }
        }
        // Connect
        cInfo.connection.connect(connectableSource, connectableTarget);
        // Bendpoints
        addBendpoints(cInfo.connection, cInfo.connectionElement);
        // Style
        addConnectionStyle(cInfo.connection, cInfo.connectionElement.getChild(ELEMENT_STYLE, ARCHIMATE3_NAMESPACE));
    }
    // Add implicit nested connections
    addNestedConnections();
}
Also used : IConnectable(com.archimatetool.model.IConnectable) Element(org.jdom2.Element) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) ArrayList(java.util.ArrayList) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship)

Example 53 with IDiagramModelArchimateConnection

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

the class XMLModelImporter method addNestedConnections.

/**
 * Add implicit nested connections
 * 1. Iterate through all diagram ArchiMate nodes and look for nested nodes
 * 2. If there is a relationship between the ArchiMate elements of the nodes and no existing connection, add one
 */
private void addNestedConnections() {
    for (IDiagramModel dm : fModel.getDiagramModels()) {
        // All diagrams
        for (Iterator<EObject> iter = dm.eAllContents(); iter.hasNext(); ) {
            // Contents of the diagram
            EObject eObject = iter.next();
            if (eObject instanceof IDiagramModelArchimateObject) {
                // ArchiMate node
                IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) eObject;
                for (IDiagramModelObject dmo : parent.getChildren()) {
                    if (dmo instanceof IDiagramModelArchimateObject) {
                        // ArchiMate child node
                        IDiagramModelArchimateObject child = (IDiagramModelArchimateObject) dmo;
                        IArchimateElement parentElement = parent.getArchimateElement();
                        IArchimateElement childElement = child.getArchimateElement();
                        // Parent -> Child
                        for (IArchimateRelationship relation : List.copyOf(parentElement.getSourceRelationships())) {
                            // work on a copy of the list
                            if (relation.getTarget() == childElement && !DiagramModelUtils.hasDiagramModelArchimateConnection(parent, child, relation)) {
                                IDiagramModelArchimateConnection connection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                                connection.connect(parent, child);
                            }
                        }
                        // Child -> Parent
                        for (IArchimateRelationship relation : List.copyOf(childElement.getSourceRelationships())) {
                            // work on a copy of the list
                            if (relation.getTarget() == parentElement && !DiagramModelUtils.hasDiagramModelArchimateConnection(child, parent, relation)) {
                                IDiagramModelArchimateConnection connection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                                connection.connect(child, parent);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject)

Example 54 with IDiagramModelArchimateConnection

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

the class GenerateViewCommand method createDiagramModel.

private IArchimateDiagramModel createDiagramModel() {
    // New Diagram
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    dm.setName(fViewName);
    dm.setViewpoint(fViewpoint.getID());
    fParentFolder = fSelectedElements.get(0).getArchimateModel().getDefaultFolderForObject(dm);
    fParentFolder.getElements().add(dm);
    int x = 20;
    int y = 20;
    getElementsToAdd();
    for (IArchimateElement element : fSelectedElements) {
        createDiagramNode(element, dm, x, y);
        y += 100;
    }
    x = 170;
    y = 20;
    for (IArchimateElement element : fAddedElements) {
        if (!fSelectedElements.contains(element)) {
            createDiagramNode(element, dm, x, y);
            y += 80;
            if (y > 700) {
                y = 20;
                x += 150;
            }
        }
    }
    // Add connections between elements first
    for (IDiagramModelObject dmoSource : dm.getChildren()) {
        IArchimateElement elementSource = ((IDiagramModelArchimateObject) dmoSource).getArchimateElement();
        for (IArchimateRelationship relation : List.copyOf(elementSource.getSourceRelationships())) {
            // work on a copy of the list
            for (IDiagramModelObject dmoTarget : dm.getChildren()) {
                IArchimateElement elementTarget = ((IDiagramModelArchimateObject) dmoTarget).getArchimateElement();
                // Don't add connections that are not connected to the main elements if option is set
                if (!fAddAllConnections && !(fSelectedElements.contains(elementSource)) && !(fSelectedElements.contains(elementTarget))) {
                    continue;
                }
                if (relation.getTarget() == elementTarget) {
                    // Create connection
                    IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                    newConnection.connect(dmoSource, dmoTarget);
                }
            }
        }
    }
    // Add connections to connections
    for (Iterator<EObject> iter1 = dm.eAllContents(); iter1.hasNext(); ) {
        EObject eObject1 = iter1.next();
        if (eObject1 instanceof IDiagramModelArchimateConnection) {
            IDiagramModelArchimateConnection connection = (IDiagramModelArchimateConnection) eObject1;
            for (IDiagramModelObject dmo : dm.getChildren()) {
                IArchimateElement element = ((IDiagramModelArchimateObject) dmo).getArchimateElement();
                for (IArchimateRelationship relation : List.copyOf(connection.getArchimateRelationship().getSourceRelationships())) {
                    // work on a copy of the list
                    if (relation.getTarget() == element) {
                        IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                        newConnection.connect(connection, dmo);
                    }
                }
                for (IArchimateRelationship relation : List.copyOf(connection.getArchimateRelationship().getTargetRelationships())) {
                    // work on a copy of the list
                    if (relation.getSource() == element) {
                        IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                        newConnection.connect(dmo, connection);
                    }
                }
            }
        }
    }
    return dm;
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) EObject(org.eclipse.emf.ecore.EObject) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IViewpoint(com.archimatetool.model.viewpoints.IViewpoint) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel)

Example 55 with IDiagramModelArchimateConnection

use of com.archimatetool.model.IDiagramModelArchimateConnection 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)

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