List of usage examples for org.eclipse.jface.bindings.keys KeySequence isEmpty
public final boolean isEmpty()
From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java
License:Open Source License
@SuppressWarnings("unused") private void createDefinitionArea(Composite parent) { final Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); composite.setLayout(new GridLayout(2, false)); new Label(composite, SWT.NONE).setText(Messages.getString("KeyPreferencePage.command2")); //$NON-NLS-1$ nameField = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER | SWT.READ_ONLY); nameField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); new Label(composite, SWT.NONE).setText(Messages.getString("KeyPreferencePage.description")); //$NON-NLS-1$ descriptionField = new Text(composite, SWT.MULTI | SWT.LEAD | SWT.BORDER | SWT.READ_ONLY | SWT.WRAP); GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); layoutData.heightHint = 50;/*from w w w . ja va 2 s . c o m*/ descriptionField.setLayoutData(layoutData); new Label(composite, SWT.NONE).setText(Messages.getString("KeyPreferencePage.key_sequence")); //$NON-NLS-1$ Composite keyGroup = new Composite(composite, SWT.NONE); keyGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true)); GridLayout layout = new GridLayout(2, false); layout.marginHeight = 0; layout.marginWidth = 0; keyGroup.setLayout(layout); keyField = new Text(keyGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER); keyField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); keySequenceField = new KeySequenceText(keyField); keySequenceField.setKeyStrokeLimit(2); keySequenceField.addPropertyChangeListener(new IPropertyChangeListener() { public final void propertyChange(final PropertyChangeEvent event) { if (!event.getOldValue().equals(event.getNewValue())) { final KeySequence keySequence = keySequenceField.getKeySequence(); if (selectedCommand == null || !keySequence.isComplete()) return; boolean empty = keySequence.isEmpty(); Binding newBinding; Binding b = commandMap.get(selectedCommand.getId()); if (b != null) { if (!keySequence.equals(b.getTriggerSequence())) { newBinding = new KeyBinding(keySequence, empty ? null : b.getParameterizedCommand(), activeSchemeId, b.getContextId(), null, null, null, Binding.USER); userMap.remove(b.getTriggerSequence()); userMap.put(keySequence, newBinding); if (empty) commandMap.remove(selectedCommand.getId()); else commandMap.put(selectedCommand.getId(), newBinding); } } else if (!empty) { ParameterizedCommand pc = new ParameterizedCommand(selectedCommand, null); newBinding = new KeyBinding(keySequence, pc, activeSchemeId, "org.eclipse.ui.contexts.window", //$NON-NLS-1$ null, null, null, Binding.USER); userMap.put(keySequence, newBinding); commandMap.put(selectedCommand.getId(), newBinding); } refreshViewer(); doValidate(); keyField.setSelection(keyField.getTextLimit()); } } }); final Button helpButton = new Button(keyGroup, SWT.ARROW | SWT.LEFT); helpButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); helpButton.setToolTipText(Messages.getString("KeyPreferencePage.add_a_special_key")); //$NON-NLS-1$ // Arrow buttons aren't normally added to the tab list. Let's fix that. final Control[] tabStops = keyGroup.getTabList(); final ArrayList<Control> newTabStops = new ArrayList<Control>(); for (int i = 0; i < tabStops.length; i++) { Control tabStop = tabStops[i]; newTabStops.add(tabStop); if (keyField.equals(tabStop)) newTabStops.add(helpButton); } keyGroup.setTabList(newTabStops.toArray(new Control[newTabStops.size()])); // Construct the menu to attach to the above button. final Menu addKeyMenu = new Menu(helpButton); final Iterator<?> trappedKeyItr = KeySequenceText.TRAPPED_KEYS.iterator(); while (trappedKeyItr.hasNext()) { final KeyStroke trappedKey = (KeyStroke) trappedKeyItr.next(); final MenuItem menuItem = new MenuItem(addKeyMenu, SWT.PUSH); menuItem.setText(trappedKey.format()); menuItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { keySequenceField.insert(trappedKey); keyField.setFocus(); keyField.setSelection(keyField.getTextLimit()); } }); } helpButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent selectionEvent) { Point buttonLocation = helpButton.getLocation(); buttonLocation = composite.toDisplay(buttonLocation.x, buttonLocation.y); Point buttonSize = helpButton.getSize(); addKeyMenu.setLocation(buttonLocation.x, buttonLocation.y + buttonSize.y); addKeyMenu.setVisible(true); } }); new Label(composite, SWT.NONE); userLabel = new Label(composite, SWT.NONE); userLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); }
From source file:com.cubrid.common.ui.query.control.jface.text.contentassist.CompletionProposalPopup.java
License:Open Source License
/** * Adds command support to the given control. * * @param control the control to watch for focus * @since 3.2// ww w . ja v a 2 s . c o m */ private void addCommandSupport(final Control control) { final KeySequence commandSequence = fContentAssistant.getRepeatedInvocationKeySequence(); if (commandSequence != null && !commandSequence.isEmpty() && fContentAssistant.isRepeatedInvocationMode()) { control.addFocusListener(new FocusListener() { private CommandKeyListener fCommandKeyListener; public void focusGained(FocusEvent e) { if (Helper.okToUse(control)) { if (fCommandKeyListener == null) { fCommandKeyListener = new CommandKeyListener(commandSequence); fProposalTable.addKeyListener(fCommandKeyListener); } } } public void focusLost(FocusEvent e) { if (fCommandKeyListener != null) { control.removeKeyListener(fCommandKeyListener); fCommandKeyListener = null; } } }); } control.addFocusListener(new FocusListener() { private TraverseListener fTraverseListener; public void focusGained(FocusEvent e) { if (Helper.okToUse(control)) { if (fTraverseListener == null) { fTraverseListener = new TraverseListener() { public void keyTraversed(TraverseEvent event) { if (event.detail == SWT.TRAVERSE_TAB_NEXT) { IInformationControl iControl = fAdditionalInfoController .getCurrentInformationControl2(); if (fAdditionalInfoController.getInternalAccessor().canReplace(iControl)) { fAdditionalInfoController.getInternalAccessor() .replaceInformationControl(true); event.doit = false; } } } }; fProposalTable.addTraverseListener(fTraverseListener); } } } public void focusLost(FocusEvent e) { if (fTraverseListener != null) { control.removeTraverseListener(fTraverseListener); fTraverseListener = null; } } }); }
From source file:org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.java
License:Open Source License
/** * @param potentialKeyStrokes// w w w . j a va2 s .c o m * @param event * @return */ public boolean press(List<KeyStroke> potentialKeyStrokes, Event event) { KeySequence errorSequence = null; Collection<Binding> errorMatch = null; KeySequence sequenceBeforeKeyStroke = state; for (Iterator<KeyStroke> iterator = potentialKeyStrokes.iterator(); iterator.hasNext();) { KeySequence sequenceAfterKeyStroke = KeySequence.getInstance(sequenceBeforeKeyStroke, iterator.next()); if (isPartialMatch(sequenceAfterKeyStroke)) { incrementState(sequenceAfterKeyStroke); return true; } else if (isPerfectMatch(sequenceAfterKeyStroke)) { final ParameterizedCommand cmd = getPerfectMatch(sequenceAfterKeyStroke); try { return executeCommand(cmd, event) || !sequenceBeforeKeyStroke.isEmpty(); } catch (final CommandException e) { return true; } } else if ((keyAssistDialog != null) && (keyAssistDialog.getShell() != null) && ((event.keyCode == SWT.ARROW_DOWN) || (event.keyCode == SWT.ARROW_UP) || (event.keyCode == SWT.ARROW_LEFT) || (event.keyCode == SWT.ARROW_RIGHT) || (event.keyCode == SWT.CR) || (event.keyCode == SWT.PAGE_UP) || (event.keyCode == SWT.PAGE_DOWN))) { // We don't want to swallow keyboard navigation keys. return false; } else { Collection<Binding> matches = getBindingService().getConflictsFor(sequenceAfterKeyStroke); if (matches != null && !matches.isEmpty()) { errorSequence = sequenceAfterKeyStroke; errorMatch = matches; } } } resetState(true); if (sequenceBeforeKeyStroke.isEmpty() && errorSequence != null) { openKeyAssistShell(errorMatch); } return !sequenceBeforeKeyStroke.isEmpty(); }
From source file:org.eclipse.ui.internal.keys.BindingPersistence.java
License:Open Source License
/** * Reads all of the binding definitions from the preferences. * // w w w .j a v a 2 s .com * @param preferences * The memento for the commands preferences key. * @param bindingManager * The binding manager to which the bindings should be added; * must not be <code>null</code>. * @param commandService * The command service for the workbench; must not be * <code>null</code>. */ private static final void readBindingsFromPreferences(final IMemento preferences, final BindingManager bindingManager, final CommandManager commandService) { List warningsToLog = new ArrayList(1); if (preferences != null) { final IMemento[] preferenceMementos = preferences.getChildren(TAG_KEY_BINDING); int preferenceMementoCount = preferenceMementos.length; for (int i = preferenceMementoCount - 1; i >= 0; i--) { final IMemento memento = preferenceMementos[i]; // Read out the command id. String commandId = readOptional(memento, ATT_COMMAND_ID); if (commandId == null) { commandId = readOptional(memento, ATT_COMMAND); } String viewParameter = null; final Command command; if (commandId != null) { command = commandService.getCommand(commandId); } else { command = null; } // Read out the scheme id. String schemeId = readOptional(memento, ATT_KEY_CONFIGURATION_ID); if (schemeId == null) { schemeId = readRequired(memento, ATT_CONFIGURATION, warningsToLog, "Key bindings need a scheme or key configuration"); //$NON-NLS-1$ if (schemeId == null) { continue; } } // Read out the context id. String contextId = readOptional(memento, ATT_CONTEXT_ID); if (contextId == null) { contextId = readOptional(memento, ATT_SCOPE); } if (LEGACY_DEFAULT_SCOPE.equals(contextId)) { contextId = null; } if (contextId == null) { contextId = IContextIds.CONTEXT_ID_WINDOW; } // Read out the key sequence. String keySequenceText = readOptional(memento, ATT_KEY_SEQUENCE); KeySequence keySequence = null; if (keySequenceText == null) { keySequenceText = readRequired(memento, ATT_STRING, warningsToLog, "Key bindings need a key sequence or string"); //$NON-NLS-1$ if (keySequenceText == null) { continue; } // The key sequence is in the old-style format. keySequence = convert2_1Sequence(parse2_1Sequence(keySequenceText)); } else { // The key sequence is in the new-style format. try { keySequence = KeySequence.getInstance(keySequenceText); } catch (final ParseException e) { addWarning(warningsToLog, "Could not parse", null, //$NON-NLS-1$ commandId, "keySequence", keySequenceText); //$NON-NLS-1$ continue; } if (keySequence.isEmpty() || !keySequence.isComplete()) { addWarning(warningsToLog, "Key bindings cannot use an empty or incomplete key sequence", //$NON-NLS-1$ null, commandId, "keySequence", keySequence //$NON-NLS-1$ .toString()); continue; } } // Read out the locale and platform. final String locale = readOptional(memento, ATT_LOCALE); final String platform = readOptional(memento, ATT_PLATFORM); // Read out the parameters final ParameterizedCommand parameterizedCommand; if (command == null) { parameterizedCommand = null; } else if (viewParameter != null) { HashMap parms = new HashMap(); parms.put(ShowViewMenu.VIEW_ID_PARM, viewParameter); parameterizedCommand = ParameterizedCommand.generateCommand(command, parms); } else { parameterizedCommand = readParameters(memento, warningsToLog, command); } final Binding binding = new KeyBinding(keySequence, parameterizedCommand, schemeId, contextId, locale, platform, null, Binding.USER); bindingManager.addBinding(binding); } } // If there were any warnings, then log them now. logWarnings(warningsToLog, "Warnings while parsing the key bindings from the preference store"); //$NON-NLS-1$ }
From source file:org.eclipse.ui.internal.keys.BindingPersistence.java
License:Open Source License
private static KeySequence readKeySequence(IConfigurationElement configurationElement, List warningsToLog, String commandId, String keySequenceText) { KeySequence keySequence = null; if (keySequenceText.equals(configurationElement.getAttribute(ATT_STRING))) { // The key sequence is in the old-style format. try {/* w ww. j av a2 s .c o m*/ keySequence = convert2_1Sequence(parse2_1Sequence(keySequenceText)); } catch (final IllegalArgumentException e) { addWarning(warningsToLog, "Could not parse key sequence", //$NON-NLS-1$ configurationElement, commandId, "keySequence", //$NON-NLS-1$ keySequenceText); return null; } } else { // The key sequence is in the new-style format. try { keySequence = KeySequence.getInstance(keySequenceText); } catch (final ParseException e) { addWarning(warningsToLog, "Could not parse key sequence", //$NON-NLS-1$ configurationElement, commandId, "keySequence", //$NON-NLS-1$ keySequenceText); return null; } if (keySequence.isEmpty() || !keySequence.isComplete()) { addWarning(warningsToLog, "Key bindings should not have an empty or incomplete key sequence", //$NON-NLS-1$ configurationElement, commandId, "keySequence", //$NON-NLS-1$ keySequence.toString()); return null; } } return keySequence; }
From source file:org.eclipse.ui.internal.keys.model.KeyController.java
License:Open Source License
/** * @param activeBinding//from w ww. j av a 2s .c om * @param oldSequence * @param keySequence */ public void updateTrigger(BindingElement activeBinding, KeySequence oldSequence, KeySequence keySequence) { if (activeBinding == null) { return; } Object obj = activeBinding.getModelObject(); if (obj instanceof KeyBinding) { KeyBinding keyBinding = (KeyBinding) obj; if (!keyBinding.getKeySequence().equals(keySequence)) { if (keySequence != null && !keySequence.isEmpty()) { String activeSchemeId = fSchemeModel.getSelectedElement().getId(); ModelElement selectedElement = contextModel.getSelectedElement(); String activeContextId = selectedElement == null ? IContextService.CONTEXT_ID_WINDOW : selectedElement.getId(); final KeyBinding binding = new KeyBinding(keySequence, keyBinding.getParameterizedCommand(), activeSchemeId, activeContextId, null, null, null, Binding.USER); Map bindingToElement = bindingModel.getBindingToElement(); bindingToElement.remove(keyBinding); if (keyBinding.getType() == Binding.USER) { fBindingManager.removeBinding(keyBinding); } else { fBindingManager.addBinding( new KeyBinding(keyBinding.getKeySequence(), null, keyBinding.getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER)); } fBindingManager.addBinding(binding); activeBinding.fill(binding, contextModel); bindingModel.getBindingToElement().put(binding, activeBinding); // Remove binding for any system conflicts bindingModel.setSelectedElement(activeBinding); } else { bindingModel.getBindingToElement().remove(keyBinding); if (keyBinding.getType() == Binding.USER) { fBindingManager.removeBinding(keyBinding); } else { fBindingManager.addBinding( new KeyBinding(keyBinding.getKeySequence(), null, keyBinding.getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER)); } activeBinding.fill(keyBinding.getParameterizedCommand()); } } } else if (obj instanceof ParameterizedCommand) { ParameterizedCommand cmd = (ParameterizedCommand) obj; if (keySequence != null && !keySequence.isEmpty()) { String activeSchemeId = fSchemeModel.getSelectedElement().getId(); ModelElement selectedElement = contextModel.getSelectedElement(); String activeContextId = selectedElement == null ? IContextService.CONTEXT_ID_WINDOW : selectedElement.getId(); final KeyBinding binding = new KeyBinding(keySequence, cmd, activeSchemeId, activeContextId, null, null, null, Binding.USER); fBindingManager.addBinding(binding); activeBinding.fill(binding, contextModel); bindingModel.getBindingToElement().put(binding, activeBinding); } } }
From source file:org.eclipse.ui.internal.keys.WorkbenchKeyboard.java
License:Open Source License
/** * Processes a key press with respect to the key binding architecture. This * updates the mode of the command manager, and runs the current handler for * the command that matches the key sequence, if any. * * @param potentialKeyStrokes// w w w . j a v a 2 s.c o m * The key strokes that could potentially match, in the order of * priority; must not be <code>null</code>. * @param event * The event; may be <code>null</code>. * @return <code>true</code> if a command is executed; <code>false</code> * otherwise. */ public boolean press(List potentialKeyStrokes, Event event) { if (DEBUG && DEBUG_VERBOSE) { Tracing.printTrace("KEYS", //$NON-NLS-1$ "WorkbenchKeyboard.press(potentialKeyStrokes = " //$NON-NLS-1$ + potentialKeyStrokes + ')'); } final Widget widget = event.widget; updateShellKludge(widget); KeySequence errorSequence = null; Collection errorMatch = null; KeySequence sequenceBeforeKeyStroke = state.getCurrentSequence(); for (Iterator iterator = potentialKeyStrokes.iterator(); iterator.hasNext();) { KeySequence sequenceAfterKeyStroke = KeySequence.getInstance(sequenceBeforeKeyStroke, (KeyStroke) iterator.next()); if (isPartialMatch(sequenceAfterKeyStroke)) { incrementState(sequenceAfterKeyStroke); return true; } else if (isPerfectMatch(sequenceAfterKeyStroke)) { final Binding binding = getPerfectMatch(sequenceAfterKeyStroke); try { return executeCommand(binding, event) || !sequenceBeforeKeyStroke.isEmpty(); } catch (final CommandException e) { logException(e, binding.getParameterizedCommand()); return true; } } else if ((keyAssistDialog != null) && (keyAssistDialog.getShell() != null) && ((event.keyCode == SWT.ARROW_DOWN) || (event.keyCode == SWT.ARROW_UP) || (event.keyCode == SWT.ARROW_LEFT) || (event.keyCode == SWT.ARROW_RIGHT) || (event.keyCode == SWT.CR) || (event.keyCode == SWT.PAGE_UP) || (event.keyCode == SWT.PAGE_DOWN))) { // We don't want to swallow keyboard navigation keys. return false; } else { Collection match = getBindingService().getConflictsFor(sequenceAfterKeyStroke); if (match != null) { errorSequence = sequenceAfterKeyStroke; errorMatch = match; } } } resetState(true); if (sequenceBeforeKeyStroke.isEmpty() && errorSequence != null) { openKeyAssistShell(errorMatch); } return !sequenceBeforeKeyStroke.isEmpty(); }