Example usage for org.eclipse.jface.bindings.keys KeySequenceText setKeySequence

List of usage examples for org.eclipse.jface.bindings.keys KeySequenceText setKeySequence

Introduction

In this page you can find the example usage for org.eclipse.jface.bindings.keys KeySequenceText setKeySequence.

Prototype

public void setKeySequence(KeySequence newKeySequence) 

Source Link

Document

A mutator for the key sequence stored within this widget.

Usage

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

License:Open Source License

/**
 * Tests that a <code>StackOverflowError</code> does not occur when
 * trying to set the key sequence in a key sequence entry widget.
 * //from   ww w .  j  a v a 2  s. c o m
 * @throws ParseException
 *             If "CTRL+" is not recognized as a key sequence.
 */
public void testStackOverflow() throws ParseException {
    Display display = Display.getCurrent();
    Shell shell = new Shell(display);
    shell.setLayout(new RowLayout());
    Text text = new Text(shell, SWT.BORDER);
    KeySequenceText keySequenceText = new KeySequenceText(text);

    shell.pack();
    shell.open();
    keySequenceText.setKeySequence(KeySequence.getInstance("CTRL+")); //$NON-NLS-1$
    shell.close();
}

From source file:org.limy.eclipse.qalab.keybind.KeybindWindow.java

License:Open Source License

/**
 * @param comp//from ww  w  .  j  ava2  s. c om
 * @param commandId 
 * @param commandBinding 
 * @param commandName
 * @param lastTarget
 * @return 
 * @throws NotDefinedException 
 */
private Control createCommandComp(Composite comp, String commandId, Control lastTarget)
        throws NotDefinedException {

    Binding[] bindings = bindingService.getBindings();

    Binding systemBinding = null;
    Collection<Binding> userBindings = new ArrayList<Binding>();
    for (Binding binding : bindings) {
        ParameterizedCommand command = binding.getParameterizedCommand();

        if (command != null && commandId.equals(command.getId())) {

            if (binding.getType() == Binding.SYSTEM) {
                systemBinding = binding;
            } else {
                userBindings.add(binding);
            }
        }
    }

    Label label = new Label(comp, SWT.NONE);
    label.setText(systemBinding.getParameterizedCommand().getCommand().getDescription());
    label.setLayoutData(FormDataCreater.controlDown(lastTarget, 6, 280));
    label.setFont(new Font(comp.getDisplay(), "Serif", 10, SWT.NORMAL));

    Text text = new Text(comp, SWT.BORDER);
    text.setLayoutData(FormDataCreater.controlDownWithWidth(lastTarget, 4, 288, 100));
    text.setData(systemBinding);

    text.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
            bindingService.setKeyFilterEnabled(false);
        }

        public void focusLost(FocusEvent e) {
            bindingService.setKeyFilterEnabled(true);
        }
    });

    KeySequenceText sequenceText = new KeySequenceText(text);
    if (!userBindings.isEmpty()) {
        sequenceText.setKeySequence((KeySequence) userBindings.iterator().next().getTriggerSequence());
    } else {
        sequenceText.setKeySequence((KeySequence) systemBinding.getTriggerSequence());
    }
    sequenceText.setKeyStrokeLimit(4);

    texts.add(text);
    sequenceTexts.add(sequenceText);
    return text;
}