EMenuService - get UI representation of menu [message #1476898] |
Mon, 17 November 2014 07:51  |
Eclipse User |
|
|
|
Hi,
I have a question on retrieving the UI representation of a menu declared in the application model programmatically.
To explain a bit more:
1. I added a popup menu to a part in the application model
2. after some investigation I've found out that with 4.4 it is possible to find the MMenu using the EModelService the following way
List<MMenu> menus = modelService.findElements(part, menuId, MMenu.class, null, EModelService.IN_PART);
Now I need to get the SWT Menu instance for the MMenu. I tried to call getWidget() on MMenu, but that returns null. I try to execute that method in @PostConstruct which should be ok from my understanding of the lifecycle.
I have seen that the SWT implementation of EMenuService contains a static helper method to get the Menu
Menu registerMenu(final Control, final MPopupMenu, IEclipseContext)
Now that method does exactly what I want. But MenuService is located in an internal package, and IMHO it is not good to rely on internal classes.
I'm currently not quite sure how to handle this correctly. Here are my questions:
1. Should MMenu#getWidget() return a valid instance if called in @PostConstruct or is there any trigger to let it be created?
2. If it is intended that it returns null, how could it be possible to get the Menu/trigger the Menu creation?
3. Since MenuService#registerMenu(Control, MPopupMenu, IEclipseContext) is public static, couldn't it be located in a place that is accessible for users? So no "internal" package.
It would be great if I could get help on this.
Greez,
Dirk
|
|
|
Re: EMenuService - get UI representation of menu [message #1477039 is a reply to message #1476898] |
Mon, 17 November 2014 10:15   |
Eclipse User |
|
|
|
You want EMenuService which got relocated from SWT to ui.services.
Tom
On 17.11.14 13:51, Dirk Fauth wrote:
> Hi,
>
> I have a question on retrieving the UI representation of a menu declared
> in the application model programmatically.
>
> To explain a bit more:
> 1. I added a popup menu to a part in the application model
> 2. after some investigation I've found out that with 4.4 it is possible
> to find the MMenu using the EModelService the following way
>
>
> List<MMenu> menus = modelService.findElements(part, menuId, MMenu.class,
> null, EModelService.IN_PART);
>
>
> Now I need to get the SWT Menu instance for the MMenu. I tried to call
> getWidget() on MMenu, but that returns null. I try to execute that
> method in @PostConstruct which should be ok from my understanding of the
> lifecycle.
>
> I have seen that the SWT implementation of EMenuService contains a
> static helper method to get the Menu
> Menu registerMenu(final Control, final MPopupMenu, IEclipseContext)
>
> Now that method does exactly what I want. But MenuService is located in
> an internal package, and IMHO it is not good to rely on internal classes.
>
> I'm currently not quite sure how to handle this correctly. Here are my
> questions:
>
> 1. Should MMenu#getWidget() return a valid instance if called in
> @PostConstruct or is there any trigger to let it be created?
> 2. If it is intended that it returns null, how could it be possible to
> get the Menu/trigger the Menu creation?
> 3. Since MenuService#registerMenu(Control, MPopupMenu, IEclipseContext)
> is public static, couldn't it be located in a place that is accessible
> for users? So no "internal" package.
>
> It would be great if I could get help on this.
> Greez,
> Dirk
>
|
|
|
|
|
Re: EMenuService - get UI representation of menu [message #1477092 is a reply to message #1477063] |
Mon, 17 November 2014 11:05  |
Eclipse User |
|
|
|
OK, found a workaround.
First I use EMenuService#registerContextMenu to create and register the menu from the application model to the NatTable.
Then I retrieve the created Menu for further usage and remove it from NatTable to avoid the SWT context menu mechanism.
menuService.registerContextMenu(natTable, menuId);
Menu swtMenu = natTable.getMenu();
natTable.setMenu(null);
//use swtMenu for NatTable configurations
|
|
|
Powered by
FUDForum. Page generated in 0.08907 seconds