Rendering an SWT Menu from MMenu? [message #1216596] |
Thu, 28 November 2013 14:52 |
Alex Kipling Messages: 260 Registered: July 2012 |
Senior Member |
|
|
My Plugin contributes a MMenu hierarchy through a Model-Fragment.
is there any chance to use a use platform renderers to generate a Menu from the MMenu hierarchy?
What I have already tried:
MenuManager invisibleRootNodeMm = new MenuManager("Root");
// append menus to the main manager
Menu invisibleParent = invisibleRootNodeMm .createContextMenu(treeViewer.getControl());
treeViewer.getControl().setMenu(invisibleParent);
// get ModuleCOntextCOntributions
MMenuContribution moduleContextContribution = null;
for (MMenuContribution mmc : mApplication.getMenuContributions()) {
if (mmc.getElementId().equals(idModuleContextContribution)) {
moduleContextContribution = mmc;
break;
}
}
// get all Menus from the Contribution
List<MMenu> menus = modelService.findElements(moduleContextContribution, null, MMenu.class, null);
MMenu menu = menus.get(0);
// Switch to the SWT API
IRendererFactory fac = eclipseContext.get(IRendererFactory.class);
AbstractPartRenderer r = fac.getRenderer(menu, parent.getShell());
// does not generate a hierarchy, but an empty menu
Menu swtMenu = (Menu) r.createWidget(menu, parent.getShell());
[Updated on: Thu, 28 November 2013 14:53] Report message to a moderator
|
|
|
|
|
Re: Rendering an SWT Menu from MMenu? [message #1220592 is a reply to message #1220554] |
Thu, 12 December 2013 16:16 |
Eclipse User |
|
|
|
On 12/12/2013 03:24 PM, Alex Kipling wrote:
>
> - I have a system of multiple plugins. Every Plugin contributes a
> fragment of the E4Model.
> - There is a central application, which collects all plugins. - Every
> plugin should contribute some menuitems to the menu in the central
> applicaiton.
> My Idea was - to use the E4-Model to implement menuitem contribution.
> Every plugin adds the MenuItems to the fragment - the central
> applicaiton collects all the Menuitems and displays the whole menu.
>
> IMPORTANT: the menu should be displayed on click inside of the part, not
> on places predefined by the E4 platform. So I can not just add the
> Menuitems using the e4Model. I have to convert it to SWT meu items. (I
> am using SWT inside of my parts)
>
> So the question is again: how would I turn the E4 MMenu into SWT widget
> Menu?
> I mean the whole hierarchy of the Menus and Menu items. The platform
> does this somehow..
Hi Alex,
you don't have to deal with the e4 model or how your plugins contribute
to it via fragments. That should all work out-of-the-box for you.
What you wanna do instead is to lookup (findElements) the model menus
with the EModelService in your part(s) (as described in your initial
post) and renderer them according to your custom needs. Unfortunately
the build-in SWT renderer isn't implemented in a away to be reusable for
such use cases. But then remember, the renderer's (logical)
responsibility is to convert the e4 model into a visual representation.
If you are not satisfied with the visual rep, you just have to roll it
yourself.
HTH
M.
|
|
|
Powered by
FUDForum. Page generated in 0.02511 seconds