I want to update selected status of MHandledItems depends on App's state.
Something likes org.eclipse.ui.commands.ICommandService.refreshElements(String, Map) on E3.
This is simple my App State model written with Xtend:
@Singleton
class AppState {
@Inject
IEventBroker eventBroker
@Accessors String mode;
def void setMode(String newMode) {
this.mode = newMode;
eventBroker.post("appstate/mode", newMode)
}
}
And this is the addon that watches model state and update MItems which is connected with specific command:
class ModeUpdater {
@Inject extension EModelService modelService
@Inject @Optional
def void didChangeMode(@UIEventTopic("appstate/mode") String newMode, MApplication app) {
var items = app.findElements(MHandledItem, EModelService.ANYWHERE) [
var item = it as MHandledItem
return item.command.elementId == "net.jeeeyul.eclipse.themes.test.e4app.changemode"
] as MHandledItem[]
items.forEach[
it.selected = it.parameters.findFirst[name == "mode"]?.value == newMode
]
}
}
When AppState.mode is updated, only MHandledToolItems are updated. So I created some test handler (Java):
@Execute
public void execute(EModelService modelService, MApplication app) {
List<MHandledMenuItem> items = modelService.findElements(app, MHandledMenuItem.class, EModelService.ANYWHERE,
new Selector() {
@Override
public boolean select(MApplicationElement element) {
return true;
}
});
for (MHandledItem each : items) {
System.out.println(each.getCommand().getCommandName());
}
}
Then I realized that any MMenuItems are never selected by EModelService.find(). Is it bug? Did I try wrong approach?
[Updated on: Mon, 08 June 2015 02:02]
Report message to a moderator