List of usage examples for org.eclipse.jface.bindings BindingManager BindingManager
public BindingManager(final ContextManager contextManager, final CommandManager commandManager)
Constructs a new instance of BindingManager.
From source file:com.google.dart.tools.ui.internal.preferences.DartKeyBindingPersistence.java
License:Open Source License
private void initBindingManager() { bindingManager = new BindingManager(new ContextManager(), new CommandManager()); Scheme[] definedSchemes = bindingService.getDefinedSchemes(); try {/* w w w .j av a 2 s . c o m*/ for (int i = 0; i < definedSchemes.length; i++) { Scheme scheme = definedSchemes[i]; Scheme copy = bindingManager.getScheme(scheme.getId()); copy.define(scheme.getName(), scheme.getDescription(), scheme.getParentId()); } bindingManager.setActiveScheme(bindingService.getActiveScheme()); } catch (NotDefinedException e) { throw new Error("Internal error in DartKeyBindingPersistence"); //$NON-NLS-1$ } bindingManager.setLocale(bindingService.getLocale()); bindingManager.setPlatform(bindingService.getPlatform()); Binding[] currentBindings = bindingService.getBindings(); Set<Binding> trimmedBindings = new HashSet<Binding>(); if (currentBindings != null) { for (Binding binding : currentBindings) { if (binding.getType() != Binding.USER) { trimmedBindings.add(binding); } } } Binding[] trimmedBindingArray = trimmedBindings.toArray(new Binding[trimmedBindings.size()]); bindingManager.setBindings(trimmedBindingArray); }
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 . ja v a 2 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.e4.ui.keybinding.tests.BindingInteractionsTest.java
License:Open Source License
/** * Creates a new context manager and a binding manager for use in the test * cases.//from w w w. j a va 2s . co m */ protected void doSetUp() { contextManager = new ContextManager(); bindingManager = new BindingManager(contextManager, new CommandManager()); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingManagerTest.java
License:Open Source License
/** * Creates a new context manager and a binding manager for use in the test * cases./*from w w w . j a va 2 s . c o m*/ */ protected final void doSetUp() { commandManager = new CommandManager(); contextManager = new ContextManager(); bindingManager = new BindingManager(contextManager, commandManager); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingManagerTest.java
License:Open Source License
/** * Tests that the constructor disallows a null context manager. *//*from w w w. j av a 2 s .c o m*/ public final void testConstructor() { try { new BindingManager(null, null); fail("A binding manager cannot be constructed with a null context manager"); } catch (final NullPointerException e) { // Success } }
From source file:org.eclipse.ui.internal.BindingToModelProcessor.java
License:Open Source License
@Execute void process(final MApplication application, IEclipseContext context) { gatherContexts(application.getRootContext()); gatherCommands(application.getCommands()); gatherTables(application.getBindingTables()); CommandManager commandManager = context.get(CommandManager.class); if (commandManager == null) { WorkbenchPlugin.log("Command manager was null in org.eclipse.ui.internal.BindingToModelProcessor"); //$NON-NLS-1$ }/*from w w w.java2 s . com*/ ContextManager contextManager = context.get(ContextManager.class); if (contextManager == null) { WorkbenchPlugin.log("Context manager was null in org.eclipse.ui.internal.BindingToModelProcessor"); //$NON-NLS-1$ } BindingManager bindingManager = new BindingManager(contextManager, commandManager); context.set(BindingManager.class, bindingManager); BindingPersistence persistence = new BindingPersistence(bindingManager, commandManager); persistence.read(); // we'll make this available, although I doubt we have a use for it application.getTags() .add(EBindingService.ACTIVE_SCHEME_TAG + ':' + bindingManager.getActiveScheme().getId()); Collection<?> activeBindingsForScheme = bindingManager.getActiveBindingsDisregardingContextFlat(); for (Object obj : activeBindingsForScheme) { Binding binding = (Binding) obj; addBinding(application, binding); } persistence.dispose(); }
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 {/*from www .ja v a 2 s . 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.eclipse.ui.tests.contexts.Bug84763Test.java
License:Open Source License
/** * Creates a new context manager and a binding manager for use in the test * cases.// w w w . ja v a 2 s.c o m */ protected void doSetUp() { contextManager = new ContextManager(); contextManagerListener = new IContextManagerListener() { public void contextManagerChanged(ContextManagerEvent contextManagerEvent) { previousContextIds = contextManagerEvent.getPreviouslyActiveContextIds(); if (previousContextIds != null) { previousContextIds = new HashSet(previousContextIds); } } }; contextManager.addContextManagerListener(contextManagerListener); bindingManager = new BindingManager(contextManager, new CommandManager()); }
From source file:org.eclipse.ui.tests.performance.CommandsPerformanceTest.java
License:Open Source License
/** * <p>//w w w . j a v a2s. c o m * Sets up a sufficiently complex set of bindings. * </p> * <p> * At the time of writing, Eclipse's key binding set contains about five * hundred bindings. Of these, 140 specify platform information, while only * 5 specify locale information. About 40 are deletion markers. The deepest * point in the context tree is four levels. There are two schemes. * </p> * <p> * The test binding set contains five thousand bindings. About 1400 specify * either locale or platform information. Five hundred are deletion markers. * The deepest point in the context tree is 40 levels. There are twenty * schemes. * </p> * <p> * The depth of the locale and platform tree is the same in both real life * and the test case. It is difficult to imagine why the locale list would * ever be anything but four elements, or why the platform list would ever * be anything but three elements. * </p> * * @throws NotDefinedException * If something went wrong initializing the active scheme. */ protected final void doSetUp() throws NotDefinedException, Exception { super.doSetUp(); /* * The constants to use in creating the various objects. The platform * locale count must be greater than or equal to the number of deletion * markers. Deletion markers are typically created based on the platform * or locale. */ final int contextTreeDepth = 40; final int schemeDepth = 20; final int bindingCount = 5000; final int platformLocaleCount = 1400; final int deletionMarkers = 500; final String currentLocale = Locale.getDefault().toString(); final String currentPlatform = Util.getWS(); // Set-up a table of modifier keys. final IKeyLookup lookup = KeyLookupFactory.getDefault(); final int modifierKeys0 = 0; final int modifierKeys1 = lookup.getAlt(); final int modifierKeys2 = lookup.getCommand(); final int modifierKeys3 = lookup.getCtrl(); final int modifierKeys4 = lookup.getShift(); final int modifierKeys5 = lookup.getAlt() | lookup.getCommand(); final int modifierKeys6 = lookup.getAlt() | lookup.getCtrl(); final int modifierKeys7 = lookup.getAlt() | lookup.getShift(); final int modifierKeys8 = lookup.getCommand() | lookup.getCtrl(); final int modifierKeys9 = lookup.getCommand() | lookup.getShift(); final int modifierKeys10 = lookup.getCtrl() | lookup.getShift(); final int modifierKeys11 = lookup.getAlt() | lookup.getCommand() | lookup.getCtrl(); final int modifierKeys12 = lookup.getAlt() | lookup.getCommand() | lookup.getShift(); final int modifierKeys13 = lookup.getAlt() | lookup.getCtrl() | lookup.getShift(); final int modifierKeys14 = lookup.getCommand() | lookup.getCtrl() | lookup.getShift(); final int modifierKeys15 = lookup.getAlt() | lookup.getCommand() | lookup.getCtrl() | lookup.getShift(); final int[] modifierKeyTable = { modifierKeys0, modifierKeys1, modifierKeys2, modifierKeys3, modifierKeys4, modifierKeys5, modifierKeys6, modifierKeys7, modifierKeys8, modifierKeys9, modifierKeys10, modifierKeys11, modifierKeys12, modifierKeys13, modifierKeys14, modifierKeys15 }; // Initialize the command manager. commandManager = new CommandManager(); // Initialize the contexts. contextManager = new ContextManager(); final List activeContextIds = new ArrayList(); createContext(contextManager, null, contextTreeDepth, activeContextIds); contextManager.setActiveContextIds(new HashSet(activeContextIds)); // Initialize the schemes. bindingManager = new BindingManager(contextManager, commandManager); final List schemes = new ArrayList(); createScheme(bindingManager, null, schemeDepth, schemes); bindingManager.setActiveScheme((Scheme) schemes.get(schemes.size() - 1)); // Create the deletion markers. final Binding[] bindings = new Binding[bindingCount]; for (int i = 0; i < deletionMarkers; i++) { /* * Set-up the locale and platform. These are based on the numbers * given above. */ String locale = null; String platform = null; if (i < platformLocaleCount) { switch (i % 4) { case 0: locale = currentLocale; break; case 1: platform = currentPlatform; break; case 2: locale = "gibberish"; break; case 3: platform = "gibberish"; break; } } // Build a key sequence. final char character = (char) ('A' + (i % 26)); final int modifierKeys = modifierKeyTable[(i / 26) % modifierKeyTable.length]; final KeyStroke keyStroke = KeyStroke.getInstance(modifierKeys, character); final KeySequence keySequence = KeySequence.getInstance(keyStroke); // Build the other parameters. final String schemeId = ((Scheme) schemes.get(i % schemes.size())).getId(); final String contextId = (String) activeContextIds.get(i % activeContextIds.size()); final int type = (i % 2); // Construct the binding. final Binding binding = new KeyBinding(keySequence, null, schemeId, contextId, locale, platform, null, type); bindings[i] = binding; } /* * Now create the regular bindings. By using the same loop structure and * resetting the index to zero, we ensure that the deletion markers will * actually delete something. */ for (int i = 0; i < bindingCount - deletionMarkers; i++) { /* * Set-up the locale and platform for those bindings that will not * be used to match the above deletion markers. These are based on * the numbers given above. */ String locale = null; String platform = null; if ((i > deletionMarkers) && (i < platformLocaleCount)) { switch (i % 4) { case 0: locale = currentLocale; break; case 1: platform = currentPlatform; break; case 2: locale = "gibberish"; break; case 3: platform = "gibberish"; break; } } // Build a key sequence. final char character = (char) ('A' + (i % 26)); final int modifierKeys = modifierKeyTable[(i / 26) % modifierKeyTable.length]; final KeyStroke keyStroke = KeyStroke.getInstance(modifierKeys, character); final KeySequence keySequence = KeySequence.getInstance(keyStroke); // Build the other parameters. final String commandId = "command" + i; final String schemeId = ((Scheme) schemes.get(i % schemes.size())).getId(); final String contextId = (String) activeContextIds.get(i % activeContextIds.size()); final int type = (i % 2); // Construct the binding. final Command command = commandManager.getCommand(commandId); final ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, null); final Binding binding = new KeyBinding(keySequence, parameterizedCommand, schemeId, contextId, locale, platform, null, type); bindings[i + deletionMarkers] = binding; } bindingManager.setBindings(bindings); }
From source file:org.limy.eclipse.qalab.action.KeyBindAction.java
License:Open Source License
/** * L?[oChRs?[???B/*from ww w . j a va 2 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; }