List of usage examples for org.eclipse.jface.bindings TriggerSequence format
public abstract String format();
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 w w . j av a 2s.c o m*/ * 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:com.google.dart.tools.ui.internal.text.dart.ContentAssistProcessor.java
License:Open Source License
private String getIterationGesture() { TriggerSequence binding = getIterationBinding(); return binding != null ? Messages.format(DartTextMessages.ContentAssistProcessor_toggle_affordance_press_gesture, new Object[] { binding.format() }) : DartTextMessages.ContentAssistProcessor_toggle_affordance_click_gesture; }
From source file:com.mousefeed.eclipse.CommandActionDescGenerator.java
License:Open Source License
/** * Generates action description from the command contribution item. * @param commandContributionItem the contribution item to generate * an action description for.//from ww w . j av a 2 s . c o m * Not <code>null</code>. * @return the action description for the provided action. * Never <code>null</code>. */ public AbstractActionDesc generate(final CommandContributionItem commandContributionItem) { notNull(commandContributionItem); final ActionDescImpl actionDesc = new ActionDescImpl(); final Command command = locator.get(commandContributionItem); if (command == null) { return null; } try { actionDesc.setLabel(command.getName()); } catch (final NotDefinedException e) { // should never happen throw new RuntimeException(e); } final String commandId = command.getId(); actionDesc.setDef(commandId); final TriggerSequence binding = bindingService.getBestActiveBindingFor(commandId); if (binding != null) { actionDesc.setAccelerator(binding.format()); } return actionDesc; }
From source file:com.mousefeed.eclipse.HandledActionDescGenerator.java
License:Open Source License
/** * Generates action description from the handled contribution item. * //from w w w .ja v a 2 s . c o m * @param handledContributionItem * the contribution item to generate an action description for. * Not <code>null</code>. * @return the action description for the provided action. */ public AbstractActionDesc generate(final HandledContributionItem handledContributionItem) { notNull(handledContributionItem); final ActionDescImpl actionDesc = new ActionDescImpl(); final Command command = locator.get(handledContributionItem); if (command == null) { return null; } try { actionDesc.setLabel(command.getName()); } catch (final NotDefinedException e) { // should never happen throw new RuntimeException(e); } final String commandId = command.getId(); actionDesc.setDef(commandId); final TriggerSequence binding = bindingService.getBestActiveBindingFor(commandId); if (binding != null) { actionDesc.setAccelerator(binding.format()); } return actionDesc; }
From source file:com.mulgasoft.emacsplus.execute.CommandHelp.java
License:Open Source License
/** * Get the best binding (as determined by Eclipse) for the Command * /*from w w w .j a va 2 s .c o m*/ * @param cmd * @return the binding or null */ public static String getBestBinding(Command cmd) { String result = null; IBindingService binder = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); TriggerSequence bindingFor = binder.getBestActiveBindingFor(cmd.getId()); if (bindingFor != null) { result = bindingFor.format(); } return result; }
From source file:de.walware.ecommons.ui.actions.HandlerContributionItem.java
License:Open Source License
private void updateMenuItem() { final MenuItem item = (MenuItem) widget; final boolean shouldBeEnabled = isEnabled(); // disabled command + visibility follows enablement == disposed if (item.isDisposed()) { return;/*from w w w . j a v a 2s .c o m*/ } String text = label; if (text == null) { if (command != null) { try { text = command.getCommand().getName(); } catch (final NotDefinedException e) { StatusManager.getManager().handle(new Status(IStatus.ERROR, SharedUIResources.PLUGIN_ID, "Update item failed " + getId(), e)); //$NON-NLS-1$ } } } text = updateMnemonic(text); String keyBindingText = null; if (command != null) { final TriggerSequence binding = bindingService.getBestActiveBindingFor(command); if (binding != null) { keyBindingText = binding.format(); } } if (text != null) { if (keyBindingText == null) { item.setText(text); } else { item.setText(text + '\t' + keyBindingText); } } if (item.getSelection() != checkedState) { item.setSelection(checkedState); } if (item.getEnabled() != shouldBeEnabled) { item.setEnabled(shouldBeEnabled); } }
From source file:de.walware.ecommons.ui.actions.HandlerContributionItem.java
License:Open Source License
private String getToolTipText(final String text) { String tooltipText = tooltip; if (tooltip == null) { if (text != null) { tooltipText = text;// w w w . j a va 2 s .c om } else { tooltipText = ""; //$NON-NLS-1$ } } if (command != null) { final TriggerSequence activeBinding = bindingService.getBestActiveBindingFor(command); if (activeBinding != null && !activeBinding.isEmpty()) { final String acceleratorText = activeBinding.format(); if (acceleratorText != null && acceleratorText.length() != 0) { tooltipText = NLS.bind("{0} ({1})", tooltipText, acceleratorText); //$NON-NLS-1$ } } } return tooltipText; }
From source file:descent.internal.ui.text.java.ContentAssistProcessor.java
License:Open Source License
private String getIterationGesture() { TriggerSequence binding = getIterationBinding(); return binding != null ? Messages.format(JavaTextMessages.ContentAssistProcessor_toggle_affordance_press_gesture, new Object[] { binding.format() }) : JavaTextMessages.ContentAssistProcessor_toggle_affordance_click_gesture; }
From source file:melnorme.lang.ide.ui.text.completion.LangContentAssistProcessor.java
License:Open Source License
protected String createIterationMessage() { TriggerSequence binding = getGroupingIterationBinding(); String nextCategoryLabel = getCategory(invocationIteration + 1).getName(); if (binding == null) { return MessageFormat.format(LangUIMessages.ContentAssistProcessor_toggle_affordance_click_gesture, getCurrentCategory().getName(), nextCategoryLabel, null); } else {/* w w w . ja va2 s. c o m*/ return MessageFormat.format(LangUIMessages.ContentAssistProcessor_toggle_affordance_press_gesture, getCurrentCategory().getName(), nextCategoryLabel, binding.format()); } }
From source file:net.yatomiya.e4.ui.workbench.renderers.swt.HandledContributionItem.java
License:Open Source License
@Override protected void updateMenuItem() { MenuItem item = (MenuItem) widget; String text = getModel().getLocalizedLabel(); ParameterizedCommand parmCmd = getModel().getWbCommand(); String keyBindingText = null; if (parmCmd != null) { if (text == null || text.isEmpty()) { try { text = parmCmd.getName(getModel().getCommand().getLocalizedCommandName()); } catch (NotDefinedException e) { e.printStackTrace();// ww w. j a v a 2s. co m } } if (bindingService != null) { TriggerSequence binding = bindingService.getBestSequenceFor(parmCmd); if (binding != null) keyBindingText = binding.format(); } } if (text != null) { if (getModel() instanceof MMenuElement) { String mnemonics = ((MMenuElement) getModel()).getMnemonics(); if (mnemonics != null && !mnemonics.isEmpty()) { int idx = text.indexOf(mnemonics); if (idx != -1) { text = text.substring(0, idx) + '&' + text.substring(idx); } } } if (keyBindingText == null) item.setText(text); else item.setText(text + '\t' + keyBindingText); } else { item.setText(""); //$NON-NLS-1$ } final String tooltip = getToolTipText(false); item.setToolTipText(tooltip); item.setSelection(getModel().isSelected()); item.setEnabled(getModel().isEnabled()); }