Search in sources :

Example 1 with WidgetEditPartFactory

use of org.csstudio.opibuilder.editparts.WidgetEditPartFactory in project yamcs-studio by yamcs.

the class OPIRuntimeDelegate method createGUI.

public void createGUI(Composite parent) {
    viewer = new PatchedScrollingGraphicalViewer();
    if (displayModel != null) {
        displayModel.setOpiRuntime(opiRuntime);
        displayModel.setViewer(viewer);
    }
    ScalableFreeformRootEditPart root = new PatchedScalableFreeformRootEditPart() {

        // In Run mode, clicking the Display or container should de-select
        // all widgets.
        @Override
        public DragTracker getDragTracker(Request req) {
            return new DragEditPartsTracker(this);
        }

        @Override
        public boolean isSelectable() {
            return false;
        }
    };
    // 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.createControl(parent);
    viewer.setRootEditPart(root);
    viewer.setEditPartFactory(new WidgetEditPartFactory(ExecutionMode.RUN_MODE, site));
    // viewer.addDropTargetListener(new
    // ProcessVariableNameTransferDropPVTargetListener(viewer));
    // viewer.addDropTargetListener(new
    // TextTransferDropPVTargetListener(viewer));
    // Add drag listener will make click feel stagnant.
    // viewer.addDragSourceListener(new DragPVSourceListener(viewer));
    // this will make viewer as a selection provider
    EditDomain editDomain = new EditDomain() {

        @Override
        public void loadDefaultTool() {
            setActiveTool(new RuntimePatchedSelectionTool());
        }
    };
    editDomain.addViewer(viewer);
    // connect the CSS menu
    ContextMenuProvider cmProvider = new OPIRunnerContextMenuProvider(viewer, opiRuntime);
    viewer.setContextMenu(cmProvider);
    opiRuntime.getSite().registerContextMenu(cmProvider, viewer);
    if (displayModelFilled) {
        viewer.setContents(displayModel);
        displayModel.setViewer(viewer);
        displayModel.setOpiRuntime(opiRuntime);
        updateEditorTitle();
    }
    zoomManager = root.getZoomManager();
    if (zoomManager != null) {
        List<String> zoomLevels = new ArrayList<>(3);
        zoomLevels.add(Draw2dSingletonUtil.ZoomManager_FIT_ALL);
        zoomLevels.add(Draw2dSingletonUtil.ZoomManager_FIT_WIDTH);
        zoomLevels.add(Draw2dSingletonUtil.ZoomManager_FIT_HEIGHT);
        zoomManager.setZoomLevelContributions(zoomLevels);
        zoomManager.setZoomLevels(createZoomLevels());
    // IAction zoomIn = new ZoomInAction(zoomManager);
    // IAction zoomOut = new ZoomOutAction(zoomManager);
    // getActionRegistry().registerAction(zoomIn);
    // getActionRegistry().registerAction(zoomOut);
    }
    /* scroll-wheel zoom */
    viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON);
    /*
         * When Figure instance which corresponds to RootEditPart is updated, calculate the frame rate and set the
         * measured rate to "frame_rate" property of the corresponding DisplayModel instance.
         *
         * By default, org.eclipse.draw2d.DeferredUpdateManager is used. This update manager queues update requests from
         * figures and others, and it repaints requested figures at once when GUI thread is ready to repaint.
         * notifyPainting() method of UpdateLister is called when it repaints. The frame rate is calculated based on the
         * timing of notifyPainting().
         *
         * Note that the update manager repaints only requested figures. It does not repaint all figures at once. For
         * example, if there are only two widgets in one display, these widgets might be repainted alternately. In that
         * case, the frame rate indicates the inverse of the time between the repainting of one widget and the
         * repainting of the other widget, which is different from our intuition. Thus, you have to be careful about the
         * meaning of "frame rate" calculated by the following code.
         */
    if (displayModelFilled && displayModel.isFreshRateEnabled()) {
        var updateManager = root.getFigure().getUpdateManager();
        updateManager.addUpdateListener(new UpdateListener() {

            // in milliseconds
            private long updateCycle = -1;

            private Date previousDate = null;

            @Override
            public void notifyPainting(Rectangle damage, @SuppressWarnings("rawtypes") Map dirtyRegions) {
                var currentDate = new Date();
                if (previousDate == null) {
                    previousDate = currentDate;
                    return;
                }
                synchronized (previousDate) {
                    updateCycle = currentDate.getTime() - previousDate.getTime();
                    displayModel.setFrameRate(1000.0 / updateCycle);
                    previousDate = currentDate;
                }
            }

            @Override
            public void notifyValidating() {
            // Do nothing
            }
        });
    }
}
Also used : EditDomain(org.eclipse.gef.EditDomain) WidgetEditPartFactory(org.csstudio.opibuilder.editparts.WidgetEditPartFactory) Request(org.eclipse.gef.Request) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DragEditPartsTracker(org.eclipse.gef.tools.DragEditPartsTracker) ConnectionLayer(org.eclipse.draw2d.ConnectionLayer) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) Date(java.util.Date) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) UpdateListener(org.eclipse.draw2d.UpdateListener) Map(java.util.Map)

Example 2 with WidgetEditPartFactory

use of org.csstudio.opibuilder.editparts.WidgetEditPartFactory 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)

Aggregations

ArrayList (java.util.ArrayList)2 WidgetEditPartFactory (org.csstudio.opibuilder.editparts.WidgetEditPartFactory)2 ConnectionLayer (org.eclipse.draw2d.ConnectionLayer)2 ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)2 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)2 Date (java.util.Date)1 Map (java.util.Map)1 RunOPIAction (org.csstudio.opibuilder.actions.RunOPIAction)1 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)1 PatchedConnectionLayerClippingStrategy (org.csstudio.opibuilder.runmode.PatchedConnectionLayerClippingStrategy)1 UpdateListener (org.eclipse.draw2d.UpdateListener)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 EditDomain (org.eclipse.gef.EditDomain)1 Request (org.eclipse.gef.Request)1 ViewportAutoexposeHelper (org.eclipse.gef.editparts.ViewportAutoexposeHelper)1 DragEditPartsTracker (org.eclipse.gef.tools.DragEditPartsTracker)1 ToggleGridAction (org.eclipse.gef.ui.actions.ToggleGridAction)1 ToggleRulerVisibilityAction (org.eclipse.gef.ui.actions.ToggleRulerVisibilityAction)1 ToggleSnapToGeometryAction (org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction)1 ZoomInAction (org.eclipse.gef.ui.actions.ZoomInAction)1