Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to find DirectMenuItem programmatically
How to find DirectMenuItem programmatically [message #946827] Tue, 16 October 2012 14:45 Go to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi,

I added a DirectMenuItem via Application Model

TrimmedWindow -> Main Menu -> Menu -> DirectMenuItem (elementId: myItem)

It is of type Check. Now I need to access that menu item in code to check its selection state. I'm trying to do it like shown in various tutorials:
@PostConstruct
public void createPartControl(Composite parent, IEclipseContext context, MApplication application, EModelService modelService) {

	MDirectMenuItem showTooltipItem = (MDirectMenuItem) modelService.find("myItem", application);

	...
}

But the EModelService always returns null.

How should I get access to a DirectMenuItem programmatically?

Greez,
Dirk
Re: How to find DirectMenuItem programmatically [message #946832 is a reply to message #946827] Tue, 16 October 2012 14:50 Go to previous messageGo to next message
Eclipse UserFriend
inject MWindow w in the postconstuct and provide the MMenu w.getMainMenu as the search root (i.e. not MApplication) .
Re: How to find DirectMenuItem programmatically [message #946837 is a reply to message #946832] Tue, 16 October 2012 14:56 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Yes that works. Thanks for the answer.

The Javadoc of the find() method says
Quote:
Returns the first element, recursively searching under the specified search root (inclusive)


I understood this as it would search recursively in all children of the given root. Therefore it should be working with MApplication, shouldn't it?
Re: How to find DirectMenuItem programmatically [message #946839 is a reply to message #946837] Tue, 16 October 2012 14:59 Go to previous messageGo to next message
Eclipse UserFriend
You've touched a hot topic https://bugs.eclipse.org/bugs/show_bug.cgi?id=383403
Re: How to find DirectMenuItem programmatically [message #946843 is a reply to message #946837] Tue, 16 October 2012 15:00 Go to previous messageGo to next message
Eclipse UserFriend
However from the performance point of view it is better to scope the searches as narrowly as possible (provide the closest node up in the hierarchy that you can access as the search root) keeping in mind that the model might grow in size.
Re: How to find DirectMenuItem programmatically [message #946847 is a reply to message #946843] Tue, 16 October 2012 15:05 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Thanks for the reply. And I perfectly agree with your statement that from the performance point of view the search root should be as narrow as possible for searching.
Re: How to find DirectMenuItem programmatically [message #946852 is a reply to message #946827] Tue, 16 October 2012 15:09 Go to previous messageGo to next message
François POYER is currently offline François POYERFriend
Messages: 6
Registered: December 2009
Junior Member
I think that this is because EModelService#find() only search through composition relation like MUIElementContainer#children, which does not include the MWindow#mainMenu relation and such.
You may want to do this in 2 steps: use find(id, root) to find the "container" of your Menu (here: the MTrimmedWindow) by its ID (or any other mean convenient to you), then call find(id, root) again, but using the menu as the search root this time.
MTrimmedWindow trim = modelService.find("myWindow", application).get(0);
MDirectMenuItem item = (MDirectMenuItem)modelService.find("myItem", trim.getMainMenu());


Hope this helps!

Edit: Ok, very, very late... nevermind me!

[Updated on: Tue, 16 October 2012 15:10]

Report message to a moderator

Re: How to find DirectMenuItem programmatically [message #947098 is a reply to message #946852] Tue, 16 October 2012 20:21 Go to previous message
Eclipse UserFriend
François POYER wrote on Tue, 16 October 2012 17:09

Edit: Ok, very, very late... nevermind me!

No problem, thanks for trying to answer!
Previous Topic:MHandledToolItem visibleWhen not working?
Next Topic:XWT ValidationRule Bug?
Goto Forum:
  


Current Time: Fri Mar 29 12:37:25 GMT 2024

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

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

Back to the top