Search in sources :

Example 21 with ScalableFreeformRootEditPart

use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project yamcs-studio by yamcs.

the class OPIEditor method getDisplayCenterPosition.

/**
 * Returns the Point, which is the center of the Display.
 *
 * @return Point The Point, which is the center of the Display
 */
public Point getDisplayCenterPosition() {
    ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) getGraphicalViewer().getRootEditPart();
    ZoomManager m = root.getZoomManager();
    Point center = m.getViewport().getBounds().getCenter();
    Rectangle x = new Rectangle(center.x, center.y, 10, 10);
    x.translate(m.getViewport().getViewLocation());
    m.getScalableFigure().translateFromParent(x);
    Point result = x.getLocation();
    return result;
}
Also used : ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

Example 22 with ScalableFreeformRootEditPart

use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project yamcs-studio by yamcs.

the class OPIEditor method configureGraphicalViewer.

@Override
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    ScrollingGraphicalViewer viewer = (ScrollingGraphicalViewer) getGraphicalViewer();
    viewer.setEditPartFactory(new WidgetEditPartFactory(ExecutionMode.EDIT_MODE));
    ScalableFreeformRootEditPart root = new ScalableFreeformRootEditPart() {

        /**
         * {@inheritDoc}
         */
        @Override
        public Object getAdapter(@SuppressWarnings("rawtypes") final Class key) {
            if (key == AutoexposeHelper.class) {
                return new ViewportAutoexposeHelper(this);
            }
            return super.getAdapter(key);
        }
    };
    // set clipping strategy for connection layer of connection can be hide
    // when its source or target is not showing.
    ConnectionLayer connectionLayer = (ConnectionLayer) root.getLayer(LayerConstants.CONNECTION_LAYER);
    connectionLayer.setClippingStrategy(new PatchedConnectionLayerClippingStrategy(connectionLayer));
    viewer.setRootEditPart(root);
    viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer).setParent(getCommonKeyHandler()));
    ContextMenuProvider cmProvider = new OPIEditorContextMenuProvider(viewer, getActionRegistry());
    viewer.setContextMenu(cmProvider);
    getSite().registerContextMenu(cmProvider, viewer);
    // Grid Action
    IAction action = new ToggleGridAction(getGraphicalViewer()) {

        @Override
        public boolean isChecked() {
            return getDisplayModel().isShowGrid();
        }

        @Override
        public void run() {
            getCommandStack().execute(new SetWidgetPropertyCommand(displayModel, DisplayModel.PROP_SHOW_GRID, !isChecked()));
        }
    };
    getActionRegistry().registerAction(action);
    // Ruler Action
    configureRuler();
    action = new ToggleRulerVisibilityAction(getGraphicalViewer()) {

        @Override
        public boolean isChecked() {
            return getDisplayModel().isShowRuler();
        }

        @Override
        public void run() {
            getCommandStack().execute(new SetWidgetPropertyCommand(displayModel, DisplayModel.PROP_SHOW_RULER, !isChecked()));
        }
    };
    getActionRegistry().registerAction(action);
    // Snap to Geometry Action
    IAction geometryAction = new ToggleSnapToGeometryAction(getGraphicalViewer()) {

        @Override
        public boolean isChecked() {
            return getDisplayModel().isSnapToGeometry();
        }

        @Override
        public void run() {
            getCommandStack().execute(new SetWidgetPropertyCommand(displayModel, DisplayModel.PROP_SNAP_GEOMETRY, !isChecked()));
        }
    };
    getActionRegistry().registerAction(geometryAction);
    // configure zoom actions
    ZoomManager zm = root.getZoomManager();
    if (zm != null) {
        List<String> zoomLevels = new ArrayList<>(3);
        zoomLevels.add(ZoomManager.FIT_ALL);
        zoomLevels.add(ZoomManager.FIT_WIDTH);
        zoomLevels.add(ZoomManager.FIT_HEIGHT);
        zm.setZoomLevelContributions(zoomLevels);
        zm.setZoomLevels(createZoomLevels());
        IAction zoomIn = new ZoomInAction(zm);
        IAction zoomOut = new ZoomOutAction(zm);
        getActionRegistry().registerAction(zoomIn);
        getActionRegistry().registerAction(zoomOut);
    }
    /* scroll-wheel zoom */
    getGraphicalViewer().setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON);
    // status line listener
    getGraphicalViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        private IStatusLineManager statusLine = ((ActionBarContributor) getEditorSite().getActionBarContributor()).getActionBars().getStatusLineManager();

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateStatusLine(statusLine);
        }
    });
}
Also used : ToggleSnapToGeometryAction(org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction) WidgetEditPartFactory(org.csstudio.opibuilder.editparts.WidgetEditPartFactory) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ViewportAutoexposeHelper(org.eclipse.gef.editparts.ViewportAutoexposeHelper) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) IAction(org.eclipse.jface.action.IAction) RunOPIAction(org.csstudio.opibuilder.actions.RunOPIAction) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) ToggleGridAction(org.eclipse.gef.ui.actions.ToggleGridAction) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ToggleRulerVisibilityAction(org.eclipse.gef.ui.actions.ToggleRulerVisibilityAction) ConnectionLayer(org.eclipse.draw2d.ConnectionLayer) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) GraphicalViewerKeyHandler(org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler) PatchedConnectionLayerClippingStrategy(org.csstudio.opibuilder.runmode.PatchedConnectionLayerClippingStrategy)

Example 23 with ScalableFreeformRootEditPart

use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project archi by archimatetool.

the class CanvasEditor method createRootEditPart.

@Override
protected void createRootEditPart(GraphicalViewer viewer) {
    /*
         * We'll have a Zoom Manager using ScalableFreeformRootEditPart
         */
    RootEditPart rootPart = new ScalableFreeformRootEditPart() {

        @SuppressWarnings("rawtypes")
        @Override
        public Object getAdapter(Class adapter) {
            if (adapter == AutoexposeHelper.class) {
                return new ExtendedViewportAutoexposeHelper(this, new Insets(50), false);
            }
            return super.getAdapter(adapter);
        }
    };
    viewer.setRootEditPart(rootPart);
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) ExtendedViewportAutoexposeHelper(com.archimatetool.editor.diagram.util.ExtendedViewportAutoexposeHelper) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart)

Example 24 with ScalableFreeformRootEditPart

use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project archi by archimatetool.

the class SketchEditor method createRootEditPart.

@Override
protected void createRootEditPart(GraphicalViewer viewer) {
    /*
         * We'll have a Zoom Manager and a background image
         */
    RootEditPart rootPart = new ScalableFreeformRootEditPart() {

        @Override
        protected ScalableFreeformLayeredPane createScaledLayers() {
            // Insert Background Image behind Grid
            // Note - background image is not on a Printable Layer, so won't print!
            fScalableFreeformLayeredPane = super.createScaledLayers();
            updateBackgroundImage();
            return fScalableFreeformLayeredPane;
        }

        @SuppressWarnings("rawtypes")
        @Override
        public Object getAdapter(Class adapter) {
            if (adapter == AutoexposeHelper.class) {
                return new ExtendedViewportAutoexposeHelper(this, new Insets(50), false);
            }
            return super.getAdapter(adapter);
        }
    };
    viewer.setRootEditPart(rootPart);
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) ExtendedViewportAutoexposeHelper(com.archimatetool.editor.diagram.util.ExtendedViewportAutoexposeHelper) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart)

Example 25 with ScalableFreeformRootEditPart

use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project jbosstools-hibernate by jbosstools.

the class DiagramContentOutlinePage method initializeOverview.

/**
 */
protected void initializeOverview() {
    LightweightSystem lws = new LightweightSystem(overview);
    RootEditPart rep = getGraphicalViewer().getRootEditPart();
    if (rep instanceof ScalableFreeformRootEditPart) {
        ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
        if (this.thumbnail != null) {
            this.thumbnail.deactivate();
        }
        thumbnail = new ScrollableThumbnail((Viewport) root.getFigure());
        thumbnail.setBorder(new MarginBorder(3));
        thumbnail.setSource(root.getLayer(LayerConstants.PRINTABLE_LAYERS));
        lws.setContents(thumbnail);
    }
}
Also used : ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) MarginBorder(org.eclipse.draw2d.MarginBorder) Viewport(org.eclipse.draw2d.Viewport) LightweightSystem(org.eclipse.draw2d.LightweightSystem) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ScrollableThumbnail(org.eclipse.draw2d.parts.ScrollableThumbnail)

Aggregations

ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)25 Viewport (org.eclipse.draw2d.Viewport)6 Point (org.eclipse.draw2d.geometry.Point)6 Rectangle (org.eclipse.draw2d.geometry.Rectangle)6 RootEditPart (org.eclipse.gef.RootEditPart)6 GraphicalViewerKeyHandler (org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler)5 ScrollingGraphicalViewer (org.eclipse.gef.ui.parts.ScrollingGraphicalViewer)5 ZoomManager (org.eclipse.gef.editparts.ZoomManager)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 EditPart (org.eclipse.gef.EditPart)3 ExtendedViewportAutoexposeHelper (com.archimatetool.editor.diagram.util.ExtendedViewportAutoexposeHelper)2 IPath (org.eclipse.core.runtime.IPath)2 IFigure (org.eclipse.draw2d.IFigure)2 Insets (org.eclipse.draw2d.geometry.Insets)2 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)2 ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)2 GraphicalViewer (org.eclipse.gef.GraphicalViewer)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 SaveAsDialog (org.eclipse.ui.dialogs.SaveAsDialog)2