Search in sources :

Example 11 with IDiagramModelComponent

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

the class MyImporter method createAndAddConnectionsToView.

protected void createAndAddConnectionsToView(IDiagramModel diagramModel, IArchimateRelationship relationship) {
    List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship.getSource());
    List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship.getTarget());
    for (IDiagramModelComponent dmcSource : sources) {
        for (IDiagramModelComponent dmcTarget : targets) {
            IDiagramModelArchimateConnection dmc = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
            dmc.setArchimateRelationship(relationship);
            dmc.connect((IDiagramModelObject) dmcSource, (IDiagramModelObject) dmcTarget);
            idLookup.put(dmc.getId(), dmc);
        }
    }
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent)

Example 12 with IDiagramModelComponent

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

the class CopySnapshotTests method testNestedConnectionIsCopied.

@Test
public void testNestedConnectionIsCopied() throws IOException {
    loadTestModel1();
    // Create parent object
    IDiagramModelArchimateObject dmoParent = ArchimateTestModel.createDiagramModelArchimateObject(IArchimateFactory.eINSTANCE.createBusinessActor());
    dmoParent.setBounds(0, 0, 200, 200);
    sourceDiagramModel.getChildren().add(dmoParent);
    // Create child object
    IDiagramModelArchimateObject dmoChild = ArchimateTestModel.createDiagramModelArchimateObject(IArchimateFactory.eINSTANCE.createBusinessRole());
    dmoChild.setBounds(0, 0, 100, 100);
    dmoParent.getChildren().add(dmoChild);
    // Create relationship
    IArchimateRelationship relationship = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
    relationship.setSource(dmoParent.getArchimateElement());
    relationship.setTarget(dmoChild.getArchimateElement());
    // Test that an explicit connection is copied
    // Create connection
    IDiagramModelArchimateConnection connection = ArchimateTestModel.createDiagramModelArchimateConnection(relationship);
    connection.connect(dmoParent, dmoChild);
    List<IDiagramModelComponent> selected = new ArrayList<IDiagramModelComponent>();
    selected.add(dmoParent);
    CopySnapshot snapshot = new CopySnapshot(selected);
    Command cmd = snapshot.getPasteCommand(targetDiagramModel, null, null, false);
    assertNotNull(cmd);
    cmd.execute();
    assertEquals(1, countAllConnections(targetDiagramModel));
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) Command(org.eclipse.gef.commands.Command) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) Test(org.junit.Test)

Example 13 with IDiagramModelComponent

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

the class CopySnapshotTests method testDiagramCopyContainsAllConnectionsAndObjects.

@Test
public void testDiagramCopyContainsAllConnectionsAndObjects() throws IOException {
    loadTestModel2();
    List<IDiagramModelComponent> selected = new ArrayList<IDiagramModelComponent>();
    // Select all
    selected.addAll(getAllDiagramComponents(sourceDiagramModel));
    CopySnapshot snapshot = new CopySnapshot(selected);
    assertTrue(snapshot.canPasteToDiagram(targetDiagramModel));
    Command cmd = snapshot.getPasteCommand(targetDiagramModel, mock(GraphicalViewer.class), null, false);
    assertTrue(cmd.canExecute());
    cmd.execute();
    // Same number of objects pasted
    assertEquals(8, countAllObjects(sourceDiagramModel));
    assertEquals(countAllObjects(sourceDiagramModel), countAllObjects(targetDiagramModel));
    // Same number of connections pasted
    assertEquals(11, countAllConnections(sourceDiagramModel));
    assertEquals(countAllConnections(sourceDiagramModel), countAllConnections(targetDiagramModel));
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) GraphicalViewer(org.eclipse.gef.GraphicalViewer) Command(org.eclipse.gef.commands.Command) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with IDiagramModelComponent

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

the class ArchimateDiagramEditor method selectArchimateConcepts.

@Override
public void selectArchimateConcepts(IArchimateConcept[] archimateConcepts) {
    List<Object> objects = new ArrayList<Object>();
    for (IArchimateConcept archimateConcept : archimateConcepts) {
        // Find Diagram Concepts
        for (IDiagramModelComponent dc : DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getModel(), archimateConcept)) {
            if (!objects.contains(dc)) {
                objects.add(dc);
            }
        }
    }
    selectObjects(objects.toArray());
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) ArrayList(java.util.ArrayList) IArchimateConcept(com.archimatetool.model.IArchimateConcept)

Example 15 with IDiagramModelComponent

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

the class CopyAction method run.

@Override
public void run() {
    List<IDiagramModelComponent> selected = new ArrayList<IDiagramModelComponent>();
    for (Object object : getSelectedObjects()) {
        if (object instanceof EditPart) {
            Object model = ((EditPart) object).getModel();
            if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                continue;
            }
            if (model instanceof IDiagramModelComponent) {
                selected.add((IDiagramModelComponent) model);
            }
        }
    }
    CopySnapshot clipBoardCopy = new CopySnapshot(selected);
    Clipboard.getDefault().setContents(clipBoardCopy);
    // Reset Paste Action
    fPasteAction.reset();
}
Also used : IDiagramModelComponent(com.archimatetool.model.IDiagramModelComponent) ArrayList(java.util.ArrayList) EditPart(org.eclipse.gef.EditPart) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) ILockable(com.archimatetool.model.ILockable)

Aggregations

IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)18 ArrayList (java.util.ArrayList)13 Command (org.eclipse.gef.commands.Command)7 Test (org.junit.Test)6 IArchimateConcept (com.archimatetool.model.IArchimateConcept)5 IDiagramModel (com.archimatetool.model.IDiagramModel)5 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)5 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)5 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)4 EObject (org.eclipse.emf.ecore.EObject)4 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)3 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)3 EditPart (org.eclipse.gef.EditPart)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)2 IArchimateElement (com.archimatetool.model.IArchimateElement)2 IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)2 Point (org.eclipse.draw2d.geometry.Point)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IArchimateDiagramEditor (com.archimatetool.editor.diagram.IArchimateDiagramEditor)1