List of usage examples for org.eclipse.jface.action Action setDisabledImageDescriptor
@Override
public void setDisabledImageDescriptor(ImageDescriptor newImage)
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.LayoutCanvas.java
License:Open Source License
/** * Helper for {@link #setupGlobalActionHandlers()}. * Copies the action attributes form the given {@link ActionFactory}'s action to * our action.//from w w w.j a va 2 s. com * <p/> * {@link ActionFactory} provides access to the standard global actions in Eclipse. * <p/> * This allows us to grab the standard labels and icons for the * global actions such as copy, cut, paste, delete and select-all. */ private void copyActionAttributes(Action action, ActionFactory factory) { IWorkbenchAction wa = factory.create(mEditorDelegate.getEditor().getEditorSite().getWorkbenchWindow()); action.setId(wa.getId()); action.setText(wa.getText()); action.setEnabled(wa.isEnabled()); action.setDescription(wa.getDescription()); action.setToolTipText(wa.getToolTipText()); action.setAccelerator(wa.getAccelerator()); action.setActionDefinitionId(wa.getActionDefinitionId()); action.setImageDescriptor(wa.getImageDescriptor()); action.setHoverImageDescriptor(wa.getHoverImageDescriptor()); action.setDisabledImageDescriptor(wa.getDisabledImageDescriptor()); action.setHelpListener(wa.getHelpListener()); }
From source file:com.arm.cmsis.pack.ui.editors.RteEditorPageHeader.java
License:Open Source License
/** * Creates save action and adds it to the right toolbar * @return created IAction//w ww.ja v a 2 s . co m */ public IAction addSaveAction() { Action saveAction = new Action("Save", IAction.AS_PUSH_BUTTON) { //$NON-NLS-1$ public void run() { ICommandService commandService = CpPlugInUI.getCommandService(); if (commandService == null) return; try { // Lookup csave ommand with its ID Command command = commandService.getCommand("org.eclipse.ui.file.save"); //$NON-NLS-1$ if (command != null && command.isEnabled()) { command.executeWithChecks(new ExecutionEvent()); } } catch (Exception e) { // Replace with real-world exception handling e.printStackTrace(); } } }; saveAction.setToolTipText(CpStringsUI.RteManagerWidget_ApplyAndSave); saveAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT)); saveAction.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages() .getImageDescriptor(ISharedImages.IMG_ETOOL_SAVE_EDIT_DISABLED)); addAction(saveAction, SWT.RIGHT); return saveAction; }
From source file:com.google.cloud.tools.eclipse.appengine.deploy.ui.DeployConsolePageParticipant.java
License:Apache License
private Action createCloseAction() { Action close = new Action(Messages.getString("action.remove")) { @Override/* ww w. j a va 2 s . c om*/ public void run() { ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[] { console }); } }; close.setToolTipText(Messages.getString("action.remove")); close.setImageDescriptor(getSharedImage(ISharedImages.IMG_ELCL_REMOVE)); close.setHoverImageDescriptor(getSharedImage(ISharedImages.IMG_ELCL_REMOVE)); close.setDisabledImageDescriptor(getSharedImage(ISharedImages.IMG_ELCL_REMOVE_DISABLED)); return close; }
From source file:com.google.cloud.tools.eclipse.appengine.deploy.ui.DeployConsolePageParticipant.java
License:Apache License
private Action createTerminateAction() { Action terminate = new Action(Messages.getString("action.stop")) { @Override//from w ww .j a v a 2s. c o m public void run() { StandardDeployJob job = console.getJob(); if (job != null) { job.cancel(); update(); } } }; terminate.setToolTipText(Messages.getString("action.stop")); terminate.setImageDescriptor(getSharedImage(ISharedImages.IMG_ELCL_STOP)); terminate.setHoverImageDescriptor(getSharedImage(ISharedImages.IMG_ELCL_STOP)); terminate.setDisabledImageDescriptor(getSharedImage(ISharedImages.IMG_ELCL_STOP_DISABLED)); return terminate; }
From source file:com.nokia.tools.media.utils.tooltip.DynamicTooltip.java
License:Open Source License
protected void addContributedControls(final Composite composite, boolean focusState) { Composite toolBarComposite = null; Composite sectionsComposite = null; children.clear();/*w w w . j a v a 2 s.c o m*/ if (style == EStyle.MENU) { GridLayout gl = new GridLayout(2, false); gl.marginHeight = gl.marginWidth = gl.horizontalSpacing = 0; composite.setLayout(gl); toolBarComposite = new Composite(composite, SWT.NONE); gl = new GridLayout(1, false); // gl.marginHeight = gl.marginWidth = 0; toolBarComposite.setLayout(gl); toolBarComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); } // horizontal toolbar if (style == EStyle.HORIZONTAL_HORIZONTAL || style == EStyle.HORIZONTAL_VERTICAL) { GridLayout gl = new GridLayout(1, false); gl.marginHeight = gl.marginWidth = gl.verticalSpacing = 0; composite.setLayout(gl); toolBarComposite = new Composite(composite, SWT.NONE); gl = new GridLayout(1, false); gl.marginHeight = gl.marginWidth = 0; toolBarComposite.setLayout(gl); toolBarComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); } // vertical toolbar if (style == EStyle.VERTICAL_VERTICAL || style == EStyle.VERTICAL_HORIZONTAL) { GridLayout gl = new GridLayout(2, false); gl.marginHeight = gl.marginWidth = gl.horizontalSpacing = 0; composite.setLayout(gl); toolBarComposite = new Composite(composite, SWT.NONE); gl = new GridLayout(1, false); gl.marginHeight = gl.marginWidth = 0; toolBarComposite.setLayout(gl); toolBarComposite.setLayoutData(new GridData(SWT.NONE, SWT.FILL, false, true)); } sectionsComposite = new Composite(composite, SWT.NONE); GridLayout gl = new GridLayout(1, false); gl.marginHeight = gl.marginWidth = 0; sectionsComposite.setLayout(gl); sectionsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); toolBarComposite.setBackground(composite.getBackground()); sectionsComposite.setBackground(composite.getBackground()); Set<ToolbarItemContribution> toolbarContributions = new TreeSet<ToolbarItemContribution>(); toolbarContributions.addAll(collectToolbarContributions(focusState)); List<SectionContribution> sectionContributions = collectSectionContributions(focusState); for (SectionContribution contribution : sectionContributions) { if (contribution.uiClass != null) { try { IDynamicTooltipUIContribution ui = contribution.uiClass.newInstance(); ui.setTooltip(this); ui.setUIContainer(uiContainer); ui.setSelection(selection); ui.setContext(context); configureUIContribution(ui); ToolbarItemContribution[] tcs = ui.contributeToolbar(); if (tcs != null) { for (ToolbarItemContribution tc : tcs) { toolbarContributions.add(tc); } } ui.createControls(sectionsComposite, focusState); } catch (Exception e) { e.printStackTrace(); } } } if (sectionsComposite.getChildren().length == 0) { sectionsComposite.dispose(); } if (toolbarContributions.size() > 0) { GridLayout layout = (GridLayout) toolBarComposite.getLayout(); layout.horizontalSpacing = 1; if (EStyle.HORIZONTAL_HORIZONTAL == style || EStyle.HORIZONTAL_VERTICAL == style || EStyle.VERTICAL_HORIZONTAL == style || EStyle.VERTICAL_VERTICAL == style) { CoolBar cb = null; if (EStyle.HORIZONTAL_HORIZONTAL == style || EStyle.HORIZONTAL_VERTICAL == style) { cb = new CoolBar(toolBarComposite, SWT.FLAT | SWT.HORIZONTAL); cb.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } else { cb = new CoolBar(toolBarComposite, SWT.FLAT | SWT.VERTICAL); cb.setLayoutData(new GridData(GridData.FILL_VERTICAL)); } Map<String, ToolBarManager> linkMap = new LinkedHashMap<String, ToolBarManager>(); final Map<ContributionItem, ToolbarItemContribution> map = new HashMap<ContributionItem, ToolbarItemContribution>(); for (final ToolbarItemContribution contribution : toolbarContributions) { ToolBarManager toolBar = linkMap.get(contribution.getTarget()); if (toolBar == null) { if (EStyle.HORIZONTAL_HORIZONTAL == style || EStyle.HORIZONTAL_VERTICAL == style) { toolBar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL); } else { toolBar = new ToolBarManager(SWT.FLAT | SWT.VERTICAL); } linkMap.put(contribution.getTarget(), toolBar); } if (contribution.getAction() == null) { Action action = new Action(contribution.getLabel()) { @Override public void run() { // do nothing } }; action.setImageDescriptor(contribution.getIcon()); action.setDisabledImageDescriptor(contribution.getDisabledIcon()); action.setHoverImageDescriptor(contribution.getHoverIcon()); ActionContributionItem item = new ActionContributionItem(action); map.put(item, contribution); toolBar.add(item); } else { IAction action = contribution.getAction(); if (contribution.getAction() instanceof IDynamicTooltipToolbarAction) { ((IDynamicTooltipToolbarAction) action).setTooltip(DynamicTooltip.this); ((IDynamicTooltipToolbarAction) action).setUIContainer(uiContainer); ((IDynamicTooltipToolbarAction) action).setSelection(selection); } if (action instanceof SeparatorAction) { Separator separator = new Separator(); map.put(separator, contribution); toolBar.add(separator); } else { ActionContributionItem item = new ActionContributionItem(action); map.put(item, contribution); toolBar.add(item); } } } Point preffered = new Point(0, 0); for (Map.Entry<String, ToolBarManager> entry : linkMap.entrySet()) { CoolItem ci = new CoolItem(cb, SWT.NONE); ToolBar tb = entry.getValue().createControl(cb); ci.setControl(tb); Point tbSize = tb.computeSize(SWT.DEFAULT, SWT.DEFAULT); Point cbSize = ci.computeSize(tbSize.x, tbSize.y); ci.setSize(cbSize); ci.setPreferredSize(cbSize); ci.setMinimumSize(tbSize); if (EStyle.HORIZONTAL_HORIZONTAL == style || EStyle.HORIZONTAL_VERTICAL == style) { preffered.x += cbSize.x; preffered.y = Math.max(preffered.y, cbSize.y); } else { preffered.x = Math.max(preffered.x, cbSize.x); preffered.y += cbSize.y; } for (int i = 0; i < tb.getItems().length; i++) { ToolItem item = tb.getItems()[i]; ContributionItem actionItem = (ContributionItem) item.getData(); if (actionItem instanceof ActionContributionItem) { createChildTooltip(map.get(actionItem), item); } } } cb.setLocked(false); cb.setLayoutData(new GridData(preffered.x, preffered.y)); } else if (EStyle.MENU == style) { for (final ToolbarItemContribution contribution : toolbarContributions) { Composite itemComposite = null; itemComposite = createMenuComposite(toolBarComposite); if (contribution.getAction() instanceof SeparatorAction) { itemComposite.setEnabled(false); final Canvas img = new Canvas(itemComposite, SWT.NONE); GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); gd.heightHint = 5; gd.horizontalSpan = 3; img.setLayoutData(gd); img.setBackground(itemComposite.getBackground()); img.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = e.gc; gc.setForeground(ColorConstants.black); e.gc.drawLine(0, 2, img.getSize().x - 1, 2); } }); continue; } final Canvas img = new Canvas(itemComposite, SWT.NONE); img.setBackground(itemComposite.getBackground()); final Label label = new Label(itemComposite, SWT.NONE); label.setBackground(itemComposite.getBackground()); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); label.setText(contribution.getLabel() != null ? contribution.getLabel() : ""); label.setEnabled(!contribution.isDisabled()); final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IAction.TEXT.equals(event.getProperty())) { label.setText(contribution.getLabel() != null ? contribution.getLabel() : ""); layout(); } if (IAction.ENABLED.equals(event.getProperty())) { label.setEnabled(!contribution.isDisabled()); } } }; contribution.addPropertyChangeListener(propertyChangeListener); label.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { contribution.removePropertyChangeListener(propertyChangeListener); } }); if (contribution.tooltip != null) { final Canvas arrow = new Canvas(itemComposite, SWT.NONE); arrow.setBackground(itemComposite.getBackground()); arrow.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); final Image image = ARROW_IMAGE.createImage(); arrow.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { image.dispose(); } }); ((GridData) arrow.getLayoutData()).widthHint = image.getImageData().width; ((GridData) arrow.getLayoutData()).heightHint = image.getImageData().height; arrow.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(image, 0, 0); } }); } img.setToolTipText(contribution.getLabel()); final IPropertyChangeListener labelChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IAction.TEXT.equals(event.getProperty())) { img.setToolTipText(contribution.getLabel()); } } }; contribution.addPropertyChangeListener(labelChangeListener); img.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { contribution.removePropertyChangeListener(labelChangeListener); } }); final Image[] image = new Image[] { contribution.isDisabled() ? contribution.getDisabledIcon().createImage() : contribution.getIcon().createImage() }; final Image[] hoverImage = new Image[] { (contribution.isDisabled() || contribution.getHoverIcon() == null) ? image[0] : contribution.getHoverIcon().createImage() }; final IPropertyChangeListener imageChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IAction.IMAGE.equals(event.getProperty()) || IAction.ENABLED.equals(event.getProperty())) { if (image[0] != null) { image[0].dispose(); } if (hoverImage[0] != null) { hoverImage[0].dispose(); } image[0] = contribution.isDisabled() ? contribution.getDisabledIcon().createImage() : contribution.getIcon().createImage(); hoverImage[0] = (contribution.isDisabled() || contribution.getHoverIcon() == null) ? image[0] : contribution.getHoverIcon().createImage(); img.redraw(); } } }; contribution.addPropertyChangeListener(imageChangeListener); img.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { contribution.removePropertyChangeListener(imageChangeListener); if (image[0] != null) { image[0].dispose(); } if (hoverImage[0] != null) { hoverImage[0].dispose(); } } }); img.setLayoutData( new GridData(image[0].getImageData().width + 4, image[0].getImageData().height + 4)); img.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { e.gc.drawImage(image[0], 2, 2); } }); if (EStyle.MENU == style) { DynamicTooltip tooltip = createChildTooltip(contribution, itemComposite); registerOnClickAction(contribution, itemComposite, tooltip); for (Control control : itemComposite.getChildren()) { registerOnClickAction(contribution, control, tooltip); } } } } } // set proper number of columns for horizontal sections alignment if ((style == EStyle.HORIZONTAL_HORIZONTAL || style == EStyle.VERTICAL_HORIZONTAL) && !sectionsComposite.isDisposed()) { ((GridLayout) sectionsComposite.getLayout()).numColumns = sectionsComposite.getChildren().length; } if (toolBarComposite.getChildren().length == 0) { toolBarComposite.dispose(); } if (sectionsComposite.isDisposed() && toolBarComposite.isDisposed()) { composite.dispose(); } }
From source file:com.nokia.tools.s60.editor.graphics.IImagePreviewComposite.java
License:Open Source License
protected void createPreview(Composite parent) { super.createPreview(parent); /* create context menu */ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); MenuManager manager = new MenuManager(); final Action copyAction = new Action(Messages.Preview_copyImage) { @Override/*from w w w. java2s . co m*/ public void run() { Display.getDefault().asyncExec(new Runnable() { public void run() { handleCopyImage(); }; }); } }; copyAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); manager.add(copyAction); final Action copyLayerWEffectsAction = new Action(Messages.Preview_copyImageWEffects) { @Override public void run() { Display.getDefault().asyncExec(new Runnable() { public void run() { handleCopyLayerWEffectsImage(); }; }); } }; copyLayerWEffectsAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); manager.add(copyLayerWEffectsAction); final Action copyAggregateAction = new Action(Messages.Preview_copyResultImage) { @Override public void run() { Display.getDefault().asyncExec(new Runnable() { public void run() { handleCopyResultImage(); }; }); } }; copyAggregateAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); manager.add(copyAggregateAction); // paste final Action pasteItem = new Action(Messages.Preview_pasteImage) { @Override public void run() { // check if valid layer is selected Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); if (getSelectedLayer() != null) { handlePasteImage(getSelectedLayer(), clip); } } }; pasteItem.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE)); pasteItem .setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED)); manager.add(pasteItem); Menu menu = manager.createContextMenu(previewCanvas); previewCanvas.setMenu(menu); manager.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { pasteItem.setEnabled(false); pasteItem.setText(Messages.Preview_pasteImage); Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); if (ClipboardHelper.clipboardContainsData(ClipboardHelper.CONTENT_TYPE_SINGLE_IMAGE, clip)) { // check if valid layer is selected if (getSelectedLayer() != null) if (getSelectedLayer().isEnabled() && !getSelectedLayer().isBackground()) { pasteItem.setEnabled(true); pasteItem.setText( Messages.Preview_pasteImage + " into \"" + getSelectedLayer().getName() + "\""); } } // enable of copy actions if (getSelectedLayer() != null) { copyAction.setEnabled(getSelectedLayer().getRAWImage() != null); copyLayerWEffectsAction.setEnabled(getSelectedLayer().getRAWImage() != null); } else { copyAction.setEnabled(false); copyLayerWEffectsAction.setEnabled(false); } } }); }
From source file:com.siteview.mde.internal.ui.editor.OrientableBlock.java
License:Open Source License
protected void createToolBarActions(IManagedForm managedForm) { final ScrolledForm form = managedForm.getForm(); Action haction = new Action("hor", IAction.AS_RADIO_BUTTON) { //$NON-NLS-1$ public void run() { sashForm.setOrientation(SWT.HORIZONTAL); form.reflow(true);/* w w w. j a v a2 s.c o m*/ } }; haction.setChecked(true); haction.setToolTipText(MDEUIMessages.DetailsBlock_horizontal); haction.setImageDescriptor(MDEPluginImages.DESC_HORIZONTAL); haction.setDisabledImageDescriptor(MDEPluginImages.DESC_HORIZONTAL_DISABLED); Action vaction = new Action("ver", IAction.AS_RADIO_BUTTON) { //$NON-NLS-1$ public void run() { sashForm.setOrientation(SWT.VERTICAL); form.reflow(true); } }; vaction.setChecked(false); vaction.setToolTipText(MDEUIMessages.DetailsBlock_vertical); vaction.setImageDescriptor(MDEPluginImages.DESC_VERTICAL); vaction.setDisabledImageDescriptor(MDEPluginImages.DESC_VERTICAL_DISABLED); form.getToolBarManager().add(haction); form.getToolBarManager().add(vaction); }
From source file:net.refractions.udig.issues.internal.view.IssuesView.java
License:Open Source License
private IAction createSaveAction() { final IIssuesManager issuesManager = IIssuesManager.defaultInstance; final Action action = new Action() { @Override/*from w w w .j av a2 s . co m*/ public void runWithEvent(Event event) { try { issuesManager.save(ProgressManager.instance().get()); } catch (IOException e) { IssuesActivator.log("", e); //$NON-NLS-1$ } } }; IWorkbenchAction template = ActionFactory.SAVE.create(getSite().getWorkbenchWindow()); action.setImageDescriptor(template.getImageDescriptor()); action.setText(template.getText()); action.setToolTipText(template.getToolTipText()); action.setDisabledImageDescriptor(template.getDisabledImageDescriptor()); action.setHoverImageDescriptor(template.getHoverImageDescriptor()); action.setEnabled((issuesManager.getIssuesList() instanceof IRemoteIssuesList) && issuesManager.isDirty()); return action; }
From source file:net.refractions.udig.issues.internal.view.IssuesView.java
License:Open Source License
private IAction createRefreshAction() { final Action action = new Action() { @Override/* www .ja v a2 s . c o m*/ public void runWithEvent(Event event) { IIssuesList list = IIssuesManager.defaultInstance.getIssuesList(); if (list instanceof IRemoteIssuesList) try { ((IRemoteIssuesList) list).refresh(); } catch (IOException e) { IssuesActivator.log("", e); //$NON-NLS-1$ } } }; IWorkbenchAction template = ActionFactory.REFRESH.create(getSite().getWorkbenchWindow()); action.setText(template.getText()); action.setToolTipText(template.getToolTipText()); ImageDescriptor dtool = IssuesActivator.imageDescriptorFromPlugin(IssuesActivator.PLUGIN_ID, "icons/dtool16/refresh_co.gif"); //$NON-NLS-1$ ImageDescriptor etool = IssuesActivator.imageDescriptorFromPlugin(IssuesActivator.PLUGIN_ID, "icons/etool16/refresh_co.gif"); //$NON-NLS-1$ action.setImageDescriptor(etool); action.setDisabledImageDescriptor(dtool); action.setEnabled(IIssuesManager.defaultInstance.getIssuesList() instanceof IRemoteIssuesList); return action; }
From source file:net.sf.eclipsensis.console.NSISConsolePage.java
License:Open Source License
private Action makeAction(Action action, String text, String tooltipText, String image, String disabledImage, ActionFactory globalActionFactory, boolean enabled) { if (!Common.isEmpty(text)) { action.setText(text);/*from ww w.ja v a2 s .co m*/ } if (!Common.isEmpty(tooltipText)) { action.setToolTipText(tooltipText); } if (!Common.isEmpty(image)) { action.setImageDescriptor(EclipseNSISPlugin.getImageManager().getImageDescriptor(image)); } if (!Common.isEmpty(disabledImage)) { action.setDisabledImageDescriptor( EclipseNSISPlugin.getImageManager().getImageDescriptor(disabledImage)); } action.setEnabled(enabled); if (globalActionFactory != null) { getSite().getActionBars().setGlobalActionHandler(globalActionFactory.getId(), action); } return action; }