Command with parameters and DI ? [message #728308] |
Thu, 22 September 2011 19:26  |
Eclipse User |
|
|
|
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 #728542 is a reply to message #728541] |
Fri, 23 September 2011 08:45   |
Eclipse User |
|
|
|
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 #1499882 is a reply to message #989264] |
Fri, 05 December 2014 08:49  |
Eclipse User |
|
|
|
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: Fri, 05 December 2014 20:04] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.10597 seconds