List of usage examples for org.eclipse.jface.bindings BindingManager setBindings
public void setBindings(Binding[] bindings)
Changes the set of bindings for this binding manager.
From source file:org.csstudio.iter.css.product.util.WorkbenchUtil.java
License:Open Source License
/** * Unbind F11 KeyBinding of org.eclipse.debug.ui to avoid conflict with * org.csstudio.opibuilder plugin/*from w w w . j a v a2 s . co m*/ */ public static void unbindDebugLast() { IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench() .getAdapter(IBindingService.class); BindingManager localChangeManager = new BindingManager(new ContextManager(), new CommandManager()); final Scheme[] definedSchemes = bindingService.getDefinedSchemes(); try { for (int i = 0; i < definedSchemes.length; i++) { final Scheme scheme = definedSchemes[i]; final Scheme copy = localChangeManager.getScheme(scheme.getId()); copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId()); } localChangeManager.setActiveScheme(bindingService.getActiveScheme()); } catch (final NotDefinedException e) { e.printStackTrace(); } localChangeManager.setLocale(bindingService.getLocale()); localChangeManager.setPlatform(bindingService.getPlatform()); localChangeManager.setBindings(bindingService.getBindings()); KeyBinding opiFullScreenBinding = null; int nbBinding = 0; Binding[] bArray = bindingService.getBindings(); if (bArray != null) { for (Binding binding : bArray) { if (binding instanceof KeyBinding) { KeyBinding kBind = (KeyBinding) binding; if (kBind.getParameterizedCommand() != null && kBind.getParameterizedCommand().getCommand() != null) { if ("org.eclipse.debug.ui.commands.DebugLast" .equals(kBind.getParameterizedCommand().getCommand().getId())) { KeySequence triggerSequence = kBind.getKeySequence(); String contextId = kBind.getContextId(); String schemeId = kBind.getSchemeId(); KeyBinding deleteBinding = new KeyBinding(triggerSequence, null, schemeId, contextId, null, null, null, Binding.USER); localChangeManager.addBinding(deleteBinding); try { bindingService.savePreferences(localChangeManager.getActiveScheme(), localChangeManager.getBindings()); } catch (IOException e) { e.printStackTrace(); } } else if ("org.csstudio.opibuilder.actions.fullscreen" .equals(kBind.getParameterizedCommand().getCommand().getId())) { if (opiFullScreenBinding == null) opiFullScreenBinding = kBind; nbBinding++; } } } } } // Rebind OPI runner full screen command if it exists only one time if (nbBinding == 1) { KeySequence triggerSequence = opiFullScreenBinding.getKeySequence(); String contextId = opiFullScreenBinding.getContextId(); String schemeId = opiFullScreenBinding.getSchemeId(); KeyBinding updateBinding = new KeyBinding(triggerSequence, opiFullScreenBinding.getParameterizedCommand(), schemeId, contextId, null, null, null, Binding.USER); localChangeManager.addBinding(updateBinding); try { bindingService.savePreferences(localChangeManager.getActiveScheme(), localChangeManager.getBindings()); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.eclipse.ui.internal.keys.BindingPersistence.java
License:Open Source License
/** * Reads all of the binding definitions from the commands extension point. * /*from w w w.j av a 2s. c o m*/ * @param configurationElements * The configuration elements in the commands extension point; * must not be <code>null</code>, but may be empty. * @param configurationElementCount * The number of configuration elements that are really in the * array. * @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 readBindingsFromRegistry(final IConfigurationElement[] configurationElements, final int configurationElementCount, final BindingManager bindingManager, final CommandManager commandService) { final Collection bindings = new ArrayList(configurationElementCount); final List warningsToLog = new ArrayList(1); HashSet cocoaTempList = new HashSet(); // IViewRegistry viewRegistry = // PlatformUI.getWorkbench().getViewRegistry(); // the local cache for the sequence modifiers IConfigurationElement[] sequenceModifiers = new IConfigurationElement[0]; if (configurationElementCount > 0) sequenceModifiers = getSequenceModifierElements(configurationElements[0]); for (int i = 0; i < configurationElementCount; i++) { final IConfigurationElement configurationElement = configurationElements[i]; // different extension. update the cache ... if (i > 0 && !configurationElement.getDeclaringExtension() .equals(configurationElements[i - 1].getDeclaringExtension())) sequenceModifiers = getSequenceModifierElements(configurationElement); /* * Read out the command id. Doing this before determining if the key * binding is actually valid is a bit wasteful. However, it is * helpful to have the command identifier when logging syntax * errors. */ String commandId = readCommandId(configurationElement); String viewParameter = null; final Command command; if (commandId != null) { // TODO should we still try processing keybindings to viewIds? // if (viewRegistry.find(commandId) == null) { command = commandService.getCommand(commandId); if (!command.isDefined()) { // Reference to an undefined command. This is invalid. addWarning(warningsToLog, "Cannot bind to an undefined command", //$NON-NLS-1$ configurationElement, commandId); continue; } } else { command = null; } // Read out the scheme id. String schemeId = readSchemeId(configurationElement, warningsToLog, commandId); if (isEmpty(schemeId)) continue; // Read out the context id. String contextId = readContextId(configurationElement); String keySequenceText = readKeySequenceText(configurationElement); if (isEmpty(keySequenceText)) { // The key sequence should never be null. This is pointless addWarning(warningsToLog, "Defining a key binding with no key sequence has no effect", //$NON-NLS-1$ configurationElement, commandId); continue; } // Read out the key sequence. KeySequence keySequence = readKeySequence(configurationElement, warningsToLog, commandId, keySequenceText); if (keySequence == null) continue; // Read out the locale and platform. String locale = readNonEmptyAttribute(configurationElement, ATT_LOCALE); String platform = readNonEmptyAttribute(configurationElement, ATT_PLATFORM); // Read out the parameters, if any. ParameterizedCommand parameterizedCommand = readParameterizedCommand(warningsToLog, configurationElement, viewParameter, command); List modifiedBindings = applyModifiers(keySequence, keySequenceText, platform, sequenceModifiers, parameterizedCommand, schemeId, contextId, locale, warningsToLog); KeyBinding binding = (KeyBinding) modifiedBindings.get(0); if (modifiedBindings.size() > 1) { for (int j = 1; j < modifiedBindings.size(); j++) { bindings.add(modifiedBindings.get(j)); } } if (Util.WS_COCOA.equals(platform)) { cocoaTempList.add(binding); } else if (Util.WS_CARBON.equals(platform)) { bindings.add(binding); // temp work around ... simply honour the carbon // bindings for cocoa. cocoaTempList.add(new KeyBinding(keySequence, parameterizedCommand, schemeId, contextId, locale, Util.WS_COCOA, null, Binding.SYSTEM)); } else { bindings.add(binding); } } if (cocoaTempList.size() > 0) { bindings.addAll(cocoaTempList); } final Binding[] bindingArray = (Binding[]) bindings.toArray(new Binding[bindings.size()]); bindingManager.setBindings(bindingArray); logWarnings(warningsToLog, "Warnings while parsing the key bindings from the 'org.eclipse.ui.commands' extension point"); //$NON-NLS-1$ }
From source file:org.eclipse.ui.internal.keys.model.KeyController.java
License:Open Source License
private static BindingManager loadModelBackend(IServiceLocator locator) { IBindingService bindingService = (IBindingService) locator.getService(IBindingService.class); BindingManager bindingManager = new BindingManager(new ContextManager(), new CommandManager()); final Scheme[] definedSchemes = bindingService.getDefinedSchemes(); try {/*ww w.ja v a 2s. c o m*/ Scheme modelActiveScheme = null; for (int i = 0; i < definedSchemes.length; i++) { final Scheme scheme = definedSchemes[i]; final Scheme copy = bindingManager.getScheme(scheme.getId()); copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId()); if (definedSchemes[i].getId().equals(bindingService.getActiveScheme().getId())) { modelActiveScheme = copy; } } bindingManager.setActiveScheme(modelActiveScheme); } catch (final NotDefinedException e) { StatusManager.getManager().handle(new Status(IStatus.WARNING, WorkbenchPlugin.PI_WORKBENCH, "Keys page found an undefined scheme", e)); //$NON-NLS-1$ } bindingManager.setLocale(bindingService.getLocale()); bindingManager.setPlatform(bindingService.getPlatform()); bindingManager.setBindings(bindingService.getBindings()); return bindingManager; }
From source file:org.limy.eclipse.qalab.action.KeyBindAction.java
License:Open Source License
/** * L?[oChRs?[???B/*from www.j ava2 s.c o m*/ * @param bindingService * @return * @throws NotDefinedException */ private BindingManager createLocalManager(IBindingService bindingService) throws NotDefinedException { BindingManager localChangeManager = new BindingManager(new ContextManager(), new CommandManager()); Scheme[] definedSchemes = bindingService.getDefinedSchemes(); // Make an internal copy of the binding manager, for local changes. for (int i = 0; i < definedSchemes.length; i++) { Scheme scheme = definedSchemes[i]; Scheme copy = localChangeManager.getScheme(scheme.getId()); copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId()); } localChangeManager.setActiveScheme(bindingService.getActiveScheme()); localChangeManager.setLocale(bindingService.getLocale()); localChangeManager.setPlatform(bindingService.getPlatform()); localChangeManager.setBindings(bindingService.getBindings()); return localChangeManager; }
From source file:org.vimplugin.editors.VimEditorPartListener.java
License:Open Source License
private BindingManager getLocalChangeManager() { BindingManager manager = new BindingManager(new ContextManager(), new CommandManager()); Scheme scheme = bindingService.getActiveScheme(); try {//from w ww. j a v a 2 s.co m try { manager.setActiveScheme(scheme); } catch (NotDefinedException nde) { // KeysPreferencePage ignores this error as well... hmmm } manager.setLocale(bindingService.getLocale()); manager.setPlatform(bindingService.getPlatform()); manager.setBindings(bindingService.getBindings()); } catch (Exception e) { logger.error("Error initializing local binding manager.", e); } return manager; }