Search code examples
eclipse-rcprcpe4

How to get/inject EPartService outside part or in LifeCycle Manager or How to control life cycle of e4 RCP app in true sense?


My application consists of many parts and they are defined in application's e4xmi file. I want to hide and show them dynamically. I am using EpartService to do so in handlers, where I can inject it.

But I also want to control the show/hide of parts with something like life cycle manager, where I can not inject EPartService. Is there any way to achieve and fully control RCP application's life cycle?

There seems the exact same question here and void of solution: https://www.eclipse.org/forums/index.php/t/595958/

I want to implement 'remember me like feature' where part having sign in screen is shown instead of other parts. Also after log out same sign-in part is to be shown. So I need to control life cycle of RCP app. But I cant inject EPartService before anything in Application's e4xmi is initiated.


Solution

  • If you are creating a class from something which is injected (such as the LifeCycle class) you can create your class with injection using ContextInjectionFactory:

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

    Or if you just pass an IEclipseContext to the class you can get the part service using:

    EPartService partService = context.get(EPartService.class);
    

    Note: There is a separate instance of the part service for each part. Depending on what you are doing you may need to make sure you have the service for the active part.