Search in sources :

Example 41 with IDiagramModelArchimateConnection

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

the class NestedElementsChecker method isNestedWithoutValidRelation.

private boolean isNestedWithoutValidRelation(IDiagramModelArchimateObject parent, IDiagramModelArchimateObject child) {
    IArchimateElement parentElement = parent.getArchimateElement();
    IArchimateElement childElement = child.getArchimateElement();
    // Ignore nested Junctions
    if (childElement instanceof IJunction) {
        return false;
    }
    // Get all diagram connections between parent and child objects
    List<IDiagramModelConnection> connections = new ArrayList<>(parent.getSourceConnections());
    connections.addAll(parent.getTargetConnections());
    for (IDiagramModelConnection connection : connections) {
        // If this is an ArchiMate connection...
        if (connection instanceof IDiagramModelArchimateConnection && (connection.getSource() == child || connection.getTarget() == child)) {
            // Get its relationship
            IArchimateRelationship relation = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship();
            // Check for non-nested type relationships
            if (!isNestedTypeRelationship(relation)) {
                return true;
            }
            // Specialization relationship needs a special check as it goes the other way around
            if (relation instanceof ISpecializationRelationship) {
                if (relation.getTarget() == childElement) {
                    return true;
                }
            } else // Else reversed nested
            if (relation.getSource() == childElement && isNestedTypeRelationship(relation)) {
                return true;
            }
        }
    }
    // Check for any nested type relationships in the model, return false if one is found
    for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(parentElement)) {
        if ((relation.getTarget() == childElement || relation.getSource() == childElement) && isNestedTypeRelationship(relation)) {
            return false;
        }
    }
    return true;
}
Also used : ISpecializationRelationship(com.archimatetool.model.ISpecializationRelationship) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IJunction(com.archimatetool.model.IJunction)

Example 42 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)

Example 43 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 44 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 45 with IDiagramModelArchimateConnection

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

the class FormatPainterToolTests method testCreateCommandForDiagramModelArchimateConnection.

@Test
public void testCreateCommandForDiagramModelArchimateConnection() throws Exception {
    // Source component
    IDiagramModelArchimateConnection sourceComponent = ArchimateTestModel.createDiagramModelArchimateConnection(IArchimateFactory.eINSTANCE.createAccessRelationship());
    // Target component
    IDiagramModelArchimateConnection targetComponent = ArchimateTestModel.createDiagramModelArchimateConnection(IArchimateFactory.eINSTANCE.createAccessRelationship());
    // Set FormatPainterInfo to Source component
    FormatPainterInfo.INSTANCE.updatePaintFormat(sourceComponent);
    PaintFormat pf = FormatPainterInfo.INSTANCE.getPaintFormat();
    // Execute command
    FormatPainterTool tool = new FormatPainterTool();
    CompoundCommand compoundCmd = tool.createCommand(pf, targetComponent);
    // Should be no commands
    assertEquals(0, compoundCmd.getCommands().size());
    // Now change some properties on the source component
    sourceComponent.setFont("Consolas");
    sourceComponent.setFontColor("#eeeeee");
    sourceComponent.setLineColor("#eeeeee");
    sourceComponent.setLineWidth(3);
    sourceComponent.setTextPosition(3);
    compoundCmd = tool.createCommand(pf, targetComponent);
    assertEquals(5, compoundCmd.getCommands().size());
}
Also used : PaintFormat(com.archimatetool.editor.diagram.tools.FormatPainterInfo.PaintFormat) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) 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