Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Changing menu programmatically
Changing menu programmatically [message #1255539] Mon, 24 February 2014 14:58 Go to next message
M. Herrmann is currently offline M. HerrmannFriend
Messages: 25
Registered: March 2010
Junior Member
Hi,

could someone please lead me into the right direction concerning programmatically changing menu items in the main menu Smile
I am trying to add menus / menu items programmatically at runtime.

As an example the code could look something like this:

List<MTrimmedWindow> windows = modelService.findElements(app, "IDEWindow", MTrimmedWindow.class, null);

MTrimmedWindow mTrimmedWindow = windows.get(0);
MMenu mainMenu = mTrimmedWindow.getMainMenu();

// Add a new menu to main menu (does not work)
MMenu menu = MMenuFactory.INSTANCE.createMenu();
menu.setElementId("ByHandler");
menu.setLabel("ByHandler");
menu.setToBeRendered(true);
menu.setVisible(true);

// add a menu item to the new menu (does not work)
MDirectMenuItem menuItem = MMenuFactory.INSTANCE.createDirectMenuItem();
menuItem.setLabel("ActionByHandler");
menuItem.setElementId("action1");
menuItem.setToBeRendered(true);
menuItem.setVisible(true);
menu.getChildren().add(menuItem);

mainMenu.getChildren().add(menu);



When this code is called from a handler (for example) it does not work.
By "it does not work" I mean that the menu items do not appear.

When the exact same code is called from a model processor it works just fine.

So am I missing something?
I thought the rendered UI always reflects the current model but in this case it seems that the changes are not picked up.

I attached a sample project.

I am using Eclipse 4.3.1 for my RCP application (pure e4)


Some more background:
---------------------
What I was originally trying to do was to display main menu items with "visibleWhen" and core expressions.
For some reason I did not manage to get it to work with main menu items. That's why I decided to do it programmatically.
So if you know how to display / hide main menu items (when the user switches perspective for example) I appreciate some tipps as well.
  • Attachment: MenuTest.zip
    (Size: 10.66KB, Downloaded 106 times)

[Updated on: Mon, 24 February 2014 15:00]

Report message to a moderator

Re: Changing menu programmatically [message #1255630 is a reply to message #1255539] Mon, 24 February 2014 16:58 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
IIRC this was a bug in 4.3, please run your code on Luna. It should work
there.

Tom

On 24.02.14 15:58, M. Herrmann wrote:
> Hi,
>
> could someone please lead me into the right direction concerning programmatically changing menu items in the main menu :)
> I am trying to add menus / menu items programmatically at runtime.
>
> As an example the code could look something like this:
>
>
> List<MTrimmedWindow> windows = modelService.findElements(app, "IDEWindow", MTrimmedWindow.class, null);
>
> MTrimmedWindow mTrimmedWindow = windows.get(0);
> MMenu mainMenu = mTrimmedWindow.getMainMenu();
>
> // Add a new menu to main menu (does not work)
> MMenu menu = MMenuFactory.INSTANCE.createMenu();
> menu.setElementId("ByHandler");
> menu.setLabel("ByHandler");
> menu.setToBeRendered(true);
> menu.setVisible(true);
>
> // add a menu item to the new menu (does not work)
> MDirectMenuItem menuItem = MMenuFactory.INSTANCE.createDirectMenuItem();
> menuItem.setLabel("ActionByHandler");
> menuItem.setElementId("action1");
> menuItem.setToBeRendered(true);
> menuItem.setVisible(true);
> menu.getChildren().add(menuItem);
>
> mainMenu.getChildren().add(menu);
>
>
>
> When this code is called from a handler (for example) it does not work.
> By "it does not work" I mean that the menu items do not appear.
>
> When the exact same code is called from a model processor it works just fine.
>
> So am I missing something?
> I thought the rendered UI always reflects the current model but in this case it seems that the changes are not picked up.
>
> I attached a sample project.
>
> I am using Eclipse 4.3
>
>
> Some more background:
> ---------------------
> What I was originally trying to do was to display main menu items with "visibleWhen" and core expressions.
> For some reason I did not manage to get it to work with main menu items. That's why I decided to do it programmatically.
> So if you know how to display / hide main menu items (when the user switches perspective for example) I appreciate some tipps as well.
>
Re: Changing menu programmatically [message #1256611 is a reply to message #1255630] Tue, 25 February 2014 16:04 Go to previous messageGo to next message
M. Herrmann is currently offline M. HerrmannFriend
Messages: 25
Registered: March 2010
Junior Member
Thanks for your hint, I tried wih Luna but the behavior is the same (model changes are not rendered in main menu).
I tried with 4.4.M5

Am I missing something else?
Re: Changing menu programmatically [message #1256621 is a reply to message #1256611] Tue, 25 February 2014 16:10 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
File a bug and attach a test-case - maybe I remember having fixed this
in e(fx)clipse.

Tom

On 25.02.14 17:04, M. Herrmann wrote:
> Thanks for your hint, I tried wih Luna but the behavior is the same
> (model changes are not rendered in main menu).
> I tried with 4.4.M5
>
> Am I missing something else?
Previous Topic:Unable to Invoke Live Model Editor
Next Topic:Switch Perspective on startup in E4 application
Goto Forum:
  


Current Time: Tue Mar 19 08:38:13 GMT 2024

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

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

Back to the top