Hints on using JFace Wizard with Dependency Injection? [message #1050147] |
Fri, 26 April 2013 15:34  |
Eclipse User |
|
|
|
Hi Community,
I'm trying to inject an OSGi-Service into a JFace Wizard (and WizardPage). My service is started and active and working fine. I know that the JFace Wizards don't get created by the Application model, so I already figured out that I need to use the ContextInjectionFactory.
What I've done so far:
One wizard class that needs OSGi-Services in the performFinish method AND in one of the pages (see constructor).
public class GiveFeedbackWizard extends Wizard implements MyWizard{
private Feedback feedback;
@Inject
DatabaseAccessService dbservice;
@Inject
CustomerService custService;
@Inject
@Named(IServiceConstants.ACTIVE_SHELL) Shell shell;
public GiveFeedbackWizard(){
feedback = TICDModelFactory.eINSTANCE.createFeedback();
setWindowTitle("Customer Feedback");
// I know the following doesn't work as the fields haven't been injected yet
addPage(new FeedbackFirstWizardPage(feedback, dbservice));
addPage(new FeedbackRatingWizardPage(feedback));
addPage(new FeedbackTextWizardPage(feedback));
}
@Override
public boolean performFinish() {
System.out.println(feedback);
Customer activeCustomer = custService.getActiveCustomer();
activeCustomer.getFeedbacks().add(feedback);
dbservice.saveCustomer(activeCustomer);
return true;
}
}
Can I use the CIF to create the WizardPage as well?
The OSGi-Service that creates my Wizards:
public void createWizard(WizardTypes type) {
IEclipseContext ctx = EclipseContextFactory.getServiceContext(Activator.getContext());
switch(type){
case CUSTOMER:
wizard = ContextInjectionFactory.make(CreateCustomerWizard.class, ctx);
// wizard.setDBAccessService(dbservice);
// wizard.setCustomerService(custService);
break;
case BOOKING:
// TODO create and return BookingWizard
wizard = null;
break;
case FEEDBACK:
// TODO create and return FeedbackWizard
wizard = ContextInjectionFactory.make(GiveFeedbackWizard.class, ctx);
// wizard.setDBAccessService(dbservice);
// wizard.setCustomerService(custService);
break;
default:
wizard = null;
break;
}
}
The setter methods show the way I did it before, but I had NullPointerExceptions.
Is my approach in general correct?
I ended up with a
org.eclipse.e4.core.di.InjectionException: Unable to process "GiveFeedbackWizard.shell": no actual value was found for the argument "Shell[@javax.inject.Named(value=activeShell)]". in my last try although the Injection of the Shell worked before (when I still used the setter methods). Any hints on that?
Thanks in advance.
Marina
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04331 seconds