|
|
Re: Command with parameters and DI ? [message #728533 is a reply to message #728386] |
Fri, 23 September 2011 12:41 |
Cristiano Gavião Messages: 279 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 12:41] Report message to a moderator
|
|
|
|
Re: Command with parameters and DI ? [message #728542 is a reply to message #728541] |
Fri, 23 September 2011 12:45 |
Thomas Schindl Messages: 6651 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 10:48 |
Dennis Melzer Messages: 244 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 07:53] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: Command with parameters and DI ? [message #989264 is a reply to message #989221] |
Wed, 05 December 2012 12: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 12:36] Report message to a moderator
|
|
|
Re: Command with parameters and DI ? [message #1499882 is a reply to message #989264] |
Fri, 05 December 2014 13:49 |
Kirill Zotkin Messages: 21 Registered: July 2009 |
Junior Member |
|
|
The TypeId is the id of commandParameterType extension of org.eclipse.ui.commands extension point. It is there the ParameterValueConverter can be defined. Then you can refer to parameter value in the @Named in Handler by command's parameter id.
Some sample that is discussed here https://www.eclipse.org/forums/index.php/m/1013263/.
This draft sample dynamically creates the menu using DynamicMenuContribution. It uses the ParameterizedCommand.generateCommand to setWbCommand of such dynamically created HandledMenuItem.
Its possible to implement your usecase. See NHandler and .e4xmi. It prints String passed from model as Object. Uses IEclipseContext in AbstractParameterValueConverter subclass to store the parameter value for Object-String-Object conversion.
For bugzilla: As far as I understood, there is no way to change this value without changing the model if using HandledMenuItem. I don't see the need to limit its type to String in such use case. Maybe there should be some value evaluator or something.
[Updated on: Sat, 06 December 2014 01:04] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.07957 seconds