Search in sources :

Example 6 with IDiagramModelArchimateObject

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

the class NestedElementsCheckerTests method testGetIssues.

@Test
public void testGetIssues() {
    List<IArchimateDiagramModel> views = new ArrayList<IArchimateDiagramModel>();
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    dm.setName("view");
    views.add(dm);
    IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo1.setArchimateElement(IArchimateFactory.eINSTANCE.createGrouping());
    dm.getChildren().add(dmo1);
    IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo2.setArchimateElement(IArchimateFactory.eINSTANCE.createLocation());
    dmo1.getChildren().add(dmo2);
    NestedElementsChecker checker = new NestedElementsChecker(views);
    // Should not be ok
    List<IIssue> issues = checker.getIssues();
    assertEquals(1, issues.size());
    assertSame(dmo2, issues.get(0).getObject());
    // With this relationship should also not be OK
    IDiagramModelArchimateConnection conn = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
    IArchimateRelationship relation = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    relation.connect(dmo1.getArchimateElement(), dmo2.getArchimateElement());
    conn.setArchimateRelationship(relation);
    conn.connect(dmo1, dmo2);
    issues = checker.getIssues();
    assertEquals(1, issues.size());
    assertSame(dmo2, issues.get(0).getObject());
    // With a valid relationship should be OK
    relation = IArchimateFactory.eINSTANCE.createCompositionRelationship();
    relation.connect(dmo1.getArchimateElement(), dmo2.getArchimateElement());
    conn.setArchimateRelationship(relation);
    issues = checker.getIssues();
    assertEquals(0, issues.size());
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IIssue(com.archimatetool.hammer.validation.issues.IIssue) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) Test(org.junit.Test)

Example 7 with IDiagramModelArchimateObject

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

the class ViewpointCheckerTests method testGetIssues.

@Test
public void testGetIssues() {
    List<IArchimateDiagramModel> views = new ArrayList<IArchimateDiagramModel>();
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    dm.setName("view");
    views.add(dm);
    IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo1.setArchimateElement(IArchimateFactory.eINSTANCE.createNode());
    dm.getChildren().add(dmo1);
    ViewpointChecker checker = new ViewpointChecker(views);
    // Should be ok
    List<IIssue> issues = checker.getIssues();
    assertEquals(0, issues.size());
    // Set viewpoint
    dm.setViewpoint("organization");
    issues = checker.getIssues();
    assertEquals(1, issues.size());
    assertSame(dmo1, issues.get(0).getObject());
}
Also used : ArrayList(java.util.ArrayList) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IIssue(com.archimatetool.hammer.validation.issues.IIssue) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) Test(org.junit.Test)

Example 8 with IDiagramModelArchimateObject

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

the class FixDefaultSizesHandler method getDefaultSize.

Dimension getDefaultSize(IDiagramModelObject dmo) {
    IBounds bounds = dmo.getBounds();
    if (bounds.getWidth() != -1 && bounds.getHeight() != -1) {
        return new Dimension(bounds.getWidth(), bounds.getHeight());
    }
    // Legacy size of ArchiMate figure
    if (dmo instanceof IDiagramModelArchimateObject) {
        if (!(((IDiagramModelArchimateObject) dmo).getArchimateElement() instanceof IJunction)) {
            return new Dimension(120, 55);
        }
    }
    IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider) ObjectUIFactory.INSTANCE.getProvider(dmo);
    return provider != null ? provider.getUserDefaultSize() : new Dimension(120, 55);
}
Also used : IBounds(com.archimatetool.model.IBounds) IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) Dimension(org.eclipse.draw2d.geometry.Dimension) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IJunction(com.archimatetool.model.IJunction)

Example 9 with IDiagramModelArchimateObject

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

the class DiagramModelUtils method findDiagramModelObjectsForElementByReference.

/**
 * Find all (visible and extant) Diagram Model Objects for a given Archimate element in a Diagram Model.
 * This is the faster method.
 * @param diagramModel The parent diagram model to search in.
 * @param element The element to check on.
 * @return The list of active Diagram Model Objects. May be empty, but never null.
 */
static List<IDiagramModelArchimateObject> findDiagramModelObjectsForElementByReference(IDiagramModel diagramModel, IArchimateElement element) {
    // This is the faster method
    List<IDiagramModelArchimateObject> list = new ArrayList<IDiagramModelArchimateObject>();
    List<IDiagramModelArchimateObject> dmos = findDiagramModelObjectsForElement(element);
    for (IDiagramModelArchimateObject dmo : dmos) {
        if (dmo.getDiagramModel() == diagramModel) {
            list.add(dmo);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 10 with IDiagramModelArchimateObject

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

the class ModelChecker method checkDiagramObjectsReferences.

List<String> checkDiagramObjectsReferences() {
    List<String> messages = new ArrayList<String>();
    for (Iterator<EObject> iter = fModel.getFolder(FolderType.DIAGRAMS).eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        if (eObject instanceof IDiagramModelArchimateObject) {
            IDiagramModelArchimateObject dmo = (IDiagramModelArchimateObject) eObject;
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String name = dmo.getDiagramModel() == null ? Messages.ModelChecker_11 : " '" + dmo.getDiagramModel().getName() + "' (" + dmo.getId() + ")";
            IArchimateElement element = dmo.getArchimateElement();
            if (element == null) {
                messages.add(Messages.ModelChecker_12 + name);
            } else if (element.getArchimateModel() == null) {
                messages.add(Messages.ModelChecker_13 + name);
            }
        }
        if (eObject instanceof IDiagramModelArchimateConnection) {
            IDiagramModelArchimateConnection conn = (IDiagramModelArchimateConnection) eObject;
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String name = conn.getDiagramModel() == null ? Messages.ModelChecker_14 : " '" + conn.getDiagramModel().getName() + "' (" + conn.getId() + ")";
            IArchimateRelationship relation = conn.getArchimateRelationship();
            if (relation == null) {
                messages.add(Messages.ModelChecker_15 + name);
            } else {
                if (relation.getArchimateModel() == null) {
                    messages.add(Messages.ModelChecker_16 + name);
                }
                if (relation.getSource() != null && relation.getSource().getArchimateModel() == null) {
                    messages.add(Messages.ModelChecker_17 + name);
                }
                if (relation.getTarget() != null && relation.getTarget().getArchimateModel() == null) {
                    messages.add(Messages.ModelChecker_18 + name);
                }
            }
        }
    }
    return messages;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

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