Search in sources :

Example 56 with IDiagramModelArchimateObject

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

the class UnusedElementsCheckerTests method testGetIssues.

@Test
public void testGetIssues() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    List<IArchimateElement> elements = new ArrayList<IArchimateElement>();
    IArchimateElement element = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
    elements.add(element);
    UnusedElementsChecker checker = new UnusedElementsChecker(elements);
    // Should not be OK
    List<IIssue> issues = checker.getIssues();
    assertEquals(1, issues.size());
    assertSame(element, issues.get(0).getObject());
    // Add it to a diagram
    IDiagramModelArchimateObject dmo = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo.setArchimateElement(element);
    model.getDefaultDiagramModel().getChildren().add(dmo);
    // Should be OK
    issues = checker.getIssues();
    assertEquals(0, issues.size());
}
Also used : ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IIssue(com.archimatetool.hammer.validation.issues.IIssue) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 57 with IDiagramModelArchimateObject

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

the class UnusedRelationsCheckerTests method testGetIssues.

@Test
public void testGetIssues() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    List<IArchimateRelationship> relations = new ArrayList<IArchimateRelationship>();
    IArchimateRelationship relation = (IArchimateRelationship) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getAssociationRelationship());
    relations.add(relation);
    IArchimateElement e1 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
    IArchimateElement e2 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
    relation.connect(e1, e2);
    UnusedRelationsChecker checker = new UnusedRelationsChecker(relations);
    // Should not be OK
    List<IIssue> issues = checker.getIssues();
    assertEquals(1, issues.size());
    assertSame(relation, issues.get(0).getObject());
    // Add it to a diagram
    IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo1.setArchimateElement(e1);
    model.getDefaultDiagramModel().getChildren().add(dmo1);
    IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo2.setArchimateElement(e2);
    model.getDefaultDiagramModel().getChildren().add(dmo2);
    IDiagramModelArchimateConnection conn = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    conn.setArchimateRelationship(relation);
    conn.connect(dmo1, dmo2);
    // Should be OK
    issues = checker.getIssues();
    assertEquals(0, issues.size());
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IIssue(com.archimatetool.hammer.validation.issues.IIssue) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 58 with IDiagramModelArchimateObject

use of com.archimatetool.model.IDiagramModelArchimateObject 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?
 */
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;
        // Specialization relationship is the other way around
        for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
            if (relation.getSource() == childElement && relation.eClass() == IArchimatePackage.eINSTANCE.getSpecializationRelationship() && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
                if (DiagramModelUtils.hasDiagramModelArchimateConnection(childObject, fParentObject, relation)) {
                    aConnectionExists = true;
                    break;
                }
            }
        }
        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) {
            // Specialization relationship is the other way around
            for (IArchimateRelationship relation : parentElement.getTargetRelationships()) {
                if (relation.getSource() == childElement && relation.eClass() == IArchimatePackage.eINSTANCE.getSpecializationRelationship() && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
                    add(new CreateDiagramArchimateConnectionCommand(childObject, fParentObject, relation));
                }
            }
            for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
                if (relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
                    add(new CreateDiagramArchimateConnectionCommand(fParentObject, childObject, 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)

Example 59 with IDiagramModelArchimateObject

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

the class DeleteNestedConnectionsCommand method createDeleteCommands.

/**
 * Child Objects that have connections
 */
void createDeleteCommands() {
    for (IDiagramModelArchimateObject child : fChildObjects) {
        for (IDiagramModelConnection connection : child.getTargetConnections()) {
            if (connection instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) connection)) {
                for (IDiagramModelConnection subconnection : connection.getTargetConnections()) {
                    Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(subconnection);
                    add(cmd);
                }
                for (IDiagramModelConnection subconnection : connection.getSourceConnections()) {
                    Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(subconnection);
                    add(cmd);
                }
            }
        }
    }
}
Also used : Command(org.eclipse.gef.commands.Command) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 60 with IDiagramModelArchimateObject

use of com.archimatetool.model.IDiagramModelArchimateObject 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 : elementSource.getSourceRelationships()) {
            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 : connection.getArchimateRelationship().getSourceRelationships()) {
                    if (relation.getTarget() == element) {
                        IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                        newConnection.connect(connection, dmo);
                    }
                }
                for (IArchimateRelationship relation : connection.getArchimateRelationship().getTargetRelationships()) {
                    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)

Aggregations

IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)64 Test (org.junit.Test)34 IArchimateElement (com.archimatetool.model.IArchimateElement)28 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)19 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)14 ArrayList (java.util.ArrayList)13 IDiagramModel (com.archimatetool.model.IDiagramModel)10 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)10 IArchimateModel (com.archimatetool.model.IArchimateModel)8 EClass (org.eclipse.emf.ecore.EClass)7 Command (org.eclipse.gef.commands.Command)7 IIssue (com.archimatetool.hammer.validation.issues.IIssue)6 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)6 EObject (org.eclipse.emf.ecore.EObject)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)6 IDiagramModelGroup (com.archimatetool.model.IDiagramModelGroup)5 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)5 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)4 IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)4 Dimension (org.eclipse.draw2d.geometry.Dimension)4