Example usage for org.eclipse.jface.action Action findKeyCode

List of usage examples for org.eclipse.jface.action Action findKeyCode

Introduction

In this page you can find the example usage for org.eclipse.jface.action Action findKeyCode.

Prototype

public static int findKeyCode(String token) 

Source Link

Document

Maps a standard keyboard key name to an SWT key code.

Usage

From source file:org.apache.directory.studio.schemaeditor.controller.ProjectsViewController.java

License:Apache License

/**
 * Initializes the Viewer./*  w w  w  .  j  a  va  2 s . co  m*/
 */
private void initViewer() {
    viewer.setInput(new ProjectsViewRoot(viewer));
    viewer.getTable().addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            if ((e.keyCode == Action.findKeyCode("BACKSPACE")) //$NON-NLS-1$
                    || (e.keyCode == Action.findKeyCode("DELETE"))) //$NON-NLS-1$
            {
                deleteProject.run();
            }
        }
    });
}

From source file:org.apache.directory.studio.schemaeditor.view.dialogs.AbstractAliasesDialog.java

License:Apache License

/**
 * Initializes the Listeners.//  w ww  .  jav a  2 s  . c om
 */
private void initListeners() {
    aliasesTable.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if ((e.keyCode == SWT.DEL) || (e.keyCode == Action.findKeyCode("BACKSPACE"))) //$NON-NLS-1$
            {
                removeSelectedAliases();
                fillAliasesTable();
                updateButtonsState();
                checkAliases();
            }
        }
    });
    aliasesTable.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            closeTableEditor();
            updateButtonsState();
        }
    });
    aliasesTable.addListener(SWT.MouseDoubleClick, new Listener() {
        public void handleEvent(Event event) {
            openTableEditor(aliasesTable.getItem(aliasesTable.getSelectionIndex()));
        }
    });

    // Aliases Table's Popup Menu
    Menu menu = new Menu(getShell(), SWT.POP_UP);
    aliasesTable.setMenu(menu);
    MenuItem removeMenuItem = new MenuItem(menu, SWT.PUSH);
    removeMenuItem.setText(Messages.getString("AbstractAliasesDialog.Remove")); //$NON-NLS-1$
    removeMenuItem
            .setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
    removeMenuItem.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            removeSelectedAliases();
            fillAliasesTable();
            updateButtonsState();
            checkAliases();
        }
    });

    // Add Button
    addButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addANewAlias();
        }
    });

    // Edit Button
    editButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            openTableEditor(aliasesTable.getItem(aliasesTable.getSelectionIndex()));
        }
    });

    // Remove Button
    removeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            removeSelectedAliases();
            fillAliasesTable();
            updateButtonsState();
            checkAliases();
        }
    });
}

From source file:org.apache.directory.studio.schemaeditor.view.dialogs.AbstractAliasesDialog.java

License:Apache License

/**
 * Opens the {@link TableEditor} on the given {@link TableItem}.
 *
 * @param item/*from ww w  . j  a  v  a  2 s  .  co  m*/
 *      the {@link TableItem}
 */
private void openTableEditor(TableItem item) {
    // Clean up any previous editor control
    Control oldEditor = tableEditor.getEditor();
    if (oldEditor != null)
        oldEditor.dispose();

    if (item == null)
        return;

    // The control that will be the editor must be a child of the Table
    Text newEditor = new Text(aliasesTable, SWT.NONE);
    newEditor.setText(item.getText());
    newEditor.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            saveTableEditorText();
        }
    });
    newEditor.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if ((e.keyCode == Action.findKeyCode("RETURN")) || (e.keyCode == SWT.KEYPAD_CR)) //$NON-NLS-1$
            {
                closeTableEditor();
            }
        }
    });
    newEditor.selectAll();
    newEditor.setFocus();
    tableEditor.setEditor(newEditor, item, 0);
    Activator.getDefault().getWorkbench().getDisplay().addFilter(SWT.Traverse, returnKeyListener);
}

From source file:org.apache.directory.studio.schemaeditor.view.views.SearchView.java

License:Apache License

/**
 * Create the Search Field Sections./*from   w  ww  .j av a  2 s .  c  o  m*/
 */
private void createSearchField() {
    // Search Inner Composite
    searchFieldInnerComposite = new Composite(searchFieldComposite, SWT.NONE);
    GridLayout searchFieldInnerCompositeGridLayout = new GridLayout(4, false);
    searchFieldInnerCompositeGridLayout.horizontalSpacing = 1;
    searchFieldInnerCompositeGridLayout.verticalSpacing = 1;
    searchFieldInnerCompositeGridLayout.marginHeight = 1;
    searchFieldInnerCompositeGridLayout.marginWidth = 2;
    searchFieldInnerComposite.setLayout(searchFieldInnerCompositeGridLayout);
    searchFieldInnerComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));

    // Search Label
    Label searchFieldLabel = new Label(searchFieldInnerComposite, SWT.NONE);
    searchFieldLabel.setText(Messages.getString("SearchView.SearchColon")); //$NON-NLS-1$
    searchFieldLabel.setLayoutData(new GridData(SWT.NONE, SWT.CENTER, false, false));

    // Search Text Field
    searchField = new Text(searchFieldInnerComposite, SWT.BORDER | SWT.SEARCH | SWT.CANCEL);
    if (searchString != null) {
        searchField.setText(searchString);
    }
    searchField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    searchField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            validateSearchField();
        }
    });
    searchField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_DOWN) {
                resultsTable.setFocus();
            } else if ((e.keyCode == Action.findKeyCode("RETURN")) || (e.keyCode == SWT.KEYPAD_CR)) //$NON-NLS-1$
            {
                search();
            }
        }
    });

    // Search Toolbar
    final ToolBar searchToolBar = new ToolBar(searchFieldInnerComposite, SWT.HORIZONTAL | SWT.FLAT);
    // Creating the Search In ToolItem
    final ToolItem searchInToolItem = new ToolItem(searchToolBar, SWT.DROP_DOWN);
    searchInToolItem.setText(Messages.getString("SearchView.SearchIn")); //$NON-NLS-1$
    // Adding the action to display the Menu when the item is clicked
    searchInToolItem.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Rectangle rect = searchInToolItem.getBounds();
            Point pt = new Point(rect.x, rect.y + rect.height);
            pt = searchToolBar.toDisplay(pt);

            Menu menu = createSearchInMenu();
            menu.setLocation(pt.x, pt.y);
            menu.setVisible(true);
        }
    });

    new ToolItem(searchToolBar, SWT.SEPARATOR);

    final ToolItem scopeToolItem = new ToolItem(searchToolBar, SWT.DROP_DOWN);
    scopeToolItem.setText(Messages.getString("SearchView.Scope")); //$NON-NLS-1$
    // Adding the action to display the Menu when the item is clicked
    scopeToolItem.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            Rectangle rect = scopeToolItem.getBounds();
            Point pt = new Point(rect.x, rect.y + rect.height);
            pt = searchToolBar.toDisplay(pt);

            Menu menu = createScopeMenu();
            menu.setLocation(pt.x, pt.y);
            menu.setVisible(true);
        }
    });
    searchToolBar.setLayoutData(new GridData(SWT.NONE, SWT.CENTER, false, false));

    // Search Button
    searchButton = new Button(searchFieldInnerComposite, SWT.PUSH | SWT.DOWN);
    searchButton.setEnabled(false);
    searchButton.setImage(Activator.getDefault().getImage(PluginConstants.IMG_SEARCH));
    searchButton.setToolTipText(Messages.getString("SearchView.Search")); //$NON-NLS-1$
    searchButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            search();
        }
    });
    searchButton.setLayoutData(new GridData(SWT.NONE, SWT.CENTER, false, false));

    // Separator Label
    separatorLabel = new Label(searchFieldComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
    separatorLabel.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
}

From source file:org.apache.directory.studio.schemaeditor.view.views.SearchView.java

License:Apache License

/**
 * Creates the TableViewer.//from  w ww .  j av a 2  s . c o  m
 */
private void createTableViewer() {
    // Creating the TableViewer
    resultsTable = new Table(parent,
            SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    resultsTable.setLayoutData(gridData);
    resultsTable.setLinesVisible(true);

    // Creating the TableViewer
    resultsTableViewer = new TableViewer(resultsTable);
    resultsTableViewer.setLabelProvider(new DecoratingLabelProvider(new SearchViewLabelProvider(),
            Activator.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator()));
    resultsTableViewer.setContentProvider(new SearchViewContentProvider());

    // Adding listeners
    resultsTable.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if ((e.keyCode == Action.findKeyCode("RETURN")) || (e.keyCode == SWT.KEYPAD_CR)) // return key //$NON-NLS-1$
            {
                openEditor();
            }
        }
    });

    resultsTableViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            openEditor();
        }
    });
}

From source file:org.eclipse.e4.ui.keybinding.tests.Bug43538Test.java

License:Open Source License

/**
 * Tests that if "Ctrl+Space" is pressed only one key down event with the
 * "CTRL" mask is received.//  ww  w . ja  va 2  s .co  m
 */
public void testCtrlSpace() {
    // Set up a working environment.
    Display display = Display.getCurrent();
    Listener listener = new Listener() {
        int count = 0;

        public void handleEvent(Event event) {
            if (event.stateMask == SWT.CTRL) {
                assertEquals("Multiple key down events for 'Ctrl+Space'", 0, count++); //$NON-NLS-1$
            }
        }
    };
    display.addFilter(SWT.KeyDown, listener);

    AutomationUtil.performKeyCodeEvent(display, SWT.KeyDown, SWT.CONTROL);
    AutomationUtil.performKeyCodeEvent(display, SWT.KeyDown, Action.findKeyCode("SPACE")); //$NON-NLS-1$
    AutomationUtil.performKeyCodeEvent(display, SWT.KeyUp, Action.findKeyCode("SPACE")); //$NON-NLS-1$
    AutomationUtil.performKeyCodeEvent(display, SWT.KeyUp, SWT.CONTROL);

    while (display.readAndDispatch())
        ;

    // Clean up the working environment.
    display.removeFilter(SWT.KeyDown, listener);
}

From source file:org.eclipse.wst.sse.ui.internal.extension.ActionDescriptor.java

License:Open Source License

/**
 * Parses the given accelerator text, and converts it to an accelerator
 * key code.//from www . jav a  2  s.c o m
 * 
 * @param acceleratorText
 *            the accelerator text
 * @result the SWT key code, or 0 if there is no accelerator
 */
private int convertAccelerator(String acceleratorText) {
    int accelerator = 0;
    StringTokenizer stok = new StringTokenizer(acceleratorText, "+"); //$NON-NLS-1$

    int keyCode = -1;

    boolean hasMoreTokens = stok.hasMoreTokens();
    while (hasMoreTokens) {
        String token = stok.nextToken();
        hasMoreTokens = stok.hasMoreTokens();
        // Every token except the last must be one of the modifiers
        // Ctrl, Shift, or Alt.
        if (hasMoreTokens) {
            int modifier = Action.findModifier(token);
            if (modifier != 0) {
                accelerator |= modifier;
            } else { //Leave if there are none
                return 0;
            }
        } else {
            keyCode = Action.findKeyCode(token);
        }
    }
    if (keyCode != -1) {
        accelerator |= keyCode;
    }
    return accelerator;
}

From source file:org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer.java

License:Open Source License

/**
 * Returns the KeyHandler with common bindings for both the Outline and Graphical Views.
 * For example, delete is a common action.
 *//*www . ja va2  s.  co  m*/
protected KeyHandler getCommonKeyHandler() {
    if (sharedKeyHandler == null) {
        sharedKeyHandler = new KeyHandler();
        sharedKeyHandler.put(KeyStroke.getPressed('\r', Action.findKeyCode("RETURN"), 0), //$NON-NLS-1$
                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(KeyStroke.getReleased(' ', Action.findKeyCode("SPACE"), 0), //$NON-NLS-1$
                getActionRegistry().getAction(LexicalSortingAction.ACTION_ID));
    }
    return sharedKeyHandler;
}