Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » MToolbar in a composite
MToolbar in a composite [message #1109022] Sat, 14 September 2013 15:56 Go to next message
Guenther Mahr is currently offline Guenther Mahr
Messages: 10
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.

Could you please give an example!

Thanks,
G√ľnther
Re: MToolbar in a composite [message #1109980 is a reply to message #1109022] Mon, 16 September 2013 03:48 Go to previous messageGo to next message
Andrzej Szczepanski is currently offline Andrzej Szczepanski
Messages: 16
Registered: May 2013
Junior Member
You can achieve something similar by creating CoolBar widget manually:
http://www.eclipse.org/swt/snippets/#coolbar

and using Eclipse services to access your application model commands programmatically:

handlerService.executeHandler(commandService.createCommand("command.id.from.app.model", params))
Re: MToolbar in a composite [message #1110334 is a reply to message #1109980] Mon, 16 September 2013 14:47 Go to previous messageGo to next message
Guenther Mahr is currently offline Guenther Mahr
Messages: 10
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).

But is there no other, more elegant way?
Re: MToolbar in a composite [message #1110357 is a reply to message #1110334] Mon, 16 September 2013 15:39 Go to previous messageGo to next message
Eric Moffatt is currently offline Eric Moffatt
Messages: 117
Registered: July 2009
Senior Member

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).
Re: MToolbar in a composite [message #1110686 is a reply to message #1110357] Tue, 17 September 2013 03:26 Go to previous message
Guenther Mahr is currently offline Guenther Mahr
Messages: 10
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?

Thanks again,
Guenther

Previous Topic:Reset perspective menu option disapear
Next Topic:Getting Eclipse IDE Look and Feel in a RCP Application
Goto Forum:
  


Current Time: Tue Jul 29 14:57:16 EDT 2014

Powered by FUDForum. Page generated in 0.14282 seconds