1
votes

I have an Eclipse product defined in a plugin - it does not define its own Application class (i.e. no custom implementation of IApplication). I am using some dynamic drop-down items in the main toolbar, defined in plugin.xml. I am building the Product using the Eclipse 4.3 (Kepler) platform.

At runtime, I would like the toolbar items to show which of the drop-down items are currently selected. For generic items, I use an icon, but for non-generic items I would like to show some identifying text. The identifying text is not always of the same length.

I am using an IElementUpdater to update the drop-down items and also the toolbar item. Everything works fine, except that the coolbar/toolbar/trimbar does not re-layout. If the new text is longer than the text it is replacing, or if I switch from icon to text or vice-versa, the toolbar appears empty - not even the drop-down arrow is showing. My test team reports that the Drop-down tool item "disappears", which is a pretty good description of the experience.

Is there any way to force the main toolbar/coolbar/trimbar complex re-layout?

I have done some research and it seems that I might be able to do this by defining my own IApplication implementation and capturing the Coolbar/Toolbar manager using an ActionBarAdvisor subclass for later calls to layout(). This is a pretty heavyweight solution - is there any other?

1

1 Answers

2
votes

You can always retrieve toolbar manager from PartSite. There are also subclasses EditorSite and ViewSite:

IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite();
        ToolBarManager mgr = null;
        if (site instanceof IEditorSite) {
            IEditorSite editorSite = (IEditorSite) site;
            mgr = (ToolBarManager) editorSite.getActionBars().getToolBarManager();
        } else if (site instanceof IViewSite) {
            IViewSite viewSite = (IViewSite) site;
            mgr = (ToolBarManager) viewSite.getActionBars().getToolBarManager();

        }

Or if you know there is an active editor available:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorSite().getActionBars().getToolBarManager();

Or inside of a view:

ToolBarManager mgr = getViewSite().getActionBars().getToolBarManager();

Then you will get a possibity to layout it:

mgr.getControl().layout(true);