Search in sources :

Example 61 with IDiagramModelArchimateObject

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

the class GenerateViewCommand method createDiagramNode.

private void createDiagramNode(IArchimateElement element, IArchimateDiagramModel dm, int x, int y) {
    IDiagramModelArchimateObject dmo = ArchimateDiagramModelFactory.createDiagramModelArchimateObject(element);
    dm.getChildren().add(dmo);
    // Location
    dmo.getBounds().setLocation(x, y);
}
Also used : IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 62 with IDiagramModelArchimateObject

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

the class FigureImagePreviewFactory method getPreviewImage.

private static Image getPreviewImage(IArchimateElementUIProvider provider, int type) {
    EClass eClass = provider.providerFor();
    String key = eClass.getName() + type;
    Image image = imageRegistry.get(key);
    if (image == null) {
        IDiagramModelArchimateObject dmo = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
        dmo.setArchimateElement((IArchimateElement) IArchimateFactory.eINSTANCE.create(eClass));
        dmo.setName(provider.getDefaultName());
        dmo.setTextPosition(ITextPosition.TEXT_POSITION_TOP);
        ColorFactory.setDefaultColors(dmo);
        dmo.setType(type);
        provider.setInstance(dmo);
        GraphicalEditPart editPart = (GraphicalEditPart) provider.createEditPart();
        editPart.setModel(dmo);
        IDiagramModelObjectFigure figure = (IDiagramModelObjectFigure) editPart.getFigure();
        figure.setSize(provider.getDefaultSize());
        figure.refreshVisuals();
        figure.validate();
        image = DiagramUtils.createImage(figure, 1, 0);
        imageRegistry.put(key, image);
    }
    return image;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObjectFigure(com.archimatetool.editor.diagram.figures.IDiagramModelObjectFigure) Image(org.eclipse.swt.graphics.Image) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart)

Example 63 with IDiagramModelArchimateObject

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

the class DiagramModelExtraTests method testDiagramModelArchimateConnection_eInverseAdd_Relationship_getReferencingDiagramObjects.

/**
 * See {@link DiagramModelArchimateConnection#eInverseAdd(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
 * See {@link DiagramModelArchimateConnection#eInverseRemove(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
 */
@Test
public void testDiagramModelArchimateConnection_eInverseAdd_Relationship_getReferencingDiagramObjects() {
    IArchimateElement element1 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IArchimateElement element2 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IArchimateElement element3 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IArchimateElement element4 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IArchimateRelationship relation1 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    IArchimateRelationship relation2 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    IArchimateRelationship relation3 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    relation1.setSource(element1);
    relation1.setTarget(element2);
    relation2.setSource(element2);
    relation2.setTarget(element3);
    relation3.setSource(element3);
    relation3.setTarget(element4);
    IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IDiagramModelArchimateObject dmo3 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IDiagramModelArchimateObject dmo4 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo1.setArchimateElement(element1);
    dmo2.setArchimateElement(element2);
    dmo3.setArchimateElement(element3);
    dmo4.setArchimateElement(element4);
    IDiagramModelArchimateConnection conn1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    IDiagramModelArchimateConnection conn2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    IDiagramModelArchimateConnection conn3 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    // conn3a shares a relationship with conn3
    IDiagramModelArchimateConnection conn3a = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    conn1.setArchimateRelationship(relation1);
    conn2.setArchimateRelationship(relation2);
    conn3.setArchimateRelationship(relation3);
    // same
    conn3a.setArchimateRelationship(relation3);
    // Set up model and diagram model
    IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
    model.setDefaults();
    IDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    model.getDefaultFolderForObject(dm).getElements().add(dm);
    // Add some parents
    IDiagramModelGroup parent1 = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
    dm.getChildren().add(parent1);
    IDiagramModelArchimateObject parent2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    parent1.getChildren().add(parent2);
    // Add the dmos
    dm.getChildren().add(dmo1);
    parent1.getChildren().add(dmo2);
    parent2.getChildren().add(dmo3);
    dm.getChildren().add(dmo4);
    // Starts at sizes
    assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
    // Connect
    conn1.connect(dmo1, dmo2);
    assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
    conn2.connect(dmo2, dmo3);
    assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
    conn3.connect(dmo3, dmo4);
    assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
    conn3a.connect(dmo3, dmo4);
    assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
    // Remove diagram model, should be the same
    ((IFolder) dm.eContainer()).getElements().remove(dm);
    assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
    // Add diagram model back again
    model.getDefaultFolderForObject(dm).getElements().add(dm);
    assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
    // Disconnect
    conn1.disconnect();
    conn2.disconnect();
    conn3.disconnect();
    conn3a.disconnect();
    assertEquals(0, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(0, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(0, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
    assertEquals(0, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
}
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) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IArchimateModel(com.archimatetool.model.IArchimateModel) Test(org.junit.Test)

Example 64 with IDiagramModelArchimateObject

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

the class AbstractModelView method getDiagramElementsToUpdate.

/**
 * Find all elements contained in Diagram or Diagram objects including any child objects
 */
private void getDiagramElementsToUpdate(List<Object> list, IDiagramModelContainer container) {
    // ArchiMate element
    if (container instanceof IDiagramModelArchimateObject) {
        IArchimateElement element = ((IDiagramModelArchimateObject) container).getArchimateElement();
        if (!list.contains(element)) {
            list.add(element);
            getRelationshipsToUpdate(list, element);
        }
    }
    // Children
    for (IDiagramModelObject child : container.getChildren()) {
        if (child instanceof IDiagramModelContainer) {
            getDiagramElementsToUpdate(list, (IDiagramModelContainer) child);
        }
    }
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

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