Search in sources :

Example 6 with IDiagramModel

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

the class ValidatorView method selectObjects.

void selectObjects(IStructuredSelection selection) {
    if (selection != null) {
        List<IArchimateConcept> treeList = new ArrayList<IArchimateConcept>();
        List<IDiagramModel> viewList = new ArrayList<IDiagramModel>();
        List<IDiagramModelComponent> viewComponentList = new ArrayList<IDiagramModelComponent>();
        for (Object o : selection.toArray()) {
            if (o instanceof IIssue) {
                IIssue issue = (IIssue) o;
                if (issue.getObject() instanceof IArchimateConcept) {
                    treeList.add((IArchimateConcept) issue.getObject());
                } else if (issue.getObject() instanceof IDiagramModel) {
                    viewList.add((IDiagramModel) issue.getObject());
                } else if (issue.getObject() instanceof IDiagramModelComponent) {
                    viewList.add(((IDiagramModelComponent) issue.getObject()).getDiagramModel());
                    viewComponentList.add(((IDiagramModelComponent) issue.getObject()));
                }
            }
        }
        if (!treeList.isEmpty()) {
            ITreeModelView view = (ITreeModelView) ViewManager.showViewPart(ITreeModelView.ID, false);
            if (view != null) {
                view.getViewer().setSelection(new StructuredSelection(treeList), true);
            }
        }
        if (!viewList.isEmpty()) {
            for (IDiagramModel dm : viewList) {
                IDiagramModelEditor editor = EditorManager.openDiagramEditor(dm);
                if (editor instanceof IArchimateDiagramEditor) {
                    ((IArchimateDiagramEditor) editor).selectObjects(viewComponentList.toArray());
                }
            }
        }
    }
}
Also used : ITreeModelView(com.archimatetool.editor.views.tree.ITreeModelView) IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IDiagramModelEditor(com.archimatetool.editor.diagram.IDiagramModelEditor) IArchimateDiagramEditor(com.archimatetool.editor.diagram.IArchimateDiagramEditor) IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IIssue(com.archimatetool.hammer.validation.issues.IIssue)

Example 7 with IDiagramModel

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

the class ArchimateModelTests method testGetDefaultDiagramModel.

@Test
public void testGetDefaultDiagramModel() {
    assertNull(model.getDefaultDiagramModel());
    IDiagramModel dm1 = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    model.getDefaultFolderForObject(dm1).getElements().add(dm1);
    IDiagramModel dm2 = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    model.getDefaultFolderForObject(dm2).getElements().add(dm2);
    assertSame(dm1, model.getDefaultDiagramModel());
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) Test(org.junit.Test)

Example 8 with IDiagramModel

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

the class DiagramModelExtraTests method testDiagramModelArchimateObject_eInverseAdd_ArchimateElement_getReferencingDiagramObjects.

/**
 * See {@link DiagramModelArchimateObject#eInverseAdd(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
 * See {@link DiagramModelArchimateObject#eInverseRemove(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
 */
@Test
public void testDiagramModelArchimateObject_eInverseAdd_ArchimateElement_getReferencingDiagramObjects() {
    IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IDiagramModelArchimateObject dmo3 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IDiagramModelArchimateObject dmo3a = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo1.setArchimateElement(IArchimateFactory.eINSTANCE.createBusinessActor());
    dmo2.setArchimateElement(IArchimateFactory.eINSTANCE.createBusinessActor());
    dmo3.setArchimateElement(IArchimateFactory.eINSTANCE.createBusinessActor());
    // dmo3a shares an archimate element with dmo3
    dmo3a.setArchimateElement(dmo3.getArchimateElement());
    // 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);
    // Starts at sizes
    assertEquals(1, dmo1.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(1, dmo2.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Add to dm
    dm.getChildren().add(dmo1);
    assertEquals(1, dmo1.getArchimateElement().getReferencingDiagramObjects().size());
    // Add to parent 1
    parent1.getChildren().add(dmo2);
    assertEquals(1, dmo2.getArchimateElement().getReferencingDiagramObjects().size());
    // Add to parent 2
    parent2.getChildren().add(dmo3);
    assertEquals(2, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Add dmo3a - dmo3.getArchimateElement() should be same
    dm.getChildren().add(dmo3a);
    assertEquals(2, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Remove diagram model, should be the same
    ((IFolder) dm.eContainer()).getElements().remove(dm);
    assertEquals(1, dmo1.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(1, dmo2.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Add diagram model back again, should be the same
    model.getDefaultFolderForObject(dm).getElements().add(dm);
    assertEquals(1, dmo1.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(1, dmo2.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Simple remove from direct parent
    dm.getChildren().remove(dmo1);
    parent1.getChildren().remove(dmo2);
    parent2.getChildren().remove(dmo3);
    assertEquals(0, dmo1.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(0, dmo2.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(1, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(1, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Remove Again
    dm.getChildren().remove(dmo3a);
    assertEquals(0, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(0, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IArchimateModel(com.archimatetool.model.IArchimateModel) Test(org.junit.Test)

Example 9 with IDiagramModel

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

the class DiagramModelTests method testGetCopy.

@Test
public void testGetCopy() {
    dm.setName("name");
    dm.setDocumentation("doc");
    dm.getProperties().add(IArchimateFactory.eINSTANCE.createProperty());
    IDiagramModel copy = (IDiagramModel) dm.getCopy();
    assertNotSame(dm, copy);
    assertNull(copy.getId());
    assertEquals(dm.getName(), copy.getName());
    assertEquals(dm.getDocumentation(), copy.getDocumentation());
    assertNotSame(dm.getProperties(), copy.getProperties());
    assertEquals(dm.getProperties().size(), copy.getProperties().size());
    assertNotSame(dm.getChildren(), copy.getChildren());
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) Test(org.junit.Test)

Example 10 with IDiagramModel

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

the class EditorModelManager method createNewModel.

@Override
public IArchimateModel createNewModel() {
    IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
    model.setName(Messages.EditorModelManager_0);
    model.setDefaults();
    // Add one default diagram
    IDiagramModel diagramModel = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    diagramModel.setName(Messages.EditorModelManager_1);
    model.getFolder(FolderType.DIAGRAMS).getElements().add(diagramModel);
    // Register
    registerModel(model);
    return model;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateModel(com.archimatetool.model.IArchimateModel)

Aggregations

IDiagramModel (com.archimatetool.model.IDiagramModel)68 Test (org.junit.Test)28 IArchimateElement (com.archimatetool.model.IArchimateElement)16 IArchimateModel (com.archimatetool.model.IArchimateModel)12 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)12 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)11 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)10 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)9 File (java.io.File)8 EObject (org.eclipse.emf.ecore.EObject)8 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)8 Image (org.eclipse.swt.graphics.Image)8 IArchimateConcept (com.archimatetool.model.IArchimateConcept)7 IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)7 ArrayList (java.util.ArrayList)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)6 Command (org.eclipse.gef.commands.Command)6 GraphicalViewerImpl (org.eclipse.gef.ui.parts.GraphicalViewerImpl)6 Shell (org.eclipse.swt.widgets.Shell)6