Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Hints on using JFace Wizard with Dependency Injection?
Hints on using JFace Wizard with Dependency Injection? [message #1050147] Fri, 26 April 2013 19:34 Go to next message
Marina Knieling is currently offline Marina KnielingFriend
Messages: 83
Registered: February 2013
Member
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
Re: Hints on using JFace Wizard with Dependency Injection? [message #1050212 is a reply to message #1050147] Fri, 26 April 2013 21:53 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hi Marina

There is no Shell in the context on the OSGi layer, only OSGi services. Does your wizard get opened by a handler? If yes, then you should use the IEclipseContext that gets injected into your @Execute method.

You can create instances of any class with CIF. That includes wizard pages.

Hope that helps!

Greetings
Christoph



Re: Hints on using JFace Wizard with Dependency Injection? [message #1050627 is a reply to message #1050212] Sat, 27 April 2013 13:37 Go to previous message
Marina Knieling is currently offline Marina KnielingFriend
Messages: 83
Registered: February 2013
Member
Hi Christoph,

yes my wizard gets opened by a handler. Changes my code and works fine. I even managed to inject my Feedback object by inserting it into a child context before. Thanks for your help.

[Updated on: Sat, 27 April 2013 13:38]

Report message to a moderator

Previous Topic:Restart Application
Next Topic:Weird behaviour with Deletey Key
Goto Forum:
  


Current Time: Tue Mar 19 10:21:11 GMT 2024

Powered by FUDForum. Page generated in 0.02182 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top