List of usage examples for org.eclipse.jface.bindings Binding getContextId
public final String getContextId()
From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java
License:Open Source License
private final Control createButtonBar(final Composite parent) { final Composite buttonBar = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginWidth = 0;//from www . j a v a 2s . c om buttonBar.setLayout(layout); buttonBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); final Button removeBindingButton = new Button(buttonBar, SWT.PUSH); removeBindingButton.setText(Messages.getString("KeyPreferencePage.remove_shortcuts")); //$NON-NLS-1$ removeBindingButton.addSelectionListener(new SelectionAdapter() { @Override public final void widgetSelected(final SelectionEvent event) { if (selectedCommand != null) { Binding b = commandMap.get(selectedCommand.getId()); if (b != null) { Binding userBinding = new KeyBinding((KeySequence) b.getTriggerSequence(), null, activeSchemeId, b.getContextId(), null, null, null, Binding.USER); userMap.put(userBinding.getTriggerSequence(), userBinding); commandMap.remove(selectedCommand.getId()); } refreshViewer(); doValidate(); } } }); final Button restore = new Button(buttonBar, SWT.PUSH); restore.setText(Messages.getString("KeyPreferencePage.restore_command")); //$NON-NLS-1$ restore.addSelectionListener(new SelectionAdapter() { @Override public final void widgetSelected(final SelectionEvent event) { if (selectedCommand != null) { String id = selectedCommand.getId(); Binding b = commandMap.get(id); userMap.remove(b.getTriggerSequence()); for (Binding sb : systemMap.values()) { if (sb.getParameterizedCommand() != null && sb.getParameterizedCommand().getId().equals(id)) { commandMap.put(sb.getParameterizedCommand().getId(), sb); break; } } refreshViewer(); doValidate(); } } }); return buttonBar; }
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 . j a v a2 s.co 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.google.dart.tools.ui.internal.preferences.DartKeyBindingPersistence.java
License:Open Source License
private void updateKeyBinding(Map<String, String> map) throws CoreException { try {//from w w w. j av a2 s .c om String platform = map.get(XML_ATTRIBUTE_PLATFORM); String commandName = map.get(XML_ATTRIBUTE_COMMANDID); String stdKeys = map.get(XML_ATTRIBUTE_KEYS); Binding binding = findBinding(commandName, platform); if (binding == null) { return; } Command command = binding.getParameterizedCommand().getCommand(); ParameterizedCommand cmd = new ParameterizedCommand(command, null); String schemeId = binding.getSchemeId(); String contextId = binding.getContextId(); String locale = binding.getLocale(); String wm = null; int type = Binding.USER; KeySequence stdSeq = KeySequence.getInstance(stdKeys); Binding newBind = new KeyBinding(stdSeq, cmd, schemeId, contextId, locale, platform, wm, type); bindingManager.removeBindings(stdSeq, schemeId, contextId, null, null, null, type); bindingManager.addBinding(newBind); } catch (NotDefinedException ex) { throw createException(ex, ex.getMessage()); } catch (ParseException ex) { throw createException(ex, ex.getMessage()); } }
From source file:com.google.eclipse.mechanic.core.keybinding.EclBinding.java
License:Open Source License
public EclBinding(Binding b) { this(calculateCid(b), KeyBindings.commandParamMap(b.getParameterizedCommand()), b.getSchemeId(), b.getPlatform(), b.getContextId(), b.getTriggerSequence().format(), BindingType.from(b)); }
From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java
License:Open Source License
static KbaChangeSetQualifier qualifierForBinding(Binding binding, Action action) { return new KbaChangeSetQualifier(binding.getSchemeId(), binding.getPlatform(), binding.getContextId(), action.toString());//from ww w . ja v a 2s . com }
From source file:com.mulgasoft.emacsplus.commands.KbdMacroLoadHandler.java
License:Open Source License
/** * Check for binding conflicts independent of the current Eclipse context * If the load is called from a non-editing context, any potential binding conflict will * not be detected; so look for conflicts in a context independent set of bindings. * // ww w . j ava 2 s . co m * @param service * @param sequence * @param binding */ private void checkConflicts(BindingService service, KeySequence sequence, Binding binding) { Collection<Binding> conflicts = getTotalBindings().get(sequence); for (Binding conflict : conflicts) { if (conflict != binding && binding.getContextId().equals(conflict.getContextId()) && binding.getSchemeId().equals(conflict.getSchemeId())) { service.removeBinding(conflict); } } }
From source file:com.mulgasoft.emacsplus.execute.CommandHelp.java
License:Open Source License
/** * Get the displayable key-binding information for the command * //from w w w . j av a 2 s. c o m * @param com - the command * @param activep - if true, return only active bindings * * @return a String array of binding sequence binding context information */ public static String[] getKeyBindingStrings(Command com, boolean activep) { String id = com.getId(); TriggerSequence trigger; // Get platform bindings for Command Binding[] bindings = getBindings(com, activep); List<String> bindingInfo = new ArrayList<String>(); ParameterizedCommand c; for (Binding bind : bindings) { c = bind.getParameterizedCommand(); if (c != null && c.getId().equals(id)) { trigger = bind.getTriggerSequence(); bindingInfo.add(trigger.toString()); bindingInfo.add(bind.getContextId()); } } return bindingInfo.toArray(new String[0]); }
From source file:com.mulgasoft.emacsplus.execute.CommandHelp.java
License:Open Source License
/** * Get the displayable key-binding information for the parameterized command * /* ww w. j a v a 2s . com*/ * @param com the command * @param activep - if true, return only active bindings * * @return a String array of binding sequence binding context information */ public static String[] getKeyBindingStrings(ParameterizedCommand com, boolean activep) { TriggerSequence trigger; // Get platform bindings for the ParameterizedCommand's Command Binding[] bindings = getBindings(com.getCommand(), activep); List<String> bindingInfo = new ArrayList<String>(); ParameterizedCommand c; for (Binding bind : bindings) { c = bind.getParameterizedCommand(); if (c != null && c.equals(com)) { trigger = bind.getTriggerSequence(); bindingInfo.add(trigger.toString()); bindingInfo.add(bind.getContextId()); } } return bindingInfo.toArray(new String[0]); }
From source file:com.mulgasoft.emacsplus.execute.MetaXDialog.java
License:Open Source License
/** * Get the displayable key-binding information for the command * /* ww w.ja v a 2s . co m*/ * @param com - the Command * @return and array of binding information */ private String[] getKeyBindingString(Command com) { // get all key bindings for the command Binding[] bindings = CommandHelp.getBindings(com, false); List<String> bindingInfo = new ArrayList<String>(); for (Binding bind : bindings) { bindingInfo.add(bind.getTriggerSequence().toString()); bindingInfo.add(bind.getContextId()); } return bindingInfo.toArray(new String[0]); }
From source file:org.brainwy.liclipsetext.shared_ui.bindings.BindKeysHelper.java
License:Open Source License
/** * Removes any bindings which match the given filter. */// ww w. j a v a 2 s .c om public void removeUserBindingsWithFilter(IFilter iFilter) { Binding[] bindings = localChangeManager.getBindings(); for (int i = 0; i < bindings.length; i++) { Binding binding = bindings[i]; // Note: we'll only work with the defined context! if (binding.getContextId().equals(this.contextId)) { if (iFilter.removeBinding(binding)) { localChangeManager.removeBinding(binding); } } } }