Search in sources :

Example 6 with IDiagramModelGroup

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

the class DiagramModelUtilsTests method getAncestorContainer.

// =================================================================================================
@Test
public void getAncestorContainer() {
    IDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    IDiagramModelGroup group1 = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
    IDiagramModelGroup group2 = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
    IDiagramModelObject child = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
    dm.getChildren().add(group1);
    group1.getChildren().add(group2);
    assertNull(DiagramModelUtils.getAncestorContainer(child));
    group2.getChildren().add(child);
    assertEquals(group1, DiagramModelUtils.getAncestorContainer(child));
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Test(org.junit.Test)

Example 7 with IDiagramModelGroup

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

the class DiagramModelUtilsTests method isArchimateConceptReferencedInDiagrams.

@Test
public void isArchimateConceptReferencedInDiagrams() {
    // This should be in a diagram
    IArchimateElement element = (IArchimateElement) tm.getObjectByID(data1[0][0]);
    assertNotNull(element);
    assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
    // This should be in a diagram
    element = (IArchimateElement) tm.getObjectByID(data2[0][0]);
    assertNotNull(element);
    assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
    // This should not be in a diagram
    element = IArchimateFactory.eINSTANCE.createBusinessActor();
    model.getDefaultFolderForObject(element).getElements().add(element);
    assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
    // Unless we add it to a diagram
    // And we'll nest it inside a Group to be cunning
    IDiagramModelArchimateObject dmo = ArchimateTestModel.createDiagramModelArchimateObject(element);
    IDiagramModelGroup group = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
    group.getChildren().add(dmo);
    model.getDefaultDiagramModel().getChildren().add(group);
    assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) Test(org.junit.Test)

Example 8 with IDiagramModelGroup

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

the class ArchimateDiagramConnectionPolicyTests method testIsValidConnection_DiagramModelConnection.

@Test
public void testIsValidConnection_DiagramModelConnection() {
    EClass relationshipType = IArchimatePackage.eINSTANCE.getDiagramModelConnection();
    IDiagramModelGroup group = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
    IDiagramModelNote note = IArchimateFactory.eINSTANCE.createDiagramModelNote();
    IDiagramModelArchimateObject dmao1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IDiagramModelArchimateObject dmao2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IDiagramModelReference dmRef = IArchimateFactory.eINSTANCE.createDiagramModelReference();
    // Source == Target
    assertFalse(ArchimateDiagramConnectionPolicy.isValidConnection(group, group, relationshipType));
    // Both ArchiMate types
    assertFalse(ArchimateDiagramConnectionPolicy.isValidConnection(dmao1, dmao2, relationshipType));
    // Target ArchiMate type
    assertFalse(ArchimateDiagramConnectionPolicy.isValidConnection(group, dmao2, relationshipType));
    // Target ArchiMate type
    assertFalse(ArchimateDiagramConnectionPolicy.isValidConnection(dmRef, dmao2, relationshipType));
    // Source ArchiMate type to Note
    assertTrue(ArchimateDiagramConnectionPolicy.isValidConnection(dmao1, note, relationshipType));
    // OK
    assertTrue(ArchimateDiagramConnectionPolicy.isValidConnection(note, group, relationshipType));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelNote(com.archimatetool.model.IDiagramModelNote) Test(org.junit.Test)

Example 9 with IDiagramModelGroup

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

the class SketchEditPartFactoryTests method testSketchGroupEditPart.

@Test
public void testSketchGroupEditPart() {
    IDiagramModelGroup group = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
    EditPart editPart = editPartFactory.createEditPart(null, group);
    assertTrue(editPart instanceof SketchGroupEditPart);
    assertEquals(group, editPart.getModel());
}
Also used : DiagramConnectionEditPart(com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart) EditPart(org.eclipse.gef.EditPart) EmptyEditPart(com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) Test(org.junit.Test)

Example 10 with IDiagramModelGroup

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

the class ArchimateDiagramConnectionPolicy method isValidConnection.

/**
 * @param source
 * @param target
 * @param relationshipType
 * @return True if valid connection source/target for connection type
 */
static boolean isValidConnection(IConnectable source, IConnectable target, EClass relationshipType) {
    /*
         * Diagram Connection from/to notes/groups/diagram refs.
         * Allowed between notes, visual groups, diagram refs and ArchiMate components
         */
    if (relationshipType == IArchimatePackage.eINSTANCE.getDiagramModelConnection()) {
        // Not circular
        if (source == target) {
            return false;
        }
        // Notes
        if (source instanceof IDiagramModelNote || target instanceof IDiagramModelNote) {
            return true;
        }
        // Groups
        if (source instanceof IDiagramModelGroup || target instanceof IDiagramModelGroup) {
            return !(source instanceof IDiagramModelArchimateComponent) && !(target instanceof IDiagramModelArchimateComponent);
        }
        // Diagram Refs
        if (source instanceof IDiagramModelReference || target instanceof IDiagramModelReference) {
            return !(source instanceof IDiagramModelArchimateComponent) && !(target instanceof IDiagramModelArchimateComponent);
        }
        return false;
    }
    // Connection from Archimate concept to Archimate concept (but not from relation to relation)
    if ((source instanceof IDiagramModelArchimateComponent && target instanceof IDiagramModelArchimateComponent) && !(source instanceof IDiagramModelArchimateConnection && target instanceof IDiagramModelArchimateConnection)) {
        // Special case if relationshipType == null. Means that the Magic connector is being used
        if (relationshipType == null) {
            return true;
        }
        IArchimateConcept sourceConcept = ((IDiagramModelArchimateComponent) source).getArchimateConcept();
        IArchimateConcept targetConcept = ((IDiagramModelArchimateComponent) target).getArchimateConcept();
        return ArchimateModelUtils.isValidRelationship(sourceConcept, targetConcept, relationshipType);
    }
    return false;
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IDiagramModelNote(com.archimatetool.model.IDiagramModelNote)

Aggregations

IDiagramModelGroup (com.archimatetool.model.IDiagramModelGroup)20 Test (org.junit.Test)14 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)6 IArchimateModel (com.archimatetool.model.IArchimateModel)4 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)4 EmptyEditPart (com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart)3 IArchimateElement (com.archimatetool.model.IArchimateElement)3 IDiagramModel (com.archimatetool.model.IDiagramModel)3 IDiagramModelNote (com.archimatetool.model.IDiagramModelNote)3 IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)3 EditPart (org.eclipse.gef.EditPart)3 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)2 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)2 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)2 ICreationFactory (com.archimatetool.editor.diagram.ICreationFactory)1 DiagramConnectionEditPart (com.archimatetool.editor.diagram.editparts.DiagramConnectionEditPart)1 GroupEditPart (com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart)1 NoteEditPart (com.archimatetool.editor.diagram.editparts.diagram.NoteEditPart)1 IObjectUIProvider (com.archimatetool.editor.ui.factory.IObjectUIProvider)1 IArchimateConcept (com.archimatetool.model.IArchimateConcept)1