Access Menu at runtime [message #1062477] |
Fri, 07 June 2013 18:25  |
Eclipse User |
|
|
|
I would like to disable/enable a HandledMenuItem based on user interaction.
Using the EModelService I can find MParts, MTrimmedWindows etc, but cannot find a MMenu (see Eclipse Bug 383403 EModelService.findElement() does not find all elements).
There is a reference in the Bug 383403 Comment 25 to "using the EModel service to get my main window, and using that window as the context in find(...) to get the menu item".
I am having trouble searching the context for the menu item via the menu item id.
private void findObjectById(MApplication application,
EModelService service) {
List<MTrimmedWindow> findElements = service.findElements(application,
"com.test.ui.mainwindow",MTrimmedWindow.class, null);
//This window is found OK
System.out.println("Found part by id: " + findElements.size());
if (findElements.size() == 1){
MTrimmedWindow window = findElements.get(0);
IEclipseContext windowContext = window.getContext();
//doesn't contain key
boolean hasKey = windowContext.containsKey("com.test.ui.filesubmenu");
if (hasKey){
System.out.println("Key found");
}
//not found in the context
Object menuItem = windowContext.get("com.test.ui.filesubmenu");
if (menuItem !=null){
System.out.println("Found in context: "+ menuItem.toString());
}
}
}
Has anyone found a way to access menu items at runtime?
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04904 seconds