Search in sources :

Example 31 with IDiagramModelArchimateConnection

use of com.archimatetool.model.IDiagramModelArchimateConnection in project archi-modelrepository-plugin by archi-contribs.

the class GraficoModelImporter method resolveProxies.

/**
 * Iterate through all model objects, and resolve proxies on known classes
 */
private void resolveProxies() {
    fUnresolvedObjects = null;
    for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        if (eObject instanceof IArchimateConcept) {
            // Resolve proxies for profiles
            IArchimateConcept concept = (IArchimateConcept) eObject;
            EList<IProfile> profiles = concept.getProfiles();
            // Assumption: most concepts don't have profiles so checking for empty has a positive impact on performance
            if (!profiles.isEmpty()) {
                ListIterator<IProfile> iterator = profiles.listIterator();
                while (iterator.hasNext()) {
                    IProfile profile = iterator.next();
                    iterator.set((IProfile) resolve(profile, concept));
                }
            }
        }
        if (eObject instanceof IArchimateRelationship) {
            // Resolve proxies for Relations
            IArchimateRelationship relation = (IArchimateRelationship) eObject;
            relation.setSource((IArchimateConcept) resolve(relation.getSource(), relation));
            relation.setTarget((IArchimateConcept) resolve(relation.getTarget(), relation));
        } else if (eObject instanceof IDiagramModelArchimateObject) {
            // Resolve proxies for Elements
            IDiagramModelArchimateObject element = (IDiagramModelArchimateObject) eObject;
            element.setArchimateElement((IArchimateElement) resolve(element.getArchimateElement(), element));
        } else if (eObject instanceof IDiagramModelArchimateConnection) {
            // Resolve proxies for Connections
            IDiagramModelArchimateConnection archiConnection = (IDiagramModelArchimateConnection) eObject;
            archiConnection.setArchimateRelationship((IArchimateRelationship) resolve(archiConnection.getArchimateRelationship(), archiConnection));
        } else if (eObject instanceof IDiagramModelReference) {
            // Resolve proxies for Model References
            IDiagramModelReference element = (IDiagramModelReference) eObject;
            element.setReferencedModel((IDiagramModel) resolve(element.getReferencedModel(), element));
        }
    }
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) IDiagramModel(com.archimatetool.model.IDiagramModel) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IProfile(com.archimatetool.model.IProfile)

Example 32 with IDiagramModelArchimateConnection

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

the class DiagramModelUtilsTests method testFindDiagramModelObjectsAndConnections_AfterDuplicateDiagram.

// =================================================================================================
@Test
public void testFindDiagramModelObjectsAndConnections_AfterDuplicateDiagram() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    IDiagramModel dm = model.getDefaultDiagramModel();
    IArchimateElement actor = IArchimateFactory.eINSTANCE.createBusinessActor();
    IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(actor);
    dm.getChildren().add(dmo1);
    IArchimateElement role = IArchimateFactory.eINSTANCE.createBusinessRole();
    IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(role);
    dm.getChildren().add(dmo2);
    IAssignmentRelationship relation = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
    relation.setSource(actor);
    relation.setTarget(role);
    IDiagramModelArchimateConnection dmc1 = tm.createDiagramModelArchimateConnectionAndAddToModel(relation);
    dmc1.connect(dmo1, dmo2);
    List<?> list = DiagramModelUtils.findDiagramModelObjectsForElement(actor);
    assertEquals(1, list.size());
    list = DiagramModelUtils.findDiagramModelObjectsForElement(role);
    assertEquals(1, list.size());
    list = DiagramModelUtils.findDiagramModelConnectionsForRelation(relation);
    assertEquals(1, list.size());
    // Duplicate
    DuplicateCommandHandler handler = new DuplicateCommandHandler(new Object[] { dm });
    handler.duplicate();
    list = DiagramModelUtils.findDiagramModelObjectsForElement(actor);
    assertEquals(2, list.size());
    list = DiagramModelUtils.findDiagramModelObjectsForElement(role);
    assertEquals(2, list.size());
    list = DiagramModelUtils.findDiagramModelConnectionsForRelation(relation);
    assertEquals(2, list.size());
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IAssignmentRelationship(com.archimatetool.model.IAssignmentRelationship) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) DuplicateCommandHandler(com.archimatetool.editor.views.tree.commands.DuplicateCommandHandler) Test(org.junit.Test)

Example 33 with IDiagramModelArchimateConnection

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

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

the class CreateDiagramArchimateConnectionWithDialogCommand method checkToReuseExistingRelationship.

private boolean checkToReuseExistingRelationship() {
    if (fSource instanceof IDiagramModelArchimateComponent && fTarget instanceof IDiagramModelArchimateComponent) {
        IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent) fSource;
        IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent) fTarget;
        EClass classType = (EClass) fRequest.getNewObjectType();
        // Find any relations of this type connecting source and target concepts
        List<IArchimateRelationship> relations = getExistingRelationshipsOfType(classType, source.getArchimateConcept(), target.getArchimateConcept());
        // If there is already a relation of this type connecting source and target concepts...
        if (!relations.isEmpty()) {
            // Ask user in dialog if they want to reference an existing one
            ChooseRelationDialog dialog = new ChooseRelationDialog(ArchiLabelProvider.INSTANCE.getDefaultName(classType), NLS.bind(Messages.CreateArchimateConnectionWithDialogCommand_1, ArchiLabelProvider.INSTANCE.getLabel(source), ArchiLabelProvider.INSTANCE.getLabel(target)), relations);
            if (dialog.open() == Window.OK) {
                // Create a new connection
                fConnection = createNewConnection();
                // set the connection's relationship to the chosen relation
                ((IDiagramModelArchimateConnection) fConnection).setArchimateRelationship(dialog.getSelected());
                return true;
            }
        }
    }
    return false;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship)

Example 35 with IDiagramModelArchimateConnection

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

the class CreateNestedArchimateConnectionsWithDialogCommand method createNewConnectionCommands.

/**
 * Create Commands for child objects that don't have connections and need new ones
 *
 * TODO A3: If O1--C1--O2. C1 is also connected to parent.
 *          O1 or O2 is added to parent - should add connection from C1 to parent?
 *          Or should it be only when O1 AND O2 are added to parent?
 */
private void createNewConnectionCommands() {
    IArchimateElement parentElement = fParentObject.getArchimateElement();
    // Check connections between parent and child objects that are being dragged in
    for (IDiagramModelArchimateObject childObject : fChildObjects) {
        IArchimateElement childElement = childObject.getArchimateElement();
        boolean aConnectionExists = false;
        for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
            if (relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
                if (DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, childObject, relation)) {
                    aConnectionExists = true;
                    break;
                }
            }
        }
        // Create connections from relationships if none already exists
        if (!aConnectionExists) {
            for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
                if (relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
                    add(new CreateDiagramArchimateConnectionCommand(fParentObject, childObject, relation));
                }
            }
        }
        // Now do the reverse direction...
        aConnectionExists = false;
        for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
            if (relation.getSource() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
                if (DiagramModelUtils.hasDiagramModelArchimateConnection(childObject, fParentObject, relation)) {
                    aConnectionExists = true;
                    break;
                }
            }
        }
        // Create connections from relationships if none already exists
        if (!aConnectionExists) {
            for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
                if (relation.getSource() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
                    add(new CreateDiagramArchimateConnectionCommand(childObject, fParentObject, relation));
                }
            }
        }
    }
    // Check connections between parent and child connections of objects
    for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
        if (relation.getTarget() instanceof IArchimateRelationship) {
            IDiagramModelArchimateConnection dmc = findConnection((IArchimateRelationship) relation.getTarget());
            if (dmc != null) {
                if (!DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, dmc, relation)) {
                    add(new CreateDiagramArchimateConnectionCommand(fParentObject, dmc, relation));
                }
            }
        }
    }
    for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
        if (relation.getSource() instanceof IArchimateRelationship) {
            IDiagramModelArchimateConnection dmc = findConnection((IArchimateRelationship) relation.getSource());
            if (dmc != null) {
                if (!DiagramModelUtils.hasDiagramModelArchimateConnection(fParentObject, dmc, relation)) {
                    add(new CreateDiagramArchimateConnectionCommand(fParentObject, dmc, relation));
                }
            }
        }
    }
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

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