Search in sources :

Example 46 with IDiagramModelArchimateObject

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

the class HTMLReportExporter method addNewBounds.

/**
 * Add new bounds for each diagram object in relation to its parent offset x,y
 */
private void addNewBounds(IDiagramModelObject dmo, int offsetX, int offsetY) {
    // Add new bounds caled to device zoom
    BoundsWithAbsolutePosition newBounds = new BoundsWithAbsolutePosition(dmo.getBounds(), ImageFactory.getDeviceZoom() / 100);
    // Add offset
    newBounds.setOffset(offsetX, offsetY);
    childBoundsMap.put(dmo.getId(), newBounds);
    // Children
    if (dmo instanceof IDiagramModelArchimateObject || dmo instanceof IDiagramModelGroup) {
        for (IDiagramModelObject child : ((IDiagramModelContainer) dmo).getChildren()) {
            addNewBounds(child, newBounds.getX1(), newBounds.getY1());
        }
    }
}
Also used : IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 47 with IDiagramModelArchimateObject

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

the class DiagramModelArchimateObject method getCopy.

@Override
public EObject getCopy() {
    IDiagramModelArchimateObject newObject = (IDiagramModelArchimateObject) super.getCopy();
    IArchimateElement element = (IArchimateElement) getArchimateElement().getCopy();
    newObject.setArchimateElement(element);
    // Clear children
    newObject.getChildren().clear();
    return newObject;
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 48 with IDiagramModelArchimateObject

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

the class ArchimateContainerLayoutPolicy method getAddCommand.

// Over-ride this method to add a sub-command for nested connections
@Override
protected Command getAddCommand(Request generic) {
    Object parent = getHost().getModel();
    ChangeBoundsRequest request = (ChangeBoundsRequest) generic;
    CompoundCommand command = new CompoundCommand();
    // Add relations/connections between parent and child if Prefs set and if parent is an Archimate object
    boolean doAddNestedConnections = ConnectionPreferences.createRelationWhenMovingElement() && parent instanceof IDiagramModelArchimateObject;
    List<IDiagramModelArchimateObject> childObjectsForNewConnections = new ArrayList<IDiagramModelArchimateObject>();
    // Delete connections between parent and child if Prefs set and if parent is an Archimate object
    boolean doDeleteNestedConnections = ConnectionPreferences.useNestedConnections();
    List<IDiagramModelArchimateObject> childObjectsForDeletedConnections = new ArrayList<IDiagramModelArchimateObject>();
    for (Object editPart : request.getEditParts()) {
        GraphicalEditPart child = (GraphicalEditPart) editPart;
        AddObjectCommand addCommand = createAddCommand(request, child, translateToModelConstraint(getConstraintFor(request, child)));
        command.add(addCommand);
        // If we use nested connections, and child is an Archimate diagram object add it to the list
        if (doAddNestedConnections && addCommand.child instanceof IDiagramModelArchimateObject) {
            childObjectsForNewConnections.add((IDiagramModelArchimateObject) addCommand.child);
        }
        // If we need to delete some nested connections
        if (doDeleteNestedConnections && addCommand.child instanceof IDiagramModelArchimateObject) {
            childObjectsForDeletedConnections.add((IDiagramModelArchimateObject) addCommand.child);
        }
    }
    // We have some child objects for deletion connections
    if (!childObjectsForDeletedConnections.isEmpty()) {
        Command cmd = new DeleteNestedConnectionsCommand((IDiagramModelArchimateObject) parent, childObjectsForDeletedConnections);
        command.add(cmd);
    }
    // We have some child objects so add the sub command
    if (!childObjectsForNewConnections.isEmpty()) {
        Command cmd = new CreateNestedArchimateConnectionsWithDialogCommand((IDiagramModelArchimateObject) parent, childObjectsForNewConnections);
        command.add(cmd);
    }
    return command.unwrap();
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) CreateNestedArchimateConnectionsWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand) Command(org.eclipse.gef.commands.Command) CreateNestedArchimateConnectionsWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateNestedArchimateConnectionsWithDialogCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) DeleteNestedConnectionsCommand(com.archimatetool.editor.diagram.commands.DeleteNestedConnectionsCommand) ArrayList(java.util.ArrayList) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) DeleteNestedConnectionsCommand(com.archimatetool.editor.diagram.commands.DeleteNestedConnectionsCommand) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 49 with IDiagramModelArchimateObject

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

the class NestedElementsChecker method findWrongNestedElements.

// Nested diagram elements without correct relationships
List<IIssue> findWrongNestedElements() {
    List<IIssue> issues = new ArrayList<IIssue>();
    for (IArchimateDiagramModel dm : fViews) {
        for (Iterator<EObject> iter = dm.eAllContents(); iter.hasNext(); ) {
            EObject eObject = iter.next();
            if (eObject instanceof IDiagramModelArchimateObject) {
                IDiagramModelArchimateObject parent = (IDiagramModelArchimateObject) eObject;
                for (IDiagramModelObject dmoChild : parent.getChildren()) {
                    if (dmoChild instanceof IDiagramModelArchimateObject) {
                        IDiagramModelArchimateObject child = (IDiagramModelArchimateObject) dmoChild;
                        if (isNestedWithoutValidRelation(parent, child)) {
                            String description = NLS.bind(fDescription, new Object[] { child.getName(), parent.getName() });
                            IIssue issue = new AdviceType(fName, description, fExplanation, child);
                            issues.add(issue);
                        }
                    }
                }
            }
        }
    }
    return issues;
}
Also used : AdviceType(com.archimatetool.hammer.validation.issues.AdviceType) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IIssue(com.archimatetool.hammer.validation.issues.IIssue) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel)

Example 50 with IDiagramModelArchimateObject

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

the class DuplicateCommandHandlerTests method testDuplicateDiagramModel_AddsConnectionsToConnections.

@Test
public void testDuplicateDiagramModel_AddsConnectionsToConnections() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    IDiagramModel dm = model.getDefaultDiagramModel();
    IArchimateElement element1 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(element1);
    dm.getChildren().add(dmo1);
    IArchimateElement element2 = IArchimateFactory.eINSTANCE.createBusinessRole();
    IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(element2);
    dm.getChildren().add(dmo2);
    IArchimateElement element3 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IDiagramModelArchimateObject dmo3 = tm.createDiagramModelArchimateObjectAndAddToModel(element3);
    dm.getChildren().add(dmo3);
    IArchimateRelationship relation1 = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
    relation1.setSource(element1);
    relation1.setTarget(element2);
    IDiagramModelArchimateConnection dmc1 = tm.createDiagramModelArchimateConnectionAndAddToModel(relation1);
    dmc1.connect(dmo1, dmo2);
    IArchimateRelationship relation2 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    relation2.setSource(element3);
    relation2.setTarget(relation1);
    IDiagramModelArchimateConnection dmc2 = tm.createDiagramModelArchimateConnectionAndAddToModel(relation2);
    dmc2.connect(dmo3, dmc1);
    DuplicateCommandHandler handler = new DuplicateCommandHandler(new Object[] { dm });
    handler.duplicate();
    IDiagramModel dmCopy = model.getDiagramModels().get(1);
    EList<IDiagramModelObject> children = dmCopy.getChildren();
    assertEquals(3, children.size());
    IDiagramModelArchimateObject dmo1Copy = (IDiagramModelArchimateObject) children.get(0);
    IDiagramModelArchimateObject dmo2Copy = (IDiagramModelArchimateObject) children.get(1);
    IDiagramModelArchimateObject dmo3Copy = (IDiagramModelArchimateObject) children.get(2);
    assertSame(element1, dmo1Copy.getArchimateConcept());
    assertSame(element2, dmo2Copy.getArchimateConcept());
    assertSame(element3, dmo3Copy.getArchimateConcept());
    IDiagramModelArchimateConnection dmc1Copy = (IDiagramModelArchimateConnection) dmo1Copy.getSourceConnections().get(0);
    assertSame(relation1, dmc1Copy.getArchimateConcept());
    assertSame(dmo2Copy, dmc1Copy.getTarget());
    // Connection to Connection
    assertSame(dmc1Copy, dmo3Copy.getSourceConnections().get(0).getTarget());
}
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) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

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