| Command with parameters and DI ? [message #728308] |
Thu, 22 September 2011 19:26  |
Cristiano Gaviao Messages: 247 Registered: July 2009 |
Senior Member |
|
|
Hi guys,
I'm trying to learn how to deal with Commands and E4. I'm using the E4 Contacts as example.
I've created this command:
<commands xmi:id="_VNE7QOVpEeCBqrdVElCRVQ" elementId="teste.c" commandName="Teste">
<parameters xmi:id="_1ec7cOVqEeCBqrdVElCRVQ" elementId="meu.par.id" name="meu.par" optional="false"/>
</commands>
<children xsi:type="menu:HandledMenuItem" xmi:id="_9Yw44OVlEeCBqrdVElCRVQ" elementId="teste" label="Change to Black" command="_VNE7QOVpEeCBqrdVElCRVQ">
<parameters xmi:id="_wFhu8OVqEeCBqrdVElCRVQ" elementId="x1" name="meu.par.id" value="example"/>
</children>
And this handler:
@Execute
public void execute(
@Named("meu.par.id") String themeId) {
logger.log(LogService.LOG_DEBUG, "starting myhandler..." + themeId);
}
It works well...
But when I try to pass another parameter in the execute method (the same as in the Contacts example), it doesn't work. The execute method is not called:
@Execute
public void execute(
@Named("meu.par.id") String themeId,
IThemeEngine engine) {
logger.log(LogService.LOG_DEBUG, "starting myhandler..." + themeId);
}
Am I missing something?
thanks for any help...
Cristiano
|
|
|
|
| Re: Command with parameters and DI ? [message #728533 is a reply to message #728386] |
Fri, 23 September 2011 08:41   |
Cristiano Gaviao Messages: 247 Registered: July 2009 |
Senior Member |
|
|
Hi Tom,
well, if you say that IThemeEngine should be in context all time, so it seems to be a bug.
But I could make it work. What I have to do was to inject IThemeManager and get IThemeEngine from it instead. It works injecting as a field and as method parameter:
@Inject
IThemeManager mgr;
@Execute
public void switchTheme(
@Named("meu.par.id") String themeId) {
System.out.println("Escolhedo o tema: " + themeId);
engine = manager.getEngineForDisplay(Display.getCurrent());
engine.setTheme(themeId, true);
}
I will file a bugzilla...
cheers
Cristiano
[Updated on: Fri, 23 September 2011 08:41] Report message to a moderator
|
|
|
|
| Re: Command with parameters and DI ? [message #728542 is a reply to message #728541] |
Fri, 23 September 2011 08:45   |
Thomas Schindl Messages: 4462 Registered: July 2009 |
Senior Member |
|
|
Hi,
Looks like IThemeEngine is not store in the root context so my
assumption was wrong.
Tom
Am 23.09.11 14:42, schrieb Tom Schindl:
> Hi,
>
> Hm ... maybe I'm wrong and IThemeEngine is not subject of injection.
>
> Tom
>
> Am 23.09.11 14:41, schrieb Cristiano avi:
>> Hi Tom,
>> HI Tom,
>> well, if you say that IThemeEngine should be in context all time, so it
>> seems to be a bug.
>> But I could make it work. What I have to do was to inject IThemeManager
>> and get IThemeEngine from it instead. It works injecting as a field and
>> as method parameter:
>>
>> @Inject
>> IThemeManager mgr;
>>
>> @Execute
>> public void switchTheme(
>> @Named("meu.par.id") String themeId) {
>>
>> System.out.println("Escolhedo o tema: " + themeId);
>> engine = manager.getEngineForDisplay(Display.getCurrent());
>>
>> engine.setTheme(themeId, true);
>>
>> }
>>
>>
>> I will file a bugzilla...
>>
>> cheers
>>
>> Cristiano
>
|
|
|
|
| Re: Command with parameters and DI ? [message #741256 is a reply to message #728632] |
Wed, 19 October 2011 06:48   |
Sir Wayne Messages: 172 Registered: July 2009 |
Senior Member |
|
|
I have the same Problem. I can't inject my own parameter:
My Handler
public class MyHandler {
@Execute
public void switchTheme(@Named("test.param.id")String param) {
System.out.println(themeId);
}
My Command
<commands xmi:id="_xkR8sPo2EeCGFcYVaQwS9g" elementId="myCommandId" commandName="myCommand">
<parameters xmi:id="_JsNMsPo8EeCGFcYVaQwS9g" elementId="test.param.id" name="test.param" optional="false"/>
</commands>
<children xsi:type="menu:HandledMenuItem" xmi:id="_VIFMYPo3EeCGFcYVaQwS9g" label="Blue Theme" command="_xkR8sPo2EeCGFcYVaQwS9g">
<parameters xmi:id="_XbYEsPo3EeCGFcYVaQwS9g" elementId="x1" name="test.param.id" value="example"/>
</children>
But nothing was executed
EDIT :
okay i need some AddOns
<addons xmi:id="_XGB3wPZlEd-XstlTZ6nTXg" elementId="org.eclipse.e4.core.commands.service" contributionURI="platform:/plugin/org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
<addons xmi:id="_XGB3wPZlEd-XstlTZ6nTXh" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="platform:/plugin/org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
<addons xmi:id="_XGB3wPZlEd-XstlTZ6nTXi" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="platform:/plugin/org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/>
<addons xmi:id="_LK0NgPZmEd-XstlTZ6nTXj" elementId="org.eclipse.e4.ui.workbench.commands.model" contributionURI="platform:/plugin/org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon"/>
<addons xmi:id="_LK0NgPZmEd-XstlTZ6nTXk" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="platform:/plugin/org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
<addons xmi:id="_LK0NgPZmEd-XstlTZ6nTXl" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributionURI="platform:/plugin/org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/>
[Updated on: Thu, 20 October 2011 03:53] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
| Re: Command with parameters and DI ? [message #989264 is a reply to message #989221] |
Wed, 05 December 2012 07:18  |
Gaetan Pitteloud Messages: 17 Registered: September 2012 |
Junior Member |
|
|
Looking through source code for the creation of parameterized commands, I notice that parameters are always converted (implicitly with a cast or explicitly with a valueConverter) into a String. Does it mean I cannot pass an arbitrary object as a parameter to a command ?
My use case consists in invoking a handler in response to a user event (list item selection). The selected item is to be passed to the @execute method of my handler, which also takes other injected parameters (like the parent shell, MApplication, EPartService). The initial solution was to use a parameterized command, with the selected item as a parameter, but it doesn't work (class cast exception). Thus the above question about TypeId. But ParameterizedCommand.generateCommand() method reads that even with TypeId (which I suppose is linked to a ParameterType object that contains a ValueConverter to convert the value into a String), I cannot implement my use case this way. Am I right ?
[Updated on: Wed, 05 December 2012 07:36] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02076 seconds