Guenther Mahr Messages: 9 Registered: September 2011
Junior Member
I would like to have MHandledToolItems in a MToolbar in a composite, not in a part. In old eclipse one could add actions to a toolbar and then just add the toolbar to the layout. I would like to do the same in e4 using MToolItems and its commands. The examples I see on the net are all referring to parts where you can define the toolbar in the Application.e4xmi, but this is not my case. I tried to create a MToolbar and its items programmatically, created a composite and set that as the widget of the toolbar but I didn't succeed to make the items appear.
Guenther Mahr Messages: 9 Registered: September 2011
Junior Member
You mean add a selection listener to the button and execute the command from there? Okay, I could also use the traditional actions with a Toolbar or add a CommandContributionItem to a Toolbar (if I knew how to get a IServiceLocator in e4).
There may be a more elegant way...the problem is that the MToolBar has to be added to the model *somewhere* before it has a chance of working. You may be able to use the EModelService's 'hostElement' API. What this does is to put the given element into a 'safe' place in the model. After that it's just a matter of using the IPresentationEngine's 'createGui' call, passing in your Composite as a parent and choosing an appropriate IEclipseContext (likely the one from the MWindow is best).
Now I'm not sure how well that will play with the internal Commands infrastructure (we've never tried it).
Guenther Mahr Messages: 9 Registered: September 2011
Junior Member
Thanks for your answer, Eric! I may try to investigate in what you wrote.
Do you maybe know anything about what I mention in my last post, is it possible to use a CommandContributionItem in e4? What would I use as a IServiceLocator then?