Search in sources :

Example 1 with ArchimateDiagramModelFactory

use of com.archimatetool.editor.diagram.ArchimateDiagramModelFactory in project archi by archimatetool.

the class ArchimateDiagramConnectionPolicyTests method testGetConnectionCreateCommand_CreatesLineConnectionCommand.

@Test
public void testGetConnectionCreateCommand_CreatesLineConnectionCommand() throws Exception {
    setupSourcePolicy(IArchimateFactory.eINSTANCE.createBusinessActor());
    CreateConnectionRequest request = new CreateConnectionRequest();
    request.setFactory(new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getDiagramModelConnection()));
    Command cmd = sourcePolicy.getConnectionCreateCommand(request);
    assertNotNull(cmd);
    assertTrue(cmd.getClass() == CreateDiagramConnectionCommand.class);
    assertEquals(cmd, request.getStartCommand());
    assertEquals(sourceDiagramObject, TestUtils.getPrivateField(cmd, "fSource"));
}
Also used : CreateDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) Command(org.eclipse.gef.commands.Command) ArchimateDiagramModelFactory(com.archimatetool.editor.diagram.ArchimateDiagramModelFactory) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) CreateDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand) Test(org.junit.Test)

Example 2 with ArchimateDiagramModelFactory

use of com.archimatetool.editor.diagram.ArchimateDiagramModelFactory in project archi by archimatetool.

the class XMLModelImporter method addNodes.

// ========================================= Nodes ======================================
private void addNodes(IDiagramModelContainer parentContainer, Element parentElement) throws XMLModelParserException {
    for (Element nodeElement : parentElement.getChildren(ELEMENT_NODE, ARCHIMATE3_NAMESPACE)) {
        IDiagramModelObject dmo = null;
        // This has an element ref so it's an ArchiMate element node
        String elementRef = nodeElement.getAttributeValue(ATTRIBUTE_ELEMENTREF);
        if (hasValue(elementRef)) {
            IArchimateConcept concept = fConceptsLookup.get(elementRef);
            if (!(concept instanceof IArchimateElement)) {
                throw new XMLModelParserException(Messages.XMLModelImporter_5 + elementRef);
            }
            // Create new diagram node object
            dmo = ArchimateDiagramModelFactory.createDiagramModelArchimateObject((IArchimateElement) concept);
        } else // No element ref so this is another type of node, but what is it?
        {
            boolean isGroup = ATTRIBUTE_CONTAINER_TYPE.equals(nodeElement.getAttributeValue(ATTRIBUTE_TYPE, XSI_NAMESPACE));
            boolean isLabel = ATTRIBUTE_LABEL_TYPE.equals(nodeElement.getAttributeValue(ATTRIBUTE_TYPE, XSI_NAMESPACE));
            // Does the graphical node have children?
            // Our notes cannot contain children, so if it does contain children it has to be a Group.
            boolean hasChildren = nodeElement.getChildren(ELEMENT_NODE, ARCHIMATE3_NAMESPACE).size() > 0;
            // Is it a label with view ref?
            boolean isViewRef = isLabel && nodeElement.getChild(ELEMENT_VIEWREF, ARCHIMATE3_NAMESPACE) != null;
            if (isGroup || hasChildren) {
                ICreationFactory factory = new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getDiagramModelGroup());
                IDiagramModelGroup group = (IDiagramModelGroup) factory.getNewObject();
                dmo = group;
                // Label
                String name = getChildElementText(nodeElement, ELEMENT_LABEL, true);
                if (name != null) {
                    dmo.setName(name);
                }
                // Documentation
                String documentation = getChildElementText(nodeElement, ELEMENT_DOCUMENTATION, false);
                if (documentation != null) {
                    group.setDocumentation(documentation);
                }
            } else // View Ref
            if (isViewRef) {
                IDiagramModelReference ref = IArchimateFactory.eINSTANCE.createDiagramModelReference();
                dmo = ref;
                // View reference
                Element viewRefElement = nodeElement.getChild(ELEMENT_VIEWREF, ARCHIMATE3_NAMESPACE);
                String viewRefID = viewRefElement.getAttributeValue(ATTRIBUTE_REF);
                // The referenced diagram model will have to be set afterwards since we may not have created it yet
                // so we use this a temp store
                fDiagramRefsLookup.put(ref, viewRefID);
            } else // A Note is our only other option
            {
                ICreationFactory factory = new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getDiagramModelNote());
                IDiagramModelNote note = (IDiagramModelNote) factory.getNewObject();
                dmo = note;
                // Text
                String text = getChildElementText(nodeElement, ELEMENT_LABEL, false);
                if (text != null) {
                    note.setContent(text);
                }
            }
        }
        if (dmo != null) {
            // Add Identifier before adding to model
            String identifier = nodeElement.getAttributeValue(ATTRIBUTE_IDENTIFIER);
            dmo.setId(identifier);
            // Add the child first
            parentContainer.getChildren().add(dmo);
            // Get the absolute bounds as declared in the XML file
            IBounds bounds = getNodeBounds(nodeElement);
            // Convert the given absolute bounds into relative bounds if this is in a child object
            if (parentContainer instanceof IDiagramModelObject) {
                bounds = DiagramModelUtils.getRelativeBounds(bounds, (IDiagramModelObject) parentContainer);
            }
            dmo.setBounds(bounds);
            // Style
            addNodeStyle(dmo, nodeElement.getChild(ELEMENT_STYLE, ARCHIMATE3_NAMESPACE));
            // Add to lookup
            fConnectionsNodesLookup.put(dmo.getId(), dmo);
            // Child nodes
            if (dmo instanceof IDiagramModelContainer) {
                addNodes((IDiagramModelContainer) dmo, nodeElement);
            }
        }
    }
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) Element(org.jdom2.Element) IArchimateElement(com.archimatetool.model.IArchimateElement) IBounds(com.archimatetool.model.IBounds) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateElement(com.archimatetool.model.IArchimateElement) ICreationFactory(com.archimatetool.editor.diagram.ICreationFactory) ArchimateDiagramModelFactory(com.archimatetool.editor.diagram.ArchimateDiagramModelFactory) IDiagramModelNote(com.archimatetool.model.IDiagramModelNote)

Example 3 with ArchimateDiagramModelFactory

use of com.archimatetool.editor.diagram.ArchimateDiagramModelFactory in project archi by archimatetool.

the class CreateDiagramArchimateConnectionWithDialogCommandTests method runOnceBeforeEachTest.

@Before
public void runOnceBeforeEachTest() {
    CreateConnectionRequest request = new CreateConnectionRequest();
    request.setFactory(new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getAssignmentRelationship()));
    cmd = new CreateDiagramArchimateConnectionWithDialogCommand(request);
}
Also used : ArchimateDiagramModelFactory(com.archimatetool.editor.diagram.ArchimateDiagramModelFactory) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) Before(org.junit.Before)

Example 4 with ArchimateDiagramModelFactory

use of com.archimatetool.editor.diagram.ArchimateDiagramModelFactory in project archi by archimatetool.

the class ArchimateDiagramConnectionPolicyTests method testGetConnectionCreateCommand_CreatesNullCommand.

@Test
public void testGetConnectionCreateCommand_CreatesNullCommand() {
    setupSourcePolicy(IArchimateFactory.eINSTANCE.createJunction());
    CreateConnectionRequest request = new CreateConnectionRequest();
    // Use a non-legal relationship
    request.setFactory(new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getSpecializationRelationship()));
    // Should be null
    Command cmd = sourcePolicy.getConnectionCreateCommand(request);
    assertNull(cmd);
}
Also used : CreateDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) Command(org.eclipse.gef.commands.Command) ArchimateDiagramModelFactory(com.archimatetool.editor.diagram.ArchimateDiagramModelFactory) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) Test(org.junit.Test)

Example 5 with ArchimateDiagramModelFactory

use of com.archimatetool.editor.diagram.ArchimateDiagramModelFactory in project archi by archimatetool.

the class ArchimateDiagramConnectionPolicyTests method testGetConnectionCompleteCommand.

@Test
public void testGetConnectionCompleteCommand() throws Exception {
    setupSourcePolicy(IArchimateFactory.eINSTANCE.createBusinessActor());
    setupTargetPolicy(IArchimateFactory.eINSTANCE.createBusinessRole());
    CreateConnectionRequest request = new CreateConnectionRequest();
    request.setFactory(new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getAssignmentRelationship()));
    EditPart sourceEditPart = mock(EditPart.class);
    when(sourceEditPart.getModel()).thenReturn(sourceDiagramObject);
    request.setSourceEditPart(sourceEditPart);
    Command startCommand = sourcePolicy.getConnectionCreateCommand(request);
    assertNotNull(startCommand);
    Command endCommand = targetPolicy.getConnectionCompleteCommand(request);
    assertNotNull(endCommand);
    assertEquals(startCommand, endCommand);
    assertEquals(targetDiagramObject, TestUtils.getPrivateField(endCommand, "fTarget"));
}
Also used : CreateDiagramConnectionCommand(com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) Command(org.eclipse.gef.commands.Command) EditPart(org.eclipse.gef.EditPart) ArchimateDiagramModelFactory(com.archimatetool.editor.diagram.ArchimateDiagramModelFactory) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) Test(org.junit.Test)

Aggregations

ArchimateDiagramModelFactory (com.archimatetool.editor.diagram.ArchimateDiagramModelFactory)6 CreateConnectionRequest (org.eclipse.gef.requests.CreateConnectionRequest)5 CreateDiagramArchimateConnectionWithDialogCommand (com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand)4 CreateDiagramConnectionCommand (com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand)4 Command (org.eclipse.gef.commands.Command)4 Test (org.junit.Test)4 ICreationFactory (com.archimatetool.editor.diagram.ICreationFactory)1 IArchimateConcept (com.archimatetool.model.IArchimateConcept)1 IArchimateElement (com.archimatetool.model.IArchimateElement)1 IBounds (com.archimatetool.model.IBounds)1 IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)1 IDiagramModelGroup (com.archimatetool.model.IDiagramModelGroup)1 IDiagramModelNote (com.archimatetool.model.IDiagramModelNote)1 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)1 IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)1 EditPart (org.eclipse.gef.EditPart)1 Element (org.jdom2.Element)1 Before (org.junit.Before)1