|
Re: Eclipse 4 RCP getting parts via EPartService [message #989931 is a reply to message #989891] |
Mon, 10 December 2012 07:05   |
|
The problem is @Inject private EPartService service; is not injected .
Why..? Because you are creating object of your SelectComposite2 class so its your responsibility to inject all necessary injection to your class. Like following.
SelectComposite2 cim = new SelectComposite2();
ContextInjectionFactory.inject(cim,iEclipseContext);
Where iEclipseContext is IEclipseContext variable. IEclipseContext automatically inject when eclipse framework will create your object . Like in case of handler.
But if you are creating your object then its your responsibility to inject it.
[Updated on: Mon, 10 December 2012 07:06] Report message to a moderator
|
|
|
Re: Eclipse 4 RCP getting parts via EPartService [message #990002 is a reply to message #989931] |
Mon, 10 December 2012 12:23   |
Daniel Stingl Messages: 11 Registered: November 2012 |
Junior Member |
|
|
Thx for your reply. Is it possible to use injection similar in Listeners as in Handlers (it didnt work when I tried it but I wouldnt be that surprised if I messed that up..)?
Otherwise, how can i get my hands on an instance of IEclipseContext? Rly tried to figure that out myselve, but no matter how many sites I browse, it seems that this is only used with injection...
[Updated on: Mon, 10 December 2012 15:02] Report message to a moderator
|
|
|
Re: Eclipse 4 RCP getting parts via EPartService [message #990374 is a reply to message #990002] |
Wed, 12 December 2012 08:35   |
|
No. In case of listeners you have to do it your self. take a look of following code . you can get your EPartService like following in your class.
Bundle bundle = FrameworkUtil.getBundle(EPartService.class);
BundleContext bundleContext = bundle.getBundleContext();
IEclipseContext eclipseCtx =
EclipseContextFactory.getServiceContext(bundleContext);
EPartService partService = (EPartService) eclipseCtx.get(EPartService.class.getName());
[Updated on: Wed, 12 December 2012 08:36] Report message to a moderator
|
|
|
|
|
Re: Eclipse 4 RCP getting parts via EPartService [message #990955 is a reply to message #990552] |
Sat, 15 December 2012 11:39   |
Eclipse User |
|
|
|
Just to elaborate on Sumit's answer -- you need to obtain a context from somewhere. Sumit's code uses the top-level OSGi context, which works in this case as the EPartService is effectively a singleton registered as an OSGi service. But you'll find that this won't work for other services as they will be registered at other points in the context tree. Generally you should do lookups from the closest context that you can find, and many of the UI classes carry a context (see the subclasses of MContext). In Eclipse 3.x compat layer, you can obtain the IEC for a part using:
getSite().getService(IEclipseContext.class);
Brian.
|
|
|
|
Powered by
FUDForum. Page generated in 0.02314 seconds