Home » Eclipse Projects » Eclipse 4 » Inject Part - What did I miss?
Inject Part - What did I miss? [message #1005611] |
Sun, 27 January 2013 14:04 |
Kirsten M. Z. Messages: 132 Registered: July 2010 |
Senior Member |
|
|
Injection can be really neat, but if something doesn't work, you have no idea
Injection works for almost all stuff I tried, but not for (visible) parts. Create a new e4 Project and modify the AboutHandler:
public class AboutHandler {
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, @Active AppPart a) {
MessageDialog.openInformation(shell, "About", "e4 Application example.");
}
@CanExecute
public boolean canExecute(MApplication app, EModelService service, @Optional AppPart appPartInjected) {
PartImpl element = (PartImpl) service.find("myapp.part.0", app);
AppPart appPart = (AppPart) element.getObject();
return true;
}
}
"appPartInjected" is always null. I also tried @Named("myapp.part.0") or @Active, but null. If I don't use @Optional, the method is not called, of course.
I worked through several tutorials (maybe a little bit too fast?), but could not find any hint, that injection of parts does not work that easily. Instead I found the code I am using within "canExecute". This code also works and I get my part, so the part is available! And should be active, right? It is the only part I am using, and it is also visible at startup? However, why is injection not working in that case?
BTW: AppPart is just a regular part. I haven't specified anything special, e.g. @Singleton... but I tried of course. I also tried @Creatable, but this is not the correct effect
Thanks in advance!
|
|
| | | | |
Re: Inject Part - What did I miss? [message #1005664 is a reply to message #1005611] |
Mon, 28 January 2013 07:22 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
AppPart is never put to a context! You can only get MPart the model
instance, from there you can the real instance using MPart#getObject()!
You don't need the @Active because a handler is always run with the
currently active context.
Tom
Am 27.01.13 15:04, schrieb Kirsten M. Z.:
> Injection can be really neat, but if something doesn't work, you have no
> idea :(
>
> Injection works for almost all stuff I tried, but not for (visible)
> parts. Create a new e4 Project and modify the AboutHandler:
>
>
> public class AboutHandler {
>
> @Execute
> public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell
> shell, @Active AppPart a) {
> MessageDialog.openInformation(shell, "About", "e4 Application
> example.");
> }
>
> @CanExecute
> public boolean canExecute(MApplication app, EModelService service,
> @Optional AppPart appPartInjected) {
> PartImpl element = (PartImpl) service.find("myapp.part.0", app);
> AppPart appPart = (AppPart) element.getObject();
> return true;
> }
> }
>
> "appPartInjected" is always null. I also tried @Named("myapp.part.0") or
> @Active, but null. If I don't use @Optional, the method is not called,
> of course.
>
> I worked through several tutorials (maybe a little bit too fast?), but
> could not find any hint, that injection of parts does not work that
> easily. Instead I found the code I am using within "canExecute". This
> code also works and I get my part, so the part is available! And should
> be active, right? It is the only part I am using, and it is also visible
> at startup? However, why is injection not working in that case?
>
> BTW: AppPart is just a regular part. I haven't specified anything
> special, e.g. @Singleton... but I tried of course. I also tried
> @Creatable, but this is not the correct effect ;)
>
> Thanks in advance!
|
|
|
Goto Forum:
Current Time: Fri Mar 29 05:34:01 GMT 2024
Powered by FUDForum. Page generated in 0.02615 seconds
|