Example usage for org.eclipse.jface.action Action setHoverImageDescriptor

List of usage examples for org.eclipse.jface.action Action setHoverImageDescriptor

Introduction

In this page you can find the example usage for org.eclipse.jface.action Action setHoverImageDescriptor.

Prototype

@Override
    public void setHoverImageDescriptor(ImageDescriptor newImage) 

Source Link

Usage

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.// w w  w  .  j  a  v  a  2  s.  c om
 * <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.google.cloud.tools.eclipse.appengine.deploy.ui.DeployConsolePageParticipant.java

License:Apache License

private Action createCloseAction() {
    Action close = new Action(Messages.getString("action.remove")) {
        @Override/*from w  ww .j  av  a  2 s .com*/
        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/* w  ww  . j av 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();//from   ww  w . j  a  v a2s  . co 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: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 a  2  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:org.eclipse.wst.server.ui.internal.provisional.UIDecorator.java

License:Open Source License

public void setupAction(Action action, int action2) {
    action.setToolTipText(Messages.actionStopToolTip);
    action.setText(Messages.actionStop);
    action.setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_ELCL_STOP));
    action.setHoverImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_STOP));
    action.setDisabledImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_DLCL_STOP));
}

From source file:org.openmaji.implementation.tool.eclipse.editor.common.actions.ActionHelper.java

License:Open Source License

static public void copyDetails(Action source, Action target) {
    if (source == null) {
        target.setText("");
        target.setDescription("");
        target.setImageDescriptor(null);
        target.setHoverImageDescriptor(null);
        target.setToolTipText(null);//from   w  ww  . j a v  a2s.co m
    } else {
        target.setText(source.getText());
        target.setDescription(source.getDescription());
        target.setImageDescriptor(source.getImageDescriptor());
        target.setHoverImageDescriptor(source.getHoverImageDescriptor());
        target.setToolTipText(source.getToolTipText());
    }
}