osgieclipse-rcpequinoxefxclipse

Detecting running Equinox IApplication ID


I have RCP E4 Application with GUI (JavaFX). It also contains several IApplication instances without GUI. The problem that, there are some DS services that run automatically, I want to detect which application (IApplication/product ID) started from within those DS services. Is that possible and what information I can get?


Solution

  • The IApplicationContext contains a number of methods to tell you about what it calls the 'Branding App'.

    getBrandingApplication gives you the id of the running application (always org.eclipse.e4.ui.workbench.swt.E4Application` for e4 for example).

    getBrandingId is the product id.

    getBrandingName is the name specified for the product.

    In an e4 app you can just inject IApplicationContext. IApplication apps are given the cpntext as a parameter to the start method. It can also be found by searching the OSGi services:

    IApplicationContext getApplicationContext(BundleContext context) {
        Collection<ServiceReference<IApplicationContext>> references;
        try {
            references = context.getServiceReferences(IApplicationContext.class, "(eclipse.application.type=main.thread)"); 
        } catch (InvalidSyntaxException e) {
            return null;
        }
        if (references == null || references.isEmpty())
            return null;
        // assumes the application context is available as a service
        ServiceReference<IApplicationContext> firstRef = references.iterator().next();
        IApplicationContext result = context.getService(firstRef);
        if (result != null) {
            context.ungetService(firstRef);
            return result;
        }
        return null;
    }
    

    (above code adapted from org.eclipse.core.internal.runtimeInternalPlatform)