I am trying to get reference to an MToolItem from my own Utility class so I can programmatically set its selected state. The problem is that I always seem to get back null. I know that I have the correct id, and similar code works from a handler class (by passing in the EModelService and MApplication in the execute method). Is it possible that the EModelService or MApplication is stale when I make the find() call? Is there a better way to do this?
public class MyUtilityClass {
@Inject
private EModelService modelService;
@Inject
private MApplication app;
private void toggle(final boolean selected) {
MToolItem toolItem = (MToolItem) modelService.find("my.tool.id", app);
// toolItem is always null
if (toolItem != null) {
toolItem.setSelected(selected);
}
// I have also tried to find it via way below but it also doesn't work
final List<MToolItem> toolItems = modelService.findElements(
app, "my.tool.id", MToolItem.class,
new ArrayList<String>(), EModelService.ANYWHERE);
}
}