Stand-alone Listener to EPartService [message #1714984] |
Wed, 18 November 2015 10:21 |
Hauke Fuhrmann Messages: 30 Registered: January 2015 |
Member |
|
|
Hi there,
I want to write a module (e.g. OSGi Service) that starts listening to
Part-Events of the EPartService.
My problem is to find the right pattern how to actually activate and
register my module.
In E3.x days I used the earlyStartup for such registering, even if that
was discouraged. I want to avoid that now in E4 and earlyStartup is no
E4 concept anyway.
I want to make the module independent of any specific Part, so I put it
in a separate plugin and tried to implement my custom OSGi Service for it.
However, for an OSGi-Service the lifecycle is not clear to me. I
implement a Pojo that expects the EPartService to be injected so I can
take it and register listeners to it.
I understand that someone needs to inject the Service to the Pojo and
its not done out of magic from within an OSGi Service. So I need to
implement an OSGi Component with the service
org.eclipse.e4.core.contexts.IContextFunction that will use the
ContextInjectionFactory.make method to actually instanciate my listener
and inject the EPartService to it.
@Component(service=org.eclipse.e4.core.contexts.IContextFunction.class,
property="service.context.key=test.MyListener", immediate=true)
public class TodoContextFunction extends ContextFunction {
@Override
public Object compute(IEclipseContext context, String contextKey) {
MyListener myListener = ContextInjectionFactory.make(MyListener.class,
context);
return myListener;
}
}
My problem is that the compute-Method of the context-Service is never
called and thus the MyListener never instanciated.
Cheers,
Hauke
|
|
|
Re: Stand-alone Listener to EPartService [message #1714986 is a reply to message #1714984] |
Wed, 18 November 2015 10:32 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
So is anyone requesting the MyListener? Please also note that an
IContextFunction is computing a value / requesting context and whenever
the IEclipseContext is reparented (eg when you switch between perspectives)
I also don't think an OSGi-Service is the correct way. You are better of
contributing your listener as an Addon and contribute that to through a
fragment or a processor, this is how min/max, detach, clean up is
handled in Eclipse 4.
I'm also uncertain why you need the EPartService for listening to
something because if not mistaken EPartService does not allow you to
register listeners but I'll point out that there's not one EPartService
but there are multiple ones! One per MWindow instance.
Tom
On 18.11.15 11:21, Hauke Fuhrmann wrote:
> Hi there,
>
> I want to write a module (e.g. OSGi Service) that starts listening to
> Part-Events of the EPartService.
>
> My problem is to find the right pattern how to actually activate and
> register my module.
>
> In E3.x days I used the earlyStartup for such registering, even if that
> was discouraged. I want to avoid that now in E4 and earlyStartup is no
> E4 concept anyway.
>
> I want to make the module independent of any specific Part, so I put it
> in a separate plugin and tried to implement my custom OSGi Service for it.
>
> However, for an OSGi-Service the lifecycle is not clear to me. I
> implement a Pojo that expects the EPartService to be injected so I can
> take it and register listeners to it.
> I understand that someone needs to inject the Service to the Pojo and
> its not done out of magic from within an OSGi Service. So I need to
> implement an OSGi Component with the service
> org.eclipse.e4.core.contexts.IContextFunction that will use the
> ContextInjectionFactory.make method to actually instanciate my listener
> and inject the EPartService to it.
>
> @Component(service=org.eclipse.e4.core.contexts.IContextFunction.class,
> property="service.context.key=test.MyListener", immediate=true)
> public class TodoContextFunction extends ContextFunction {
>
> @Override
> public Object compute(IEclipseContext context, String contextKey)
> {
> MyListener myListener =
> ContextInjectionFactory.make(MyListener.class, context);
> return myListener;
> }
> }
>
> My problem is that the compute-Method of the context-Service is never
> called and thus the MyListener never instanciated.
>
> Cheers,
> Hauke
|
|
|
Powered by
FUDForum. Page generated in 0.03453 seconds