Search in sources :

Example 16 with ScrollingGraphicalViewer

use of org.eclipse.gef.ui.parts.ScrollingGraphicalViewer in project dbeaver by serge-rider.

the class LockGraphicalView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    setEditDomain(new DefaultEditDomain(null));
    setGraphicalViewer(new ScrollingGraphicalViewer());
    getGraphicalViewer().createControl(parent);
    getGraphicalViewer().setRootEditPart(new FreeformGraphicalRootEditPart());
    getGraphicalViewer().setEditPartFactory(new LockGraphEditPartFactory());
    getGraphicalViewer().setContextMenu(new ContextMenuProvider(graphicalViewer) {

        @Override
        public void buildContextMenu(IMenuManager menu) {
            menu.add(viewer.getKillAction());
        }
    });
}
Also used : ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) FreeformGraphicalRootEditPart(org.eclipse.gef.editparts.FreeformGraphicalRootEditPart) IMenuManager(org.eclipse.jface.action.IMenuManager) DefaultEditDomain(org.eclipse.gef.DefaultEditDomain) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider)

Example 17 with ScrollingGraphicalViewer

use of org.eclipse.gef.ui.parts.ScrollingGraphicalViewer in project yamcs-studio by yamcs.

the class OPIEditor method configureGraphicalViewer.

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

        @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.
    var 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
    var 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) GraphicalViewerKeyHandler(org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler) PatchedConnectionLayerClippingStrategy(org.csstudio.opibuilder.runmode.PatchedConnectionLayerClippingStrategy)

Example 18 with ScrollingGraphicalViewer

use of org.eclipse.gef.ui.parts.ScrollingGraphicalViewer in project dbeaver by dbeaver.

the class LockGraphicalView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    setEditDomain(new DefaultEditDomain(null));
    setGraphicalViewer(new ScrollingGraphicalViewer());
    getGraphicalViewer().createControl(parent);
    getGraphicalViewer().setRootEditPart(new FreeformGraphicalRootEditPart());
    getGraphicalViewer().setEditPartFactory(new LockGraphEditPartFactory());
    getGraphicalViewer().setContextMenu(new ContextMenuProvider(graphicalViewer) {

        @Override
        public void buildContextMenu(IMenuManager menu) {
            menu.add(viewer.getKillAction());
        }
    });
}
Also used : ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) FreeformGraphicalRootEditPart(org.eclipse.gef.editparts.FreeformGraphicalRootEditPart) IMenuManager(org.eclipse.jface.action.IMenuManager) DefaultEditDomain(org.eclipse.gef.DefaultEditDomain) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider)

Aggregations

ScrollingGraphicalViewer (org.eclipse.gef.ui.parts.ScrollingGraphicalViewer)18 ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)6 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)5 GraphicalViewerKeyHandler (org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler)5 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)4 Dimension (org.eclipse.draw2d.geometry.Dimension)3 ToggleGridAction (org.eclipse.gef.ui.actions.ToggleGridAction)3 ToggleSnapToGeometryAction (org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction)3 IAction (org.eclipse.jface.action.IAction)3 ArrayList (java.util.ArrayList)2 ConnectionLayer (org.eclipse.draw2d.ConnectionLayer)2 FigureCanvas (org.eclipse.draw2d.FigureCanvas)2 DefaultEditDomain (org.eclipse.gef.DefaultEditDomain)2 GraphicalViewer (org.eclipse.gef.GraphicalViewer)2 FreeformGraphicalRootEditPart (org.eclipse.gef.editparts.FreeformGraphicalRootEditPart)2 ZoomInAction (org.eclipse.gef.ui.actions.ZoomInAction)2 ZoomOutAction (org.eclipse.gef.ui.actions.ZoomOutAction)2 IMenuManager (org.eclipse.jface.action.IMenuManager)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2