Skip to main content


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: 117
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: 117
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
Eclipse UserFriend
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.
Previous Topic:Injection of Death
Next Topic:P2 UIs in Eclipse 4
Goto Forum:
  


Current Time: Tue Mar 19 03:07:01 GMT 2024

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

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

Back to the top