List of usage examples for org.eclipse.jface.bindings Binding toString
@Override
public String toString()
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++;/* w w w. j ava2s .co m*/ 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); } }
From source file:org.eclipse.e4.ui.keybinding.tests.BindingPersistenceTest.java
License:Open Source License
public final void testBindingTransform() throws Exception { ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); ParameterizedCommand addWS = new ParameterizedCommand( commandService.getCommand("org.eclipse.ui.navigate.addToWorkingSet"), null); KeySequence m18w = KeySequence.getInstance("M1+8 W"); KeySequence m28w = KeySequence.getInstance("M2+8 W"); boolean foundDeleteMarker = false; int numOfMarkers = 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 (addWS.equals(binding.getParameterizedCommand())) { if (m18w.equals(binding.getTriggerSequence())) { numOfMarkers++;/*from ww w .j a v a 2 s. c o m*/ assertNull(m18w.format(), binding.getPlatform()); } else if (m28w.equals(binding.getTriggerSequence())) { numOfMarkers++; assertTrue(platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform) || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform)); } } else if (binding.getParameterizedCommand() == null && m18w.equals(binding.getTriggerSequence())) { assertTrue(platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform) || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform)); numOfMarkers++; foundDeleteMarker = true; } } } assertEquals(3, numOfMarkers); assertTrue("Unable to find delete marker", foundDeleteMarker); TriggerSequence[] activeBindingsFor = bindingService.getActiveBindingsFor(addWS); assertEquals(1, activeBindingsFor.length); }
From source file:org.eclipse.ui.tests.keys.BindingPersistenceTest.java
License:Open Source License
public final void testBindingTransform() throws Exception { ICommandService commandService = (ICommandService) fWorkbench.getAdapter(ICommandService.class); IBindingService bindingService = (IBindingService) fWorkbench.getAdapter(IBindingService.class); ParameterizedCommand addWS = new ParameterizedCommand( commandService.getCommand("org.eclipse.ui.navigate.addToWorkingSet"), null); KeySequence m18w = KeySequence.getInstance("M1+8 W"); KeySequence m28w = KeySequence.getInstance("M2+8 W"); boolean foundDeleteMarker = false; int numOfMarkers = 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 (addWS.equals(binding.getParameterizedCommand())) { if (m18w.equals(binding.getTriggerSequence())) { numOfMarkers++;/*from w w w . ja v a2s .c om*/ assertNull(m18w.format(), binding.getPlatform()); } else if (m28w.equals(binding.getTriggerSequence())) { numOfMarkers++; assertTrue(platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform) || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform)); } } else if (binding.getParameterizedCommand() == null && m18w.equals(binding.getTriggerSequence())) { assertTrue(platform, Util.WS_CARBON.equals(platform) || Util.WS_COCOA.equals(platform) || Util.WS_GTK.equals(platform) || Util.WS_WIN32.equals(platform)); numOfMarkers++; foundDeleteMarker = true; } } } assertEquals(3, numOfMarkers); assertTrue("Unable to find delete marker", foundDeleteMarker); // make sure that the proper contexts are currently active IContextService contextService = (IContextService) fWorkbench.getService(IContextService.class); contextService.activateContext(IContextService.CONTEXT_ID_DIALOG_AND_WINDOW); contextService.activateContext(IContextService.CONTEXT_ID_WINDOW); TriggerSequence[] activeBindingsFor = bindingService.getActiveBindingsFor(addWS); assertEquals(1, activeBindingsFor.length); }
From source file:org.python.pydev.debug.newconsole.prefs.InterativeConsoleCommandsPreferencesEditor.java
License:Open Source License
/** * Returns whether the keybinding is valid. * @return/*from w w w .j a va 2 s . co m*/ */ private boolean validateAndSetKeybinding(String comboText, InteractiveConsoleCommand interactiveConsoleCommand) { try { String text = textKeybinding.getText().trim(); if (text.length() == 0) { showKeybindingError("The keybinding must be specified."); return false; } Set<String> currentBindings = getCurrentBindings(comboText); if (currentBindings.contains(text)) { showKeybindingError("The keybinding: " + text + " is already being used."); return false; } KeySequence keySequence = KeyBindingHelper.getKeySequence(text); // Just check if it's valid IBindingService bindingService = null; try { bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); } catch (Throwable e) { } FastStringBuffer bufConflicts = new FastStringBuffer(); int numberOfConflicts = 0; if (bindingService != null) { //We can only do this check if the workbench is running... Binding[] bindings = bindingService.getBindings(); for (Binding binding : bindings) { if (binding.getContextId().equals(PyEdit.PYDEV_EDITOR_KEYBINDINGS_CONTEXT_ID)) { if (binding.getTriggerSequence().equals(keySequence)) { ParameterizedCommand parameterizedCommand = binding.getParameterizedCommand(); if (parameterizedCommand == null) { bufConflicts.append(binding.toString()).append('\n'); } else { if (!parameterizedCommand.getCommand().getId() .startsWith(InteractiveConsoleCommand.USER_COMMAND_PREFIX)) { bufConflicts.append(" - ").append(parameterizedCommand.getName()).append('\n'); numberOfConflicts += 1; } } } } } } interactiveConsoleCommand.keybinding = text; if (bufConflicts.length() > 0) { showKeybindingError("The current keybinding (" + text + ") conflicts with:\n" + bufConflicts.toString() + "(" + (numberOfConflicts == 1 ? "they" : "it") + "'ll be removed if the changes are applied and\n" + "can only be restored in the 'Keys' preferences page)."); // Although we show an error, it's valid return true; } else { hideKeybindingError(); return true; } } catch (ParseException | IllegalArgumentException e1) { showKeybindingError(e1); return false; } catch (Exception e1) { showKeybindingError(e1); Log.log(e1); return false; } }