Search in sources :

Example 51 with IArchimateRelationship

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

the class FieldDataFactory method getFieldValue.

public static Object getFieldValue(Object dataElement, String fieldName) {
    if ("this".equals(fieldName)) {
        // $NON-NLS-1$
        return dataElement;
    }
    if ("id".equals(fieldName) && dataElement instanceof IIdentifier) {
        // $NON-NLS-1$
        return ((IIdentifier) dataElement).getId();
    }
    if ("name".equals(fieldName) && dataElement instanceof INameable) {
        // $NON-NLS-1$
        String name = ((INameable) dataElement).getName();
        if (name == null || "".equals(name)) {
            // $NON-NLS-1$
            name = ArchiLabelProvider.INSTANCE.getDefaultName(((EObject) dataElement).eClass());
        }
        return name;
    }
    if ("type".equals(fieldName) && dataElement instanceof EObject) {
        // $NON-NLS-1$
        return ArchiLabelProvider.INSTANCE.getDefaultName(((EObject) dataElement).eClass());
    }
    if ("documentation".equals(fieldName) && dataElement instanceof IDocumentable) {
        // $NON-NLS-1$
        String s = ((IDocumentable) dataElement).getDocumentation();
        return StringUtils.isSet(s) ? s : null;
    }
    if ("purpose".equals(fieldName) && dataElement instanceof IArchimateModel) {
        // $NON-NLS-1$
        String s = ((IArchimateModel) dataElement).getPurpose();
        return StringUtils.isSet(s) ? s : null;
    }
    if ("relation_source".equals(fieldName) && dataElement instanceof IArchimateRelationship) {
        // $NON-NLS-1$
        IArchimateRelationship relation = (IArchimateRelationship) dataElement;
        IArchimateConcept source = relation.getSource();
        String s = source.getName();
        return StringUtils.isSet(s) ? s : null;
    }
    if ("relation_target".equals(fieldName) && dataElement instanceof IArchimateRelationship) {
        // $NON-NLS-1$
        IArchimateRelationship relation = (IArchimateRelationship) dataElement;
        IArchimateConcept target = relation.getTarget();
        String s = target.getName();
        return StringUtils.isSet(s) ? s : null;
    }
    return null;
}
Also used : IDocumentable(com.archimatetool.model.IDocumentable) IIdentifier(com.archimatetool.model.IIdentifier) INameable(com.archimatetool.model.INameable) EObject(org.eclipse.emf.ecore.EObject) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 52 with IArchimateRelationship

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

the class DeleteCommandHandlerTests method testDelete_Relations_Deleted_Diagram_Connections.

@Test
public void testDelete_Relations_Deleted_Diagram_Connections() {
    // Connecting relationship
    IArchimateRelationship relationship = (IArchimateRelationship) ArchimateModelUtils.getObjectByID(model, "3bede7f0");
    assertNotNull(relationship);
    // Relationship is there on a diagram
    assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(relationship));
    // Zap
    DeleteCommandHandler commandHandler = new DeleteCommandHandler(treeModelViewer, new Object[] { relationship });
    commandHandler.delete();
    // All gone
    assertNull(ArchimateModelUtils.getObjectByID(model, relationship.getId()));
    assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(relationship));
}
Also used : IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) Test(org.junit.Test)

Example 53 with IArchimateRelationship

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

the class DuplicateCommandHandlerTests method testDuplicateArchimateElements.

@Test
public void testDuplicateArchimateElements() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    IFolder folder = model.getFolder(FolderType.BUSINESS);
    IArchimateElement element1 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
    element1.setName("Actor 1");
    element1.setDocumentation("Doc 1");
    assertEquals(1, folder.getElements().size());
    assertSame(element1, folder.getElements().get(0));
    IArchimateElement element2 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
    element2.setName("Actor 2");
    element2.setDocumentation("Doc 2");
    assertEquals(2, folder.getElements().size());
    assertSame(element2, folder.getElements().get(1));
    IArchimateRelationship relation = (IArchimateRelationship) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getAssociationRelationship());
    relation.connect(element1, element2);
    assertTrue(element1.getSourceRelationships().contains(relation));
    assertTrue(element2.getTargetRelationships().contains(relation));
    DuplicateCommandHandler handler = new DuplicateCommandHandler(new Object[] { element1, element2 });
    handler.duplicate();
    assertEquals(4, folder.getElements().size());
    assertSame(element1, folder.getElements().get(0));
    assertSame(element2, folder.getElements().get(1));
    IArchimateElement copy1 = (IArchimateElement) folder.getElements().get(2);
    assertNotSame(element1, copy1);
    assertNotEquals(element1.getId(), copy1.getId());
    assertEquals(element1.getName() + " (copy)", copy1.getName());
    assertEquals(element1.getDocumentation(), copy1.getDocumentation());
    IArchimateElement copy2 = (IArchimateElement) folder.getElements().get(3);
    assertNotSame(element2, copy2);
    assertNotEquals(element2.getId(), copy2.getId());
    assertEquals(element2.getName() + " (copy)", copy2.getName());
    assertEquals(element2.getDocumentation(), copy2.getDocumentation());
    assertTrue(copy1.getSourceRelationships().isEmpty());
    assertTrue(copy1.getTargetRelationships().isEmpty());
    assertTrue(copy2.getSourceRelationships().isEmpty());
    assertTrue(copy2.getTargetRelationships().isEmpty());
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 54 with IArchimateRelationship

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

the class DuplicateCommandHandlerTests method testDuplicateDiagramModel_AddsConnectionsToConnections.

@Test
public void testDuplicateDiagramModel_AddsConnectionsToConnections() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    IDiagramModel dm = model.getDefaultDiagramModel();
    IArchimateElement element1 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(element1);
    dm.getChildren().add(dmo1);
    IArchimateElement element2 = IArchimateFactory.eINSTANCE.createBusinessRole();
    IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(element2);
    dm.getChildren().add(dmo2);
    IArchimateElement element3 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IDiagramModelArchimateObject dmo3 = tm.createDiagramModelArchimateObjectAndAddToModel(element3);
    dm.getChildren().add(dmo3);
    IArchimateRelationship relation1 = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
    relation1.setSource(element1);
    relation1.setTarget(element2);
    IDiagramModelArchimateConnection dmc1 = tm.createDiagramModelArchimateConnectionAndAddToModel(relation1);
    dmc1.connect(dmo1, dmo2);
    IArchimateRelationship relation2 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    relation2.setSource(element3);
    relation2.setTarget(relation1);
    IDiagramModelArchimateConnection dmc2 = tm.createDiagramModelArchimateConnectionAndAddToModel(relation2);
    dmc2.connect(dmo3, dmc1);
    DuplicateCommandHandler handler = new DuplicateCommandHandler(new Object[] { dm });
    handler.duplicate();
    IDiagramModel dmCopy = model.getDiagramModels().get(1);
    EList<IDiagramModelObject> children = dmCopy.getChildren();
    assertEquals(3, children.size());
    IDiagramModelArchimateObject dmo1Copy = (IDiagramModelArchimateObject) children.get(0);
    IDiagramModelArchimateObject dmo2Copy = (IDiagramModelArchimateObject) children.get(1);
    IDiagramModelArchimateObject dmo3Copy = (IDiagramModelArchimateObject) children.get(2);
    assertSame(element1, dmo1Copy.getArchimateConcept());
    assertSame(element2, dmo2Copy.getArchimateConcept());
    assertSame(element3, dmo3Copy.getArchimateConcept());
    IDiagramModelArchimateConnection dmc1Copy = (IDiagramModelArchimateConnection) dmo1Copy.getSourceConnections().get(0);
    assertSame(relation1, dmc1Copy.getArchimateConcept());
    assertSame(dmo2Copy, dmc1Copy.getTarget());
    // Connection to Connection
    assertSame(dmc1Copy, dmo3Copy.getSourceConnections().get(0).getTarget());
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) 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) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 55 with IArchimateRelationship

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

the class DiagramModelUtilsTests method hasDiagramModelArchimateConnection.

@Test
public void hasDiagramModelArchimateConnection() {
    IArchimateRelationship relationship = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    IArchimateRelationship relationship2 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    IDiagramModel diagramModel = tm.addNewArchimateDiagramModel();
    // Create various IDiagramModelArchimateObject objects
    createDataForDiagramModelArchimateObjects(IArchimateFactory.eINSTANCE.createBusinessActor(), diagramModel);
    // And make some connections using the relationship
    createDataForDiagramModelConnections(relationship);
    // Should not be found
    boolean result = DiagramModelUtils.hasDiagramModelArchimateConnection(dmo1, dmo2, relationship2);
    assertFalse(result);
    // Should be found
    result = DiagramModelUtils.hasDiagramModelArchimateConnection(dmo1, dmo2, relationship);
    assertTrue(result);
    result = DiagramModelUtils.hasDiagramModelArchimateConnection(dmo3, dmo4, relationship);
    assertTrue(result);
    result = DiagramModelUtils.hasDiagramModelArchimateConnection(dmo4, dmo1, relationship);
    assertTrue(result);
    // Reverse the target and source
    result = DiagramModelUtils.hasDiagramModelArchimateConnection(dmo2, dmo1, relationship);
    assertFalse(result);
    result = DiagramModelUtils.hasDiagramModelArchimateConnection(dmo4, dmo3, relationship);
    assertFalse(result);
    result = DiagramModelUtils.hasDiagramModelArchimateConnection(dmo1, dmo4, relationship);
    assertFalse(result);
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) Test(org.junit.Test)

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