Search in sources :

Example 1 with KeyHandler

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

the class AbstractTalendEditor method getCommonKeyHandler.

/**
     * DOC qzhang Comment method "getCommonKeyHandler".
     * 
     * @return
     */
public KeyHandler getCommonKeyHandler() {
    if (sharedKeyHandler == null) {
        sharedKeyHandler = new KeyHandler();
        sharedKeyHandler.put(KeyStroke.getPressed(SWT.F1, 0), new Action() {

            @Override
            public void run() {
                ISelection selection = getGraphicalViewer().getSelection();
                if (selection != null) {
                    if (selection instanceof IStructuredSelection) {
                        Object input = ((IStructuredSelection) selection).getFirstElement();
                        Node node = null;
                        if (input instanceof NodeTreeEditPart) {
                            NodeTreeEditPart nTreePart = (NodeTreeEditPart) input;
                            node = (Node) nTreePart.getModel();
                        } else {
                            if (input instanceof NodePart) {
                                EditPart editPart = (EditPart) input;
                                node = (Node) editPart.getModel();
                            }
                        }
                        if (node != null) {
                            String helpLink = (String) node.getPropertyValue(EParameterName.HELP.getName());
                            String requiredHelpLink = ((Process) node.getProcess()).getBaseHelpLink() + node.getComponent().getName();
                            if (helpLink == null || "".equals(helpLink) || !requiredHelpLink.equals(helpLink)) {
                                helpLink = ((Process) node.getProcess()).getBaseHelpLink() + node.getComponent().getName();
                            }
                            PlatformUI.getWorkbench().getHelpSystem().displayHelp(helpLink);
                        }
                    }
                }
            }
        });
        sharedKeyHandler.put(KeyStroke.getPressed(SWT.DEL, 0), getActionRegistry().getAction(ActionFactory.DELETE.getId()));
    // deactivate the F2 shortcut as it's not used anymore
    // sharedKeyHandler.put(KeyStroke.getPressed(SWT.F2, 0),
    // getActionRegistry().getAction(GEFActionConstants.DIRECT_EDIT));
    }
    return sharedKeyHandler;
}
Also used : ModifyConnectionOrderAction(org.talend.designer.core.ui.action.ModifyConnectionOrderAction) GEFDeleteAction(org.talend.designer.core.ui.action.GEFDeleteAction) GEFPasteAction(org.talend.designer.core.ui.action.GEFPasteAction) DirectEditAction(org.eclipse.gef.ui.actions.DirectEditAction) ToggleSubjobsAction(org.talend.designer.core.ui.action.ToggleSubjobsAction) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) ModifyOutputOrderAction(org.talend.designer.core.ui.action.ModifyOutputOrderAction) IAction(org.eclipse.jface.action.IAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) ModifyMergeOrderAction(org.talend.designer.core.ui.action.ModifyMergeOrderAction) ToggleGridAction(org.eclipse.gef.ui.actions.ToggleGridAction) Action(org.eclipse.jface.action.Action) GEFRedoAction(org.talend.designer.core.ui.action.GEFRedoAction) GEFCopyAction(org.talend.designer.core.ui.action.GEFCopyAction) ToggleSnapToGeometryAction(org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction) GEFUndoAction(org.talend.designer.core.ui.action.GEFUndoAction) NodeTreeEditPart(org.talend.designer.core.ui.editor.outline.NodeTreeEditPart) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) ISelection(org.eclipse.jface.viewers.ISelection) EditPart(org.eclipse.gef.EditPart) NodeTreeEditPart(org.talend.designer.core.ui.editor.outline.NodeTreeEditPart) AbstractEditPart(org.eclipse.gef.editparts.AbstractEditPart) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) TalendDrawerEditPart(org.talend.designer.core.ui.editor.palette.TalendDrawerEditPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) EventObject(java.util.EventObject) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) KeyHandler(org.eclipse.gef.KeyHandler)

Example 2 with KeyHandler

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

the class MonitorDashboardEditor method configureGraphicalViewer.

/**
	 * @see org.eclipse.gef.ui.parts.GraphicalEditor.configureGraphicalViewer
	 */
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    GraphicalViewer viewer = getGraphicalViewer();
    ScalableFreeformRootEditPart rootEditPart = new ScalableFreeformRootEditPart();
    viewer.setRootEditPart(rootEditPart);
    viewer.setEditPartFactory(new MonitorEditPartFacotry());
    ZoomManager manager = rootEditPart.getZoomManager();
    double[] zoomLevels = new double[] { 1.0, 1.2, 1.4, 1.6, 1.8, 2.0 };
    manager.setZoomLevels(zoomLevels);
    getActionRegistry().registerAction(new ZoomInAction(manager));
    getActionRegistry().registerAction(new ZoomOutAction(manager));
    KeyHandler keyHandler = new GefViewerKeyHandler(viewer);
    keyHandler.put(KeyStroke.getReleased('', 97, SWT.CONTROL), getActionRegistry().getAction(ActionFactory.SELECT_ALL.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));
    viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.CTRL), MouseWheelZoomHandler.SINGLETON);
    viewer.setKeyHandler(keyHandler);
    //initialize context menu
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        /**
			 * get menus to show.
			 * 
			 * @param manager IMenuManager
			 */
        public void menuAboutToShow(IMenuManager manager) {
            IStructuredSelection selection = (IStructuredSelection) getGraphicalViewer().getSelection();
            String[] ids = new String[] {};
            if (null == selection || selection.isEmpty() || selection.getFirstElement() instanceof DashboardPart) {
                manager.add(getActionRegistry().getAction(ActionFactory.SELECT_ALL.getId()));
                ids = new String[] { AddHostMonitorAction.ID, SEPARATOR, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof HostMonitorPart) {
                ids = new String[] { MonitorDetailAction.ID, DeleteHostMonitorAction.ID, EditAliasNameAction.ID, SEPARATOR, //HARoleChangeAction.ID, SEPARATOR,
                HostDashboardHistoryAction.ID, AddDatabaseMonitorAction.ID, AddBrokerMonitorAction.ID, SEPARATOR, HideHostAction.ID, MinimizeFigureAction.ID, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof DatabaseMonitorPart) {
                ids = new String[] { MonitorDetailAction.ID, DeleteDatabaseMonitorAction.ID, EditAliasNameAction.ID, SEPARATOR, DbDashboardHistoryAction.ID, OpenApplyLogDBLogAction.ID, OpenCopyLogDBLogAction.ID, OpenDatabaseLogAction.ID, SEPARATOR, ShowHostAction.ID, MinimizeFigureAction.ID, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof BrokerMonitorPart) {
                ids = new String[] { MonitorDetailAction.ID, DeleteBrokerMonitorAction.ID, EditAliasNameAction.ID, SEPARATOR, ShowBrokerClientAction.ID, ShowBrokerDabaseAction.ID, SEPARATOR, ShowHostAction.ID, MinimizeFigureAction.ID, DashboardRefreshAction.ID };
            } else if (selection.getFirstElement() instanceof ClientMonitorPart) {
                ids = new String[] { EditAliasNameAction.ID };
            } else if (selection.getFirstElement() instanceof BrokerDBListMonitorPart) {
                ids = new String[] { EditAliasNameAction.ID };
            }
            for (String id : ids) {
                if (id.equals(SEPARATOR)) {
                    manager.add(new Separator());
                } else {
                    IAction action = ActionManager.getInstance().getAction(id);
                    ((ISelectionAction) action).setSelectionProvider(getGraphicalViewer());
                    ActionManager.addActionToManager(manager, action);
                }
            }
            manager.update(true);
        }
    });
    viewer.setContextMenu(menuManager);
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) BrokerDBListMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.BrokerDBListMonitorPart) IAction(org.eclipse.jface.action.IAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) BrokerMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.BrokerMonitorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HostMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.HostMonitorPart) IMenuListener(org.eclipse.jface.action.IMenuListener) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ClientMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.ClientMonitorPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) DashboardPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.DashboardPart) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) DatabaseMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.DatabaseMonitorPart) MonitorEditPartFacotry(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.MonitorEditPartFacotry) KeyHandler(org.eclipse.gef.KeyHandler) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) Separator(org.eclipse.jface.action.Separator)

Example 3 with KeyHandler

use of org.eclipse.gef.KeyHandler in project knime-core by knime.

the class WorkflowEditor method createGraphicalViewer.

/**
 * Creates the graphical viewer that is hosted in this editor and hooks
 * keyhandler and edit domain.
 *
 * @see org.eclipse.gef.ui.parts.GraphicalEditor
 *      #createGraphicalViewer(org.eclipse.swt.widgets.Composite)
 * @param parent The parent
 */
@Override
protected void createGraphicalViewer(final Composite parent) {
    IEditorSite editorSite = getEditorSite();
    GraphicalViewer viewer = new WorkflowGraphicalViewerCreator(editorSite, this.getActionRegistry()).createViewer(parent);
    // Add a listener to the static node provider
    NodeProvider.INSTANCE.addListener(this);
    // Configure the key handler
    GraphicalViewerKeyHandler keyHandler = new GraphicalViewerKeyHandler(viewer);
    KeyHandler parentKeyHandler = keyHandler.setParent(getCommonKeyHandler());
    viewer.setKeyHandler(parentKeyHandler);
    // hook the viewer into the EditDomain
    getEditDomain().addViewer(viewer);
    // activate the viewer as selection provider for Eclipse
    getSite().setSelectionProvider(viewer);
    // remember this viewer
    m_graphicalViewer = viewer;
    // load properties like grid- or node-connections settings (e.g. width, curved)
    // needs to be called before getGraphicalViewer().setContents(m_manager), since
    // the node connections are repainted on that setContents-call and the properties need
    // to be set by then
    loadProperties();
    // We already have the model - set it into the viewer
    getGraphicalViewer().setContents(m_manager);
    // add Help context
    WorkbenchHelpSystem.getInstance().setHelp(m_graphicalViewer.getControl(), "org.knime.workbench.help.flow_editor_context");
    updateEditorBackgroundColor();
    updateJobManagerDisplay();
    updateTempRemoteWorkflowMessage();
    RootEditPart rep = getGraphicalViewer().getRootEditPart();
    ((WorkflowRootEditPart) rep.getChildren().get(0)).createToolTipHelper(getSite().getShell());
    ZoomManager zm = this.getZoomManager();
    zm.setZoomLevels(ZOOM_LEVELS);
    m_zoomWheelListener = new ZoomWheelListener(zm, (FigureCanvas) getViewer().getControl());
}
Also used : FigureCanvas(org.eclipse.draw2d.FigureCanvas) GraphicalViewer(org.eclipse.gef.GraphicalViewer) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager) GraphicalViewerKeyHandler(org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler) KeyHandler(org.eclipse.gef.KeyHandler) GraphicalViewerKeyHandler(org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler) IEditorSite(org.eclipse.ui.IEditorSite) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart)

Example 4 with KeyHandler

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

the class DiagramViewer method getCommonKeyHandler.

/**
 * Returns the KeyHandler with common bindings for both the Outline and Graphical Views.
 * For example, delete is a common action.
 */
protected KeyHandler getCommonKeyHandler() {
    if (sharedKeyHandler == null) {
        sharedKeyHandler = new KeyHandler();
        sharedKeyHandler.put(// $NON-NLS-1$
        KeyStroke.getPressed('\r', Action.findKeyCode("RETURN"), 0), getActionRegistry().getAction(ToggleShapeExpandStateAction.ACTION_ID));
        sharedKeyHandler.put(KeyStroke.getPressed('\r', SWT.KEYPAD_CR, 0), getActionRegistry().getAction(ToggleShapeExpandStateAction.ACTION_ID));
        sharedKeyHandler.put(KeyStroke.getPressed('+', SWT.KEYPAD_ADD, 0), getActionRegistry().getAction(ToggleShapeVisibleStateAction.ACTION_ID));
        sharedKeyHandler.put(KeyStroke.getPressed('=', '=', 0), getActionRegistry().getAction(ToggleShapeVisibleStateAction.ACTION_ID));
        sharedKeyHandler.put(// $NON-NLS-1$
        KeyStroke.getReleased(' ', Action.findKeyCode("SPACE"), 0), getActionRegistry().getAction(LexicalSortingAction.ACTION_ID));
    }
    return sharedKeyHandler;
}
Also used : GraphicalViewerKeyHandler(org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler) KeyHandler(org.eclipse.gef.KeyHandler)

Example 5 with KeyHandler

use of org.eclipse.gef.KeyHandler in project statecharts by Yakindu.

the class StatechartDiagramEditor method getKeyHandler.

/**
 * Overrides the GMF key handler to fix key binding for zooming and to remove
 * unused key bindings.
 */
@Override
protected KeyHandler getKeyHandler() {
    if (keyHandler == null) {
        keyHandler = new KeyHandler();
        registerZoomActions();
        // Zoom in - Unix - Numpad plus
        getKeyHandler().put(KeyStroke.getPressed('+', SWT.KEYPAD_ADD, SWT.MOD1), getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
        // Zoom in - Unix - Numpad minus
        getKeyHandler().put(KeyStroke.getPressed('-', SWT.KEYPAD_SUBTRACT, SWT.MOD1), getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT));
        // Zoom out - all OS - German and English keyboard layout
        getKeyHandler().put(KeyStroke.getPressed('-', 0x2d, SWT.MOD1), getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT));
        // Zoom in - all OS - English keyboard layout
        getKeyHandler().put(KeyStroke.getPressed('=', 0x3d, SWT.MOD1), getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
        // Zoom in - Unix - German layout ([CTRL++] propagates char '+')
        getKeyHandler().put(KeyStroke.getPressed('+', 0x2b, SWT.MOD1), getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
        // Zoom in - Windows - German layout ([CTRL++] propagates char 0x1d)
        getKeyHandler().put(KeyStroke.getPressed((char) 0x1d, 0x2b, SWT.MOD1), getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
        // Zoom original - all OS
        getKeyHandler().put(/* CTRL + '0' */
        KeyStroke.getPressed('0', 0x30, SWT.MOD1), new Action() {

            @Override
            public void run() {
                resetZoom();
            }
        });
        // Zoom original - all OS - Numpad 0
        getKeyHandler().put(/* CTRL + '0' */
        KeyStroke.getPressed('0', SWT.KEYPAD_0, SWT.MOD1), new Action() {

            @Override
            public void run() {
                resetZoom();
            }
        });
        // Test Error - for AERI testing only
        // DOWN: stateMask=0x50000 CTRL ALT, keyCode=0x6c 'l', character=0xc
        // ' '
        getKeyHandler().put(KeyStroke.getPressed((char) 0xc, 0x6c, 0x50000), new Action() {

            @Override
            public void run() {
                DiagramActivator.getDefault().getLog().log(new Status(IStatus.ERROR, DiagramActivator.PLUGIN_ID, "AERI Testing error"));
            }
        });
    }
    return keyHandler;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DomainStatus(org.yakindu.sct.domain.extension.DomainStatus) IAction(org.eclipse.jface.action.IAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) Action(org.eclipse.jface.action.Action) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) ContentProposalViewerKeyHandler(org.yakindu.sct.ui.editor.proposals.ContentProposalViewerKeyHandler) DiagramGraphicalViewerKeyHandler(org.eclipse.gmf.runtime.diagram.ui.internal.parts.DiagramGraphicalViewerKeyHandler) KeyHandler(org.eclipse.gef.KeyHandler)

Aggregations

KeyHandler (org.eclipse.gef.KeyHandler)10 GraphicalViewerKeyHandler (org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler)6 ZoomInAction (org.eclipse.gef.ui.actions.ZoomInAction)5 ZoomOutAction (org.eclipse.gef.ui.actions.ZoomOutAction)5 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)4 IAction (org.eclipse.jface.action.IAction)4 GraphicalViewer (org.eclipse.gef.GraphicalViewer)3 ZoomManager (org.eclipse.gef.editparts.ZoomManager)3 Action (org.eclipse.jface.action.Action)3 ContextMenuProvider (org.eclipse.gef.ContextMenuProvider)2 RootEditPart (org.eclipse.gef.RootEditPart)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IEditorSite (org.eclipse.ui.IEditorSite)2 SchemaContextMenuProvider (com.cubrid.common.ui.er.SchemaContextMenuProvider)1 AddColumnAction (com.cubrid.common.ui.er.action.AddColumnAction)1 DeleteAction (com.cubrid.common.ui.er.action.DeleteAction)1 EditTableAction (com.cubrid.common.ui.er.action.EditTableAction)1 ImportERwinDataAction (com.cubrid.common.ui.er.action.ImportERwinDataAction)1 ModifyTableNameAction (com.cubrid.common.ui.er.action.ModifyTableNameAction)1 BrokerDBListMonitorPart (com.cubrid.cubridmanager.ui.mondashboard.editor.parts.BrokerDBListMonitorPart)1