Example usage for org.eclipse.jface.action IAction getToolTipText

List of usage examples for org.eclipse.jface.action IAction getToolTipText

Introduction

In this page you can find the example usage for org.eclipse.jface.action IAction getToolTipText.

Prototype

String getToolTipText();

Source Link

Document

Returns the tool tip text for this action.

Usage

From source file:ch.elexis.core.application.advisors.ApplicationActionBarAdvisor.java

License:Open Source License

protected void fillCoolBar(ICoolBarManager coolBar) {
    ToolBarManager tbm = new ToolBarManager();

    tbm.add(GlobalActions.homeAction);//w  w  w.j  a  v  a 2 s . co m
    tbm.add(GlobalActions.resetPerspectiveAction);

    tbm.add(new Separator());
    tbm.add(GlobalActions.printEtikette);
    tbm.add(GlobalActions.printVersionedEtikette);
    tbm.add(GlobalActions.printAdresse);

    coolBar.add(tbm);
    if (CoreHub.localCfg.get(Preferences.SHOWTOOLBARITEMS, Boolean.toString(true))
            .equalsIgnoreCase(Boolean.toString(true))) {
        ToolBarManager tb2 = new ToolBarManager();

        List<IAction> l = new ArrayList<>();
        for (IAction action : openPerspectiveActions) {
            if (action != null) {
                l.add(action);
            }
        }
        Collections.sort(l, new Comparator<IAction>() {
            @Override
            public int compare(IAction o1, IAction o2) {
                if (o1.getToolTipText() != null && o2.getToolTipText() != null) {
                    return o1.getToolTipText().compareTo(o2.getToolTipText());
                }
                return o1.getToolTipText() != null ? 1 : -1;
            }
        });

        // ci.getToolBarManager().add(new Separator());
        for (IAction action : l) {
            tb2.add(action);
        }
        coolBar.add(tb2);
    }

}

From source file:ch.elexis.core.ui.laboratory.views.LaborOrderPulldownMenuCreator.java

License:Open Source License

/**
 * Pulldown menu wird anhand selection angepasst
 * //from w ww .  ja v a 2  s . c  o  m
 * @param parent
 * @param action
 * @param image
 */
private void select(final Control parent, final IAction action, final Image image) {
    if (parent instanceof ToolBar) {
        ToolBar toolBar = (ToolBar) parent;
        if (toolBar.getItemCount() > 0) {
            ToolItem toolItem = toolBar.getItem(0);
            toolItem.setImage(image);
            toolItem.setHotImage(image);
            toolItem.setToolTipText(action.getToolTipText());

            this.selectedAction = action;
            CoreHub.localCfg.set(LAB_ORDER_SELECTED_ACTION_ID, this.selectedAction.getId());
        }
    }
}

From source file:ch.elexis.views.LaborOrderPulldownMenuCreator.java

License:Open Source License

/**
 * Pulldown menu wird anhand selection angepasst
 * //from   ww w  .j a  v  a  2s. com
 * @param parent
 * @param action
 * @param image
 */
private void select(final Control parent, final IAction action, final Image image) {
    if (parent instanceof ToolBar) {
        ToolBar toolBar = (ToolBar) parent;
        if (toolBar.getItemCount() > 0) {
            ToolItem toolItem = toolBar.getItem(0);
            toolItem.setImage(image);
            toolItem.setHotImage(image);
            toolItem.setToolTipText(action.getToolTipText());

            this.selectedAction = action;
            Hub.localCfg.set(LAB_ORDER_SELECTED_ACTION_ID, this.selectedAction.getId());
        }
    }
}

From source file:com.aptana.ide.editors.views.actions.ActionsView.java

License:Open Source License

/**
 * createTreeViewer/* ww w  .  j  a va  2  s .c  o m*/
 * 
 * @param parent
 * @return TreeViewer
 */
protected TreeViewer createTreeViewer(Composite parent) {
    final TreeViewer treeViewer = new TreeViewer(new Tree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL));

    // Implement a "fake" tooltip
    final Listener labelListener = new Listener() {
        public void handleEvent(Event event) {
            StyledText label = (StyledText) event.widget;
            Shell shell = (Shell) label.getData("_SHELL"); // label.getShell(); //$NON-NLS-1$

            switch (event.type) {
            // case SWT.MouseDown:
            case SWT.MouseDoubleClick:
                Event e = new Event();
                e.item = (TreeItem) label.getData("_TREEITEM"); //$NON-NLS-1$
                // Assuming table is single select, set the selection as if
                // the mouse down event went through to the table
                treeViewer.getTree().setSelection(new TreeItem[] { (TreeItem) e.item });
                actionDoubleClick.run();
                // treeViewer.getTree().notifyListeners(SWT.Selection, e);
                shell.dispose();
                // fallthrough

            case SWT.MouseExit:
                shell.dispose();
                break;

            default:
                break;
            }
        }
    };

    final Shell shell = getSite().getShell();

    Listener tableListener = new Listener() {
        UnifiedInformationControl info = null;

        public void handleEvent(Event event) {
            switch (event.type) {
            case SWT.Dispose:
            case SWT.KeyDown:
            case SWT.MouseMove: {
                if (info == null || info.getShell() == null) {
                    break;
                }
                info.getShell().dispose();
                info = null;
                break;
            }
            case SWT.MouseHover: {
                TreeItem item = treeViewer.getTree().getItem(new Point(event.x, event.y));
                if (item != null) {
                    if (info != null && info.getShell() != null && !info.getShell().isDisposed()) {
                        info.getShell().dispose();
                    }

                    info = new UnifiedInformationControl(shell, SWT.NONE, new HTMLTextPresenter(false));

                    info.getStyledTextWidget().setData("_TREEITEM", item); //$NON-NLS-1$
                    info.getStyledTextWidget().setData("_SHELL", info.getShell()); //$NON-NLS-1$
                    info.getStyledTextWidget().addListener(SWT.MouseExit, labelListener);
                    // info.getStyledTextWidget().addListener(SWT.MouseDown, labelListener);
                    info.getStyledTextWidget().addListener(SWT.MouseDoubleClick, labelListener);

                    Object data = item.getData();
                    String txt = null;

                    if (data instanceof IAction) {
                        IAction action = (IAction) data;

                        txt = action.getToolTipText();
                    } else if (data instanceof IPath) {
                        IPath path = (IPath) data;

                        txt = path.toOSString();
                    }

                    if (txt != null) {
                        if (txt.indexOf("<") != -1) //$NON-NLS-1$
                        {
                            txt = txt.replaceAll("<", "&lt;"); //$NON-NLS-1$ //$NON-NLS-2$
                        }

                        info.setSizeConstraints(300, 500);
                        info.setInformation(txt);

                        StyledText styledText = info.getStyledTextWidget();
                        GC gc = new GC(styledText);
                        int width = gc.getFontMetrics().getAverageCharWidth();

                        width = ((txt.length() + 2) * width);

                        Rectangle rect = item.getBounds(0);
                        Point pt = treeViewer.getTree().toDisplay(20 + rect.x, rect.y);

                        info.setSize(width, 0);
                        info.setLocation(pt);
                        info.setVisible(true);
                    }
                }
            }

            default:
                break;
            }
        }
    };

    treeViewer.getTree().addListener(SWT.Dispose, tableListener);
    treeViewer.getTree().addListener(SWT.KeyDown, tableListener);
    treeViewer.getTree().addListener(SWT.MouseMove, tableListener);
    treeViewer.getTree().addListener(SWT.MouseHover, tableListener);

    return treeViewer;
}

From source file:com.aptana.ide.server.ui.views.GenericServersView.java

License:Open Source License

/**
 * Creates and registers the context menu
 *//*from  ww  w. java  2  s .c  o m*/
private void createPopupMenu() {
    deleteAction = ActionFactory.DELETE.create(getViewSite().getWorkbenchWindow());
    MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown(true);
    getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.DELETE.getId(), new Action() {

        public void run() {
            doDelete();
        }
    });
    menuMgr.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager manager) {
            IContributionItem[] items = getViewSite().getActionBars().getToolBarManager().getItems();
            for (int i = 0; i < items.length; i++) {

                if (items[i] instanceof ActionContributionItem) {
                    ActionContributionItem aci = (ActionContributionItem) items[i];
                    IAction action = aci.getAction();
                    if (action == openLog) {
                        // adds the Open Log action to the context menu as a push button instead of 
                        // drop-down
                        boolean enabled = action.isEnabled();
                        action = new OpenLogAction(serverViewer, Action.AS_PUSH_BUTTON);
                        action.setEnabled(enabled);
                    }
                    if (action.isEnabled() && action.getStyle() != Action.AS_DROP_DOWN_MENU) {
                        if (action.getText() == null || action.getText().length() == 0) {
                            action.setText(action.getToolTipText());
                        }
                        manager.add(action);
                    }
                } else {
                    if (items[i] instanceof Separator) {
                        manager.add(new Separator());
                    }
                }
            }
            manager.add(new Separator());
            IStructuredSelection selection = (IStructuredSelection) serverViewer.getSelection();
            final IServer server = (IServer) selection.getFirstElement();
            if (server != null) {
                deleteAction.setText(StringUtils.format(Messages.ServersView_DELETE, getShortenName(server)));
                // deleteAction.setEnabled(server.getServerState() == IServer.STATE_STOPPED);
                deleteAction.setEnabled(server.canDelete().isOK());
                manager.add(deleteAction);

                Action action = new Action() {
                    public void run() {
                        doEdit(server);
                    }
                };
                action.setText(StringUtils.format(Messages.ServersView_EDIT, getShortenName(server)));
                IStatus canModify = server.canModify();
                IStatus canModifyInStoppedStateOnly = server.canModifyInStoppedStateOnly();
                action.setEnabled(((canModifyInStoppedStateOnly == null
                        || canModifyInStoppedStateOnly.getCode() == IStatus.OK)
                                ? server.getServerState() == IServer.STATE_STOPPED
                                : true)
                        && (canModify == null || canModify.getCode() == IStatus.OK));
                manager.add(action);
            }
            // deleteAction.setEnabled(!selection.isEmpty());
            manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); // Allow
        }

        private String getShortenName(final IServer server) {
            String name = server.getName();
            int length = name.length();
            if (length > MAX_SHOWN_SERVER_NAME) {
                int delta = (length - 15) / 2;
                int pivot = length / 2;
                int start = pivot - delta;
                int end = pivot + delta;
                String s1 = name.substring(0, start);
                String s2 = name.substring(end, length);
                String s = s1 + ELLIPSIS + s2;
                return s;
            }
            return name;
        }
    });
    Menu menu = menuMgr.createContextMenu(serverViewer.getControl());
    serverViewer.getControl().setMenu(menu);
    getSite().registerContextMenu(menuMgr, serverViewer);
}

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.editor.parts.ExpandablePart.java

License:Open Source License

protected ImageHyperlink createActionHyperlink(Composite actionsComposite, FormToolkit toolkit,
        final IAction action) {

    if (action instanceof IReviewAction) {
        ((IReviewAction) action).setActionListener(actionListener);
    }//  w  w w. j a  v  a2 s . co  m
    ImageHyperlink link = toolkit.createImageHyperlink(actionsComposite, SWT.NONE);
    if (action.getImageDescriptor() != null) {
        link.setImage(CommonImages.getImage(action.getImageDescriptor()));
    } else {
        link.setText(action.getText());
    }
    link.setToolTipText(action.getToolTipText());
    link.addHyperlinkListener(new HyperlinkAdapter() {
        @Override
        public void linkActivated(HyperlinkEvent e) {
            action.run();
        }
    });
    return link;
}

From source file:com.diffplug.common.swt.jface.Actions.java

License:Apache License

private Actions(IAction action) {
    this.text = action.getText();
    this.style = Style.of(action);
    if (action instanceof ActionImp) {
        callback = ((ActionImp) action).callback;
    } else {//w  w w.j  a v a2  s. c o  m
        callback = (a, e) -> {
            if (e == null) {
                action.run();
            } else {
                action.runWithEvent(e);
            }
        };
    }
    this.img = action.getImageDescriptor();
    this.accelerator = action.getAccelerator();
    this.tooltip = action.getToolTipText();

    if (accelerator != SWT.NONE) {
        // the toolTip might have had an accelerator added,
        // which we'll want to strip so it doesn't get doubled
        String hint = getAcceleratorHint(accelerator);
        if (tooltip.endsWith(hint)) {
            tooltip = tooltip.substring(0, tooltip.length() - hint.length());
        }
    }
}

From source file:com.diffplug.common.swt.jface.ActionsTest.java

License:Apache License

@Test
public void testCopy() {
    // we'll set this variable to show that it's running as expected
    Box.Nullable<String> toSet = Box.Nullable.ofNull();

    // create an action
    IAction action = Actions.builder().setText("Name").setTooltip("Tooltip").setAccelerator(SWT.SHIFT | 'a')
            .setRunnable(() -> toSet.set("WasRun")).build();

    // make sure it's doing what we expect
    Assert.assertEquals("Name", action.getText());
    Assert.assertEquals("Tooltip [Shift A]", action.getToolTipText());
    Assert.assertEquals(SWT.SHIFT | 'a', action.getAccelerator());
    Assert.assertEquals(null, toSet.get());
    action.run();/*w w  w  .  j ava  2 s  .com*/
    Assert.assertEquals("WasRun", toSet.get());

    // copy that action
    IAction copy = Actions.builderCopy(action).setAccelerator(SWT.NONE)
            .setRunnable(() -> toSet.set("CopyWasRun")).build();

    Assert.assertEquals(SWT.NONE, copy.getAccelerator());
    // test that the tooltip was stripped correctly in the copy
    Assert.assertEquals("Tooltip", copy.getToolTipText());
    // make sure that the runnable took
    copy.run();
    Assert.assertEquals("CopyWasRun", toSet.get());
    // but didn't screw up the other one
    action.run();
    Assert.assertEquals("WasRun", toSet.get());
}

From source file:com.google.gdt.eclipse.designer.gef.policy.LayoutPanelSelectionEditPolicy.java

License:Open Source License

private void installSupport_AlignmentFigures() {
    new AlignmentActionsHelper<W>(this) {
        @Override/*from   w ww.  ja  v a 2s .c  o  m*/
        protected Figure createAlignmentFigure(final W widget, final boolean horizontal) {
            IEditPartViewer viewer = getHost().getViewer();
            final Anchor anchor = m_panel.getAnchor(widget, horizontal);
            if (horizontal) {
                return new AbstractPopupFigure(viewer, 16, 8) {
                    @Override
                    protected Image getImage() {
                        return anchor != null ? anchor.getSmallImage(horizontal) : null;
                    }

                    @Override
                    protected void fillMenu(IMenuManager manager) {
                        addAlignmentActions(manager, widget, horizontal);
                    }
                };
            } else {
                return new AbstractPopupFigure(viewer, 8, 16) {
                    @Override
                    protected Image getImage() {
                        return anchor != null ? anchor.getSmallImage(horizontal) : null;
                    }

                    @Override
                    protected void fillMenu(IMenuManager manager) {
                        addAlignmentActions(manager, widget, horizontal);
                    }
                };
            }
        }

        private void addAlignmentActions(IMenuManager manager, W widget, boolean horizontal) {
            List<Object> actionObjects = Lists.newArrayList();
            {
                LayoutPanelAlignmentSupport<W> alignmentSupport = m_panel.getAlignmentSupport();
                List<W> widgets = ImmutableList.of(widget);
                if (horizontal) {
                    alignmentSupport.addAnchorActions_horizontal(actionObjects, widgets);
                } else {
                    alignmentSupport.addAnchorActions_vertical(actionObjects, widgets);
                }
            }
            for (Object actionObject : actionObjects) {
                if (actionObject instanceof IAction) {
                    IAction action = (IAction) actionObject;
                    action.setText(action.getToolTipText());
                    manager.add(action);
                }
            }
        }
    };
}

From source file:com.microsoft.tfs.client.common.ui.framework.action.ToolbarPulldownAction.java

License:Open Source License

/**
 * Sets a previously added sub-action as the default sub-action of this
 * {@link ToolbarPulldownAction}. The default sub-action is the sub-action
 * that is invoked when the {@link ToolbarPulldownAction} is selected
 * directly./*from   ww w  . ja  v a2s . co  m*/
 *
 * @param action
 *        a previously added sub-action to set as the default sub-action
 *        (must not be <code>null</code>)
 */
public void setDefaultSubAction(final IAction action) {
    Check.notNull(action, "action"); //$NON-NLS-1$

    final int index = subActions.indexOf(action);

    if (index == -1) {
        throw new IllegalArgumentException(
                "the specified action is not contained in this ToolbarPulldownAction"); //$NON-NLS-1$
    }

    defaultSubActionIndex = index;

    setToolTipText(action.getToolTipText());
}