List of usage examples for org.eclipse.jface.bindings TriggerSequence equals
@Override
public final boolean equals(final Object object)
From source file:eu.esdihumboldt.hale.ui.functions.groovy.GroovyScriptPage.java
License:Open Source License
@Override protected void addActions(ToolBar toolbar, final CompilingSourceViewer<GroovyAST> viewer) { super.addActions(toolbar, viewer); // GroovyASTTray.createToolItem(toolbar, this, viewer); try {/* ww w . j ava 2 s .c o m*/ final TriggerSequence astTrigger = KeySequence.getInstance("F8"); viewer.appendVerifyKeyListener(new VerifyKeyListener() { @Override public void verifyKey(VerifyEvent event) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(event); KeySequence sequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); if (astTrigger.equals(sequence)) { GroovyASTTray.showTray(GroovyScriptPage.this, viewer); event.doit = false; } } }); } catch (Exception e) { log.error("Error installing AST view listener", e); } }
From source file:eu.esdihumboldt.hale.ui.util.source.SourceViewerKeyBindings.java
License:Open Source License
/** * Install the ability to delete a line through <code>CTRL+D</code> on a * text viewer.//from w w w . j av a 2 s. c om * * @param viewer the text viewer */ public static void installDeleteLine(final TextViewer viewer) { try { final TriggerSequence trigger = KeySequence.getInstance("CTRL+D"); viewer.appendVerifyKeyListener(new VerifyKeyListener() { @Override public void verifyKey(VerifyEvent event) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(event); KeySequence sequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); if (trigger.equals(sequence)) { // determine the current selection int startOffset; int endOffset; Point sel = viewer.getTextWidget().getSelectionRange(); if (sel != null) { startOffset = sel.x; endOffset = startOffset + sel.y; } else { startOffset = viewer.getTextWidget().getCaretOffset(); endOffset = startOffset; } try { // determine the involved lines IDocument doc = viewer.getDocument(); int startLine = doc.getLineOfOffset(startOffset); int endLine = doc.getLineOfOffset(endOffset); // derive start and end offset startOffset = doc.getLineOffset(startLine); if (startLine != endLine) { // delete multiple lines endOffset = doc.getLineOffset(endLine) + doc.getLineLength(endLine); } else { // delete one line endOffset = startOffset + doc.getLineLength(endLine); } // delete the line doc.replace(startOffset, endOffset - startOffset, ""); event.doit = false; } catch (Exception e) { log.warn("Failed to delete line in document", e); } } } }); } catch (ParseException e) { log.error("Failed to install delete line listener on source viewer", e); } }
From source file:org.eclipse.ui.internal.keys.model.ConflictModel.java
License:Open Source License
public void updateConflictsFor(BindingElement newValue, TriggerSequence oldTrigger, TriggerSequence newTrigger, boolean removal) { Collection matches = (Collection) conflictsMap.get(newValue); if (matches != null) { if (newTrigger == null || removal) { // we need to clear this match matches.remove(newValue);//from w w w.ja v a 2 s .co m conflictsMap.remove(newValue); if (matches == conflicts) { controller.firePropertyChange(this, PROP_CONFLICTS_REMOVE, null, newValue); } if (matches.size() == 1) { BindingElement tbe = (BindingElement) matches.iterator().next(); conflictsMap.remove(tbe); tbe.setConflict(Boolean.FALSE); if (matches == conflicts) { setConflicts(null); } } return; } else if (oldTrigger != null && !newTrigger.equals(oldTrigger)) { // we need to clear this match matches.remove(newValue); conflictsMap.remove(newValue); if (matches == conflicts) { controller.firePropertyChange(this, PROP_CONFLICTS_REMOVE, null, newValue); } if (matches.size() == 1) { BindingElement tbe = (BindingElement) matches.iterator().next(); conflictsMap.remove(tbe); tbe.setConflict(Boolean.FALSE); if (matches == conflicts) { setConflicts(null); } } } else { return; } } if (newValue.getTrigger() == null || !(newValue.getModelObject() instanceof Binding)) { return; } Binding binding = (Binding) newValue.getModelObject(); TriggerSequence trigger = binding.getTriggerSequence(); matches = (Collection) bindingManager.getActiveBindingsDisregardingContext().get(trigger); ArrayList localConflicts = new ArrayList(); if (matches != null) { localConflicts.add(newValue); Iterator i = matches.iterator(); while (i.hasNext()) { Binding b = (Binding) i.next(); if (binding != b && b.getContextId().equals(binding.getContextId()) && b.getSchemeId().equals(binding.getSchemeId())) { Object element = bindingModel.getBindingToElement().get(b); if (element != null) { localConflicts.add(element); } } } } if (localConflicts.size() > 1) { // first find if it is already a conflict collection Collection knownConflicts = null; Iterator i = localConflicts.iterator(); while (i.hasNext() && knownConflicts == null) { BindingElement tbe = (BindingElement) i.next(); knownConflicts = (Collection) conflictsMap.get(tbe); } if (knownConflicts != null) { knownConflicts.add(newValue); conflictsMap.put(newValue, knownConflicts); newValue.setConflict(Boolean.TRUE); if (knownConflicts == conflicts) { controller.firePropertyChange(this, PROP_CONFLICTS_ADD, null, newValue); } else if (newValue == getSelectedElement()) { setConflicts(knownConflicts); } return; } boolean isSelected = false; i = localConflicts.iterator(); while (i.hasNext()) { BindingElement tbe = (BindingElement) i.next(); if (tbe != null) { conflictsMap.put(tbe, localConflicts); tbe.setConflict(Boolean.TRUE); } if (tbe == getSelectedElement()) { isSelected = true; } } if (isSelected) { setConflicts(localConflicts); } } }
From source file:org.eclipse.ui.tests.dynamicplugins.BindingsExtensionDynamicTest.java
License:Open Source License
/** * Tests whether the items defined in the extension point can be added and * removed dynamically. It tests that the data doesn't exist, and then loads * the extension. It tests that the data then exists, and unloads the * extension. It tests that the data then doesn't exist. * //from ww w . jav a2 s. c o m * @throws ParseException * If "M1+W" can't be parsed by the extension point. */ public void testBindings() throws ParseException { final IBindingService bindingService = (IBindingService) getWorkbench().getAdapter(IBindingService.class); final TriggerSequence triggerSequence = KeySequence.getInstance("M1+W"); Binding[] bindings; Scheme scheme; boolean found; found = false; bindings = bindingService.getBindings(); if (bindings != null) { for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if ("monkey".equals(binding.getSchemeId()) && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId()) && "org.eclipse.ui.views.showView".equals(binding.getParameterizedCommand().getId()) && binding.getParameterizedCommand().getParameterMap() .containsKey(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID) && binding.getPlatform() == null && binding.getLocale() == null && binding.getType() == Binding.SYSTEM && triggerSequence.equals(binding.getTriggerSequence())) { found = true; } } } assertTrue(!found); scheme = bindingService.getScheme("monkey"); try { scheme.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } getBundle(); found = false; bindings = bindingService.getBindings(); if (bindings != null) { for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if ("monkey".equals(binding.getSchemeId()) && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId()) && "org.eclipse.ui.views.showView".equals(binding.getParameterizedCommand().getId()) && binding.getParameterizedCommand().getParameterMap() .containsKey(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID) && binding.getPlatform() == null && binding.getLocale() == null && binding.getType() == Binding.SYSTEM && triggerSequence.equals(binding.getTriggerSequence())) { found = true; } } } assertTrue(found); scheme = bindingService.getScheme("monkey"); try { assertTrue("Monkey".equals(scheme.getName())); } catch (final NotDefinedException e) { fail(); } removeBundle(); found = false; bindings = bindingService.getBindings(); if (bindings != null) { for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if ("monkey".equals(binding.getSchemeId()) && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId()) && "org.eclipse.ui.views.showView".equals(binding.getParameterizedCommand().getId()) && binding.getParameterizedCommand().getParameterMap() .containsKey(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID) && binding.getPlatform() == null && binding.getLocale() == null && binding.getType() == Binding.SYSTEM && triggerSequence.equals(binding.getTriggerSequence())) { found = true; } } } assertTrue(!found); scheme = bindingService.getScheme("monkey"); try { scheme.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } }
From source file:org.eclipse.ui.tests.dynamicplugins.CommandsExtensionDynamicTest.java
License:Open Source License
/** * Tests whether the items defined in the extension point can be added and * removed dynamically. It tests that the data doesn't exist, and then loads * the extension. It tests that the data then exists, and unloads the * extension. It tests that the data then doesn't exist. * //from w w w .j a v a 2 s .co m * @throws ParseException * If "M1+W" can't be parsed by the extension point. */ public final void testCommands() throws ParseException { final IBindingService bindingService = (IBindingService) getWorkbench().getAdapter(IBindingService.class); final ICommandService commandService = (ICommandService) getWorkbench().getAdapter(ICommandService.class); final IContextService contextService = (IContextService) getWorkbench().getAdapter(IContextService.class); final TriggerSequence triggerSequence = KeySequence.getInstance("M1+W"); NamedHandleObject namedHandleObject; Binding[] bindings; Command command; boolean found; assertTrue(!"monkey".equals(bindingService.getActiveScheme().getId())); found = false; bindings = bindingService.getBindings(); if (bindings != null) { for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if ("monkey".equals(binding.getSchemeId()) && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId()) && "monkey".equals(binding.getParameterizedCommand().getId()) && binding.getPlatform() == null && binding.getLocale() == null && binding.getType() == Binding.SYSTEM && triggerSequence.equals(binding.getTriggerSequence())) { found = true; } } } assertTrue(!found); namedHandleObject = bindingService.getScheme("monkey"); try { namedHandleObject.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } namedHandleObject = commandService.getCategory("monkey"); try { namedHandleObject.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } command = commandService.getCommand("monkey"); try { command.execute(new ExecutionEvent()); fail(); } catch (final ExecutionException e) { fail(); } catch (final NotHandledException e) { assertTrue(true); } try { command.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } namedHandleObject = contextService.getContext("context"); try { namedHandleObject.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } namedHandleObject = contextService.getContext("scope"); try { namedHandleObject.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } getBundle(); assertTrue("monkey".equals(bindingService.getActiveScheme().getId())); found = false; bindings = bindingService.getBindings(); if (bindings != null) { for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if ("monkey".equals(binding.getSchemeId()) && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId()) && "monkey".equals(binding.getParameterizedCommand().getId()) && binding.getPlatform() == null && binding.getLocale() == null && binding.getType() == Binding.SYSTEM && triggerSequence.equals(binding.getTriggerSequence())) { found = true; } } } assertTrue(found); namedHandleObject = bindingService.getScheme("monkey"); try { assertTrue("Monkey".equals(namedHandleObject.getName())); } catch (final NotDefinedException e) { fail(); } command = commandService.getCommand("monkey"); try { command.execute(new ExecutionEvent()); } catch (final ExecutionException e) { fail(); } catch (final NotHandledException e) { fail(); } try { assertEquals("Monkey", command.getName()); } catch (final NotDefinedException e) { fail(); } namedHandleObject = commandService.getCommand("monkey"); try { assertTrue("Monkey".equals(namedHandleObject.getName())); } catch (final NotDefinedException e) { fail(); } namedHandleObject = contextService.getContext("context"); try { assertTrue("Monkey".equals(namedHandleObject.getName())); } catch (final NotDefinedException e) { fail(); } namedHandleObject = contextService.getContext("scope"); try { assertTrue("Monkey".equals(namedHandleObject.getName())); } catch (final NotDefinedException e) { fail(); } removeBundle(); assertTrue(!"monkey".equals(bindingService.getActiveScheme().getId())); found = false; bindings = bindingService.getBindings(); if (bindings != null) { for (int i = 0; i < bindings.length; i++) { final Binding binding = bindings[i]; if ("monkey".equals(binding.getSchemeId()) && IContextIds.CONTEXT_ID_WINDOW.equals(binding.getContextId()) && "monkey".equals(binding.getParameterizedCommand().getId()) && binding.getPlatform() == null && binding.getLocale() == null && binding.getType() == Binding.SYSTEM && triggerSequence.equals(binding.getTriggerSequence())) { found = true; } } } assertTrue(!found); namedHandleObject = bindingService.getScheme("monkey"); try { namedHandleObject.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } namedHandleObject = commandService.getCategory("monkey"); try { namedHandleObject.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } command = commandService.getCommand("monkey"); try { command.execute(new ExecutionEvent()); fail(); } catch (final ExecutionException e) { fail(); } catch (final NotHandledException e) { assertTrue(true); } try { command.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } namedHandleObject = contextService.getContext("context"); try { namedHandleObject.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } namedHandleObject = contextService.getContext("scope"); try { namedHandleObject.getName(); fail(); } catch (final NotDefinedException e) { assertTrue(true); } }
From source file:org.springframework.ide.eclipse.aop.ui.inplace.AopReferenceModelInplaceDialog.java
License:Open Source License
private KeyAdapter getKeyAdapter() { if (keyAdapter == null) { keyAdapter = new KeyAdapter() { @Override//from ww w.ja v a 2 s .c om public void keyPressed(KeyEvent e) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence keySequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); TriggerSequence[] sequences = getInvokingCommandKeySequences(); if (sequences == null) return; for (TriggerSequence element : sequences) { if (element.equals(keySequence)) { e.doit = false; toggleShowParentCrosscutting(); return; } } } }; } return keyAdapter; }
From source file:org.springframework.ide.eclipse.beans.ui.inplace.BeansInplaceOutlineDialog.java
License:Open Source License
private KeyAdapter getKeyAdapter() { if (keyAdapter == null) { keyAdapter = new KeyAdapter() { @Override/* www . jav a 2 s. c om*/ public void keyPressed(KeyEvent e) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(e); KeySequence keySequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); TriggerSequence[] sequences = getInvokingCommandKeySequences(); if (sequences == null) return; for (TriggerSequence element : sequences) { if (element.equals(keySequence)) { e.doit = false; toggleShowParent(); return; } } } }; } return keyAdapter; }