List of usage examples for org.eclipse.jface.action IAction TOOL_TIP_TEXT
String TOOL_TIP_TEXT
To view the source code for org.eclipse.jface.action IAction TOOL_TIP_TEXT.
Click Source Link
"toolTipText"). 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 a va 2 s. 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.nokia.tools.media.utils.tooltip.TitlebarComposite.java
License:Open Source License
public void addTitleAction(final IAction action, EActionLocation location) { final Canvas canvas = new Canvas(titlebar, SWT.NONE); switch (location) { case BEGINNING: canvas.moveAbove(null);//from w w w. ja v a2s . com break; case END: canvas.moveBelow(null); break; case ABOVE_TITLE: canvas.moveAbove(title); break; case BELOV_TITLE: default: canvas.moveBelow(title); break; } ((GridLayout) titlebar.getLayout()).numColumns++; if (resourcesToDispose == null) { resourcesToDispose = new ArrayList<Resource>(); } final CanvasListener canvasListener = new CanvasListener(action, canvas); final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IAction.IMAGE == event.getProperty()) { ImageDescriptor imgDesc = action.getImageDescriptor(); ImageDescriptor hoverImgDesc = action.getHoverImageDescriptor(); ImageDescriptor disabledImgDesc = action.getDisabledImageDescriptor(); canvasListener.setImg(imgDesc); canvasListener.setHoverImg(hoverImgDesc); canvasListener.setDisabledImg(disabledImgDesc); } if (IAction.TEXT == event.getProperty() || IAction.TOOL_TIP_TEXT == event.getProperty()) { if (action.getToolTipText() != null) { canvas.setToolTipText(action.getToolTipText()); } else if (action.getText() != null) { canvas.setToolTipText(action.getText()); } } canvas.redraw(); canvas.update(); } }; action.addPropertyChangeListener(propertyChangeListener); canvas.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { action.removePropertyChangeListener(propertyChangeListener); } }); propertyChangeListener.propertyChange(new PropertyChangeEvent(this, IAction.IMAGE, null, null)); propertyChangeListener.propertyChange(new PropertyChangeEvent(this, IAction.TEXT, null, null)); Rectangle bounds = canvasListener.img.getBounds(); GridData gd = new GridData(bounds.width, bounds.height); canvas.setLayoutData(gd); canvas.addListener(SWT.Paint, canvasListener); canvas.addListener(SWT.MouseEnter, canvasListener); canvas.addListener(SWT.MouseExit, canvasListener); canvas.addListener(SWT.MouseUp, canvasListener); }
From source file:net.refractions.udig.style.sld.editor.internal.PageHistoryHolder.java
License:Open Source License
/** * Updates the history controls./* w w w .j a va 2 s . c o m*/ * */ private void updateHistoryControls() { historyToolbar.update(false); IContributionItem[] items = historyToolbar.getItems(); for (int i = 0; i < items.length; i++) { items[i].update(IAction.ENABLED); items[i].update(IAction.TOOL_TIP_TEXT); } }
From source file:org.apache.sling.ide.eclipse.ui.internal.ServersActionModeFiddlerActionDelegate.java
License:Apache License
@Override public void selectionChanged(IAction action, ISelection selection) { server = null;//from w w w.jav a 2 s. c o m modules = null; if (selection != null && (selection instanceof IStructuredSelection)) { IStructuredSelection iss = (IStructuredSelection) selection; Object first = iss.getFirstElement(); if (first instanceof IServer) { server = (IServer) first; modules = null; if (iss.size() > 1) { // verify that all selected elements are of type IServer Iterator<?> it = iss.iterator(); it.next(); // skip the first, we have that above already while (it.hasNext()) { Object next = it.next(); if (!(next instanceof IServer)) { server = null; modules = null; break; } } } } else if (first instanceof IServerModule) { modules = new LinkedList<>(); IServerModule module = (IServerModule) first; modules.add(module.getModule()); server = module.getServer(); if (iss.size() > 1) { // verify that all selected elements are of type IServerModule // plus add the module[] to the modules list Iterator<?> it = iss.iterator(); it.next(); // skip the first, we have that above already while (it.hasNext()) { Object next = it.next(); if (!(next instanceof IServerModule)) { server = null; module = null; break; } else { module = (IServerModule) next; modules.add(module.getModule()); } } } } } if (server != null) { if (server.getServerState() != IServer.STATE_STARTED) { server = null; modules = null; } } cleanAction.setEnabled(server != null); publishAction.setEnabled(server != null); action.setEnabled(true); final IAction serverRunAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.run"); final IAction serverDebugAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.debug"); IAction stopRunAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.stop"); if (serverRunAction == null || stopRunAction == null || serverDebugAction == null) { return; } // serverRunAction.setHoverImageDescriptor(SharedImages.SLING_LOG); serverRunAction.setHoverImageDescriptor(SharedImages.RUN_CONNECT); serverDebugAction.setHoverImageDescriptor(SharedImages.DEBUG_CONNECT); stopRunAction.setHoverImageDescriptor(SharedImages.DISCONNECT); findWstPublishAction(); for (ActionContributionItem appendedAction : appendedToolbarActionContributionItems) { if (!contributionAdded(appendedAction)) { actionBars.getToolBarManager().add(appendedAction); } } if (wstPublishAction != null) { wstPublishAction.setVisible(false); publishActionContributionItem.setVisible(true); } else { // otherwise hide it, as it is an unexpected situation publishActionContributionItem.setVisible(false); } final String runText = "Connect to server in run mode"; if (runTooltipListener == null) { runTooltipListener = new IPropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) { if (!event.getNewValue().equals(runText)) { serverRunAction.setToolTipText(runText); } } } }; serverRunAction.addPropertyChangeListener(runTooltipListener); } final String debugText = "Connect to server in debug mode"; if (debugTooltipListener == null) { debugTooltipListener = new IPropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) { if (!event.getNewValue().equals(debugText)) { serverDebugAction.setToolTipText(debugText); } } } }; serverDebugAction.addPropertyChangeListener(debugTooltipListener); } final String disconnectText = "Disconnect from server"; if (disconnectTooltipListener == null) { disconnectTooltipListener = new IPropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) { if (!event.getNewValue().equals(disconnectText)) { serverRunAction.setToolTipText(disconnectText); } } } }; stopRunAction.addPropertyChangeListener(disconnectTooltipListener); } serverRunAction.setToolTipText(runText); serverDebugAction.setToolTipText(debugText); stopRunAction.setToolTipText(disconnectText); }
From source file:org.eclipse.birt.core.ui.frameworks.taskwizard.internal.SubtaskHistory.java
License:Open Source License
/** * Updates the history controls./* ww w . j av a 2 s . c o m*/ * */ private void updateHistoryControls() { if (historyToolbar != null) { historyToolbar.update(false); IContributionItem[] items = historyToolbar.getItems(); for (int i = 0; i < items.length; i++) { items[i].update(IAction.ENABLED); items[i].update(IAction.TOOL_TIP_TEXT); } } }
From source file:org.eclipse.birt.report.designer.data.ui.dataset.HistoryToolBar.java
License:Open Source License
/** * update history control//from www . jav a 2 s . c o m * */ private void updateHistoryControls() { toolbarManager.update(false); IContributionItem[] items = toolbarManager.getItems(); for (int i = 0; i < items.length; i++) { items[i].update(IAction.ENABLED); items[i].update(IAction.TOOL_TIP_TEXT); } }
From source file:org.eclipse.rcptt.ui.panels.Actions.java
License:Open Source License
public static final IObservableValue observeToolTipText(IAction action) { return JFaceProperties.value(IAction.class, "toolTipText", //$NON-NLS-1$ IAction.TOOL_TIP_TEXT).observe(action); }
From source file:org.eclipse.riena.e4.launcher.part.MenuHelper.java
License:Open Source License
public static MToolItem createToolItem(final MApplication application, final ActionContributionItem item) { final IAction action = item.getAction(); final String id = action.getActionDefinitionId(); if (id != null) { for (final MCommand command : application.getCommands()) { if (id.equals(command.getElementId())) { final MHandledToolItem toolItem = MenuFactoryImpl.eINSTANCE.createHandledToolItem(); toolItem.setCommand(command); toolItem.setContributorURI(command.getContributorURI()); String iconURI = getIconURI(action.getImageDescriptor(), application.getContext()); if (iconURI == null) { iconURI = getIconURI(id, application.getContext(), ICommandImageService.TYPE_DEFAULT); if (iconURI == null) { toolItem.setLabel(command.getCommandName()); } else { toolItem.setIconURI(iconURI); }//from w ww.j a v a 2 s . c o m } else { toolItem.setIconURI(iconURI); } if (action.getToolTipText() != null) { toolItem.setTooltip(action.getToolTipText()); } String disabledIconURI = getIconURI(action.getDisabledImageDescriptor(), application.getContext()); if (disabledIconURI == null) { disabledIconURI = getIconURI(id, application.getContext(), ICommandImageService.TYPE_DEFAULT); } if (disabledIconURI != null) { setDisabledIconURI(toolItem, disabledIconURI); } switch (action.getStyle()) { case IAction.AS_CHECK_BOX: toolItem.setType(ItemType.CHECK); toolItem.setSelected(action.isChecked()); break; case IAction.AS_RADIO_BUTTON: toolItem.setType(ItemType.RADIO); toolItem.setSelected(action.isChecked()); break; default: toolItem.setType(ItemType.PUSH); break; } final String itemId = item.getId(); toolItem.setElementId(itemId == null ? id : itemId); return toolItem; } } } else { final MDirectToolItem toolItem = MenuFactoryImpl.eINSTANCE.createDirectToolItem(); final String itemId = item.getId(); toolItem.setElementId(itemId); String iconURI = getIconURI(action.getImageDescriptor(), application.getContext()); if (iconURI == null) { if (itemId == null) { if (action.getText() != null) { toolItem.setLabel(action.getText()); } } else { iconURI = getIconURI(itemId, application.getContext(), ICommandImageService.TYPE_DEFAULT); if (iconURI == null) { if (action.getText() != null) { toolItem.setLabel(action.getText()); } } else { toolItem.setIconURI(iconURI); } } } else { toolItem.setIconURI(iconURI); } if (action.getToolTipText() != null) { toolItem.setTooltip(action.getToolTipText()); } switch (action.getStyle()) { case IAction.AS_CHECK_BOX: toolItem.setType(ItemType.CHECK); toolItem.setSelected(action.isChecked()); break; case IAction.AS_RADIO_BUTTON: toolItem.setType(ItemType.RADIO); toolItem.setSelected(action.isChecked()); break; default: toolItem.setType(ItemType.PUSH); break; } toolItem.setContributionURI("bundleclass://org.eclipse.ui.workbench/programmic.contribution"); //$NON-NLS-1$ toolItem.setObject(new DirectProxy(action)); toolItem.setEnabled(action.isEnabled()); final IPropertyChangeListener propertyListener = new IPropertyChangeListener() { public void propertyChange(final PropertyChangeEvent event) { final String property = event.getProperty(); if (property.equals(IAction.ENABLED)) { toolItem.setEnabled(action.isEnabled()); } else if (property.equals(IAction.CHECKED)) { toolItem.setSelected(action.isChecked()); } else if (property.equals(IAction.TEXT)) { toolItem.setLabel(action.getText()); } else if (property.equals(IAction.TOOL_TIP_TEXT)) { toolItem.setLabel(action.getToolTipText()); } } }; // property listener is removed in // DirectContributionItem#handleWidgetDispose() action.addPropertyChangeListener(propertyListener); toolItem.getTransientData().put(DirectContributionItem.DISPOSABLE, new Runnable() { public void run() { action.removePropertyChangeListener(propertyListener); } }); return toolItem; } return null; }
From source file:org.eclipse.team.internal.ccvs.ui.actions.CVSAction.java
License:Open Source License
/** * Initializes a retarget action that will listen to part changes and allow parts to * override this action's behavior. The retarget action is used if this * action is shown in a top-level menu or toolbar. * @param window the workbench window showing this action * @since 3.1// w w w . j a va 2 s . c om */ private void initializeRetargetAction(IWorkbenchWindow window) { // Don't need to specify a the title because it will use this actions // title instead. retargetAction = new RetargetAction(getId(), ""); //$NON-NLS-1$ retargetAction.addPropertyChangeListener(new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(IAction.ENABLED)) { Object val = event.getNewValue(); if (val instanceof Boolean && action != null) { action.setEnabled(((Boolean) val).booleanValue()); } } else if (event.getProperty().equals(IAction.CHECKED)) { Object val = event.getNewValue(); if (val instanceof Boolean && action != null) { action.setChecked(((Boolean) val).booleanValue()); } } else if (event.getProperty().equals(IAction.TEXT)) { Object val = event.getNewValue(); if (val instanceof String && action != null) { action.setText((String) val); } } else if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) { Object val = event.getNewValue(); if (val instanceof String && action != null) { action.setToolTipText((String) val); } } else if (event.getProperty().equals(SubActionBars.P_ACTION_HANDLERS)) { if (action != null && retargetAction != null) { action.setEnabled(retargetAction.isEnabled()); } } } }); window.getPartService().addPartListener(retargetAction); IWorkbenchPart activePart = window.getPartService().getActivePart(); if (activePart != null) retargetAction.partActivated(activePart); }
From source file:org.eclipse.ui.actions.LabelRetargetAction.java
License:Open Source License
/** * The action handler has changed. Update self. *///from ww w. j a v a 2 s . c o m protected void propagateChange(PropertyChangeEvent event) { super.propagateChange(event); String prop = event.getProperty(); if (prop.equals(IAction.TEXT)) { String str = (String) event.getNewValue(); super.setText(appendAccelerator(str)); } else if (prop.equals(IAction.TOOL_TIP_TEXT)) { String str = (String) event.getNewValue(); super.setToolTipText(str); } else if (prop.equals(IAction.IMAGE)) { updateImages(getActionHandler()); } }