| Inject Part - What did I miss? [message #1005611] |
Sun, 27 January 2013 09:04  |
Kirsten M. Z. Messages: 106 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!
|
|
|