List of usage examples for org.eclipse.jface.bindings Binding getType
public final int getType()
From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java
License:Open Source License
@SuppressWarnings("unused") private void createBindingTable(Composite composite) { bindingViewer = new TableViewer(composite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.FULL_SELECTION); Table table = bindingViewer.getTable(); table.setLayoutData(new GridData(550, 300)); table.setHeaderVisible(true);/*w w w.j ava 2 s . co m*/ table.setLinesVisible(true); commandColumn = createColumn(bindingViewer, Messages.getString("KeyPreferencePage.command"), 200); //$NON-NLS-1$ commandLabelProvider = new ZColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof Command) { try { return ((Command) element).getName(); } catch (NotDefinedException e) { return Messages.getString("KeyPreferencePage.undefined"); //$NON-NLS-1$ } } return element.toString(); } @Override public Font getFont(Object element) { if (element instanceof Command) { Binding binding = commandMap.get(((Command) element).getId()); if (binding != null && binding.getType() == Binding.USER) return JFaceResources.getFont(UiConstants.ITALICFONT); } return super.getFont(element); } }; commandColumn.setLabelProvider(commandLabelProvider); keyColumn = createColumn(bindingViewer, Messages.getString("KeyPreferencePage.keys"), 150); //$NON-NLS-1$ keyLabelProvider = new ZColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof Command) { Binding binding = commandMap.get(((Command) element).getId()); if (binding != null) return binding.getTriggerSequence().format(); return null; } return element.toString(); } }; keyColumn.setLabelProvider(keyLabelProvider); catColumn = createColumn(bindingViewer, Messages.getString("KeyPreferencePage.category"), 150); //$NON-NLS-1$ catLabelProvider = new ZColumnLabelProvider() { @Override public String getText(Object element) { if (element instanceof Command) try { return ((Command) element).getCategory().getName(); } catch (NotDefinedException e) { return Messages.getString("KeyPreferencePage.undefined"); //$NON-NLS-1$ } return element.toString(); } }; catColumn.setLabelProvider(catLabelProvider); bindingViewer.setContentProvider(ArrayContentProvider.getInstance()); new SortColumnManager(bindingViewer, new int[] { SWT.UP, SWT.UP, SWT.UP }, 0); bindingViewer.setComparator(ZViewerComparator.INSTANCE); bindingViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateDetails(); } }); }
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();// w ww . ja va2 s. c o m 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
private void updateDetails() { selectedCommand = (Command) bindingViewer.getStructuredSelection().getFirstElement(); if (selectedCommand != null) { try {// w w w. j a va 2 s. com String name = selectedCommand.getName(); nameField.setText(name == null ? "" : name); //$NON-NLS-1$ String description = selectedCommand.getDescription(); descriptionField.setText(description == null ? "" //$NON-NLS-1$ : description); Binding binding = commandMap.get(selectedCommand.getId()); if (binding != null) { TriggerSequence triggerSequence = binding.getTriggerSequence(); if (triggerSequence instanceof KeySequence) keySequenceField.setKeySequence((KeySequence) triggerSequence); else keySequenceField.setKeySequence(null); userLabel.setText( binding.getType() == Binding.USER ? Messages.getString("KeyPreferencePage.user_defined") //$NON-NLS-1$ : ""); //$NON-NLS-1$ } else { keySequenceField.setKeySequence(null); userLabel.setText(""); //$NON-NLS-1$ } } catch (NotDefinedException e) { // ignore } } }
From source file:com.google.dart.tools.ui.internal.preferences.DartKeyBindingPersistence.java
License:Open Source License
private Element createBindingElement(Binding binding, Document document) { // binding is known to have a ParameterizedCommand whose command ID matches a registered Command String keys = binding.getTriggerSequence().toString(); String platform = binding.getPlatform(); String commandName;//from w ww .j ava 2 s. com try { commandName = binding.getParameterizedCommand().getName(); } catch (NotDefinedException ex) { return null; } String id = keys + commandName + (platform == null ? "" : platform); if (knownBindings.containsKey(id)) { if (binding.getType() == Binding.USER) { // A SYSTEM binding has already been created return null; // do not add it again } else { // A USER binding has already been created; update its standard key binding Element element = knownBindings.get(id); element.setAttribute(XML_ATTRIBUTE_KEYS, binding.getTriggerSequence().toString()); return null; } } Element element = document.createElement(XML_NODE_BINDING); element.setAttribute(XML_ATTRIBUTE_KEYS, keys); element.setAttribute(XML_ATTRIBUTE_COMMANDID, commandName); if (platform != null) { element.setAttribute(XML_ATTRIBUTE_PLATFORM, platform); } knownBindings.put(id, element); return element; }
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 w w w. j a v a2s .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:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java
License:Open Source License
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);/*from w w w.j a v a2 s.c om*/
} 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);
}
From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java
License:Open Source License
/** * Bind a scheme / platform / context / trigger sequence to a command. *///from w ww . j av a 2s . co m public void addIfNotPresent(Scheme scheme, String platform, String contextId, KeySequence triggerSequence, ParameterizedCommand command) { Map<String, String> params = commandParamMap(command); Binding binding = find(scheme, platform, triggerSequence, command.getId(), params); // If no binding exists, create the user binding, add it and return true. if (binding == null) { Binding bindingToAdd = createBinding(scheme, platform, contextId, triggerSequence, command); addUserBinding(bindingToAdd); addedBindings.add(bindingToAdd); return; } /* * If a system binding exists for this scheme / sequence, find out if there's a * user binding hiding it, and if so remove it. */ if ((binding.getType() == Binding.SYSTEM)) { // Finding a user binding to a null command. // ZORZELLA: do we even need to supply params? Binding userBinding = find(scheme, platform, triggerSequence, null, params, userBindings); if (userBinding != null) { userBindings.remove(userBinding); return; } } return; }
From source file:com.google.eclipse.mechanic.core.keybinding.KeyBindings.java
License:Open Source License
private void addUserBinding(Binding binding) { if (binding.getType() != Binding.USER) { throw new IllegalArgumentException("Can only accept user bindings."); }/* w w w .j ava2 s . com*/ userBindings.add(binding); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingPersistenceTest.java
License:Open Source License
/** * <p>/*from w w w . ja v a2 s . com*/ * Tests whether the preference store will be read automatically when a * change to the preference store is made. * </p> * * @throws ParseException * If "ALT+SHIFT+Q A" cannot be parsed by KeySequence. */ public final void testAutoLoad() throws ParseException { // Get the services. ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); bindingService.readRegistryAndPreferences(commandService); // Check the pre-conditions. final String emacsSchemeId = EMACS_SCHEME_ID; assertFalse("The active scheme should be Emacs yet", emacsSchemeId.equals(bindingService.getActiveScheme().getId())); final KeySequence formalKeySequence = KeySequence.getInstance("ALT+SHIFT+Q A"); final String commandId = "org.eclipse.ui.views.showView"; Binding[] bindings = bindingService.getBindings(); int i; for (i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if ((binding.getType() == Binding.USER) && (formalKeySequence.equals(binding.getTriggerSequence()))) { final ParameterizedCommand command = binding.getParameterizedCommand(); final String actualCommandId = (command == null) ? null : command.getCommand().getId(); assertFalse("The command should not yet be bound", commandId.equals(actualCommandId)); break; } } assertEquals("There shouldn't be a matching command yet", bindings.length, i); // Modify the preference store. final IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore(); store.setValue("org.eclipse.ui.commands", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><org.eclipse.ui.commands><activeKeyConfiguration keyConfigurationId=\"" + emacsSchemeId + "\"/><keyBinding commandId=\"" + commandId + "\" contextId=\"org.eclipse.ui.contexts.window\" keyConfigurationId=\"org.eclipse.ui.defaultAcceleratorConfiguration\" keySequence=\"" + formalKeySequence + "\"/></org.eclipse.ui.commands>"); // Check that the values have changed. assertEquals("The active scheme should now be Emacs", emacsSchemeId, bindingService.getActiveScheme().getId()); bindings = bindingService.getBindings(); for (i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if ((binding.getType() == Binding.USER) && (formalKeySequence.equals(binding.getTriggerSequence()))) { final ParameterizedCommand command = binding.getParameterizedCommand(); final String actualCommandId = (command == null) ? null : command.getCommand().getId(); assertEquals("The command should be bound to 'ALT+SHIFT+Q A'", commandId, actualCommandId); break; } } assertFalse("There should be a matching command now", (bindings.length == i)); }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingPersistenceTest.java
License:Open Source License
public final void testSinglePlatform() throws Exception { // Get the services. ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); ParameterizedCommand about = new ParameterizedCommand( commandService.getCommand("org.eclipse.ui.help.aboutAction"), null); KeySequence m18A = KeySequence.getInstance("M1+8 A"); KeySequence m18B = KeySequence.getInstance("M1+8 B"); int numAboutBindings = 0; Binding[] bindings = bindingService.getBindings(); for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if (binding.getType() == Binding.SYSTEM) { String platform = binding.getPlatform(); int idx = (platform == null ? -1 : platform.indexOf(',')); assertEquals(binding.toString(), -1, idx); if (about.equals(binding.getParameterizedCommand())) { if (m18A.equals(binding.getTriggerSequence())) { numAboutBindings++;//from w ww .ja v a 2s. c om assertNull("M+8 A", binding.getPlatform()); } else if (m18B.equals(binding.getTriggerSequence())) { numAboutBindings++; // assertEquals(Util.WS_CARBON, binding.getPlatform()); // temp work around for honouring carbon bindings assertTrue("failure for platform: " + binding.getPlatform(), Util.WS_CARBON.equals(binding.getPlatform()) || Util.WS_COCOA.equals(binding.getPlatform())); } } } } if (Util.WS_CARBON.equals(SWT.getPlatform()) || Util.WS_COCOA.equals(SWT.getPlatform())) { assertEquals(2, numAboutBindings); } else { assertEquals(1, numAboutBindings); } }