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:
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?
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.)
Thank for the answer. I understand that injection doesn't autoconvert. That would be too much magic.
But what is the TypeId in command parameters for if not for conversion? In Eclipse 3.x the typeId was used for this.
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?
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:
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.