Search in sources :

Example 1 with IDiagramModelArchimateConnection

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

the class DiagramModelUtils method findDiagramModelConnectionsForRelationByReference.

/**
 * Find all (visible and extant) Diagram Model Connections for a given Archimate relationship in a Diagram Model.
 * This is the faster method.
 * @param diagramModel The parent diagram model to search in.
 * @param relationship The relationship to check on.
 * @return The list of active Diagram Model Connections. May be empty, but never null.
 */
static List<IDiagramModelArchimateConnection> findDiagramModelConnectionsForRelationByReference(IDiagramModel diagramModel, IArchimateRelationship relationship) {
    List<IDiagramModelArchimateConnection> list = new ArrayList<IDiagramModelArchimateConnection>();
    List<IDiagramModelArchimateConnection> connections = findDiagramModelConnectionsForRelation(relationship);
    for (IDiagramModelArchimateConnection connection : connections) {
        if (connection.getDiagramModel() == diagramModel) {
            list.add(connection);
        }
    }
    return list;
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList)

Example 2 with IDiagramModelArchimateConnection

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

the class ModelChecker method checkDiagramObjectsReferences.

List<String> checkDiagramObjectsReferences() {
    List<String> messages = new ArrayList<String>();
    for (Iterator<EObject> iter = fModel.getFolder(FolderType.DIAGRAMS).eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        if (eObject instanceof IDiagramModelArchimateObject) {
            IDiagramModelArchimateObject dmo = (IDiagramModelArchimateObject) eObject;
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String name = dmo.getDiagramModel() == null ? Messages.ModelChecker_11 : " '" + dmo.getDiagramModel().getName() + "' (" + dmo.getId() + ")";
            IArchimateElement element = dmo.getArchimateElement();
            if (element == null) {
                messages.add(Messages.ModelChecker_12 + name);
            } else if (element.getArchimateModel() == null) {
                messages.add(Messages.ModelChecker_13 + name);
            }
        }
        if (eObject instanceof IDiagramModelArchimateConnection) {
            IDiagramModelArchimateConnection conn = (IDiagramModelArchimateConnection) eObject;
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String name = conn.getDiagramModel() == null ? Messages.ModelChecker_14 : " '" + conn.getDiagramModel().getName() + "' (" + conn.getId() + ")";
            IArchimateRelationship relation = conn.getArchimateRelationship();
            if (relation == null) {
                messages.add(Messages.ModelChecker_15 + name);
            } else {
                if (relation.getArchimateModel() == null) {
                    messages.add(Messages.ModelChecker_16 + name);
                }
                if (relation.getSource() != null && relation.getSource().getArchimateModel() == null) {
                    messages.add(Messages.ModelChecker_17 + name);
                }
                if (relation.getTarget() != null && relation.getTarget().getArchimateModel() == null) {
                    messages.add(Messages.ModelChecker_18 + name);
                }
            }
        }
    }
    return messages;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 3 with IDiagramModelArchimateConnection

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

the class ModelCheckerTests method checkDiagramObjectsReferences_Connection.

@Test
public void checkDiagramObjectsReferences_Connection() {
    model.getDefaultDiagramModel().setName("dm");
    IArchimateElement actor = IArchimateFactory.eINSTANCE.createBusinessActor();
    IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(actor);
    model.getDefaultDiagramModel().getChildren().add(dmo1);
    IArchimateElement role = IArchimateFactory.eINSTANCE.createBusinessRole();
    IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(role);
    model.getDefaultDiagramModel().getChildren().add(dmo2);
    IAssignmentRelationship relation = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
    relation.setSource(actor);
    relation.setTarget(role);
    IDiagramModelArchimateConnection dmc1 = tm.createDiagramModelArchimateConnectionAndAddToModel(relation);
    dmc1.connect(dmo1, dmo2);
    List<String> messages = modelChecker.checkDiagramObjectsReferences();
    assertEquals(0, messages.size());
    model.getFolder(FolderType.RELATIONS).getElements().remove(relation);
    model.getFolder(FolderType.BUSINESS).getElements().remove(actor);
    model.getFolder(FolderType.BUSINESS).getElements().remove(role);
    messages = modelChecker.checkDiagramObjectsReferences();
    assertEquals(5, messages.size());
    assertTrue(messages.get(0).startsWith("Diagram Element has orphaned ArchiMate element in 'dm'"));
    assertTrue(messages.get(1).startsWith("Diagram Connection has orphaned ArchiMate relation in 'dm'"));
    assertTrue(messages.get(2).startsWith("Diagram Connection has orphaned ArchiMate source element in 'dm'"));
    assertTrue(messages.get(3).startsWith("Diagram Connection has orphaned ArchiMate target element in 'dm'"));
    assertTrue(messages.get(4).startsWith("Diagram Element has orphaned ArchiMate element in 'dm'"));
}
Also used : IAssignmentRelationship(com.archimatetool.model.IAssignmentRelationship) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) Test(org.junit.Test)

Example 4 with IDiagramModelArchimateConnection

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

the class ArchimateDiagramModelFactory method createDiagramModelArchimateConnection.

/**
 * Factory method for creating a new IDiagramModelArchimateConnection for an IRelationship
 * @param element
 * @return a new IDiagramModelArchimateConnection
 */
public static IDiagramModelArchimateConnection createDiagramModelArchimateConnection(IArchimateRelationship relation) {
    IDiagramModelArchimateConnection connection = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    connection.setArchimateRelationship(relation);
    // Set user default colors as set in prefs
    ColorFactory.setDefaultColors(connection);
    return connection;
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection)

Example 5 with IDiagramModelArchimateConnection

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

the class MyImporter method createAndAddConnectionsToView.

protected void createAndAddConnectionsToView(IDiagramModel diagramModel, IArchimateRelationship relationship) {
    List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship.getSource());
    List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship.getTarget());
    for (IDiagramModelComponent dmcSource : sources) {
        for (IDiagramModelComponent dmcTarget : targets) {
            IDiagramModelArchimateConnection dmc = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
            dmc.setArchimateRelationship(relationship);
            dmc.connect((IDiagramModelObject) dmcSource, (IDiagramModelObject) dmcTarget);
            idLookup.put(dmc.getId(), dmc);
        }
    }
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent)

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