Cannot replace menu items at runtime [message #909161] |
Thu, 06 September 2012 12:44  |
Eclipse User |
|
|
|
I managed to add a few menu items to my application's main menu from within a processor. (What I want to do is implement a recently used files list in the file menu.)
So when the application starts up the file menu gets populated as it should. But I fail to figure out how to replace elements in that list later on. My suspicion is that the menu no longer gets updated after it has been initially created from the model.
What I mean is that I can remove elements from the MMenu and add new ones to replace them. It looks like the MMenu object hierarchy is okay but the newly created menu items just don't show up in the real (rendered) menu.
Do I have to trigger that update somehow?
Here's my code:
private void updateMenuItems() {
List<MMenuElement> elements = findRecentMenuElements();
elements.clear();
int index = 0;
for (ProfileInfo profileInfo : recentProfileList) {
String label = buildLabel(index++, profileInfo.shortName);
addOpenRecentItem(elements, label, profileInfo.id);
}
// debug output seem to be okay
for (MMenuElement element : fileMenu.getChildren()) {
System.out.println(element);
}
System.out.println();
}
private void addOpenRecentItem(List<MMenuElement> elements, String label, String profileId) {
MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem();
menuItem.setLabel(label);
menuItem.setCommand(openRecentCommand);
MParameter parameter = MCommandsFactory.INSTANCE.createParameter();
parameter.setName(OpenRecentHandler.PARAM_ID_PROFILE_ID);
parameter.setValue(profileId);
menuItem.getParameters().add(parameter);
elements.add(menuItem);
}
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05955 seconds