Search in sources :

Example 41 with IDiagramModelArchimateObject

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

the class ArchimateDiagramModelFactoryTests method testCreateDiagramModelArchimateObject.

@Test
public void testCreateDiagramModelArchimateObject() {
    IArchimateElement element = IArchimateFactory.eINSTANCE.createBusinessProcess();
    Preferences.STORE.setValue(IPreferenceConstants.DEFAULT_FIGURE_PREFIX + element.eClass().getName(), 1);
    Preferences.STORE.setValue(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR, true);
    Preferences.STORE.setValue(IPreferenceConstants.DEFAULT_FILL_COLOR_PREFIX + element.eClass().getName(), "#ededed");
    IDiagramModelArchimateObject dmo = ArchimateDiagramModelFactory.createDiagramModelArchimateObject(element);
    assertNotNull(dmo);
    assertEquals(element, dmo.getArchimateElement());
    assertEquals(1, dmo.getType());
    assertEquals("#ededed", dmo.getFillColor());
    Preferences.STORE.setToDefault(IPreferenceConstants.DEFAULT_FIGURE_PREFIX + element.eClass().getName());
    Preferences.STORE.setToDefault(IPreferenceConstants.SAVE_USER_DEFAULT_COLOR);
    Preferences.STORE.setToDefault(IPreferenceConstants.DEFAULT_FILL_COLOR_PREFIX + element.eClass().getName());
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) Test(org.junit.Test)

Example 42 with IDiagramModelArchimateObject

use of com.archimatetool.model.IDiagramModelArchimateObject 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 43 with IDiagramModelArchimateObject

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

the class CreateDiagramArchimateConnectionWithDialogCommandTests method testCreationOfConnectionAndRelationship.

@Test
public void testCreationOfConnectionAndRelationship() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(IArchimateFactory.eINSTANCE.createBusinessActor());
    IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(IArchimateFactory.eINSTANCE.createBusinessRole());
    model.getDefaultDiagramModel().getChildren().add(dmo1);
    model.getDefaultDiagramModel().getChildren().add(dmo2);
    cmd.setSource(dmo1);
    cmd.setTarget(dmo2);
    cmd.execute();
    IDiagramModelConnection connection = cmd.fConnection;
    assertTrue(connection instanceof IDiagramModelArchimateConnection);
    assertSame(dmo1, connection.getSource());
    assertSame(dmo2, connection.getTarget());
    IArchimateRelationship relationship = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship();
    assertTrue(relationship instanceof IAssignmentRelationship);
    assertNotNull(relationship.eContainer());
    cmd.undo();
    assertNull(relationship.eContainer());
}
Also used : IAssignmentRelationship(com.archimatetool.model.IAssignmentRelationship) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 44 with IDiagramModelArchimateObject

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

the class ArchimateDiagramEditPartFactoryTests method testArchimateObjectEditPart.

@Test
public void testArchimateObjectEditPart() {
    IArchimateElement element = IArchimateFactory.eINSTANCE.createBusinessActor();
    IDiagramModelArchimateObject dmo = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo.setArchimateElement(element);
    EditPart editPart = editPartFactory.createEditPart(null, dmo);
    assertTrue(editPart instanceof ArchimateElementEditPart);
    assertEquals(dmo, editPart.getModel());
}
Also used : GroupEditPart(com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart) NoteEditPart(com.archimatetool.editor.diagram.editparts.diagram.NoteEditPart) EditPart(org.eclipse.gef.EditPart) EmptyEditPart(com.archimatetool.editor.diagram.editparts.diagram.EmptyEditPart) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) Test(org.junit.Test)

Example 45 with IDiagramModelArchimateObject

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

the class CopySnapshot method createPasteObject.

private IDiagramModelObject createPasteObject(IDiagramModelContainer container, IDiagramModelObject snapshotObject) {
    // Don't paste invalid objects
    if (!isValidPasteComponent(fTargetDiagramModel, snapshotObject)) {
        return null;
    }
    IDiagramModelObject pasteObject = (IDiagramModelObject) snapshotObject.getCopy();
    createID(pasteObject);
    // Offset top level objects if container is diagram
    if (container instanceof IDiagramModel) {
        IDiagramModelObject originalObject = (IDiagramModelObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
        IBounds bounds = originalObject.getBounds().getCopy();
        Point pt = new Point(bounds.getX(), bounds.getY());
        translateToAbsolute(originalObject, pt);
        bounds.setX(pt.x + fXOffSet);
        bounds.setY(pt.y + fYOffSet);
        pasteObject.setBounds(bounds);
    }
    // If Archimate object
    if (pasteObject instanceof IDiagramModelArchimateObject) {
        IDiagramModelArchimateObject dmo = (IDiagramModelArchimateObject) pasteObject;
        // Re-use original ArchiMate components
        if (!fDoCreateNewArchimateComponents) {
            IDiagramModelArchimateObject originalDiagramObject = (IDiagramModelArchimateObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
            IArchimateElement element = originalDiagramObject.getArchimateElement();
            dmo.setArchimateElement(element);
        }
        // Provide new names if required
        if (fDoCreateNewArchimateComponents && isSourceAndTargetArchiMateModelSame()) {
            String name = dmo.getArchimateElement().getName();
            // $NON-NLS-1$
            dmo.getArchimateElement().setName(name + " " + Messages.CopySnapshot_1);
        }
    }
    // Add to Mapping
    fSnapshotToNewComponentMapping.put(snapshotObject, pasteObject);
    // Object is Container, so recurse
    if (snapshotObject instanceof IDiagramModelContainer) {
        for (IDiagramModelObject child : ((IDiagramModelContainer) snapshotObject).getChildren()) {
            IDiagramModelObject dmo = createPasteObject((IDiagramModelContainer) pasteObject, child);
            if (dmo != null) {
                ((IDiagramModelContainer) pasteObject).getChildren().add(dmo);
            }
        }
    }
    return pasteObject;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IBounds(com.archimatetool.model.IBounds) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Point(org.eclipse.draw2d.geometry.Point) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

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