Search in sources :

Example 1 with GraphicalViewerImpl

use of org.eclipse.gef.ui.parts.GraphicalViewerImpl in project archi by archimatetool.

the class DiagramUtilsTests method testGetDiagramExtents_WithConnections.

@Test
public void testGetDiagramExtents_WithConnections() {
    IDiagramModel dm = model.getDiagramModels().get(3);
    Shell shell = new Shell();
    GraphicalViewerImpl viewer = DiagramUtils.createViewer(dm, shell);
    shell.dispose();
    org.eclipse.draw2d.geometry.Rectangle rect = DiagramUtils.getDiagramExtents(viewer);
    assertEquals(new org.eclipse.draw2d.geometry.Rectangle(12, 24, 587, 323), rect);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IDiagramModel(com.archimatetool.model.IDiagramModel) GraphicalViewerImpl(org.eclipse.gef.ui.parts.GraphicalViewerImpl) Test(org.junit.Test)

Example 2 with GraphicalViewerImpl

use of org.eclipse.gef.ui.parts.GraphicalViewerImpl in project archi by archimatetool.

the class DiagramUtilsTests method testGetDiagram_IsMinimumSize.

@Test
public void testGetDiagram_IsMinimumSize() {
    IDiagramModel dm = model.getDiagramModels().get(0);
    Shell shell = new Shell();
    GraphicalViewerImpl viewer = DiagramUtils.createViewer(dm, shell);
    shell.dispose();
    org.eclipse.draw2d.geometry.Rectangle rect = DiagramUtils.getDiagramExtents(viewer);
    assertEquals(new org.eclipse.draw2d.geometry.Rectangle(0, 0, 100, 100), rect);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IDiagramModel(com.archimatetool.model.IDiagramModel) GraphicalViewerImpl(org.eclipse.gef.ui.parts.GraphicalViewerImpl) Test(org.junit.Test)

Example 3 with GraphicalViewerImpl

use of org.eclipse.gef.ui.parts.GraphicalViewerImpl in project archi by archimatetool.

the class DiagramUtils method createViewer.

/**
 * Create a GraphicalViewerImpl to show the model. The Viewer has no Scroll Bars
 * @param model
 * @return A Graphical Viewer
 */
public static GraphicalViewerImpl createViewer(IDiagramModel model, Composite parent) {
    EditPartFactory editPartFactory = null;
    if (model instanceof IArchimateDiagramModel) {
        editPartFactory = new ArchimateDiagramEditPartFactory();
    } else if (model instanceof ISketchModel) {
        editPartFactory = new SketchEditPartFactory();
    } else {
        // Extensions
        IDiagramEditorFactory factory = DiagramEditorFactoryExtensionHandler.INSTANCE.getFactory(model);
        if (factory != null) {
            editPartFactory = factory.createEditPartFactory();
        }
    }
    if (editPartFactory == null) {
        // $NON-NLS-1$
        throw new RuntimeException("Unsupported model type");
    }
    GraphicalViewerImpl viewer = new GraphicalViewerImpl();
    viewer.createControl(parent);
    viewer.setEditPartFactory(editPartFactory);
    RootEditPart rootPart = new FreeformGraphicalRootEditPart();
    viewer.setRootEditPart(rootPart);
    viewer.setContents(model);
    viewer.flush();
    return viewer;
}
Also used : IDiagramEditorFactory(com.archimatetool.editor.diagram.IDiagramEditorFactory) ArchimateDiagramEditPartFactory(com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory) GraphicalViewerImpl(org.eclipse.gef.ui.parts.GraphicalViewerImpl) SketchEditPartFactory(com.archimatetool.editor.diagram.sketch.editparts.SketchEditPartFactory) SketchEditPartFactory(com.archimatetool.editor.diagram.sketch.editparts.SketchEditPartFactory) EditPartFactory(org.eclipse.gef.EditPartFactory) ArchimateDiagramEditPartFactory(com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory) FreeformGraphicalRootEditPart(org.eclipse.gef.editparts.FreeformGraphicalRootEditPart) ISketchModel(com.archimatetool.model.ISketchModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) RootEditPart(org.eclipse.gef.RootEditPart) FreeformGraphicalRootEditPart(org.eclipse.gef.editparts.FreeformGraphicalRootEditPart)

Example 4 with GraphicalViewerImpl

use of org.eclipse.gef.ui.parts.GraphicalViewerImpl 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 5 with GraphicalViewerImpl

use of org.eclipse.gef.ui.parts.GraphicalViewerImpl 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)

Aggregations

GraphicalViewerImpl (org.eclipse.gef.ui.parts.GraphicalViewerImpl)8 IDiagramModel (com.archimatetool.model.IDiagramModel)6 Shell (org.eclipse.swt.widgets.Shell)6 Test (org.junit.Test)6 FreeformGraphicalRootEditPart (org.eclipse.gef.editparts.FreeformGraphicalRootEditPart)3 ArchimateDiagramEditPartFactory (com.archimatetool.editor.diagram.editparts.ArchimateDiagramEditPartFactory)2 SketchEditPartFactory (com.archimatetool.editor.diagram.sketch.editparts.SketchEditPartFactory)2 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)2 ISketchModel (com.archimatetool.model.ISketchModel)2 IDiagramEditorFactory (com.archimatetool.editor.diagram.IDiagramEditorFactory)1 EditPartFactory (org.eclipse.gef.EditPartFactory)1 GraphicalViewer (org.eclipse.gef.GraphicalViewer)1 RootEditPart (org.eclipse.gef.RootEditPart)1 Image (org.eclipse.swt.graphics.Image)1