Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » EMenuService - get UI representation of menu
EMenuService - get UI representation of menu [message #1476898] Mon, 17 November 2014 12:51 Go to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2800
Registered: July 2012
Senior Member
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 15:15 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6580
Registered: July 2009
Senior Member
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 #1477044 is a reply to message #1477039] Mon, 17 November 2014 15:21 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6580
Registered: July 2009
Senior Member
[...]

>> 1. Should MMenu#getWidget() return a valid instance if called in
>> @PostConstruct or is there any trigger to let it be created?

Not necessarily because the Menu could be created lazily IIRC in SWT
(and JavaFX) it is done greedy.

So at the point you called EMenuService#registerContextMenu getWidget
should return a type.

>> 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.
>>

No. Why should it? Maybe you should explain why you need to get access
to the native instance. There's not guarantee of what type the menu is
because it depends on the renderer. I could supply a renderer who does
create a completely different menu type.

Tom
Re: EMenuService - get UI representation of menu [message #1477063 is a reply to message #1477044] Mon, 17 November 2014 15:40 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2800
Registered: July 2012
Senior Member
Quote:
Maybe you should explain why you need to get access to the native instance.


The reason is the menu mechanism in NatTable. The SWT popup menu mechanism registers the menu for the whole control. Now for NatTable this would mean to have the same menu in all regions (column header, row header, body). Therefore NatTable comes with a custom menu handling where menus are opened with actions dependent on the region. Internally the menu instances are created and handled manually.

The NatTable mechanism allows to extend existing Menu instances and I used that in 3.x before. The idea is to get the menu declared in the application model and register it with the NatTable mechanism to a specific region. But for this I need the Menu instance.

Calling EMenuService#registerContextMenu will register the menu to the whole control, so I can't use it in that case. EMenuService#registerMenu only creates the menu without registering it to the parent control. And the later is what I search for.

Dirk
Re: EMenuService - get UI representation of menu [message #1477092 is a reply to message #1477063] Mon, 17 November 2014 16:05 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2800
Registered: July 2012
Senior Member
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
Previous Topic:How to contribute to the toolbar of an e4view?
Next Topic:Eclipse Luna Problem with @Inject
Goto Forum:
  


Current Time: Mon Jan 25 02:24:35 GMT 2021

Powered by FUDForum. Page generated in 0.02117 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top