Search in sources :

Example 1 with ContextMenuProvider

use of org.eclipse.gef.ContextMenuProvider in project tdi-studio-se by Talend.

the class AbstractTalendEditor method configureGraphicalViewer.

@Override
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    /** * Manage the view in the Outline ** */
    ScrollingGraphicalViewer viewer = (ScrollingGraphicalViewer) getGraphicalViewer();
    viewer.setSelectionManager(new TalendSelectionManager());
    TalendScalableFreeformRootEditPart root = new TalendScalableFreeformRootEditPart(getEditorInput());
    List<String> zoomLevels = new ArrayList<String>();
    zoomLevels.add(ZoomManager.FIT_ALL);
    zoomLevels.add(ZoomManager.FIT_WIDTH);
    zoomLevels.add(ZoomManager.FIT_HEIGHT);
    root.getZoomManager().setZoomLevelContributions(zoomLevels);
    // root.getZoomManager().setZoomAnimationStyle(ZoomManager.ANIMATE_NEVER);
    IAction zoomIn = new ZoomInAction(root.getZoomManager());
    IAction zoomOut = new ZoomOutAction(root.getZoomManager());
    getActionRegistry().registerAction(zoomIn);
    getActionRegistry().registerAction(zoomOut);
    IHandlerService service = (IHandlerService) getEditorSite().getService(IHandlerService.class);
    service.activateHandler(zoomIn.getActionDefinitionId(), new ActionHandler(zoomIn));
    service.activateHandler(zoomOut.getActionDefinitionId(), new ActionHandler(zoomOut));
    IAction directEditAction = new DirectEditAction(this);
    getActionRegistry().registerAction(directEditAction);
    getSelectionActions().add(directEditAction.getId());
    IAction copyAction = new GEFCopyAction(this);
    getActionRegistry().registerAction(copyAction);
    getSelectionActions().add(copyAction.getId());
    // setAction(copyAction.getId(), copyAction);
    IAction pasteAction = new GEFPasteAction(this);
    getActionRegistry().registerAction(pasteAction);
    getSelectionActions().add(pasteAction.getId());
    // setAction(pasteAction.getId(), pasteAction);
    IAction deleteAction = new GEFDeleteAction(this);
    getActionRegistry().registerAction(deleteAction);
    getSelectionActions().add(deleteAction.getId());
    // setAction(deleteAction.getId(), deleteAction);
    IAction undoAction = new GEFUndoAction(this);
    getActionRegistry().registerAction(undoAction);
    getSelectionActions().add(undoAction.getId());
    IAction redoAction = new GEFRedoAction(this);
    getActionRegistry().registerAction(redoAction);
    getSelectionActions().add(redoAction.getId());
    IAction setRefAction = new ConnectionSetAsMainRef(this);
    getActionRegistry().registerAction(setRefAction);
    getSelectionActions().add(setRefAction.getId());
    IAction modifyMergeAction = new ModifyMergeOrderAction(this);
    getActionRegistry().registerAction(modifyMergeAction);
    getSelectionActions().add(modifyMergeAction.getId());
    IAction modifyOutputOrderAction = new ModifyOutputOrderAction(this);
    getActionRegistry().registerAction(modifyOutputOrderAction);
    getSelectionActions().add(modifyOutputOrderAction.getId());
    List<IAction> calcOrderActions = ModifyConnectionOrderAction.getOrderActions(this);
    for (IAction orderAction : calcOrderActions) {
        getActionRegistry().registerAction(orderAction);
        getSelectionActions().add(orderAction.getId());
    }
    viewer.setRootEditPart(root);
    PartFactory partFactory = new PartFactory();
    // set the factory to use for creating EditParts for elements in the model
    getGraphicalViewer().setEditPartFactory(partFactory);
    getGraphicalViewer().setKeyHandler(new NodePartKeyHander(getGraphicalViewer()).setParent(getCommonKeyHandler()));
    // GraphicalViewer graViewer = getGraphicalViewer();
    // graViewer.setKeyHandler(new GraphicalViewerKeyHandler(graViewer));
    initializeActivationCodeTrigger();
    /** * Management of the context menu ** */
    ContextMenuProvider cmProvider = new TalendEditorContextMenuProvider(this, viewer, getActionRegistry());
    viewer.setContextMenu(cmProvider);
    /** * Management of the Zoom ** */
    /*
         * ZoomManager manager = (ZoomManager) getGraphicalViewer().getProperty(ZoomManager.class.toString()); if
         * (manager != null) { manager.setZoom(getProcess().getZoom()); }
         */
    // Scroll-wheel Zoom
    getGraphicalViewer().setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON);
    /** * Snap To Grid ** */
    // Grid properties
    getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_SPACING, new Dimension(AbstractTalendEditor.GRID_SIZE, AbstractTalendEditor.GRID_SIZE));
    getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, new Boolean(true));
    // We keep grid visibility and enablement in sync
    getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, new Boolean(true));
    IAction showGrid = new ToggleGridAction(getGraphicalViewer());
    getActionRegistry().registerAction(showGrid);
    /** * Snap To Geometry ** */
    getGraphicalViewer().setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, new Boolean(false));
    IAction snapAction = new ToggleSnapToGeometryAction(getGraphicalViewer());
    getActionRegistry().registerAction(snapAction);
    configurationSubJob(viewer);
}
Also used : ModifyMergeOrderAction(org.talend.designer.core.ui.action.ModifyMergeOrderAction) ToggleSnapToGeometryAction(org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction) GEFCopyAction(org.talend.designer.core.ui.action.GEFCopyAction) GEFPasteAction(org.talend.designer.core.ui.action.GEFPasteAction) GEFDeleteAction(org.talend.designer.core.ui.action.GEFDeleteAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) ProcessTreePartFactory(org.talend.designer.core.ui.editor.outline.ProcessTreePartFactory) ArrayList(java.util.ArrayList) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) NodePartKeyHander(org.talend.designer.core.ui.NodePartKeyHander) ModifyOutputOrderAction(org.talend.designer.core.ui.action.ModifyOutputOrderAction) DirectEditAction(org.eclipse.gef.ui.actions.DirectEditAction) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) IAction(org.eclipse.jface.action.IAction) ConnectionSetAsMainRef(org.talend.designer.core.ui.action.ConnectionSetAsMainRef) ToggleGridAction(org.eclipse.gef.ui.actions.ToggleGridAction) GEFUndoAction(org.talend.designer.core.ui.action.GEFUndoAction) Dimension(org.eclipse.draw2d.geometry.Dimension) IHandlerService(org.eclipse.ui.handlers.IHandlerService) GEFRedoAction(org.talend.designer.core.ui.action.GEFRedoAction) ActionHandler(org.eclipse.jface.commands.ActionHandler)

Example 2 with ContextMenuProvider

use of org.eclipse.gef.ContextMenuProvider in project tdi-studio-se by Talend.

the class BusinessDiagramEditor method configureGraphicalViewer.

/**
     * @generated
     */
@Override
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    IDiagramGraphicalViewer viewer = getDiagramGraphicalViewer();
    // customize popup menu
    ContextMenuProvider provider = new BusinessDiagramActionProvider(this, viewer);
    viewer.setContextMenu(provider);
    getSite().registerContextMenu(ActionIds.DIAGRAM_EDITOR_CONTEXT_MENU, provider, viewer);
    DiagramRootEditPart root = (DiagramRootEditPart) getDiagramGraphicalViewer().getRootEditPart();
    LayeredPane printableLayers = (LayeredPane) root.getLayer(LayerConstants.PRINTABLE_LAYERS);
    FreeformLayer extLabelsLayer = new FreeformLayer();
    extLabelsLayer.setLayoutManager(new DelegatingLayout());
    printableLayers.addLayerAfter(extLabelsLayer, BusinessEditPartFactory.EXTERNAL_NODE_LABELS_LAYER, LayerConstants.PRIMARY_LAYER);
    LayeredPane scalableLayers = (LayeredPane) root.getLayer(LayerConstants.SCALABLE_LAYERS);
    FreeformLayer scaledFeedbackLayer = new FreeformLayer();
    scaledFeedbackLayer.setEnabled(false);
    scalableLayers.addLayerAfter(scaledFeedbackLayer, LayerConstants.SCALED_FEEDBACK_LAYER, DiagramRootEditPart.DECORATION_UNPRINTABLE_LAYER);
}
Also used : IDiagramGraphicalViewer(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer) DelegatingLayout(org.eclipse.draw2d.DelegatingLayout) LayeredPane(org.eclipse.draw2d.LayeredPane) FreeformLayer(org.eclipse.draw2d.FreeformLayer) BusinessDiagramActionProvider(org.talend.designer.business.model.business.diagram.providers.BusinessDiagramActionProvider) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) DiagramRootEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart)

Example 3 with ContextMenuProvider

use of org.eclipse.gef.ContextMenuProvider in project whole by wholeplatform.

the class ModelMergeViewer method createMergeArea.

protected Control createMergeArea(Composite parent) {
    IImportAsModelDialogFactory factory = ContextInjectionFactory.make(ImportAsModelDialogFactory.class, getContext());
    IEclipseContext params = EclipseContextFactory.create();
    params.set("parent", parent);
    params.set(IImportAsModelDialogFactory.class, factory);
    viewer = ContextInjectionFactory.make(E4GraphicalViewer.class, getContext(), params);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateSelection(E4Utils.createSelectionBindings(event, getContext()));
        }
    });
    viewer.getControl().addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent event) {
        }

        @SuppressWarnings("unchecked")
        @Override
        public void focusGained(FocusEvent event) {
            getContext().set(IEntityPartViewer.class, viewer);
            getContext().set(ActionRegistry.class, actionRegistry);
            updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, getContext()));
        }
    });
    viewer.addPartFocusListener(new IPartFocusListener() {

        @SuppressWarnings("unchecked")
        public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
            updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, getContext()));
        }
    });
    E4KeyHandler keyHandler = new E4KeyHandler(getContext());
    keyHandler.setParent(new E4NavigationKeyHandler(getContext()));
    viewer.setKeyHandler(keyHandler);
    viewer.setEntityContents(createDefaultContents());
    getContext().set(IEntityPartViewer.class, viewer);
    actionRegistry = ContextInjectionFactory.make(ActionRegistry.class, getContext());
    actionRegistry.registerWorkbenchActions();
    getContext().set(ActionRegistry.class, actionRegistry);
    JFaceMenuBuilder uiBuilder = ContextInjectionFactory.make(JFaceMenuBuilder.class, getContext());
    contextMenuProvider = new PopupMenuProvider<IContributionItem, IMenuManager>(uiBuilder);
    viewer.setContextMenu(new ContextMenuProvider(viewer) {

        @Override
        public void buildContextMenu(IMenuManager menuManager) {
            contextMenuProvider.populate(menuManager);
        }
    });
    return parent;
}
Also used : E4GraphicalViewer(org.whole.lang.e4.ui.viewers.E4GraphicalViewer) IContributionItem(org.eclipse.jface.action.IContributionItem) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IImportAsModelDialogFactory(org.whole.lang.ui.dialogs.IImportAsModelDialogFactory) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) ActionRegistry(org.whole.lang.e4.ui.actions.ActionRegistry) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) JFaceMenuBuilder(org.whole.lang.e4.ui.menu.JFaceMenuBuilder) E4KeyHandler(org.whole.lang.e4.ui.actions.E4KeyHandler) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) GridData(org.eclipse.swt.layout.GridData) E4NavigationKeyHandler(org.whole.lang.e4.ui.actions.E4NavigationKeyHandler) IMenuManager(org.eclipse.jface.action.IMenuManager) FocusListener(org.eclipse.swt.events.FocusListener) IPartFocusListener(org.whole.lang.ui.editparts.IPartFocusListener) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) IEntityPart(org.whole.lang.ui.editparts.IEntityPart)

Example 4 with ContextMenuProvider

use of org.eclipse.gef.ContextMenuProvider in project whole by wholeplatform.

the class AbstractE4Part method configureContextMenu.

protected void configureContextMenu() {
    JFaceMenuBuilder uiBuilder = ContextInjectionFactory.make(JFaceMenuBuilder.class, context);
    contextMenuProvider = new PopupMenuProvider<IContributionItem, IMenuManager>(uiBuilder);
    viewer.setContextMenu(new ContextMenuProvider(viewer) {

        @Override
        public void buildContextMenu(IMenuManager menuManager) {
            try {
                if (!getViewer().getEditDomain().isDisabled())
                    contextMenuProvider.populate(menuManager);
            } catch (Exception e) {
                getMenu().setVisible(false);
            }
        }
    });
}
Also used : JFaceMenuBuilder(org.whole.lang.e4.ui.menu.JFaceMenuBuilder) IContributionItem(org.eclipse.jface.action.IContributionItem) IMenuManager(org.eclipse.jface.action.IMenuManager) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider)

Example 5 with ContextMenuProvider

use of org.eclipse.gef.ContextMenuProvider 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)

Aggregations

ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)15 IMenuManager (org.eclipse.jface.action.IMenuManager)7 ScrollingGraphicalViewer (org.eclipse.gef.ui.parts.ScrollingGraphicalViewer)6 ArrayList (java.util.ArrayList)4 IContributionItem (org.eclipse.jface.action.IContributionItem)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)4 JFaceMenuBuilder (org.whole.lang.e4.ui.menu.JFaceMenuBuilder)4 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)3 ToggleGridAction (org.eclipse.gef.ui.actions.ToggleGridAction)3 ToggleSnapToGeometryAction (org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction)3 ZoomInAction (org.eclipse.gef.ui.actions.ZoomInAction)3 ZoomOutAction (org.eclipse.gef.ui.actions.ZoomOutAction)3 GraphicalViewerKeyHandler (org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler)3 IAction (org.eclipse.jface.action.IAction)3 FocusEvent (org.eclipse.swt.events.FocusEvent)3 FocusListener (org.eclipse.swt.events.FocusListener)3 GridData (org.eclipse.swt.layout.GridData)3 WidgetEditPartFactory (org.csstudio.opibuilder.editparts.WidgetEditPartFactory)2