Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » EMenuService.registerContextMenu causes NullPointerException(Problem registering e4 model popup menu to FX component; no EBindingService in context)
EMenuService.registerContextMenu causes NullPointerException [message #1732004] Wed, 11 May 2016 15:22 Go to next message
Elias Vasylenko is currently offline Elias VasylenkoFriend
Messages: 15
Registered: December 2015
Junior Member
I have a TreeCell implementation something like the following:

@Creatable
public class ExampleTreeCell extends TreeCell<TreeItemData<?>> {
	private static String CONTEXT_MENU_ID = "blah.blah.blah.example";

	@PostConstruct
	void initialise(EMenuService menuService, @LocalInstance FXMLLoader loader) throws IOException {
		loader.setLocation(location());
		loader.setRoot(this);
		loader.setController(this);
		loader.load();

		menuService.registerContextMenu(this, CONTEXT_MENU_ID);
	}

	/*
	 * ...
	 */
}


Where instances are created elsewhere via a "javax.inject.Provider<ExampleTreeCell>" injection.

This works fine for an empty popup menu, it comes up on the screen on right click so I know it's attached to a valid component and stuff.

The problem occurs when I add a handled menu item to the e4 model, after which injection fails with a null pointer exception:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
	at org.eclipse.fx.ui.workbench.renderers.base.BaseMenuItemRenderer.initWidget(BaseMenuItemRenderer.java:63)
	at org.eclipse.fx.ui.workbench.renderers.base.BaseMenuItemRenderer.initWidget(BaseMenuItemRenderer.java:1)
	at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.createWidget(BaseRenderer.java:189)
	at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.createWidget(BaseRenderer.java:1)
	at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createWidget(PartRenderingEngine.java:277)
	at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:241)
	at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:323)
	at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.engineCreateWidget(BaseRenderer.java:619)
	at org.eclipse.fx.ui.workbench.renderers.base.BasePopupMenuRenderer.doProcessContent(BasePopupMenuRenderer.java:191)
	at org.eclipse.fx.ui.workbench.renderers.base.BasePopupMenuRenderer.doProcessContent(BasePopupMenuRenderer.java:1)
	at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.processContent(BaseRenderer.java:713)
	at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:244)
	at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:323)
	at org.eclipse.fx.ui.workbench.renderers.fx.internal.PartPopupMenuServiceImpl.registerMenu(PartPopupMenuServiceImpl.java:59)
	at org.eclipse.fx.ui.workbench.renderers.fx.internal.PartPopupMenuServiceImpl.registerContextMenu(PartPopupMenuServiceImpl.java:41)
	at uk.co.strangeskies.eclipse.E4TreeItemType.configureCell(E4TreeItemType.java:49)
	at ... (not sure if more is useful)


I've tried a few different ways of reorganising it, e.g. to construct ExampleTreeCell manually rather than making it @Creatable and then having the containing Part itself register the context menu to it. I always end up with that null pointer exception, with no EBindingService instance found in the model context of the menu item renderer.

I have no clue what I'm doing wrong here, any pointers would be appreciated.

[Updated on: Tue, 28 June 2016 08:42]

Report message to a moderator

Re: EMenuService.registerContextMenu causes NullPointerException [message #1736296 is a reply to message #1732004] Tue, 28 June 2016 10:11 Go to previous messageGo to next message
Elias Vasylenko is currently offline Elias VasylenkoFriend
Messages: 15
Registered: December 2015
Junior Member
Okay I came back to this today and figured out I needed to add the org.eclipse.fx.ui.keybindings.e4.BindingServiceAddon addon to the application. Is this documented anywhere? It wasn't exactly obvious, to me at least ...

Anyway, hope this helps someone having similar problems Smile
Re: EMenuService.registerContextMenu causes NullPointerException [message #1736308 is a reply to message #1736296] Tue, 28 June 2016 10:51 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6347
Registered: July 2009
Senior Member
Well the wizards should have bootstrapped an e4xmi with that, not?

Tom

On 28.06.16 12:11, Elias Vasylenko wrote:
> Okay I came back to this today and figured out I needed to add the
> org.eclipse.fx.ui.keybindings.e4.BindingServiceAddon addon to the
> application. Is this documented anywhere? It wasn't exactly obvious, to
> me at least ...
>
> Anyway, hope this helps someone having similar problems :)
Re: EMenuService.registerContextMenu causes NullPointerException [message #1736312 is a reply to message #1736308] Tue, 28 June 2016 11:30 Go to previous messageGo to next message
Elias Vasylenko is currently offline Elias VasylenkoFriend
Messages: 15
Registered: December 2015
Junior Member
Sure, it looks like they do, fair point. I hadn't used the wizard as A) I was porting from an existing swt project and B) I am using some different tooling so much of the generated project configuration isn't really relevant to me.

Cheers
Re: EMenuService.registerContextMenu causes NullPointerException [message #1736313 is a reply to message #1736296] Tue, 28 June 2016 11:31 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6347
Registered: July 2009
Senior Member
Hi,

Can you please file a bug we should not throw an NPE but log an error a
continue.

To your question which addons are mandatory more or less

> <addons xmi:id="_HxbWpPWZEeWvDMBH5dUovg" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
> <addons xmi:id="_HxbWpfWZEeWvDMBH5dUovg" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
> <addons xmi:id="_HxbWpvWZEeWvDMBH5dUovg" elementId="org.eclipse.fx.ui.keybindings.e4.service" contributionURI="bundleclass://org.eclipse.fx.ui.keybindings.e4/org.eclipse.fx.ui.keybindings.e4.BindingServiceAddon"/>
> <addons xmi:id="_HxbWp_WZEeWvDMBH5dUovg" elementId="org.eclipse.e4.ui.workbench.commands.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon"/>
> <addons xmi:id="_HxbWqPWZEeWvDMBH5dUovg" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
> <addons xmi:id="_HxbWqfWZEeWvDMBH5dUovg" elementId="org.eclipse.fx.ui.keybindings.e4.model" contributionURI="bundleclass://org.eclipse.fx.ui.keybindings.e4/org.eclipse.fx.ui.keybindings.e4.BindingProcessingAddon"/>
> <addons xmi:id="_HxbWqvWZEeWvDMBH5dUovg" elementId="org.eclipse.e4.ui.workbench.addons.HandlerProcessingAddon" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>


Tom

On 28.06.16 12:11, Elias Vasylenko wrote:
> Okay I came back to this today and figured out I needed to add the
> org.eclipse.fx.ui.keybindings.e4.BindingServiceAddon addon to the
> application. Is this documented anywhere? It wasn't exactly obvious, to
> me at least ...
>
> Anyway, hope this helps someone having similar problems :)
Re: EMenuService.registerContextMenu causes NullPointerException [message #1736316 is a reply to message #1736312] Tue, 28 June 2016 11:39 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2452
Registered: July 2012
Senior Member
Elias Vasylenko wrote on Tue, 28 June 2016 13:30
Sure, it looks like they do, fair point. I hadn't used the wizard as A) I was porting from an existing swt project and B) I am using some different tooling so much of the generated project configuration isn't really relevant to me.

Cheers


I think I mentioned thad addon in my SWT to JavaFX migration guide [1] Wink

https://blog.codecentric.de/en/2015/02/swt-javafx-migration-eclipse-rcp-cookbook/
Re: EMenuService.registerContextMenu causes NullPointerException [message #1736345 is a reply to message #1736316] Tue, 28 June 2016 16:04 Go to previous messageGo to next message
Elias Vasylenko is currently offline Elias VasylenkoFriend
Messages: 15
Registered: December 2015
Junior Member
Fantastic, thanks for the help/resources, guys Smile. Dirk, I'll definitely have a look through that. Thomas, it's the end of the day here now, but yes I'll be happy to file a bug for this tomorrow morning.
Re: EMenuService.registerContextMenu causes NullPointerException [message #1736347 is a reply to message #1736345] Tue, 28 June 2016 16:17 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2452
Registered: July 2012
Senior Member
Oh, almost forgot that my tutorial is about 1.2 (still contains some valid information). But there is also one by Christoph Keimel that covers e(fx)clipse 2.0 [1]. Small but important differences that need to be considered.

Both tutorials together should give a good introduction on a migration from SWT to JavaFX for Eclipse RCP applications.

[1] http://www.kware.net/?p=64
Previous Topic:Maven build problem
Next Topic:[BUG] Parts disappear when dragged between stacks in a perspective
Goto Forum:
  


Current Time: Fri Aug 18 05:42:29 GMT 2017

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

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