List of usage examples for org.eclipse.jface.bindings BindingManager getScheme
public Scheme getScheme(final String schemeId)
Gets the scheme with the given identifier.
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 a 2 s . c o 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
/** * <p>//from w w w . jav a2 s.com * Reads the registry and the preference store, and determines the * identifier for the scheme that should be active. There is a complicated * order of priorities for this. The registry will only be read if there is * no user preference, and the default active scheme id is different than * the default default active scheme id. * </p> * <ol> * <li>A non-default preference.</li> * <li>The legacy preference XML memento.</li> * <li>A default preference value that is different than the default * default active scheme id.</li> * <li>The registry.</li> * <li>The default default active scheme id.</li> * </ol> * * @param configurationElements * The configuration elements from the commands extension point; * must not be <code>null</code>. * @param configurationElementCount * The number of configuration elements that are really in the * array. * @param preferences * The memento wrapping the commands preference key; may be * <code>null</code>. * @param bindingManager * The binding manager that should be updated with the active * scheme. This binding manager must already have its schemes * defined. This value must not be <code>null</code>. */ private static final void readActiveScheme(final IConfigurationElement[] configurationElements, final int configurationElementCount, final IMemento preferences, final BindingManager bindingManager) { // A non-default preference. final IPreferenceStore store = PlatformUI.getPreferenceStore(); final String defaultActiveSchemeId = store .getDefaultString(IWorkbenchPreferenceConstants.KEY_CONFIGURATION_ID); final String preferenceActiveSchemeId = store.getString(IWorkbenchPreferenceConstants.KEY_CONFIGURATION_ID); if ((preferenceActiveSchemeId != null) && (!preferenceActiveSchemeId.equals(defaultActiveSchemeId))) { try { bindingManager.setActiveScheme(bindingManager.getScheme(preferenceActiveSchemeId)); return; } catch (final NotDefinedException e) { // Let's keep looking.... } } // A legacy preference XML memento. if (preferences != null) { final IMemento[] preferenceMementos = preferences.getChildren(TAG_ACTIVE_KEY_CONFIGURATION); int preferenceMementoCount = preferenceMementos.length; for (int i = preferenceMementoCount - 1; i >= 0; i--) { final IMemento memento = preferenceMementos[i]; String id = memento.getString(ATT_KEY_CONFIGURATION_ID); if (id != null) { try { bindingManager.setActiveScheme(bindingManager.getScheme(id)); return; } catch (final NotDefinedException e) { // Let's keep looking.... } } } } // A default preference value that is different than the default. if ((defaultActiveSchemeId != null && defaultActiveSchemeId.length() > 0) && (!defaultActiveSchemeId.equals(IBindingService.DEFAULT_DEFAULT_ACTIVE_SCHEME_ID))) { try { bindingManager.setActiveScheme(bindingManager.getScheme(defaultActiveSchemeId)); return; } catch (final NotDefinedException e) { // Let's keep looking.... } } // The registry. for (int i = configurationElementCount - 1; i >= 0; i--) { final IConfigurationElement configurationElement = configurationElements[i]; String id = configurationElement.getAttribute(ATT_KEY_CONFIGURATION_ID); if (id != null) { try { bindingManager.setActiveScheme(bindingManager.getScheme(id)); return; } catch (final NotDefinedException e) { // Let's keep looking.... } } id = configurationElement.getAttribute(ATT_VALUE); if (id != null) { try { bindingManager.setActiveScheme(bindingManager.getScheme(id)); return; } catch (final NotDefinedException e) { // Let's keep looking.... } } } // The default default active scheme id. try { bindingManager .setActiveScheme(bindingManager.getScheme(IBindingService.DEFAULT_DEFAULT_ACTIVE_SCHEME_ID)); } catch (final NotDefinedException e) { //this is bad - the default default scheme should always exist throw new Error("The default default active scheme id is not defined."); //$NON-NLS-1$ } }
From source file:org.eclipse.ui.internal.keys.BindingPersistence.java
License:Open Source License
/** * Reads all of the scheme definitions from the registry. * // w w w . j a v a 2 s . c om * @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 schemes should be added; must * not be <code>null</code>. */ private static final void readSchemesFromRegistry(final IConfigurationElement[] configurationElements, final int configurationElementCount, final BindingManager bindingManager) { // Undefine all the previous handle objects. final HandleObject[] handleObjects = bindingManager.getDefinedSchemes(); if (handleObjects != null) { for (int i = 0; i < handleObjects.length; i++) { handleObjects[i].undefine(); } } final List warningsToLog = new ArrayList(1); for (int i = 0; i < configurationElementCount; i++) { final IConfigurationElement configurationElement = configurationElements[i]; // Read out the attributes. final String id = readRequired(configurationElement, ATT_ID, warningsToLog, "Schemes need an id"); //$NON-NLS-1$ if (id == null) { continue; } final String name = readRequired(configurationElement, ATT_NAME, warningsToLog, "A scheme needs a name", //$NON-NLS-1$ id); if (name == null) { continue; } final String description = readOptional(configurationElement, ATT_DESCRIPTION); String parentId = configurationElement.getAttribute(ATT_PARENT_ID); if ((parentId != null) && (parentId.length() == 0)) { parentId = configurationElement.getAttribute(ATT_PARENT); if ((parentId != null) && (parentId.length() == 0)) { parentId = null; } } // Define the scheme. final Scheme scheme = bindingManager.getScheme(id); scheme.define(name, description, parentId); } logWarnings(warningsToLog, "Warnings while parsing the key bindings from the 'org.eclipse.ui.bindings', 'org.eclipse.ui.acceleratorConfigurations' and '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 {/* w ww . j ava 2 s . co 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.eclipse.ui.tests.performance.CommandsPerformanceTest.java
License:Open Source License
/** * <p>/* w w w . j a va 2 s .co m*/ * Constructs a branch of a scheme tree. This creates a branch of the given * depth -- remembering the schemes along the way. This method operates * recursively. * </p> * <p> * TODO This should add a bit of breadth to the tree. * </p> * * @param bindingManager * The binding manager in which the schemes should be defined; * must not be <code>null</code>. * @param parent * The parent scheme identifier for the scheme to be created; may * be <code>null</code>. * @param successors * The number of successors to create. The depth of the branch to * be created. If this number is zero, then a scheme is created, * but no recursive call is made. * @param schemes * The list of created schemes; must not be <code>null</code>. */ private static final void createScheme(final BindingManager bindingManager, final String parent, final int successors, final List schemes) { final int count = schemes.size(); final String schemeString = "scheme" + count; final Scheme scheme = bindingManager.getScheme(schemeString); scheme.define(schemeString, schemeString, parent); schemes.add(scheme); if (successors == 0) { return; } createScheme(bindingManager, schemeString, successors - 1, schemes); }
From source file:org.limy.eclipse.qalab.action.KeyBindAction.java
License:Open Source License
/** * L?[oChRs?[???B//from w w w . ja v a 2s .co 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; }