JimmyD JimmyD - 1 month ago 17
Java Question

Add items to toolbar in Eclipse RCP

I'm searching for a way to dynamicly add items to a toolbar in Eclipse RCP.

I use the EModelSerivce to lookup the toolbar in the view of my application.

List<MToolBar> toolbar = service.findElements(application, "toolbar_top", MToolBar.class , null);
MToolBar toolbar = toolbar.get(0);


Now I need to add some Toolbar items to it. How can I do this?

Answer

I placed all the toolitems in the .e4xmi file. Default the toolitems are hidden by disable the flag on "To be Rendered". When some MPart need to enable a tooltitem it will be enabled by using:

toolItem.setToBeRendered(true);
toolItem.setVisible(true);

Hiding it when some other part need to be rendered can be done by setting all the flags back to false.

Comments