List of usage examples for org.eclipse.jface.bindings Binding getSchemeId
public final String getSchemeId()
From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java
License:Open Source License
@Override protected void fillValues() { IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class); userMap.clear();/*from w w w . jav a 2 s . c om*/ systemMap.clear(); commandMap.clear(); activeSchemeId = bindingService.getActiveScheme().getId(); Binding[] bindings = bindingService.getBindings(); for (Binding binding : bindings) { if (activeSchemeId.equals(binding.getSchemeId())) { TriggerSequence triggerSequence = binding.getTriggerSequence(); if (binding.getType() == Binding.SYSTEM) systemMap.put(triggerSequence, binding); else userMap.put(triggerSequence, binding); } } updateViewer(); ISelection selection = bindingViewer.getSelection(); if (selection.isEmpty()) bindingViewer.setSelection(new StructuredSelection(bindingViewer.getElementAt(0)), true); }
From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java
License:Open Source License
@Override protected String doValidate() { Map<TriggerSequence, List<Binding>> conflictMap = new HashMap<>(); for (Map.Entry<TriggerSequence, Binding> entry : systemMap.entrySet()) { TriggerSequence key = entry.getKey(); Binding binding = userMap.get(key); if (binding == null) binding = entry.getValue();/* ww w.j a v a2s .c o m*/ if (binding.getParameterizedCommand() != null && binding.getSchemeId().equals(activeSchemeId)) { TriggerSequence triggerSequence = binding.getTriggerSequence(); List<Binding> list = conflictMap.get(triggerSequence); if (list == null) { list = new ArrayList<Binding>(); conflictMap.put(triggerSequence, list); } list.add(binding); } } for (Map.Entry<TriggerSequence, Binding> entry : userMap.entrySet()) { TriggerSequence key = entry.getKey(); Binding userBinding = entry.getValue(); Binding binding = systemMap.get(key); if (binding != null && binding.getParameterizedCommand() != null && userBinding.getParameterizedCommand() != null && !binding.getParameterizedCommand().getId() .equals(userBinding.getParameterizedCommand().getId()) && binding.getSchemeId().equals(activeSchemeId)) { TriggerSequence triggerSequence = binding.getTriggerSequence(); List<Binding> list = conflictMap.get(triggerSequence); if (list == null) { list = new ArrayList<Binding>(); conflictMap.put(triggerSequence, list); } if (!list.contains(binding)) list.add(binding); } } List<Binding[]> conflicts = new ArrayList<Binding[]>(); for (List<Binding> conflict : conflictMap.values()) if (conflict.size() > 1) conflicts.add(conflict.toArray(new Binding[conflict.size()])); conflictViewer.setInput(conflicts); return conflicts.isEmpty() ? null : Messages.getString("KeyPreferencePage.there_are_conflicts"); //$NON-NLS-1$ }
From source file:com.google.dart.tools.ui.internal.preferences.DartKeyBindingPersistence.java
License:Open Source License
public Binding findBinding(String commandName, String platform) throws NotDefinedException { Binding[] bindings = bindingService.getBindings(); if (bindings != null) { for (Binding binding : bindings) { if (binding.getSchemeId().equals(DART_BINDING_SCHEME)) { if ((platform != null && platform.equals(binding.getPlatform())) || binding.getPlatform() == null) { ParameterizedCommand pc = binding.getParameterizedCommand(); if (pc != null) { Command cmd = pc.getCommand(); if (cmd != null) { if (commandName.equals(pc.getName())) { return binding; }/* ww w .j av a 2 s . c om*/ } } } } } } return null; }
From source file:com.google.dart.tools.ui.internal.preferences.DartKeyBindingPersistence.java
License:Open Source License
private void updateKeyBinding(Map<String, String> map) throws CoreException { try {/*from w w w . ja v a2s .c o m*/ String platform = map.get(XML_ATTRIBUTE_PLATFORM); String commandName = map.get(XML_ATTRIBUTE_COMMANDID); String stdKeys = map.get(XML_ATTRIBUTE_KEYS); Binding binding = findBinding(commandName, platform); if (binding == null) { return; } Command command = binding.getParameterizedCommand().getCommand(); ParameterizedCommand cmd = new ParameterizedCommand(command, null); String schemeId = binding.getSchemeId(); String contextId = binding.getContextId(); String locale = binding.getLocale(); String wm = null; int type = Binding.USER; KeySequence stdSeq = KeySequence.getInstance(stdKeys); Binding newBind = new KeyBinding(stdSeq, cmd, schemeId, contextId, locale, platform, wm, type); bindingManager.removeBindings(stdSeq, schemeId, contextId, null, null, null, type); bindingManager.addBinding(newBind); } catch (NotDefinedException ex) { throw createException(ex, ex.getMessage()); } catch (ParseException ex) { throw createException(ex, ex.getMessage()); } }
From source file:com.google.dart.tools.ui.internal.preferences.DartKeyBindingPersistence.java
License:Open Source License
private void writeKeyBindingsToStream(OutputStream stream, String encoding) throws CoreException { try {//from ww w . j a va2s . com knownBindings = new HashMap<String, Element>(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element rootElement = document.createElement(XML_NODE_ROOT); rootElement.setAttribute(XML_ATTRIBUTE_VERSION, Integer.toString(1)); document.appendChild(rootElement); Comment comment = document.createComment(DESCR_FORMAT); document.getElementsByTagName(XML_NODE_ROOT).item(0).appendChild(comment); Binding[] bindings = bindingService.getBindings(); if (bindings != null) { bindings = sort(bindings); for (Binding binding : bindings) { if (binding.getSchemeId().equals(DART_BINDING_SCHEME)) { ParameterizedCommand pc = binding.getParameterizedCommand(); if (pc != null) { Command cmd = pc.getCommand(); if (cmd != null && isActive(cmd)) { Element bindingElement = createBindingElement(binding, document); if (bindingElement != null) { rootElement.appendChild(bindingElement); } } } } } } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$ transformer.setOutputProperty(OutputKeys.ENCODING, encoding); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ transformer.transform(new DOMSource(document), new StreamResult(stream)); } catch (TransformerException e) { throw createException(e, SERIALIZATION_PROBLEM); } catch (ParserConfigurationException e) { throw createException(e, SERIALIZATION_PROBLEM); } }
From source file:com.google.eclipse.mechanic.core.keybinding.EclBinding.java
License:Open Source License
public EclBinding(Binding b) { this(calculateCid(b), KeyBindings.commandParamMap(b.getParameterizedCommand()), b.getSchemeId(), b.getPlatform(), b.getContextId(), b.getTriggerSequence().format(), BindingType.from(b)); }
From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java
License:Open Source License
static KbaChangeSetQualifier qualifierForBinding(Binding binding, Action action) { return new KbaChangeSetQualifier(binding.getSchemeId(), binding.getPlatform(), binding.getContextId(), action.toString());/*from w ww . j ava 2s . c o m*/ }
From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java
License:Open Source License
/** * Finds a binding in {@code list} that matches the given * {@code triggerSequence}, {@code scheme} and {@code cid}. If not found, * return {@code null}.// w w w. ja v a 2 s .c o m */ private static Binding find(Scheme scheme, String platform, KeySequence triggerSequence, String cid, Map<String, String> params, List<Binding> list) { for (Binding binding : list) { if (binding.getSchemeId().equals(scheme.getId()) && (binding.getTriggerSequence().equals(triggerSequence)) && Objects.equal(binding.getPlatform(), platform)) { ParameterizedCommand param = binding.getParameterizedCommand(); if (param == null) { if (cid == null) { return binding; } continue; } Command command = param.getCommand(); if (cid == null) { return command == null ? binding : null; } if (cid.equals(command.getId())) { Map<String, String> temp = commandParamMap(param); if (equalMaps(temp, params)) { return binding; } } } } return null; }
From source file:com.mulgasoft.emacsplus.commands.KbdMacroLoadHandler.java
License:Open Source License
/** * Check for binding conflicts independent of the current Eclipse context * If the load is called from a non-editing context, any potential binding conflict will * not be detected; so look for conflicts in a context independent set of bindings. * //from w ww . j a va 2s.c o m * @param service * @param sequence * @param binding */ private void checkConflicts(BindingService service, KeySequence sequence, Binding binding) { Collection<Binding> conflicts = getTotalBindings().get(sequence); for (Binding conflict : conflicts) { if (conflict != binding && binding.getContextId().equals(conflict.getContextId()) && binding.getSchemeId().equals(conflict.getSchemeId())) { service.removeBinding(conflict); } } }
From source file:org.eclipse.e4.ui.bindings.internal.BindingTable.java
License:Open Source License
/** * @param binding//from ww w . j a v a2 s.c o m */ private void evaluateOrderedBindings(TriggerSequence sequence, Binding binding) { ArrayList<Binding> bindingList = orderedBindingsByTrigger.get(sequence); // calculate binding to be used or any conflicts if (bindingList != null) { if (bindingList.isEmpty()) { orderedBindingsByTrigger.remove(sequence); } else if (bindingList.size() > 1) { Binding msb = bindingList.get(0); Binding lsb = bindingList.get(1); int rc = compareSchemes(BEST_SEQUENCE.getActiveSchemes(), msb.getSchemeId(), lsb.getSchemeId()); if (rc == 0) { ArrayList<Binding> conflictList = conflicts.get(sequence); if (conflictList == null) { conflictList = new ArrayList<Binding>(); conflicts.put(sequence, conflictList); } else { conflictList.clear(); } Iterator<Binding> i = bindingList.iterator(); Binding prev = i.next(); conflictList.add(prev); while (i.hasNext() && rc == 0) { Binding next = i.next(); rc = compareSchemes(BEST_SEQUENCE.getActiveSchemes(), prev.getSchemeId(), next.getSchemeId()); if (rc == 0) { conflictList.add(next); } prev = next; } } else { conflicts.remove(sequence); if (bindingsByTrigger.get(sequence) == null) { addBindingSimple(msb); } } } else { if (bindingsByTrigger.get(sequence) == null) { addBindingSimple(bindingList.get(0)); } orderedBindingsByTrigger.remove(sequence); } } else if (binding != null) { conflicts.remove(sequence); if (bindingsByTrigger.get(sequence) == null) { addBindingSimple(binding); } } }