Example usage for org.eclipse.jface.action ContributionItem getId

List of usage examples for org.eclipse.jface.action ContributionItem getId

Introduction

In this page you can find the example usage for org.eclipse.jface.action ContributionItem getId.

Prototype

@Override
    public String getId() 

Source Link

Usage

From source file:com.google.cloud.tools.eclipse.ui.util.OpenDropDownMenuHandler.java

License:Apache License

/**
 * Retrieve the menu id to show from the contribution item's ID (following the documented approach
 * for DROP_DOWN items)./*www  . java 2  s. c o m*/
 */
private static String getMenuId(ExecutionEvent event, ToolItem toolItem) throws ExecutionException {
    if (toolItem.getData() instanceof ContributionItem) {
        ContributionItem data = (ContributionItem) toolItem.getData();
        if (!Strings.isNullOrEmpty(data.getId())) {
            return data.getId();
        }
    }
    throw new ExecutionException("Unable to determine menu ID");
}

From source file:com.google.code.t4eclipse.tools.model.ModelData.java

License:Open Source License

/**
 *
 * @param item/*from  w ww.  j av  a2  s .  com*/
 * @return a good model when it is a ActionContributionItem and not
 *         Separator or GroupMarker<BR>
 *         null if it is a separator or groupmarker or other conditions<br>
 */
private static LocalViewToolBarModel getToolBarModel(ToolItem item) {

    Object data = item.getData();

    ContributionItem tbcon = null;

    if (data != null) {
        if (data instanceof ContributionItem) {
            tbcon = (ContributionItem) data;
        }
        if (data instanceof SubContributionItem) {
            SubContributionItem sub = (SubContributionItem) data;
            IContributionItem internlItem = sub.getInnerItem();
            if (internlItem instanceof ContributionItem) {
                tbcon = (ContributionItem) internlItem;
            }
        }
    }

    if (tbcon != null) {
        if (tbcon.isSeparator() || tbcon.isGroupMarker()) {
            return null;
        }
        LocalViewToolBarModel model = new LocalViewToolBarModel();
        if (tbcon.getId() != null) {
            model.ID = tbcon.getId();
        }
        if (item.getToolTipText() != null) {
            model.ToolTip = item.getToolTipText();
        }
        model.Enabled = tbcon.isEnabled();

        model.item = item;
        // model.Style = item.getStyle();
        model.Selected = item.getSelection();

        return model;
    }
    return null;
}

From source file:net.refractions.udig.project.ui.internal.tool.display.ToolManager.java

License:Open Source License

/**
 * This method goes through the steps of deactivating the current tool option contribution and 
 * activating the new tool option contribution.
 * /*from  w  ww .j  a va  2s.c o m*/
 * @param statusLine
 * @param modalToolProxy
 */
private void initToolOptionsContribution(IStatusLineManager statusLine, ToolProxy modalToolProxy) {
    if (statusLine != null) {

        if (preferencesShortcutToolOptions == null || preferencesShortcutToolOptions.isDisposed()) {
            preferencesShortcutToolOptions = new PreferencesShortcutToolOptionsContributionItem();
            statusLine.appendToGroup(StatusLineManager.BEGIN_GROUP, preferencesShortcutToolOptions);
            preferencesShortcutToolOptions.setVisible(true);
        }
        preferencesShortcutToolOptions.update(modalToolProxy);

        //TODO, cache contributions instead of destroying them and recreating them

        //remove old tool contribution
        for (ContributionItem contribution : optionsContribution) {
            statusLine.remove(contribution.getId());
        }

        //get the new contributions
        optionsContribution = modalToolProxy.getOptionsContribution();

        //set all new contributions
        for (ContributionItem contribution : optionsContribution) {
            statusLine.appendToGroup(StatusLineManager.BEGIN_GROUP, contribution);
            contribution.setVisible(true);
        }

        statusLine.update(true);
    }
}