Java Code Examples for org.eclipse.jface.bindings.Binding#USER
The following examples show how to use
org.eclipse.jface.bindings.Binding#USER .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyBindings.java From workspacemechanic with Eclipse Public License 1.0 | 6 votes |
KeyBindings(MechanicLog log, Binding[] bindings) { this.log = log; List<Binding> ub = new ArrayList<Binding>(); List<Binding> sb = new ArrayList<Binding>(); for (Binding binding : bindings) { if (binding.getType() == Binding.USER) { ub.add(binding); } else if (binding.getType() == Binding.SYSTEM) { sb.add(binding); } else { throw new UnsupportedOperationException("Unexpected binding type: " + binding.getType()); } } this.userBindings = ub; this.systemBindings = Collections.unmodifiableList(sb); this.userBindingsMap = buildQualifierToBindingMap(userBindings); this.systemBindingsMap = buildQualifierToBindingMap(systemBindings); }
Example 2
Source File: KeyController2.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * Sets the bindings to default. * @param bindingService * @throws NotDefinedException */ public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException { // Fix the scheme in the local changes. final String defaultSchemeId = bindingService.getDefaultSchemeId(); final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId); try { fBindingManager.setActiveScheme(defaultScheme); } catch (final NotDefinedException e) { // At least we tried.... } // Restore any User defined bindings Binding[] bindings = fBindingManager.getBindings(); for (int i = 0; i < bindings.length; i++) { ParameterizedCommand pCommand = bindings[i].getParameterizedCommand(); String commandId = null; if (pCommand != null) { commandId = pCommand.getCommand().getId(); } if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) { fBindingManager.removeBinding(bindings[i]); } } bindingModel.refresh(contextModel, lstRemove); saveBindings(bindingService); }
Example 3
Source File: KeyController2.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * Sets the bindings to default. * @param bindingService * @throws NotDefinedException */ public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException { // Fix the scheme in the local changes. final String defaultSchemeId = bindingService.getDefaultSchemeId(); final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId); try { fBindingManager.setActiveScheme(defaultScheme); } catch (final NotDefinedException e) { // At least we tried.... } // Restore any User defined bindings Binding[] bindings = fBindingManager.getBindings(); for (int i = 0; i < bindings.length; i++) { ParameterizedCommand pCommand = bindings[i].getParameterizedCommand(); String commandId = null; if (pCommand != null) { commandId = pCommand.getCommand().getId(); } if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) { fBindingManager.removeBinding(bindings[i]); } } bindingModel.refresh(contextModel, lstRemove); saveBindings(bindingService); }
Example 4
Source File: KeyController2.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * Sets the bindings to default. * @param bindingService * @throws NotDefinedException */ public void setDefaultBindings(IBindingService bindingService, List<String> lstRemove) throws NotDefinedException { // Fix the scheme in the local changes. final String defaultSchemeId = bindingService.getDefaultSchemeId(); final Scheme defaultScheme = fBindingManager.getScheme(defaultSchemeId); try { fBindingManager.setActiveScheme(defaultScheme); } catch (final NotDefinedException e) { // At least we tried.... } // Restore any User defined bindings Binding[] bindings = fBindingManager.getBindings(); for (int i = 0; i < bindings.length; i++) { ParameterizedCommand pCommand = bindings[i].getParameterizedCommand(); String commandId = null; if (pCommand != null) { commandId = pCommand.getCommand().getId(); } if (bindings[i].getType() == Binding.USER || (commandId != null && lstRemove.contains(commandId))) { fBindingManager.removeBinding(bindings[i]); } } bindingModel.refresh(contextModel, lstRemove); saveBindings(bindingService); }
Example 5
Source File: KbdMacroLoadHandler.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Bind the loaded macro to its previous key binding, removing any conflicts * * @param editor * @param command - the new kbd macro command * @param sequence - key sequence for binding * @param previous - conflicting binding */ private void bindMacro(ITextEditor editor, Command command, KeySequence sequence, Binding previous) { if (command != null && sequence != null) { IBindingService service = (editor != null) ? (IBindingService) editor.getSite().getService(IBindingService.class) : (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); if (service instanceof BindingService) { BindingService bindingMgr = (BindingService) service; if (previous != null) { bindingMgr.removeBinding(previous); } ParameterizedCommand p = new ParameterizedCommand(command, null); Binding binding = new KeyBinding(sequence, p, KBD_SCHEMEID, KBD_CONTEXTID, null, null, null, Binding.USER); bindingMgr.addBinding(binding); // check for conflicts independent of the current Eclipse context checkConflicts(bindingMgr,sequence,binding); } } }
Example 6
Source File: KeyBindings.java From workspacemechanic with Eclipse Public License 1.0 | 5 votes |
private Binding createBinding( Scheme scheme, String platform, String contextId, KeySequence triggerSequence, ParameterizedCommand parameterizedCommand) { Binding newBinding = new KeyBinding(triggerSequence, parameterizedCommand, scheme.getId(), contextId, null, platform, null, Binding.USER); return newBinding; }
Example 7
Source File: KeyBindingsManualFormatter.java From workspacemechanic with Eclipse Public License 1.0 | 5 votes |
static BindingType from(int eclipseBindingType) { if (eclipseBindingType == Binding.SYSTEM) { return SYSTEM; } else if (eclipseBindingType == Binding.USER) { return USER; } else { throw new UnsupportedOperationException("Binding type: " + eclipseBindingType); } }
Example 8
Source File: KeyController2.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
private void updateBindingContext(ContextElement context) { if (context == null) { return; } BindingElement activeBinding = (BindingElement) bindingModel.getSelectedElement(); if (activeBinding == null) { return; } String activeSchemeId = fSchemeModel.getSelectedElement().getId(); Object obj = activeBinding.getModelObject(); if (obj instanceof KeyBinding) { KeyBinding keyBinding = (KeyBinding) obj; if (!keyBinding.getContextId().equals(context.getId())) { final KeyBinding binding = new KeyBinding(keyBinding.getKeySequence(), keyBinding.getParameterizedCommand(), activeSchemeId, context.getId(), null, null, null, Binding.USER); if (keyBinding.getType() == Binding.USER) { fBindingManager.removeBinding(keyBinding); } else { fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding .getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER)); } bindingModel.getBindingToElement().remove(activeBinding.getModelObject()); fBindingManager.addBinding(binding); activeBinding.fill(binding, contextModel); bindingModel.getBindingToElement().put(binding, activeBinding); } } }
Example 9
Source File: KeyController2.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private void updateBindingContext(ContextElement context) { if (context == null) { return; } BindingElement activeBinding = (BindingElement) bindingModel.getSelectedElement(); if (activeBinding == null) { return; } String activeSchemeId = fSchemeModel.getSelectedElement().getId(); Object obj = activeBinding.getModelObject(); if (obj instanceof KeyBinding) { KeyBinding keyBinding = (KeyBinding) obj; if (!keyBinding.getContextId().equals(context.getId())) { final KeyBinding binding = new KeyBinding(keyBinding.getKeySequence(), keyBinding.getParameterizedCommand(), activeSchemeId, context.getId(), null, null, null, Binding.USER); if (keyBinding.getType() == Binding.USER) { fBindingManager.removeBinding(keyBinding); } else { fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding .getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER)); } bindingModel.getBindingToElement().remove(activeBinding.getModelObject()); fBindingManager.addBinding(binding); activeBinding.fill(binding, contextModel); bindingModel.getBindingToElement().put(binding, activeBinding); } } }
Example 10
Source File: KeyController2.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private void updateBindingContext(ContextElement context) { if (context == null) { return; } BindingElement activeBinding = (BindingElement) bindingModel.getSelectedElement(); if (activeBinding == null) { return; } String activeSchemeId = fSchemeModel.getSelectedElement().getId(); Object obj = activeBinding.getModelObject(); if (obj instanceof KeyBinding) { KeyBinding keyBinding = (KeyBinding) obj; if (!keyBinding.getContextId().equals(context.getId())) { final KeyBinding binding = new KeyBinding(keyBinding.getKeySequence(), keyBinding.getParameterizedCommand(), activeSchemeId, context.getId(), null, null, null, Binding.USER); if (keyBinding.getType() == Binding.USER) { fBindingManager.removeBinding(keyBinding); } else { fBindingManager.addBinding(new KeyBinding(keyBinding.getKeySequence(), null, keyBinding .getSchemeId(), keyBinding.getContextId(), null, null, null, Binding.USER)); } bindingModel.getBindingToElement().remove(activeBinding.getModelObject()); fBindingManager.addBinding(binding); activeBinding.fill(binding, contextModel); bindingModel.getBindingToElement().put(binding, activeBinding); } } }
Example 11
Source File: KbdMacroBindHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Add the binding to the Emacs+ scheme * * @param editor * @param bindingResult */ private void addBinding(ITextEditor editor, IBindingResult bindingResult, String name) { IBindingService service = (IBindingService) editor.getSite().getService(IBindingService.class); if (service instanceof BindingService) { try { BindingService bindingMgr = (BindingService) service; if (bindingResult.getKeyBinding() != null) { // we're overwriting a binding, out with the old bindingMgr.removeBinding(bindingResult.getKeyBinding()); } Command command = null; if (name != null) { ICommandService ics = (ICommandService) editor.getSite().getService(ICommandService.class); String id = EmacsPlusUtils.kbdMacroId(name); // check first, as getCommand will create it if it doesn't already exist if (ics.getDefinedCommandIds().contains(id)) { command = ics.getCommand(id); } } else { // use the unexposed category command = nameKbdMacro(KBD_LNAME + nameid++, editor, KBD_GAZONK); } if (command != null) { Binding binding = new KeyBinding(bindingResult.getTrigger(), new ParameterizedCommand(command, null), KBD_SCHEMEID, KBD_CONTEXTID, null, null, null, Binding.USER); bindingMgr.addBinding(binding); asyncShowMessage(editor, String.format(BOUND, bindingResult.getKeyString()), false); } else { asyncShowMessage(editor, String.format(NO_NAME_UNO, name), true); } } catch (Exception e) { asyncShowMessage(editor, String.format(ABORT, bindingResult.getKeyString()), true); } } }
Example 12
Source File: KeyBindings.java From workspacemechanic with Eclipse Public License 1.0 | 4 votes |
private void addUserBinding(Binding binding) { if (binding.getType() != Binding.USER) { throw new IllegalArgumentException("Can only accept user bindings."); } userBindings.add(binding); }
Example 13
Source File: BindingModel2.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * Removes the <code>bindingElement</code> binding. * @param bindingElement */ public void remove(BindingElement bindingElement) { if (bindingElement == null || !(bindingElement.getModelObject() instanceof Binding)) { return; } KeyBinding keyBinding = (KeyBinding) bindingElement.getModelObject(); if (keyBinding.getType() == Binding.USER) { bindingManager.removeBinding(keyBinding); } else { KeySequence keySequence = keyBinding.getKeySequence(); // Add the delete binding bindingManager.addBinding(new KeyBinding(keySequence, null, keyBinding.getSchemeId(), keyBinding .getContextId(), null, null, null, Binding.USER)); // Unbind any conflicts affected by the delete binding ConflictModel conflictModel = controller.getConflictModel(); conflictModel.updateConflictsFor(bindingElement); Collection conflictsList = conflictModel.getConflicts(); if (conflictsList != null) { Object[] conflicts = conflictsList.toArray(); for (int i = 0; i < conflicts.length; i++) { BindingElement be = (BindingElement) conflicts[i]; if (be == bindingElement) { continue; } Object modelObject = be.getModelObject(); if (modelObject instanceof Binding) { Binding binding = (Binding) modelObject; if (binding.getType() != Binding.SYSTEM) { continue; } ParameterizedCommand pCommand = binding.getParameterizedCommand(); be.fill(pCommand); commandToElement.put(pCommand, be); } } } } ParameterizedCommand parameterizedCommand = keyBinding.getParameterizedCommand(); bindingElement.fill(parameterizedCommand); commandToElement.put(parameterizedCommand, bindingElement); controller.firePropertyChange(this, PROP_CONFLICT_ELEMENT_MAP, null, bindingElement); }
Example 14
Source File: BindingModel2.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * Removes the <code>bindingElement</code> binding. * @param bindingElement */ public void remove(BindingElement bindingElement) { if (bindingElement == null || !(bindingElement.getModelObject() instanceof Binding)) { return; } KeyBinding keyBinding = (KeyBinding) bindingElement.getModelObject(); if (keyBinding.getType() == Binding.USER) { bindingManager.removeBinding(keyBinding); } else { KeySequence keySequence = keyBinding.getKeySequence(); // Add the delete binding bindingManager.addBinding(new KeyBinding(keySequence, null, keyBinding.getSchemeId(), keyBinding .getContextId(), null, null, null, Binding.USER)); // Unbind any conflicts affected by the delete binding ConflictModel conflictModel = controller.getConflictModel(); conflictModel.updateConflictsFor(bindingElement); Collection conflictsList = conflictModel.getConflicts(); if (conflictsList != null) { Object[] conflicts = conflictsList.toArray(); for (int i = 0; i < conflicts.length; i++) { BindingElement be = (BindingElement) conflicts[i]; if (be == bindingElement) { continue; } Object modelObject = be.getModelObject(); if (modelObject instanceof Binding) { Binding binding = (Binding) modelObject; if (binding.getType() != Binding.SYSTEM) { continue; } ParameterizedCommand pCommand = binding.getParameterizedCommand(); be.fill(pCommand); commandToElement.put(pCommand, be); } } } } ParameterizedCommand parameterizedCommand = keyBinding.getParameterizedCommand(); bindingElement.fill(parameterizedCommand); commandToElement.put(parameterizedCommand, bindingElement); controller.firePropertyChange(this, PROP_CONFLICT_ELEMENT_MAP, null, bindingElement); }
Example 15
Source File: BindingModel2.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * Removes the <code>bindingElement</code> binding. * @param bindingElement */ public void remove(BindingElement bindingElement) { if (bindingElement == null || !(bindingElement.getModelObject() instanceof Binding)) { return; } KeyBinding keyBinding = (KeyBinding) bindingElement.getModelObject(); if (keyBinding.getType() == Binding.USER) { bindingManager.removeBinding(keyBinding); } else { KeySequence keySequence = keyBinding.getKeySequence(); // Add the delete binding bindingManager.addBinding(new KeyBinding(keySequence, null, keyBinding.getSchemeId(), keyBinding .getContextId(), null, null, null, Binding.USER)); // Unbind any conflicts affected by the delete binding ConflictModel conflictModel = controller.getConflictModel(); conflictModel.updateConflictsFor(bindingElement); Collection conflictsList = conflictModel.getConflicts(); if (conflictsList != null) { Object[] conflicts = conflictsList.toArray(); for (int i = 0; i < conflicts.length; i++) { BindingElement be = (BindingElement) conflicts[i]; if (be == bindingElement) { continue; } Object modelObject = be.getModelObject(); if (modelObject instanceof Binding) { Binding binding = (Binding) modelObject; if (binding.getType() != Binding.SYSTEM) { continue; } ParameterizedCommand pCommand = binding.getParameterizedCommand(); be.fill(pCommand); commandToElement.put(pCommand, be); } } } } ParameterizedCommand parameterizedCommand = keyBinding.getParameterizedCommand(); bindingElement.fill(parameterizedCommand); commandToElement.put(parameterizedCommand, bindingElement); controller.firePropertyChange(this, PROP_CONFLICT_ELEMENT_MAP, null, bindingElement); }