0

New to Eclipse RCP (e4), am trying to get a handler to update a UI widget within a Part.

I have tried injecting the EPartService to first access the Part by ID, like so:

public class Example {

    public static final String PART_ID = “au.org.example.app.part”;

    @Inject
    private EPartService partService;

    public void eventOccured()
    {
        MPart part = partService.findPart(PART_ID); // exception thrown here    
    }

} 

But this is throwing a NPE.

findPart() should at least safely return null if the ID were incorrect? So what am I missing?

Am also open to suggestions of relevant tutorials (have worked through some of Lars Vogella's great tutorials, but to no avail for this problem).

Any further info required please let me know.

EDIT : Looks like EPartService is not being injected? Have I not added it correctly?

danwild
  • 1,886
  • 1
  • 26
  • 31

1 Answers1

2

Injection is only done automatically on objects which are known to the Application Model - things like parts and handlers.

For objects which you create you can do injection using the ContextInjectionFactory. You can create an object with:

@Inject
IEclipseContext context;

...

MyClass myClass = ContextInjectionFactory.make(MyClass.class, context);

or you can do injection on an existing class instance with:

ContextInjectionFactory.inject(myClass, context);

in this case injection is not done on the class constructor.

There are other variants of make and inject which have a second context which allows additional values to be added to the context being injected.

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Didn't directly solve my problem (due to another issue in my project), but this does answer the underlying question of using injection outside of the application model. Thanks Greg. – danwild Jul 15 '14 at 01:28