Example usage for org.eclipse.jface.action CoolBarManager getControl

List of usage examples for org.eclipse.jface.action CoolBarManager getControl

Introduction

In this page you can find the example usage for org.eclipse.jface.action CoolBarManager getControl.

Prototype

public CoolBar getControl() 

Source Link

Document

Returns the cool bar control for this manager.

Usage

From source file:com.aptana.ide.core.ui.actions.AbstractWorkbenchWindowPulldownDelegate.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *//* w w w .  j  a  v  a  2s . c  o  m*/
public void run(IAction action) {
    String id = action.getId();
    ToolItem widget = null;

    WorkbenchWindow window = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    CoolBarManager manager = window.getCoolBarManager();
    CoolBar parent = manager.getControl();
    // this returns the list of actionSets groups
    IContributionItem[] items = manager.getItems();
    for (IContributionItem item : items) {
        if (item instanceof IToolBarContributionItem) {
            IToolBarContributionItem toolbarItem = (IToolBarContributionItem) item;
            // this returns the list of actual items for the actions
            IContributionItem[] children = toolbarItem.getToolBarManager().getItems();
            for (IContributionItem child : children) {
                if (child.getId().equals(id)) {
                    // found the toolbar item that corresponds to the action
                    ActionContributionItem actionItem = (ActionContributionItem) child;
                    if (CoreUIUtils.inEclipse34orHigher) {
                        // uses the 3.4 API
                        widget = (ToolItem) actionItem.getWidget();
                    }
                    break;
                }
            }
        }
    }
    Menu menu = getMenu(parent);
    if (widget != null) {
        // sets the location of where the menu is displayed to be the same
        // as when the dropdown arrow is clicked
        Rectangle bounds = widget.getBounds();
        Point point = widget.getParent().toDisplay(bounds.x, bounds.y + bounds.height);
        menu.setLocation(point);
    }
    menu.setVisible(true);
}

From source file:com.google.code.t4eclipse.core.utility.ToolBarUtility.java

License:Open Source License

public static CoolBar getEclipseCoolBar() {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    Object data = shell.getData();
    if (data instanceof ApplicationWindow) {
        ApplicationWindow window = (ApplicationWindow) data;
        CoolBarManager coolMng = window.getCoolBarManager();
        return coolMng.getControl();
    }/*  w w  w.jav  a  2  s .com*/
    return null;
}

From source file:org.eclipse.pde.internal.ui.tests.macro.MacroUtil.java

License:Open Source License

private static boolean onToolbar(ToolItem toolItem) {
    ToolBar toolBar = toolItem.getParent();
    Shell shell = toolBar.getShell();/*from  w w w  .  j  av a2  s. c o  m*/
    Object data = shell.getData();
    if (data instanceof ApplicationWindow) {
        ApplicationWindow window = (ApplicationWindow) data;
        ToolBarManager mng = window.getToolBarManager();
        if (mng != null) {
            if (mng.getControl() != null && mng.getControl() == toolBar)
                return true;
        }
        CoolBarManager cmng = window.getCoolBarManager();
        if (cmng != null) {
            CoolBar cbar = cmng.getControl();
            Composite parent = toolBar.getParent();
            while (parent != null) {
                if (parent == cbar)
                    return true;
                parent = parent.getParent();
            }
        }
    }
    return false;
}