DynamicMenuContribution and IEclipseContext [message #1674589] |
Sat, 14 March 2015 20:32 |
Stefan Häusler Messages: 23 Registered: May 2013 |
Junior Member |
|
|
Hello all,
i currently have some problems within the following scenario:
I have a file menu entry that is populated with dynamic menu contribution, each of the created direct menu items has a handler that sets a global object into the eclipse context (this context objects does influence the whole UI). Furthermore, the menu item representing the currently selected context object shall be selected. Therefore, i also ask the eclipse object for the current value.
Interestingly, most of the time, the selection is not detected correctly. Also sometimes the change of the context object has no influence to the views listening to the named object.
When i went into debugging, i observed the following facts:
- The injected IEclipseContext within the @AboutToShow method always points to the TrimmedWindow context. Looks ok to me, as it is in the context of the MainMenu
- The injected IEclipseContext wthin the handlers @Execute method always points to the Context of a part. Only that part reacts to a change within the named object. This also leads to the conclusion (to my understanding) why a call in the other method always return null, when i want to retrieve the named object value again (as it is the trimmed window context).
Am i doing something wrong here?
Dynamic Menu Contribution
@AboutToShow
public void createEntries(List<MMenuElement> items) {
Object currentMaster = context.get(Constant.SOME_GLOBAL_SELECTION);
List<SomeObject> allObjects= service.getAllObjects();
for (SomeObject obj: allObjects) {
MDirectMenuItem dynamicItem = MMenuFactory.INSTANCE.createDirectMenuItem();
dynamicItem.setLabel(obj.getName());
dynamicItem.setType(ItemType.CHECK);
dynamicItem.getTransientData().put(OBJECTKEY, obj);
dynamicItem.setContributorURI(CONTRIBUTOR);
dynamicItem.setContributionURI(HANDLER_CLASS);
//Set the dynamic item as selected, if it represents the architecture that was already
//selected previously
dynamicItem.setSelected(currentMaster != null && obj.equals(currentMaster));
items.add(dynamicItem);
}
}
The handler looks as follows
@Execute
public void elementSelected(MDirectMenuItem selectedItem, IEclipseContext context) {
Object object = selectedItem.getTransientData().get(OBJECTKEY);
context.set(CONTEXTOBJECT, object);
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03444 seconds