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

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

Introduction

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

Prototype

@Override
    public IContributionItem[] getItems() 

Source Link

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)
 *///  ww  w  .j a  va  2  s.c  om
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.eclipse.helper.EclipseToolBarHelper.java

License:Open Source License

/**
 * only for debugging purpose//from  w w  w.  j  a  v a  2  s  . c  o m
 *
 * @return all eclipse toolbars
 */
public String[] printAllToolBar() {

    ArrayList<String> list = new ArrayList<String>();
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    Object data = shell.getData();
    if (data instanceof ApplicationWindow) {
        ApplicationWindow window = (ApplicationWindow) data;
        CoolBarManager coolMng = window.getCoolBarManager();
        if (coolMng != null) {
            IContributionItem[] items = coolMng.getItems();
            for (int i = 0; i < items.length; i++) {
                if (items[i] instanceof ToolBarContributionItem) {
                    ToolBarContributionItem item = (ToolBarContributionItem) items[i];
                    ToolBarManager toolMng = (ToolBarManager) item.getToolBarManager();
                    ToolBar tb = toolMng.getControl();
                    ToolItem[] toolItems = tb.getItems();
                    for (int j = 0; j < toolItems.length; j++) {
                        ToolItem toolItem = toolItems[j];
                        list.add(getToolItemStr(toolItem));
                    }

                }
            }
        }
    }
    return list.toArray(new String[0]);
}

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

License:Open Source License

public MainToolBarItemModel[] getToolBarModelList() {

    Shell shell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell();

    Object data = shell.getData();
    if (data instanceof ApplicationWindow) {
        Vector<MainToolBarItemModel> v = new Vector<MainToolBarItemModel>();
        ApplicationWindow window = (ApplicationWindow) data;
        CoolBarManager coolMng = window.getCoolBarManager();
        if (coolMng != null) {
            //coolMng.
            IContributionItem[] items = coolMng.getItems();

            if (items != null) {
                for (int i = 0; i < items.length; i++) {
                    //System.out.println(items[i].getClass().getName());
                    if (items[i] instanceof ToolBarContributionItem) {
                        ToolBarContributionItem item = (ToolBarContributionItem) items[i];
                        ToolBarManager toolMng = (ToolBarManager) item.getToolBarManager();

                        ToolBar tb = toolMng.getControl();
                        if (tb != null) {
                            ToolItem[] toolItems = tb.getItems();
                            if (toolItems != null) {

                                for (int j = 0; j < toolItems.length; j++) {
                                    MainToolBarItemModel model = new MainToolBarItemModel(toolItems[j]);
                                    v.add(model);

                                }//from   ww  w. ja  va2s.c o  m

                            }
                        }
                    }
                }

                return v.toArray(new MainToolBarItemModel[] {});
            }
        }
    }

    return null;
}

From source file:com.google.code.t4eclipse.tools.utility.EclipseToolBarUtility.java

License:Open Source License

public static List<EclipseToolBarModel> getToolBarModel() {

    ArrayList<EclipseToolBarModel> list = new ArrayList<EclipseToolBarModel>();
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    Object data = shell.getData();
    if (data instanceof ApplicationWindow) {
        ApplicationWindow window = (ApplicationWindow) data;
        CoolBarManager coolMng = window.getCoolBarManager();
        if (coolMng != null) {
            IContributionItem[] items = coolMng.getItems();

            if (items != null) {
                for (int i = 0; i < items.length; i++) {
                    if (items[i] instanceof ToolBarContributionItem) {
                        ToolBarContributionItem item = (ToolBarContributionItem) items[i];
                        ToolBarManager toolMng = (ToolBarManager) item.getToolBarManager();

                        ToolBar tb = toolMng.getControl();
                        if (tb != null) {
                            ToolItem[] toolItems = tb.getItems();
                            if (toolItems != null) {

                                for (int j = 0; j < toolItems.length; j++) {
                                    EclipseToolBarModel m = new EclipseToolBarModel();
                                    ToolItem toolItem = toolItems[j];
                                    m.Enabled = toolItem.isEnabled();
                                    m.ID = getString(getActionId(toolItem));
                                    m.ToolTip = getString(toolItem.getToolTipText());
                                    if ((toolItem.getStyle() & SWT.CHECK) != 0
                                            || (toolItem.getStyle() & SWT.RADIO) != 0)
                                        m.Selected = Boolean.valueOf(toolItem.getSelection()).toString();
                                    else {
                                        m.Selected = "";
                                    }/*from   ww  w . jav a2s. c  om*/
                                    list.add(m);
                                }

                            }
                        }
                    }
                }
            }
        }
    }
    return list;

}

From source file:org.eclipse.rcptt.tesla.ui.Q7KeyFormatter.java

License:Open Source License

public static void installQ7Formatter() {
    KeyFormatterFactory.setDefault(new Q7KeyFormatter());
    IWorkbench workbench = PlatformUI.getWorkbench();
    for (IWorkbenchWindow w : workbench.getWorkbenchWindows()) {
        if (!(w instanceof WorkbenchWindow))
            continue;

        final WorkbenchWindow ww = (WorkbenchWindow) w;
        final Shell shell = ww.getShell();
        final CoolBarManager coolBarManager = ww.getCoolBarManager();

        if (shell != null && coolBarManager != null)
            shell.getDisplay().syncExec(new Runnable() {
                public void run() {
                    try {
                        shell.setLayoutDeferred(true);
                        IContributionItem[] items = coolBarManager.getItems();
                        coolBarManager.setItems(new IContributionItem[0]);
                        coolBarManager.setItems(items);
                    } finally {
                        shell.setLayoutDeferred(false);
                    }/*from ww  w .  ja v  a  2  s  .co m*/
                }
            });
    }
}