Search in sources :

Example 61 with IArchimateRelationship

use of com.archimatetool.model.IArchimateRelationship 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 62 with IArchimateRelationship

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

the class FieldDataFactoryTests method testGetFieldValue_RelationSource.

@Test
public void testGetFieldValue_RelationSource() {
    IArchimateRelationship relation = IArchimateFactory.eINSTANCE.createServingRelationship();
    IArtifact source = IArchimateFactory.eINSTANCE.createArtifact();
    source.setName("source");
    relation.setSource(source);
    Object o = FieldDataFactory.getFieldValue(relation, "relation_source");
    assertEquals("source", o);
}
Also used : IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IArtifact(com.archimatetool.model.IArtifact) Test(org.junit.Test)

Example 63 with IArchimateRelationship

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

the class AbstractArchimateConnectionFigure method getToolTip.

@Override
public IFigure getToolTip() {
    ToolTipFigure toolTipFigure = (ToolTipFigure) super.getToolTip();
    if (toolTipFigure == null) {
        return null;
    }
    IArchimateRelationship relation = getModelConnection().getArchimateRelationship();
    String text = ArchiLabelProvider.INSTANCE.getLabel(relation);
    toolTipFigure.setText(text);
    String type = ArchiLabelProvider.INSTANCE.getDefaultName(relation.eClass());
    // $NON-NLS-1$
    toolTipFigure.setType(Messages.AbstractArchimateConnectionFigure_0 + " " + type);
    String rubric = ArchiLabelProvider.INSTANCE.getRelationshipSentence(relation);
    toolTipFigure.setRubric(rubric);
    return toolTipFigure;
}
Also used : ToolTipFigure(com.archimatetool.editor.diagram.figures.ToolTipFigure) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship)

Example 64 with IArchimateRelationship

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

the class CreateDiagramArchimateConnectionWithDialogCommand method checkToReuseExistingRelationship.

boolean checkToReuseExistingRelationship() {
    EClass classType = (EClass) fRequest.getNewObjectType();
    if (fSource instanceof IDiagramModelArchimateComponent && fTarget instanceof IDiagramModelArchimateComponent) {
        IDiagramModelArchimateComponent source = (IDiagramModelArchimateComponent) fSource;
        IDiagramModelArchimateComponent target = (IDiagramModelArchimateComponent) fTarget;
        // If there is already a relation of this type in the model...
        IArchimateRelationship relation = getExistingRelationshipOfType(classType, source.getArchimateConcept(), target.getArchimateConcept());
        if (relation != null) {
            // ...then ask the user if they want to re-use it
            boolean answer = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.CreateArchimateConnectionWithDialogCommand_0, NLS.bind(Messages.CreateArchimateConnectionWithDialogCommand_1, ArchiLabelProvider.INSTANCE.getLabel(source), ArchiLabelProvider.INSTANCE.getLabel(target)));
            // Yes...
            if (answer) {
                // ...set connection's relationship to the existing relation
                fConnection = createNewConnection();
                ((IDiagramModelArchimateConnection) fConnection).setArchimateRelationship(relation);
                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 65 with IArchimateRelationship

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

Aggregations

IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)74 Test (org.junit.Test)39 IArchimateElement (com.archimatetool.model.IArchimateElement)33 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)22 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)15 ArrayList (java.util.ArrayList)15 IArchimateConcept (com.archimatetool.model.IArchimateConcept)14 IDiagramModel (com.archimatetool.model.IDiagramModel)12 IArchimateModel (com.archimatetool.model.IArchimateModel)9 EObject (org.eclipse.emf.ecore.EObject)9 IIssue (com.archimatetool.hammer.validation.issues.IIssue)7 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)7 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)7 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)5 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)5 ErrorType (com.archimatetool.hammer.validation.issues.ErrorType)4 IFolder (com.archimatetool.model.IFolder)4 EClass (org.eclipse.emf.ecore.EClass)4 Command (org.eclipse.gef.commands.Command)4 NoteEditPart (com.archimatetool.editor.diagram.editparts.diagram.NoteEditPart)3