List of usage examples for org.eclipse.jface.bindings Scheme getParentId
public final String getParentId() throws NotDefinedException
Returns the identifier of the parent of the scheme represented by this handle.
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 {//ww w .j a v a 2 s .co 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 ww.j av a 2 s.c o m*/ 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 . ja va 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.KeysPreferencePage.java
License:Open Source License
/** * Builds the internal look-up tables before allowing the page to become * visible.//from ww w . j a va 2s.co m */ public final void setVisible(final boolean visible) { if (visible == true) { Map contextsByName = new HashMap(); for (Iterator iterator = contextService.getDefinedContextIds().iterator(); iterator.hasNext();) { Context context = contextService.getContext((String) iterator.next()); try { String name = context.getName(); Collection contexts = (Collection) contextsByName.get(name); if (contexts == null) { contexts = new HashSet(); contextsByName.put(name, contexts); } contexts.add(context); } catch (final NotDefinedException e) { // Do nothing. } } Map commandsByName = new HashMap(); for (Iterator iterator = commandService.getDefinedCommandIds().iterator(); iterator.hasNext();) { Command command = commandService.getCommand((String) iterator.next()); if (!isActive(command)) { continue; } try { String name = command.getName(); Collection commands = (Collection) commandsByName.get(name); if (commands == null) { commands = new HashSet(); commandsByName.put(name, commands); } commands.add(command); } catch (NotDefinedException eNotDefined) { // Do nothing } } // moved here to allow us to remove any empty categories commandIdsByCategoryId = new HashMap(); for (Iterator iterator = commandService.getDefinedCommandIds().iterator(); iterator.hasNext();) { final Command command = commandService.getCommand((String) iterator.next()); if (!isActive(command)) { continue; } try { String categoryId = command.getCategory().getId(); Collection commandIds = (Collection) commandIdsByCategoryId.get(categoryId); if (commandIds == null) { commandIds = new HashSet(); commandIdsByCategoryId.put(categoryId, commandIds); } commandIds.add(command.getId()); } catch (NotDefinedException eNotDefined) { // Do nothing } } Map categoriesByName = new HashMap(); for (Iterator iterator = commandService.getDefinedCategoryIds().iterator(); iterator.hasNext();) { Category category = commandService.getCategory((String) iterator.next()); try { if (commandIdsByCategoryId.containsKey(category.getId())) { String name = category.getName(); Collection categories = (Collection) categoriesByName.get(name); if (categories == null) { categories = new HashSet(); categoriesByName.put(name, categories); } categories.add(category); } } catch (NotDefinedException eNotDefined) { // Do nothing } } Map schemesByName = new HashMap(); final Scheme[] definedSchemes = bindingService.getDefinedSchemes(); for (int i = 0; i < definedSchemes.length; i++) { final Scheme scheme = definedSchemes[i]; try { String name = scheme.getName(); Collection schemes = (Collection) schemesByName.get(name); if (schemes == null) { schemes = new HashSet(); schemesByName.put(name, schemes); } schemes.add(scheme); } catch (final NotDefinedException e) { // Do nothing. } } contextIdsByUniqueName = new HashMap(); contextUniqueNamesById = new HashMap(); for (Iterator iterator = contextsByName.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); String name = (String) entry.getKey(); Set contexts = (Set) entry.getValue(); Iterator iterator2 = contexts.iterator(); if (contexts.size() == 1) { Context context = (Context) iterator2.next(); contextIdsByUniqueName.put(name, context.getId()); contextUniqueNamesById.put(context.getId(), name); } else { while (iterator2.hasNext()) { Context context = (Context) iterator2.next(); String uniqueName = MessageFormat .format(Util.translateString(RESOURCE_BUNDLE, "uniqueName"), new Object[] { name, //$NON-NLS-1$ context.getId() }); contextIdsByUniqueName.put(uniqueName, context.getId()); contextUniqueNamesById.put(context.getId(), uniqueName); } } } categoryIdsByUniqueName = new HashMap(); categoryUniqueNamesById = new HashMap(); for (Iterator iterator = categoriesByName.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); String name = (String) entry.getKey(); Set categories = (Set) entry.getValue(); Iterator iterator2 = categories.iterator(); if (categories.size() == 1) { Category category = (Category) iterator2.next(); categoryIdsByUniqueName.put(name, category.getId()); categoryUniqueNamesById.put(category.getId(), name); } else { while (iterator2.hasNext()) { Category category = (Category) iterator2.next(); String uniqueName = MessageFormat .format(Util.translateString(RESOURCE_BUNDLE, "uniqueName"), new Object[] { name, //$NON-NLS-1$ category.getId() }); categoryIdsByUniqueName.put(uniqueName, category.getId()); categoryUniqueNamesById.put(category.getId(), uniqueName); } } } schemeIdsByUniqueName = new HashMap(); schemeUniqueNamesById = new HashMap(); for (Iterator iterator = schemesByName.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); String name = (String) entry.getKey(); Set keyConfigurations = (Set) entry.getValue(); Iterator iterator2 = keyConfigurations.iterator(); if (keyConfigurations.size() == 1) { Scheme scheme = (Scheme) iterator2.next(); schemeIdsByUniqueName.put(name, scheme.getId()); schemeUniqueNamesById.put(scheme.getId(), name); } else { while (iterator2.hasNext()) { Scheme scheme = (Scheme) iterator2.next(); String uniqueName = MessageFormat .format(Util.translateString(RESOURCE_BUNDLE, "uniqueName"), new Object[] { name, //$NON-NLS-1$ scheme.getId() }); schemeIdsByUniqueName.put(uniqueName, scheme.getId()); schemeUniqueNamesById.put(scheme.getId(), uniqueName); } } } Scheme activeScheme = bindingService.getActiveScheme(); // Make an internal copy of the binding manager, for local changes. 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) { throw new Error("There is a programmer error in the keys preference page"); //$NON-NLS-1$ } localChangeManager.setLocale(bindingService.getLocale()); localChangeManager.setPlatform(bindingService.getPlatform()); localChangeManager.setBindings(bindingService.getBindings()); // Populate the category combo box. List categoryNames = new ArrayList(categoryIdsByUniqueName.keySet()); Collections.sort(categoryNames, Collator.getInstance()); if (commandIdsByCategoryId.containsKey(null)) { categoryNames.add(0, Util.translateString(RESOURCE_BUNDLE, "other")); //$NON-NLS-1$ } comboCategory.setItems((String[]) categoryNames.toArray(new String[categoryNames.size()])); comboCategory.clearSelection(); comboCategory.deselectAll(); if (commandIdsByCategoryId.containsKey(null) || !categoryNames.isEmpty()) { comboCategory.select(0); } // Populate the scheme combo box. List schemeNames = new ArrayList(schemeIdsByUniqueName.keySet()); Collections.sort(schemeNames, Collator.getInstance()); comboScheme.setItems((String[]) schemeNames.toArray(new String[schemeNames.size()])); setScheme(activeScheme); // Update the entire page. update(true); } super.setVisible(visible); }
From source file:org.eclipse.ui.internal.keys.KeysPreferencePage.java
License:Open Source License
/** * Updates the label next to the scheme that says "extends" if the scheme is * a child of another scheme. If the scheme is not a child of another * scheme, then the label is simply blank. *///from w w w .j av a 2 s. c om private final void updateLabelSchemeExtends() { final String schemeId = getSchemeId(); if (schemeId != null) { final Scheme scheme = bindingService.getScheme(schemeId); try { final String name = (String) schemeUniqueNamesById.get(scheme.getParentId()); if (name != null) { labelSchemeExtends .setText(MessageFormat.format(Util.translateString(RESOURCE_BUNDLE, "extends"), //$NON-NLS-1$ new Object[] { name })); return; } } catch (final NotDefinedException e) { // Do nothing } } labelSchemeExtends.setText(Util.ZERO_LENGTH_STRING); }
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 w w w . j a va 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.limy.eclipse.qalab.action.KeyBindAction.java
License:Open Source License
/** * L?[oChRs?[???B/*w ww . j av a 2 s . 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; }