Search in sources :

Example 26 with IArchimateDiagramModel

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

the class GenerateViewCommand method createDiagramModel.

private IArchimateDiagramModel createDiagramModel() {
    // New Diagram
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    dm.setName(fViewName);
    dm.setViewpoint(fViewpoint.getID());
    fParentFolder = fSelectedElements.get(0).getArchimateModel().getDefaultFolderForObject(dm);
    fParentFolder.getElements().add(dm);
    int x = 20;
    int y = 20;
    getElementsToAdd();
    for (IArchimateElement element : fSelectedElements) {
        createDiagramNode(element, dm, x, y);
        y += 100;
    }
    x = 170;
    y = 20;
    for (IArchimateElement element : fAddedElements) {
        if (!fSelectedElements.contains(element)) {
            createDiagramNode(element, dm, x, y);
            y += 80;
            if (y > 700) {
                y = 20;
                x += 150;
            }
        }
    }
    // Add connections between elements first
    for (IDiagramModelObject dmoSource : dm.getChildren()) {
        IArchimateElement elementSource = ((IDiagramModelArchimateObject) dmoSource).getArchimateElement();
        for (IArchimateRelationship relation : elementSource.getSourceRelationships()) {
            for (IDiagramModelObject dmoTarget : dm.getChildren()) {
                IArchimateElement elementTarget = ((IDiagramModelArchimateObject) dmoTarget).getArchimateElement();
                // Don't add connections that are not connected to the main elements if option is set
                if (!fAddAllConnections && !(fSelectedElements.contains(elementSource)) && !(fSelectedElements.contains(elementTarget))) {
                    continue;
                }
                if (relation.getTarget() == elementTarget) {
                    // Create connection
                    IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                    newConnection.connect(dmoSource, dmoTarget);
                }
            }
        }
    }
    // Add connections to connections
    for (Iterator<EObject> iter1 = dm.eAllContents(); iter1.hasNext(); ) {
        EObject eObject1 = iter1.next();
        if (eObject1 instanceof IDiagramModelArchimateConnection) {
            IDiagramModelArchimateConnection connection = (IDiagramModelArchimateConnection) eObject1;
            for (IDiagramModelObject dmo : dm.getChildren()) {
                IArchimateElement element = ((IDiagramModelArchimateObject) dmo).getArchimateElement();
                for (IArchimateRelationship relation : connection.getArchimateRelationship().getSourceRelationships()) {
                    if (relation.getTarget() == element) {
                        IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                        newConnection.connect(connection, dmo);
                    }
                }
                for (IArchimateRelationship relation : connection.getArchimateRelationship().getTargetRelationships()) {
                    if (relation.getSource() == element) {
                        IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
                        newConnection.connect(dmo, connection);
                    }
                }
            }
        }
    }
    return dm;
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) EObject(org.eclipse.emf.ecore.EObject) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IViewpoint(com.archimatetool.model.viewpoints.IViewpoint) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel)

Example 27 with IArchimateDiagramModel

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

the class DiagramModelArchimateConnectionTests method testAdd_Remove_ArchimateRelationshipToModel.

@Test
public void testAdd_Remove_ArchimateRelationshipToModel() {
    IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    model.getDefaultFolderForObject(dm).getElements().add(dm);
    dm.getChildren().add(source);
    dm.getChildren().add(target);
    connection.connect(source, target);
    // Passing null uses a default folder in the model
    IFolder expectedFolder = model.getDefaultFolderForObject(connection.getArchimateRelationship());
    connection.addArchimateConceptToModel(null);
    assertSame(expectedFolder, connection.getArchimateRelationship().eContainer());
    connection.removeArchimateConceptFromModel();
    assertNull(connection.getArchimateRelationship().eContainer());
    expectedFolder = IArchimateFactory.eINSTANCE.createFolder();
    connection.addArchimateConceptToModel(expectedFolder);
    assertSame(expectedFolder, connection.getArchimateRelationship().eContainer());
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 28 with IArchimateDiagramModel

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

the class DiagramModelArchimateObjectTests method testAdd_Remove_ArchimateElementToModel.

@Test
public void testAdd_Remove_ArchimateElementToModel() {
    IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    model.getDefaultFolderForObject(dm).getElements().add(dm);
    dm.getChildren().add(object);
    // Passing null uses a default folder in the model
    IFolder expectedFolder = model.getDefaultFolderForObject(object.getArchimateElement());
    object.addArchimateConceptToModel(null);
    assertSame(expectedFolder, object.getArchimateElement().eContainer());
    object.removeArchimateConceptFromModel();
    assertNull(object.getArchimateElement().eContainer());
    expectedFolder = IArchimateFactory.eINSTANCE.createFolder();
    object.addArchimateConceptToModel(expectedFolder);
    assertSame(expectedFolder, object.getArchimateElement().eContainer());
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 29 with IArchimateDiagramModel

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

the class ViewpointManagerTests method testIsAllowedConceptForDiagramModel.

@Test
public void testIsAllowedConceptForDiagramModel() {
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    dm.setViewpoint("organization");
    assertTrue(ViewpointManager.INSTANCE.isAllowedConceptForDiagramModel(dm, IArchimatePackage.eINSTANCE.getBusinessActor()));
    assertFalse(ViewpointManager.INSTANCE.isAllowedConceptForDiagramModel(dm, IArchimatePackage.eINSTANCE.getNode()));
}
Also used : IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) Test(org.junit.Test)

Aggregations

IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)29 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)8 IIssue (com.archimatetool.hammer.validation.issues.IIssue)6 IArchimateModel (com.archimatetool.model.IArchimateModel)6 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)6 IViewpoint (com.archimatetool.model.viewpoints.IViewpoint)5 EObject (org.eclipse.emf.ecore.EObject)5 AdviceType (com.archimatetool.hammer.validation.issues.AdviceType)4 ISketchModel (com.archimatetool.model.ISketchModel)4 IArchimateElement (com.archimatetool.model.IArchimateElement)3 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)3 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)3 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)3 IDiagramEditorFactory (com.archimatetool.editor.diagram.IDiagramEditorFactory)2 ArchimateDiagramEditPartFactory (com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory)2 IFolder (com.archimatetool.model.IFolder)2 FreeformGraphicalRootEditPart (org.eclipse.gef.editparts.FreeformGraphicalRootEditPart)2 GraphicalViewerImpl (org.eclipse.gef.ui.parts.GraphicalViewerImpl)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2