List of usage examples for org.eclipse.jface.bindings.keys IKeyLookup getCtrl
int getCtrl();
From source file:com.github.haixing_hu.swt.action.ActionContributionItemEx.java
License:Open Source License
/** * Synchronizes the UI with the given property. * * @param propertyName//from w ww . j ava 2s. c om * the name of the property, or <code>null</code> meaning all * applicable properties */ @Override public void update(String propertyName) { if (widget != null) { // determine what to do final boolean textChanged = (propertyName == null) || propertyName.equals(IAction.TEXT); boolean imageChanged = (propertyName == null) || propertyName.equals(IAction.IMAGE); final boolean tooltipTextChanged = (propertyName == null) || propertyName.equals(IAction.TOOL_TIP_TEXT); final boolean enableStateChanged = (propertyName == null) || propertyName.equals(IAction.ENABLED) || propertyName.equals(IContributionManagerOverrides.P_ENABLED); final boolean checkChanged = ((action.getStyle() == IAction.AS_CHECK_BOX) || (action.getStyle() == IAction.AS_RADIO_BUTTON)) && ((propertyName == null) || propertyName.equals(IAction.CHECKED)); if (!showImage) { // do not update the image if not show image imageChanged = false; } if (widget instanceof ToolItem) { final ToolItem ti = (ToolItem) widget; String text = action.getText(); // the set text is shown only if there is no image or if forced // by MODE_FORCE_TEXT final boolean showText = (text != null) && (((getMode() & MODE_FORCE_TEXT) != 0) || !hasImages(action)); // only do the trimming if the text will be used if (showText && (text != null)) { text = Action.removeAcceleratorText(text); text = Action.removeMnemonics(text); } if (textChanged) { final String textToSet = showText ? text : ""; //$NON-NLS-1$ final boolean rightStyle = (ti.getParent().getStyle() & SWT.RIGHT) != 0; if (rightStyle || !ti.getText().equals(textToSet)) { // In addition to being required to update the text if // it // gets nulled out in the action, this is also a // workaround // for bug 50151: Using SWT.RIGHT on a ToolBar leaves // blank space ti.setText(textToSet); } } if (imageChanged) { // only substitute a missing image if it has no text updateImages(!showText); } if (tooltipTextChanged || textChanged) { String toolTip = action.getToolTipText(); if ((toolTip == null) || (toolTip.length() == 0)) { toolTip = text; } final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance() .getCallback(); final String commandId = action.getActionDefinitionId(); if ((callback != null) && (commandId != null) && (toolTip != null)) { final String acceleratorText = callback.getAcceleratorText(commandId); if ((acceleratorText != null) && (acceleratorText.length() != 0)) { toolTip = JFaceResources.format("Toolbar_Tooltip_Accelerator", //$NON-NLS-1$ new Object[] { toolTip, acceleratorText }); } } // if the text is showing, then only set the tooltip if // different if (!showText || ((toolTip != null) && !toolTip.equals(text))) { ti.setToolTipText(toolTip); } else { ti.setToolTipText(null); } } if (enableStateChanged) { final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (ti.getEnabled() != shouldBeEnabled) { ti.setEnabled(shouldBeEnabled); } } if (checkChanged) { final boolean bv = action.isChecked(); if (ti.getSelection() != bv) { ti.setSelection(bv); } } return; } if (widget instanceof MenuItem) { final MenuItem mi = (MenuItem) widget; if (textChanged) { int accelerator = 0; String acceleratorText = null; final ActionEx updatedAction = getAction(); String text = null; accelerator = updatedAction.getAccelerator(); final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance() .getCallback(); // Block accelerators that are already in use. if ((accelerator != 0) && (callback != null) && (callback.isAcceleratorInUse(accelerator))) { accelerator = 0; } /* * Process accelerators on GTK in a special way to avoid Bug 42009. We * will override the native input method by allowing these reserved * accelerators to be placed on the menu. We will only do this for * "Ctrl+Shift+[0-9A-FU]". */ final String commandId = updatedAction.getActionDefinitionId(); if ((Util.isGtk()) && (callback instanceof IBindingManagerCallback) && (commandId != null)) { final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback; final IKeyLookup lookup = KeyLookupFactory.getDefault(); final TriggerSequence[] triggerSequences = bindingManagerCallback .getActiveBindingsFor(commandId); for (final TriggerSequence triggerSequence : triggerSequences) { final Trigger[] triggers = triggerSequence.getTriggers(); if (triggers.length == 1) { final Trigger trigger = triggers[0]; if (trigger instanceof KeyStroke) { final KeyStroke currentKeyStroke = (KeyStroke) trigger; final int currentNaturalKey = currentKeyStroke.getNaturalKey(); if ((currentKeyStroke .getModifierKeys() == (lookup.getCtrl() | lookup.getShift())) && (((currentNaturalKey >= '0') && (currentNaturalKey <= '9')) || ((currentNaturalKey >= 'A') && (currentNaturalKey <= 'F')) || (currentNaturalKey == 'U'))) { accelerator = currentKeyStroke.getModifierKeys() | currentNaturalKey; acceleratorText = triggerSequence.format(); break; } } } } } if (accelerator == 0) { if ((callback != null) && (commandId != null)) { acceleratorText = callback.getAcceleratorText(commandId); } } IContributionManagerOverrides overrides = null; if (getParent() != null) { overrides = getParent().getOverrides(); } if (overrides != null) { text = getParent().getOverrides().getText(this); } mi.setAccelerator(accelerator); if (text == null) { text = updatedAction.getText(); } if ((text != null) && (acceleratorText == null)) { // use extracted accelerator text in case accelerator // cannot be fully represented in one int (e.g. // multi-stroke keys) acceleratorText = LegacyActionTools.extractAcceleratorText(text); if ((acceleratorText == null) && (accelerator != 0)) { acceleratorText = Action.convertAccelerator(accelerator); } } if (text == null) { text = ""; //$NON-NLS-1$ } else { text = Action.removeAcceleratorText(text); } // add "..." if the action will show a dialog if (updatedAction.isShowDialog()) { text = text + dialogIndicator; } if (acceleratorText == null) { mi.setText(text); } else { mi.setText(text + '\t' + acceleratorText); } } if (imageChanged) { updateImages(false); } if (enableStateChanged) { final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (mi.getEnabled() != shouldBeEnabled) { mi.setEnabled(shouldBeEnabled); } } if (checkChanged) { final boolean bv = action.isChecked(); if (mi.getSelection() != bv) { mi.setSelection(bv); } } return; } if (widget instanceof Button) { final Button button = (Button) widget; if (imageChanged) { updateImages(false); } if (textChanged) { String text = action.getText(); final boolean showText = (text != null) && (((getMode() & MODE_FORCE_TEXT) != 0) || !hasImages(action)); // only do the trimming if the text will be used if (showText) { text = Action.removeAcceleratorText(text); } final String textToSet = showText ? text : ""; //$NON-NLS-1$ button.setText(textToSet); } if (tooltipTextChanged) { button.setToolTipText(action.getToolTipText()); } if (enableStateChanged) { final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (button.getEnabled() != shouldBeEnabled) { button.setEnabled(shouldBeEnabled); } } if (checkChanged) { final boolean bv = action.isChecked(); if (button.getSelection() != bv) { button.setSelection(bv); } } return; } } }
From source file:de.xirp.util.XirpKeyFormatter.java
License:Open Source License
/** * Separates the modifier keys from each other, and then places * them in an array in some sorted order. The sort order is * dependent on the type of formatter.//from w ww. j a va 2s. c o m * * @see org.eclipse.jface.bindings.keys.formatting.NativeKeyFormatter */ @Override protected int[] sortModifierKeys(final int modifierKeys) { final IKeyLookup lookup = KeyLookupFactory.getDefault(); final String platform = SWT.getPlatform(); final int[] sortedKeys = new int[4]; int index = 0; if ("win32".equals(platform)) { //$NON-NLS-1$ if ((modifierKeys & lookup.getCtrl()) != 0) { sortedKeys[index++] = lookup.getCtrl(); } if ((modifierKeys & lookup.getAlt()) != 0) { sortedKeys[index++] = lookup.getAlt(); } if ((modifierKeys & lookup.getShift()) != 0) { sortedKeys[index++] = lookup.getShift(); } } else if ("gtk".equals(platform) || "motif".equals(platform)) { //$NON-NLS-1$ //$NON-NLS-2$ if ((modifierKeys & lookup.getShift()) != 0) { sortedKeys[index++] = lookup.getShift(); } if ((modifierKeys & lookup.getCtrl()) != 0) { sortedKeys[index++] = lookup.getCtrl(); } if ((modifierKeys & lookup.getAlt()) != 0) { sortedKeys[index++] = lookup.getAlt(); } } else if ("carbon".equals(platform)) { //$NON-NLS-1$ if ((modifierKeys & lookup.getShift()) != 0) { sortedKeys[index++] = lookup.getShift(); } if ((modifierKeys & lookup.getCtrl()) != 0) { sortedKeys[index++] = lookup.getCtrl(); } if ((modifierKeys & lookup.getAlt()) != 0) { sortedKeys[index++] = lookup.getAlt(); } if ((modifierKeys & lookup.getCommand()) != 0) { sortedKeys[index++] = lookup.getCommand(); } } return sortedKeys; }
From source file:org.eclipse.debug.internal.ui.actions.expressions.WatchExpressionDialog.java
License:Open Source License
/** * Returns a string representation of the "Ctrl+Return" key sequence. * /* w w w . j a v a 2s. c o m*/ * @return a string representation of the "Ctrl+Return" key sequence. */ private String getCtrlReturnText() { IKeyLookup keyLookup = KeyLookupFactory.getDefault(); int ctrlKey = keyLookup.getCtrl(); int returnKey = keyLookup.formalKeyLookup(IKeyLookup.RETURN_NAME); KeyStroke ctrlReturnKeyStroke = KeyStroke.getInstance(ctrlKey, returnKey); KeySequence ctrltReturnKeySequence = KeySequence.getInstance(ctrlReturnKeyStroke); return SWTKeySupport.getKeyFormatterForPlatform().format(ctrltReturnKeySequence); }
From source file:org.eclipse.rcptt.tesla.internal.ui.player.SWTKeyboard.java
License:Open Source License
private static int[] sortModifierKeys(final int modifierKeys) { final IKeyLookup lookup = KeyLookupFactory.getDefault(); final int[] sortedKeys = new int[4]; int index = 0; if ((modifierKeys & lookup.getAlt()) != 0) { sortedKeys[index++] = lookup.getAlt(); }//from w w w . j a va 2s . co m if ((modifierKeys & lookup.getCommand()) != 0) { sortedKeys[index++] = lookup.getCommand(); } if ((modifierKeys & lookup.getCtrl()) != 0) { sortedKeys[index++] = lookup.getCtrl(); } if ((modifierKeys & lookup.getShift()) != 0) { sortedKeys[index++] = lookup.getShift(); } return sortedKeys; }
From source file:org.eclipse.sirius.common.ui.tools.api.dialog.quickoutline.QuickOutlineControl.java
License:Open Source License
/** * Creates the outline's tree viewer./*from w ww. j ava2 s. co m*/ * * @param parent * the parent composite. */ protected void createTreeViewer(Composite parent) { filteredTree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL, new CustomPatternFilter(), true) { @Override protected void updateToolbar(boolean visible) { super.updateToolbar(visible); treeViewer.expandToLevel(3); } @Override protected void updateTreeSelection(boolean setFocus) { super.updateTreeSelection(setFocus); Tree t = treeViewer.getTree(); if (getFilterControl().getText().trim().length() == 0 && t.getSelectionCount() == 0 && t.getItemCount() > 0) { TreeItem root = t.getItem(0); if (root != null) { t.setSelection(root); } } } }; filteredTree.setQuickSelectionMode(true); treeViewer = filteredTree.getViewer(); final Tree tree = treeViewer.getTree(); filteredTree.getFilterControl().addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { int accelerator = SWTKeySupport.convertEventToUnmodifiedAccelerator(event); KeySequence keySequence = KeySequence .getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); if (keySequence.getTriggers().length == 1) { Trigger trigger = keySequence.getTriggers()[0]; if (trigger instanceof KeyStroke) { KeyStroke keyStroke = (KeyStroke) trigger; IKeyLookup lookup = KeyLookupFactory.getDefault(); if (keyStroke.getModifierKeys() == lookup.getCtrl() && keyStroke.getNaturalKey() == 'O') { event.doit = false; gotoNextPage(); } } } if (event.keyCode == SWT.CR) { gotoSelectedElement(); return; } // clear all matches previously stored in the label provider ((IQuickOutlineLabelProvider) treeViewer.getLabelProvider()).clear(); TreeItem target = null; if (event.keyCode == SWT.ARROW_DOWN) { target = getTargetDown(); } if (event.keyCode == SWT.ARROW_UP) { target = getTargetUp(); } if (target != null) { event.doit = false; tree.setSelection(new TreeItem[] { target }); } setFocus(); } }); tree.addKeyListener(new TreeKeyListener(tree)); tree.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { // do nothing } public void widgetDefaultSelected(SelectionEvent e) { gotoSelectedElement(); } }); treeViewer.setContentProvider(this.currentPage.getContentProvider()); treeViewer.setLabelProvider(this.currentPage.getLabelProvider()); }
From source file:org.eclipse.ui.tests.performance.CommandsPerformanceTest.java
License:Open Source License
/** * <p>/*w w w . j a v a 2s.co m*/ * Sets up a sufficiently complex set of bindings. * </p> * <p> * At the time of writing, Eclipse's key binding set contains about five * hundred bindings. Of these, 140 specify platform information, while only * 5 specify locale information. About 40 are deletion markers. The deepest * point in the context tree is four levels. There are two schemes. * </p> * <p> * The test binding set contains five thousand bindings. About 1400 specify * either locale or platform information. Five hundred are deletion markers. * The deepest point in the context tree is 40 levels. There are twenty * schemes. * </p> * <p> * The depth of the locale and platform tree is the same in both real life * and the test case. It is difficult to imagine why the locale list would * ever be anything but four elements, or why the platform list would ever * be anything but three elements. * </p> * * @throws NotDefinedException * If something went wrong initializing the active scheme. */ protected final void doSetUp() throws NotDefinedException, Exception { super.doSetUp(); /* * The constants to use in creating the various objects. The platform * locale count must be greater than or equal to the number of deletion * markers. Deletion markers are typically created based on the platform * or locale. */ final int contextTreeDepth = 40; final int schemeDepth = 20; final int bindingCount = 5000; final int platformLocaleCount = 1400; final int deletionMarkers = 500; final String currentLocale = Locale.getDefault().toString(); final String currentPlatform = Util.getWS(); // Set-up a table of modifier keys. final IKeyLookup lookup = KeyLookupFactory.getDefault(); final int modifierKeys0 = 0; final int modifierKeys1 = lookup.getAlt(); final int modifierKeys2 = lookup.getCommand(); final int modifierKeys3 = lookup.getCtrl(); final int modifierKeys4 = lookup.getShift(); final int modifierKeys5 = lookup.getAlt() | lookup.getCommand(); final int modifierKeys6 = lookup.getAlt() | lookup.getCtrl(); final int modifierKeys7 = lookup.getAlt() | lookup.getShift(); final int modifierKeys8 = lookup.getCommand() | lookup.getCtrl(); final int modifierKeys9 = lookup.getCommand() | lookup.getShift(); final int modifierKeys10 = lookup.getCtrl() | lookup.getShift(); final int modifierKeys11 = lookup.getAlt() | lookup.getCommand() | lookup.getCtrl(); final int modifierKeys12 = lookup.getAlt() | lookup.getCommand() | lookup.getShift(); final int modifierKeys13 = lookup.getAlt() | lookup.getCtrl() | lookup.getShift(); final int modifierKeys14 = lookup.getCommand() | lookup.getCtrl() | lookup.getShift(); final int modifierKeys15 = lookup.getAlt() | lookup.getCommand() | lookup.getCtrl() | lookup.getShift(); final int[] modifierKeyTable = { modifierKeys0, modifierKeys1, modifierKeys2, modifierKeys3, modifierKeys4, modifierKeys5, modifierKeys6, modifierKeys7, modifierKeys8, modifierKeys9, modifierKeys10, modifierKeys11, modifierKeys12, modifierKeys13, modifierKeys14, modifierKeys15 }; // Initialize the command manager. commandManager = new CommandManager(); // Initialize the contexts. contextManager = new ContextManager(); final List activeContextIds = new ArrayList(); createContext(contextManager, null, contextTreeDepth, activeContextIds); contextManager.setActiveContextIds(new HashSet(activeContextIds)); // Initialize the schemes. bindingManager = new BindingManager(contextManager, commandManager); final List schemes = new ArrayList(); createScheme(bindingManager, null, schemeDepth, schemes); bindingManager.setActiveScheme((Scheme) schemes.get(schemes.size() - 1)); // Create the deletion markers. final Binding[] bindings = new Binding[bindingCount]; for (int i = 0; i < deletionMarkers; i++) { /* * Set-up the locale and platform. These are based on the numbers * given above. */ String locale = null; String platform = null; if (i < platformLocaleCount) { switch (i % 4) { case 0: locale = currentLocale; break; case 1: platform = currentPlatform; break; case 2: locale = "gibberish"; break; case 3: platform = "gibberish"; break; } } // Build a key sequence. final char character = (char) ('A' + (i % 26)); final int modifierKeys = modifierKeyTable[(i / 26) % modifierKeyTable.length]; final KeyStroke keyStroke = KeyStroke.getInstance(modifierKeys, character); final KeySequence keySequence = KeySequence.getInstance(keyStroke); // Build the other parameters. final String schemeId = ((Scheme) schemes.get(i % schemes.size())).getId(); final String contextId = (String) activeContextIds.get(i % activeContextIds.size()); final int type = (i % 2); // Construct the binding. final Binding binding = new KeyBinding(keySequence, null, schemeId, contextId, locale, platform, null, type); bindings[i] = binding; } /* * Now create the regular bindings. By using the same loop structure and * resetting the index to zero, we ensure that the deletion markers will * actually delete something. */ for (int i = 0; i < bindingCount - deletionMarkers; i++) { /* * Set-up the locale and platform for those bindings that will not * be used to match the above deletion markers. These are based on * the numbers given above. */ String locale = null; String platform = null; if ((i > deletionMarkers) && (i < platformLocaleCount)) { switch (i % 4) { case 0: locale = currentLocale; break; case 1: platform = currentPlatform; break; case 2: locale = "gibberish"; break; case 3: platform = "gibberish"; break; } } // Build a key sequence. final char character = (char) ('A' + (i % 26)); final int modifierKeys = modifierKeyTable[(i / 26) % modifierKeyTable.length]; final KeyStroke keyStroke = KeyStroke.getInstance(modifierKeys, character); final KeySequence keySequence = KeySequence.getInstance(keyStroke); // Build the other parameters. final String commandId = "command" + i; final String schemeId = ((Scheme) schemes.get(i % schemes.size())).getId(); final String contextId = (String) activeContextIds.get(i % activeContextIds.size()); final int type = (i % 2); // Construct the binding. final Command command = commandManager.getCommand(commandId); final ParameterizedCommand parameterizedCommand = new ParameterizedCommand(command, null); final Binding binding = new KeyBinding(keySequence, parameterizedCommand, schemeId, contextId, locale, platform, null, type); bindings[i + deletionMarkers] = binding; } bindingManager.setBindings(bindings); }
From source file:org.eclipse.xtext.ui.editor.autoedit.AbstractEditStrategy.java
License:Open Source License
private boolean shouldSkipNext(int keyCode) { IKeyLookup lookUp = KeyLookupFactory.getDefault(); return lookUp.getCommand() == keyCode || lookUp.getCtrl() == keyCode; }
From source file:org.gemoc.execution.concurrent.ccsljavaxdsml.ui.dashboard.utils.AbstractKeyAdapter.java
License:Open Source License
/** * Is CTRL pressed for specified key event. * /*from w w w . j a va 2 s . co m*/ * @param event_p * @return */ protected boolean isCtrlPressed(KeyEvent event_p) { IKeyLookup keyLookup = KeyLookupFactory.getSWTKeyLookup(); return keyLookup.getCtrl() == event_p.stateMask || keyLookup.getCtrl() == event_p.keyCode; }
From source file:org.springframework.ide.eclipse.boot.dash.util.ToolbarPulldownContributionItem.java
License:Open Source License
/** * Synchronizes the UI with the given property. * * @param propertyName/* w ww . j av a 2 s . com*/ * the name of the property, or <code>null</code> meaning all * applicable properties */ @Override public void update(String propertyName) { if (widget != null) { // determine what to do boolean textChanged = propertyName == null || propertyName.equals(IAction.TEXT); boolean imageChanged = propertyName == null || propertyName.equals(IAction.IMAGE); boolean tooltipTextChanged = propertyName == null || propertyName.equals(IAction.TOOL_TIP_TEXT); boolean enableStateChanged = propertyName == null || propertyName.equals(IAction.ENABLED) || propertyName.equals(IContributionManagerOverrides.P_ENABLED); boolean checkChanged = (action.getStyle() == IAction.AS_CHECK_BOX || action.getStyle() == IAction.AS_RADIO_BUTTON) && (propertyName == null || propertyName.equals(IAction.CHECKED)); if (widget instanceof ToolItem) { ToolItem ti = (ToolItem) widget; String text = action.getText(); // the set text is shown only if there is no image or if forced // by MODE_FORCE_TEXT boolean showText = text != null && ((getMode() & MODE_FORCE_TEXT) != 0 || !hasImages(action)); // only do the trimming if the text will be used if (showText && text != null) { text = Action.removeAcceleratorText(text); text = Action.removeMnemonics(text); } if (textChanged) { String textToSet = showText ? text : ""; //$NON-NLS-1$ boolean rightStyle = (ti.getParent().getStyle() & SWT.RIGHT) != 0; if (rightStyle || !ti.getText().equals(textToSet)) { // In addition to being required to update the text if // it // gets nulled out in the action, this is also a // workaround // for bug 50151: Using SWT.RIGHT on a ToolBar leaves // blank space ti.setText(textToSet); } } if (imageChanged) { // only substitute a missing image if it has no text updateImages(!showText); } if (tooltipTextChanged || textChanged) { String toolTip = action.getToolTipText(); if ((toolTip == null) || (toolTip.length() == 0)) { toolTip = text; } ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback(); String commandId = action.getActionDefinitionId(); if ((callback != null) && (commandId != null) && (toolTip != null)) { String acceleratorText = callback.getAcceleratorText(commandId); if (acceleratorText != null && acceleratorText.length() != 0) { toolTip = JFaceResources.format("Toolbar_Tooltip_Accelerator", //$NON-NLS-1$ new Object[] { toolTip, acceleratorText }); } } // if the text is showing, then only set the tooltip if // different if (!showText || toolTip != null && !toolTip.equals(text)) { ti.setToolTipText(toolTip); } else { ti.setToolTipText(null); } } if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (ti.getEnabled() != shouldBeEnabled) { ti.setEnabled(shouldBeEnabled); } } if (checkChanged) { boolean bv = action.isChecked(); if (ti.getSelection() != bv) { ti.setSelection(bv); } } return; } if (widget instanceof MenuItem) { MenuItem mi = (MenuItem) widget; if (textChanged) { int accelerator = 0; String acceleratorText = null; IAction updatedAction = getAction(); String text = null; accelerator = updatedAction.getAccelerator(); ExternalActionManager.ICallback callback = ExternalActionManager.getInstance().getCallback(); // Block accelerators that are already in use. if ((accelerator != 0) && (callback != null) && (callback.isAcceleratorInUse(accelerator))) { accelerator = 0; } /* * Process accelerators on GTK in a special way to avoid Bug * 42009. We will override the native input method by * allowing these reserved accelerators to be placed on the * menu. We will only do this for "Ctrl+Shift+[0-9A-FU]". */ final String commandId = updatedAction.getActionDefinitionId(); if ((Util.isGtk()) && (callback instanceof IBindingManagerCallback) && (commandId != null)) { final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback; final IKeyLookup lookup = KeyLookupFactory.getDefault(); final TriggerSequence[] triggerSequences = bindingManagerCallback .getActiveBindingsFor(commandId); for (int i = 0; i < triggerSequences.length; i++) { final TriggerSequence triggerSequence = triggerSequences[i]; final Trigger[] triggers = triggerSequence.getTriggers(); if (triggers.length == 1) { final Trigger trigger = triggers[0]; if (trigger instanceof KeyStroke) { final KeyStroke currentKeyStroke = (KeyStroke) trigger; final int currentNaturalKey = currentKeyStroke.getNaturalKey(); if ((currentKeyStroke .getModifierKeys() == (lookup.getCtrl() | lookup.getShift())) && ((currentNaturalKey >= '0' && currentNaturalKey <= '9') || (currentNaturalKey >= 'A' && currentNaturalKey <= 'F') || (currentNaturalKey == 'U'))) { accelerator = currentKeyStroke.getModifierKeys() | currentNaturalKey; acceleratorText = triggerSequence.format(); break; } } } } } if (accelerator == 0) { if ((callback != null) && (commandId != null)) { acceleratorText = callback.getAcceleratorText(commandId); } } IContributionManagerOverrides overrides = null; if (getParent() != null) { overrides = getParent().getOverrides(); } if (overrides != null) { text = getParent().getOverrides().getText(this); } mi.setAccelerator(accelerator); if (text == null) { text = updatedAction.getText(); } if (text != null && acceleratorText == null) { // use extracted accelerator text in case accelerator // cannot be fully represented in one int (e.g. // multi-stroke keys) acceleratorText = LegacyActionTools.extractAcceleratorText(text); if (acceleratorText == null && accelerator != 0) { acceleratorText = Action.convertAccelerator(accelerator); } } if (text == null) { text = ""; //$NON-NLS-1$ } else { text = Action.removeAcceleratorText(text); } if (acceleratorText == null) { mi.setText(text); } else { mi.setText(text + '\t' + acceleratorText); } } if (imageChanged) { updateImages(false); } if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (mi.getEnabled() != shouldBeEnabled) { mi.setEnabled(shouldBeEnabled); } } if (checkChanged) { boolean bv = action.isChecked(); if (mi.getSelection() != bv) { mi.setSelection(bv); } } return; } if (widget instanceof Button) { Button button = (Button) widget; if (imageChanged) { updateImages(false); } if (textChanged) { String text = action.getText(); boolean showText = text != null && ((getMode() & MODE_FORCE_TEXT) != 0 || !hasImages(action)); // only do the trimming if the text will be used if (showText) { text = Action.removeAcceleratorText(text); } String textToSet = showText ? text : ""; //$NON-NLS-1$ button.setText(textToSet); } if (tooltipTextChanged) { button.setToolTipText(action.getToolTipText()); } if (enableStateChanged) { boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed(); if (button.getEnabled() != shouldBeEnabled) { button.setEnabled(shouldBeEnabled); } } if (checkChanged) { boolean bv = action.isChecked(); if (button.getSelection() != bv) { button.setSelection(bv); } } return; } } }
From source file:org.whole.lang.text.ui.actions.TextActionFactory.java
License:Open Source License
public Object[][] textActions() { IKeyLookup keyLookup = KeyLookupFactory.getDefault(); int ctrlKey = keyLookup.getCtrl(); int spaceKey = keyLookup.formalKeyLookup(IKeyLookup.SPACE_NAME); KeyStroke ctrlSpaceKeyStroke = KeyStroke.getInstance(ctrlKey, spaceKey); KeySequence ctrltSpaceKeySequence = KeySequence.getInstance(ctrlSpaceKeyStroke); int returnKey = keyLookup.formalKeyLookup(IKeyLookup.RETURN_NAME); KeyStroke returnKeyStroke = KeyStroke.getInstance(returnKey); KeySequence returnKeySequence = KeySequence.getInstance(returnKeyStroke); int backspaceKey = keyLookup.formalKeyLookup(IKeyLookup.BACKSPACE_NAME); KeyStroke backspaceKeyStroke = KeyStroke.getInstance(backspaceKey); KeySequence backspaceKeySequence = KeySequence.getInstance(backspaceKeyStroke); int deleteKey = keyLookup.formalKeyLookup(IKeyLookup.DELETE_NAME); KeyStroke deleteKeyStroke = KeyStroke.getInstance(deleteKey); KeySequence deleteKeySequence = KeySequence.getInstance(deleteKeyStroke); return new Object[][] { { ctrltSpaceKeySequence, TextEntityDescriptorEnum.Text, SplitOnCaretAction.class }, { returnKeySequence, TextEntityDescriptorEnum.Text, NewlineAction.class }, { backspaceKeySequence, TextEntityDescriptorEnum.Text, BackspaceAction.class }, { deleteKeySequence, TextEntityDescriptorEnum.Text, DeleteAction.class }, // { leftKeySequence, TextEntityDescriptorEnum.Text, LeftTextualAction.class }, // { rightKeySequence, TextEntityDescriptorEnum.Text, RightTextualAction.class }, // { upKeySequence, TextEntityDescriptorEnum.Text, UpTextualAction.class }, // { downKeySequence, TextEntityDescriptorEnum.Text, DownTextualAction.class }, };// w ww . j a va 2s . co m }