Search in sources :

Example 6 with ContextMenuProvider

use of org.eclipse.gef.ContextMenuProvider in project cubrid-manager by CUBRID.

the class ERSchemaEditor method createGraphicalViewer.

/**
	 * Creates a new <code>GraphicalViewer</code>, configures, registers and
	 * initializes it.
	 * 
	 * @param parent the parent composite
	 * @return a new <code>GraphicalViewer</code>
	 */
protected void createGraphicalViewer(Composite parent) {
    IEditorSite editorSite = getEditorSite();
    ScrollingGraphicalViewer viewer = createGraphicalViewer(editorSite, parent);
    ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) viewer.getRootEditPart();
    zoomManager = rootEditPart.getZoomManager();
    zoomManager.setZoomLevels(ZOOM_LEVELS);
    // hook the viewer into the EditDomain
    getEditDomain().addViewer(viewer);
    // acticate the viewer as selection provider for Eclipse
    getSite().setSelectionProvider(viewer);
    viewer.setContents(erSchema);
    ContextMenuProvider provider = new SchemaContextMenuProvider(viewer, getActionRegistry());
    viewer.setContextMenu(provider);
    getSite().registerContextMenu(provider.getId(), provider, viewer);
    graphicalViewer = viewer;
    // key handler
    GraphicalViewerKeyHandler graphicalViewerKeyHandler = new GraphicalViewerKeyHandler(viewer);
    KeyHandler parentKeyHandler = graphicalViewerKeyHandler.setParent(getCommonKeyHandler());
    viewer.setKeyHandler(parentKeyHandler);
    registDropTarget();
}
Also used : ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) GraphicalViewerKeyHandler(org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler) GraphicalViewerKeyHandler(org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler) KeyHandler(org.eclipse.gef.KeyHandler) IEditorSite(org.eclipse.ui.IEditorSite) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) SchemaContextMenuProvider(com.cubrid.common.ui.er.SchemaContextMenuProvider) SchemaContextMenuProvider(com.cubrid.common.ui.er.SchemaContextMenuProvider)

Example 7 with ContextMenuProvider

use of org.eclipse.gef.ContextMenuProvider in project cubrid-manager by CUBRID.

the class ReplicationEditor method configureGraphicalViewer.

/**
	 * @see org.eclipse.gef.ui.parts.GraphicalEditor#configureGraphicalViewer()
	 */
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    GraphicalViewer viewer = getGraphicalViewer();
    ScalableRootEditPart rootEditPart = new ScalableRootEditPart();
    viewer.setRootEditPart(rootEditPart);
    viewer.setEditPartFactory(new PartFactory(this));
    ZoomManager manager = rootEditPart.getZoomManager();
    getActionRegistry().registerAction(new ZoomInAction(manager));
    getActionRegistry().registerAction(new ZoomOutAction(manager));
    double[] zoomLevels = new double[] { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 10.0, 20.0 };
    manager.setZoomLevels(zoomLevels);
    List<String> zoomContributions = new ArrayList<String>();
    zoomContributions.add(ZoomManager.FIT_ALL);
    zoomContributions.add(ZoomManager.FIT_HEIGHT);
    zoomContributions.add(ZoomManager.FIT_WIDTH);
    manager.setZoomLevelContributions(zoomContributions);
    KeyHandler keyHandler = new KeyHandler();
    if (isEditable) {
        keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0), getActionRegistry().getAction(ActionFactory.DELETE.getId()));
    }
    keyHandler.put(KeyStroke.getPressed('+', SWT.KEYPAD_ADD, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
    keyHandler.put(KeyStroke.getPressed('-', SWT.KEYPAD_SUBTRACT, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT));
    keyHandler.put(KeyStroke.getPressed('a', 97, 0), getActionRegistry().getAction(ActionFactory.SELECT_ALL.getId()));
    viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.NONE), MouseWheelZoomHandler.SINGLETON);
    viewer.setKeyHandler(keyHandler);
    ContextMenuProvider provider = new ReplEditorContextMenuProvider(viewer, getActionRegistry());
    viewer.setContextMenu(provider);
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) PartFactory(com.cubrid.cubridmanager.ui.replication.editor.parts.PartFactory) ScalableRootEditPart(org.eclipse.gef.editparts.ScalableRootEditPart) ArrayList(java.util.ArrayList) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) ZoomManager(org.eclipse.gef.editparts.ZoomManager) KeyHandler(org.eclipse.gef.KeyHandler) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction)

Example 8 with ContextMenuProvider

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

the class ErdiagramDiagramEditor method configureGraphicalViewer.

//$NON-NLS-1$
@SuppressWarnings("unchecked")
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    ScrollingGraphicalViewer viewer = (ScrollingGraphicalViewer) getGraphicalViewer();
    ErDiagramRootEditPart root = new ErDiagramRootEditPart();
    IAction deleteAction = new ErDiagramItemDeleteAction(this);
    getActionRegistry().registerAction(deleteAction);
    getSelectionActions().add(deleteAction.getId());
    viewer.setRootEditPart(root);
    ErDiagramPartFactory partFactory = new ErDiagramPartFactory();
    // set the factory to use for creating EditParts for elements in the
    // model
    getGraphicalViewer().setEditPartFactory(partFactory);
    getGraphicalViewer().setKeyHandler(new GraphicalViewerKeyHandler(getGraphicalViewer()).setParent(getCommonKeyHandler()));
    /** * Management of the context menu ** */
    ContextMenuProvider cmProvider = new ErDiagramMenuProvider(this, viewer, getActionRegistry());
    viewer.setContextMenu(cmProvider);
    /** * Snap To Grid ** */
    // Grid properties
    getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_SPACING, new Dimension(GRID_SIZE, 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);
}
Also used : ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) ToggleSnapToGeometryAction(org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction) IAction(org.eclipse.jface.action.IAction) ErDiagramItemDeleteAction(org.talend.sqlbuilder.erdiagram.ui.actions.ErDiagramItemDeleteAction) ToggleGridAction(org.eclipse.gef.ui.actions.ToggleGridAction) GraphicalViewerKeyHandler(org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler) Dimension(org.eclipse.draw2d.geometry.Dimension) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider)

Example 9 with ContextMenuProvider

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

the class E4Dialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    if (E4Utils.isLegacyApplication())
        HandlersBehavior.registerHandlers(handlerService);
    IEclipseContext params = EclipseContextFactory.create();
    params.set("parent", parent);
    viewer = ContextInjectionFactory.make(E4GraphicalViewer.class, context, 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, context));
        }
    });
    viewer.getControl().addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent event) {
        }

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

        @SuppressWarnings("unchecked")
        public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
            updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, context));
            context.activateBranch();
        }
    });
    E4KeyHandler keyHandler = new E4KeyHandler(context);
    keyHandler.setParent(new E4NavigationKeyHandler(context));
    context.set(IEntityPartViewer.class, viewer);
    viewer.setKeyHandler(keyHandler);
    viewer.setEntityContents(createDefaultContents());
    actionRegistry = ContextInjectionFactory.make(ActionRegistry.class, context);
    actionRegistry.registerWorkbenchActions();
    context.set(ActionRegistry.class, actionRegistry);
    JFaceMenuBuilder uiBuilder = ContextInjectionFactory.make(JFaceMenuBuilder.class, context);
    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) 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 10 with ContextMenuProvider

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

the class E4FindReplaceDialog method createReplaceArea.

protected Control createReplaceArea(Composite parent) {
    IEclipseContext params = EclipseContextFactory.create();
    params.set("parent", parent);
    replaceViewer = ContextInjectionFactory.make(E4GraphicalViewer.class, context, params);
    replaceViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    replaceViewer.addSelectionChangedListener(new ISelectionChangedListener() {

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

        @Override
        public void focusLost(FocusEvent e) {
        }

        @SuppressWarnings("unchecked")
        @Override
        public void focusGained(FocusEvent e) {
            context.set(IEntityPartViewer.class, replaceViewer);
            context.set(ActionRegistry.class, replaceActionRegistry);
            updateSelection(E4Utils.createSelectionBindings(replaceViewer.getSelectedEditParts(), replaceViewer, context));
        }
    });
    replaceViewer.addPartFocusListener(new IPartFocusListener() {

        @SuppressWarnings("unchecked")
        public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
            updateSelection(E4Utils.createSelectionBindings(replaceViewer.getSelectedEditParts(), replaceViewer, context));
        }
    });
    E4KeyHandler keyHandler = new E4KeyHandler(context);
    keyHandler.setParent(new E4NavigationKeyHandler(context));
    replaceViewer.setKeyHandler(keyHandler);
    replaceViewer.setEntityContents(createDefaultContents());
    context.set(IEntityPartViewer.class, replaceViewer);
    replaceActionRegistry = ContextInjectionFactory.make(ActionRegistry.class, context);
    replaceActionRegistry.registerWorkbenchActions();
    context.set(ActionRegistry.class, replaceActionRegistry);
    replaceViewer.setContextMenu(new ContextMenuProvider(replaceViewer) {

        @Override
        public void buildContextMenu(IMenuManager menuManager) {
            contextMenuProvider.populate(menuManager);
        }
    });
    return parent;
}
Also used : E4GraphicalViewer(org.whole.lang.e4.ui.viewers.E4GraphicalViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) 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) 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)

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