Search in sources :

Example 36 with IDiagramModel

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

the class SketchDNDEditPolicy method getDropCommand.

@Override
protected Command getDropCommand(DiagramDropRequest request) {
    if (!(request.getData() instanceof IStructuredSelection)) {
        return null;
    }
    // XY drop point
    Point pt = getDropLocation(request);
    // Origin
    int origin = pt.x;
    int x = pt.x;
    int y = pt.y;
    // Gather an actual list of elements dragged onto the container, omitting duplicates and anything already on the diagram
    Object[] objects = ((IStructuredSelection) request.getData()).toArray();
    List<IDiagramModel> list = getDiagramRefsToAdd(objects);
    // Compound Command
    CompoundCommand result = new CompoundCommand(Messages.SketchDNDEditPolicy_0);
    for (IDiagramModel diagramModel : list) {
        result.add(new AddDiagramModelReferenceCommand(getTargetContainer(), diagramModel, x, y));
        x += 150;
        if (x > origin + 400) {
            x = origin;
            y += 100;
        }
    }
    return result;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.draw2d.geometry.Point) AddDiagramModelReferenceCommand(com.archimatetool.editor.diagram.commands.AddDiagramModelReferenceCommand) Point(org.eclipse.draw2d.geometry.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 37 with IDiagramModel

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

the class DiagramUtilsTests method testCreateImage_Model_Scaled.

@Test
public void testCreateImage_Model_Scaled() {
    IDiagramModel dm = model.getDiagramModels().get(2);
    // x of furthest object in diagram, and its width
    int width = 720 + 193;
    // x of furthest object in diagram, and its height
    int height = 468 + 85;
    Image img = DiagramUtils.createImage(dm, 1, 0);
    assertEquals(new Rectangle(0, 0, width, height), img.getBounds());
    img.dispose();
    img = DiagramUtils.createImage(dm, 0.5, 0);
    assertEquals(new Rectangle(0, 0, width / 2, height / 2), img.getBounds());
    img.dispose();
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) Test(org.junit.Test)

Example 38 with IDiagramModel

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

the class DiagramUtilsTests method testCreateViewer_SketchModel.

@Test
public void testCreateViewer_SketchModel() {
    IDiagramModel dm = model.getDiagramModels().get(1);
    assertTrue(dm instanceof ISketchModel);
    Shell shell = new Shell();
    GraphicalViewerImpl viewer = DiagramUtils.createViewer(dm, shell);
    assertNotNull(viewer);
    assertTrue(viewer.getEditPartFactory() instanceof SketchEditPartFactory);
    assertTrue(viewer.getRootEditPart() instanceof FreeformGraphicalRootEditPart);
    assertSame(dm, viewer.getContents().getModel());
    assertSame(shell, viewer.getControl().getShell());
    shell.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IDiagramModel(com.archimatetool.model.IDiagramModel) GraphicalViewerImpl(org.eclipse.gef.ui.parts.GraphicalViewerImpl) SketchEditPartFactory(com.archimatetool.editor.diagram.sketch.editparts.SketchEditPartFactory) FreeformGraphicalRootEditPart(org.eclipse.gef.editparts.FreeformGraphicalRootEditPart) ISketchModel(com.archimatetool.model.ISketchModel) Test(org.junit.Test)

Example 39 with IDiagramModel

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

the class DiagramUtilsTests method testCreateImage_GraphicalViewer.

@Test
public void testCreateImage_GraphicalViewer() {
    IDiagramModel dm = model.getDiagramModels().get(2);
    Shell shell = new Shell();
    GraphicalViewerImpl viewer = DiagramUtils.createViewer(dm, shell);
    shell.dispose();
    Image img = DiagramUtils.createImage(viewer, 1, 0);
    assertNotNull(img);
    img.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IDiagramModel(com.archimatetool.model.IDiagramModel) GraphicalViewerImpl(org.eclipse.gef.ui.parts.GraphicalViewerImpl) Image(org.eclipse.swt.graphics.Image) Test(org.junit.Test)

Example 40 with IDiagramModel

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

the class DiagramUtilsTests method testCreateImage_Model_NoChildren.

@Test
public void testCreateImage_Model_NoChildren() {
    // This is the blank View
    IDiagramModel dm = model.getDiagramModels().get(0);
    Image img = DiagramUtils.createImage(dm, 1, 0);
    // Blank View is minimum 100 x 100
    assertEquals(new Rectangle(0, 0, 100, 100), img.getBounds());
    img.dispose();
    // Margin will not be used for Blank View
    img = DiagramUtils.createImage(dm, 1, 20);
    assertEquals(new Rectangle(0, 0, 100, 100), img.getBounds());
    img.dispose();
    // Margin & Ratio
    img = DiagramUtils.createImage(dm, 0.2, 0);
    assertEquals(new Rectangle(0, 0, 20, 20), img.getBounds());
    img.dispose();
    img = DiagramUtils.createImage(dm, 0.5, 10);
    assertEquals(new Rectangle(0, 0, 50, 50), img.getBounds());
    img.dispose();
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) Test(org.junit.Test)

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