List of usage examples for org.eclipse.jface.bindings Scheme define
public final void define(final String name, final String description, final String parentId)
Defines this scheme by giving it a name, and possibly a description and a parent identifier as well.
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 {//from www. j a v 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.brainwy.liclipsetext.shared_ui.bindings.BindKeysHelper.java
License:Open Source License
/** * @param contextId defines the keys context we'll work with... * * We'll only remove/add bindings to this context. */// w w w.j a v a 2 s . com public BindKeysHelper(String contextId) { Assert.isNotNull(contextId); this.contextId = contextId; // Set the context we're working with. Set<String> activeContextIds = new HashSet<>(); activeContextIds.add(contextId); contextManager.setActiveContextIds(activeContextIds); // Check that the context we're working with actually exists IWorkbench workbench = PlatformUI.getWorkbench(); bindingService = (IBindingService) workbench.getService(IBindingService.class); IContextService contextService = (IContextService) workbench.getService(IContextService.class); Context context = contextService.getContext(contextId); if (context == null || context.isDefined() == false) { throw new RuntimeException("The context: " + contextId + " does not exist."); } Scheme activeScheme = bindingService.getActiveScheme(); final Scheme[] definedSchemes = bindingService.getDefinedSchemes(); // Make a copy we can work with locally (we'll apply changes later based on this copy). 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(activeScheme); } catch (final NotDefinedException e) { throw new Error("There is a programmer error in the bind keys helper"); //$NON-NLS-1$ } localChangeManager.setLocale(bindingService.getLocale()); localChangeManager.setPlatform(bindingService.getPlatform()); Binding[] bindings = bindingService.getBindings(); for (Binding binding : bindings) { initialState.add(binding); } localChangeManager.setBindings(bindings); }
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 ww . jav a 2s . com */ 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
/** * <p>//from w w w .j a v a 2 s . c o m * Tests whether two identical bindings lead to a conflict. * </p> * * @throws NotDefinedException * If the scheme we try to activate is not defined. */ public void testConflict() throws NotDefinedException { final Context context = contextManager.getContext("na"); context.define("name", "description", null); final Scheme scheme = bindingManager.getScheme("na"); scheme.define("name", "description", null); bindingManager.setActiveScheme(scheme); final Set activeContextIds = new HashSet(); activeContextIds.add("na"); contextManager.setActiveContextIds(activeContextIds); final Binding binding1 = new TestBinding("conflict1", "na", "na", null, null, Binding.SYSTEM, null); bindingManager.addBinding(binding1); final Binding binding2 = new TestBinding("conflict2", "na", "na", null, null, Binding.SYSTEM, null); bindingManager.addBinding(binding2); TriggerSequence[] activeBindings = bindingManager.getActiveBindingsFor(binding1.getParameterizedCommand()); assertFalse(binding1.equals(binding2)); assertTrue("Neither binding should be active", activeBindings.length == 0); activeBindings = bindingManager.getActiveBindingsFor(binding2.getParameterizedCommand()); assertTrue("Neither binding should be active", activeBindings.length == 0); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java
License:Open Source License
/** * <p>/*from ww w .j a va 2 s . c o m*/ * Tests whether a plug-in developer can override a binding in a child * context. * </p> * * @throws NotDefinedException * If the scheme we try to activate is not defined. */ public void testContextOverride() throws NotDefinedException { final Context parentContext = contextManager.getContext("parent"); parentContext.define("parent", "parent context", null); final Context childContext = contextManager.getContext("child"); childContext.define("child", "child context", "parent"); final Scheme scheme = bindingManager.getScheme("na"); scheme.define("name", "description", null); bindingManager.setActiveScheme(scheme); final Binding binding1 = new TestBinding("parent", "na", "parent", null, null, Binding.SYSTEM, null); bindingManager.addBinding(binding1); final Binding binding2 = new TestBinding("child", "na", "child", null, null, Binding.SYSTEM, null); bindingManager.addBinding(binding2); // Only "parent" final Set activeContextIds = new HashSet(); activeContextIds.add("parent"); contextManager.setActiveContextIds(activeContextIds); assertEquals("When only the parent context is active, only the parent binding is active.", binding1, bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE)); // Only "child" activeContextIds.clear(); activeContextIds.add("child"); contextManager.setActiveContextIds(activeContextIds); assertEquals("When only the child context is active, only the child binding is active.", binding2, bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE)); // Both "parent" and "child" activeContextIds.add("parent"); contextManager.setActiveContextIds(activeContextIds); assertEquals("When both contexts are active, only the child binding is active.", binding2, bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE)); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java
License:Open Source License
/** * <p>/*from w w w .j a v a 2 s .c o m*/ * Tests whether a user-defined deletion actually works. * </p> * * @throws NotDefinedException * If the scheme we try to activate is not defined. */ public void testDeletedBinding() throws NotDefinedException { final Context context = contextManager.getContext("na"); context.define("name", "description", null); final Scheme scheme = bindingManager.getScheme("na"); scheme.define("name", "description", null); bindingManager.setActiveScheme(scheme); final Set activeContextIds = new HashSet(); activeContextIds.add("na"); contextManager.setActiveContextIds(activeContextIds); final Binding binding1 = new TestBinding(null, "na", "na", null, null, Binding.USER, null); bindingManager.addBinding(binding1); final Binding binding2 = new TestBinding("system", "na", "na", null, null, Binding.SYSTEM, null); bindingManager.addBinding(binding2); assertEquals("The user should be able to remove bindings", null, bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE)); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java
License:Open Source License
/** * <p>//from w w w . ja va2 s. c o m * Tests whether a user-defined deletion in one context will allow a binding * in a parent context to match. Bug 105655. * </p> * * @throws NotDefinedException * If the scheme we try to activate is not defined. */ public void testDeletedBindingAllowsParent() throws NotDefinedException { final Context parentContext = contextManager.getContext("parent"); parentContext.define("name", "description", null); final Context childContext = contextManager.getContext("child"); childContext.define("name", "description", "parent"); final Scheme scheme = bindingManager.getScheme("na"); scheme.define("name", "description", null); bindingManager.setActiveScheme(scheme); final Set activeContextIds = new HashSet(); activeContextIds.add("parent"); activeContextIds.add("child"); contextManager.setActiveContextIds(activeContextIds); final Binding childBinding = new TestBinding("childCommand", "na", "child", null, null, Binding.SYSTEM, null); bindingManager.addBinding(childBinding); final Binding deletion = new TestBinding(null, "na", "child", null, null, Binding.USER, null); bindingManager.addBinding(deletion); final Binding parentBinding = new TestBinding("parentCommand", "na", "parent", null, null, Binding.SYSTEM, null); bindingManager.addBinding(parentBinding); assertEquals("The user should be able to remove bindings to allow a parent binding", "parentCommand", bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE).getParameterizedCommand().getId()); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java
License:Open Source License
/** * <p>/*from www .j a va 2 s. c om*/ * Tests a common case for binding deletion. The binding is defined on all * platforms, then deleted on a specific platform, and defined again as * something else. * </p> * * @throws NotDefinedException * If the scheme we try to activate is not defined. */ public void testDeletedBindingPlatform() throws NotDefinedException { final String na = "na"; final Context context = contextManager.getContext(na); context.define("name", "description", null); final Scheme scheme = bindingManager.getScheme(na); scheme.define("name", "description", null); bindingManager.setActiveScheme(scheme); final Set activeContextIds = new HashSet(); activeContextIds.add("na"); contextManager.setActiveContextIds(activeContextIds); final Binding allPlatforms = new TestBinding("allPlatforms", na, na, null, null, Binding.SYSTEM, null); bindingManager.addBinding(allPlatforms); final Binding deletion = new TestBinding(null, na, na, null, Util.getWS(), Binding.SYSTEM, null); bindingManager.addBinding(deletion); final Binding platformSpecific = new TestBinding("platformSpecific", na, na, null, Util.getWS(), Binding.SYSTEM, null); bindingManager.addBinding(platformSpecific); assertEquals("We should be able to change a binding on a particular platform", platformSpecific, bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE)); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java
License:Open Source License
/** * <p>//from ww w.j av a 2 s . c o m * Tests whether a system deletion for a different locale or platform * actually works. It shouldn't. Deletions should only work if they specify * a matching locale or platform. * </p> * * @throws NotDefinedException * If the scheme we try to activate is not defined. */ public void testDeletedBindingUnnecessarily() throws NotDefinedException { final Context context = contextManager.getContext("na"); context.define("name", "description", null); final Scheme scheme = bindingManager.getScheme("na"); scheme.define("name", "description", null); bindingManager.setActiveScheme(scheme); final Set activeContextIds = new HashSet(); activeContextIds.add("na"); contextManager.setActiveContextIds(activeContextIds); final Binding binding1 = new TestBinding(null, "na", "na", "not the current locale", null, Binding.SYSTEM, null); final Binding binding2 = new TestBinding("system", "na", "na", null, null, Binding.SYSTEM, null); final Binding binding3 = new TestBinding(null, "na", "na", null, "not the current platform", Binding.SYSTEM, null); final Binding[] bindings = new Binding[3]; bindings[0] = binding1; bindings[1] = binding2; bindings[2] = binding3; bindingManager.setBindings(bindings); assertEquals("A binding should not cause a deletion if its locale or platform doesn't match", binding2, bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE)); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingInteractionsTest.java
License:Open Source License
/** * <p>//from w w w .j a v a 2 s .co m * Tests whether a user can add a binding to the same conditions once * they've deleted the system binding. * </p> * * @throws NotDefinedException * If the scheme we try to activate is not defined. */ public void testDeletedBindingWithAddition() throws NotDefinedException { final Context context = contextManager.getContext("na"); context.define("name", "description", null); final Scheme scheme = bindingManager.getScheme("na"); scheme.define("name", "description", null); bindingManager.setActiveScheme(scheme); final Set activeContextIds = new HashSet(); activeContextIds.add("na"); contextManager.setActiveContextIds(activeContextIds); final Binding binding1 = new TestBinding(null, "na", "na", null, null, Binding.USER, null); bindingManager.addBinding(binding1); final Binding binding2 = new TestBinding("system", "na", "na", null, null, Binding.SYSTEM, null); bindingManager.addBinding(binding2); final Binding binding3 = new TestBinding("user", "na", "na", null, null, Binding.USER, null); bindingManager.addBinding(binding3); assertEquals("The user redefine a particular binding", binding3, bindingManager.getPerfectMatch(TestBinding.TRIGGER_SEQUENCE)); }