Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » NPE for typed command parameter
NPE for typed command parameter [message #938954] Wed, 10 October 2012 09:52 Go to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi,

I created a command with two parameters. I want one of the parameters to be of type java.lang.Boolean, so I entered java.lang.Boolean to the TypeId of the CommandParameter.

The handler looks like this:
@Execute
public void execute(EPartService partService,
	@Named(PART_ID) String viewId, 
	@Named(HIDE_ON_RESHOW) @Optional Boolean hideOnReshow)


Then I try to add a HandledMenuItem to a menu, setting the parameter value of the boolean parameter to TRUE (also tried true).

The menu isn't rendered because of the following exception:
java.lang.NullPointerException
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.generateCommand(HandledContributionItem.java:286)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.setModel(HandledContributionItem.java:265)
	at org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer.processHandledItem(MenuManagerRenderer.java:703)


If I remove the TypeId there is no exception. The value for the optional Boolean parameter is null as the type doesn't match and the parameter is @Optional.
Changing the type of that parameter to String results in the correct injection of the parameter value. Of course it is then the String "TRUE".

Are typed parameters not supported in Eclipse 4? Or am I missing something on using typed parameters?

Greez,
Dirk
Re: NPE for typed command parameter [message #939384 is a reply to message #938954] Wed, 10 October 2012 18:08 Go to previous messageGo to next message
Eclipse UserFriend
Command parameters are always strings. Injection doesn't auto-convert the values for you-- it only lets you scope down the match. That is, if the injected value is a Boolean, then your method will be injected; if it's a Foo then your method won't be injected.

(What version of Eclipse are you running -- I couldn't match line 286 of HandledContributionItem.java to something that would cause an NPE.)

Brian.
Re: NPE for typed command parameter [message #939981 is a reply to message #939384] Thu, 11 October 2012 07:44 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Thank for the answer. I understand that injection doesn't autoconvert. That would be too much magic. Smile
But what is the TypeId in command parameters for if not for conversion? In Eclipse 3.x the typeId was used for this.

Quote:
Specifying a typeId allows handlers of a command to convert string parameter values to objects in a consistent way


In Eclipse 4 the Javadoc only says that the meaning is unclear.

So compared to Eclipse 3.x I tried to configure a command parameter type. Well this isn't possible in the Application Model, so I switched to the plugin.xml and added the extension org.eclipse.ui.commands and added a command parameter type. I created a converter for it and used the if of this type within my command parameter typeId. So now there is no NPE anymore, but there is also no conversion. The value is still a String.

I have seen that in Eclipse 3.x you needed to get the command parameter type out of the command, then get the value converter and then convert manually. But should you really try to get the converter out of a domain model in Eclipse 4 where the values getting injected?

So for me it seems the NPE was thrown because of the missing parameter type definition. But in fact the conversion isn't executed. Or do I still miss something about the typeId of command parameters and conversion?

Oh, I'm working with Eclipse 4.2.1 M20120914-1800

Greez,
Dirk
Re: NPE for typed command parameter [message #941253 is a reply to message #939981] Fri, 12 October 2012 10:37 Go to previous messageGo to next message
Eclipse UserFriend
Hmm good point Dirk. The MCommand-related items are transformed into the equivalent old-school Command objects. Have you defined a type converter for java.lang.Boolean using an extension point? See the <commandParameterType> element:

http://help.eclipse.org/juno/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_commands.html#e.commandParameterType
Re: NPE for typed command parameter [message #941316 is a reply to message #941253] Fri, 12 October 2012 11:52 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
As posted before, yes I defined a converter for java.lang.Boolean and used the id for it as TypeId for the command in application model. I don't get a NPE anymore, but there is also no conversion in the back. And I don't know how to get the configured converter. At least the whole concept doesn't make real sense in eclipse 4 if I need to retrieve a converter out of whereever to do the conversion. If this is necessary, I can do the conversion in the handler.

Please correct me if I'm seeing this wrong. At least I didn't find a solution for automatic conversion and did it manually.
Previous Topic:Programmatically show a part
Next Topic:e4 rcp focus on window
Goto Forum:
  


Current Time: Fri Mar 29 14:20:48 GMT 2024

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

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

Back to the top