Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » EModelService.find never matches with MMenuItem
EModelService.find never matches with MMenuItem [message #1697739] Mon, 08 June 2015 01:53 Go to next message
Jeeeyul Lee is currently offline Jeeeyul LeeFriend
Messages: 115
Registered: July 2009
Location: Seoul
Senior Member

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

Re: EModelService.find never matches with MMenuItem [message #1697740 is a reply to message #1697739] Mon, 08 June 2015 02:13 Go to previous messageGo to next message
Jeeeyul Lee is currently offline Jeeeyul LeeFriend
Messages: 115
Registered: July 2009
Location: Seoul
Senior Member

I solved this problem with searchFlag EModelService.ANYWHERE | EModelService.IN_PART.
My menu items are located at the part menu.

I think the meaning of the EModelService.ANYWHERE can be confusing.
Re: EModelService.find never matches with MMenuItem [message #1697783 is a reply to message #1697740] Mon, 08 June 2015 13:11 Go to previous message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 653
Registered: January 2012
Senior Member

In 4.4 on, you can fire the UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC event to request re-evaluation. See the javadocs for REQUEST_ENABLEMENT_UPDATE_TOPIC for details.

Brian.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Previous Topic:Injection of Death
Next Topic:Model Spy not working
Goto Forum:
  


Current Time: Mon Sep 25 10:00:00 GMT 2017

Powered by FUDForum. Page generated in 0.02974 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software