Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Stand-alone Listener to EPartService
Stand-alone Listener to EPartService [message #1714984] Wed, 18 November 2015 10:21 Go to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
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 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
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
Previous Topic:Extending default E4 application with a custom editor
Next Topic:@PostConstruct not executed in 4.5.1
Goto Forum:
  


Current Time: Fri Apr 26 17:51:24 GMT 2024

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

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

Back to the top