SWT Actions problem
Perhaps I'm missing something obvious, but here is my problem:
(description follows after the code)
== CLASSES ===================================
interface SomeDomainObject {
boolean canModify();
void modify(SomeData data);
}
Action cmd = new Action("Name") {
@Override
public boolean isEnabled() {
return domainObjectInstance.canModify();
}
void run() {
domainObjectInstance.modify(WidgetClass.this.getData());
}
}
== SETUP CODE ================================
MenuManager mmgr = new MenuManager();
mmgr.add(cmd);
Menu menu = mmgr.createContrxtMenu(aTable);
aTable.setMenu(menu);
== END OF CODE ===============================
I would expect that every time I right-click on the table, the context
menu would show the action in its propper enabled/disabled state.
Instead, it seems that the action state is read only once and cached in
the menu item and the only way to change the MenuItem's state is to call
directly menuItem.setEnabled(). This forces me to keep the menu items as
class members and create a listener for each and every domain object.
Am I missing something?
thanks,
Dimitar