首页 > 解决方案 > 检测正在运行的 Equinox IApplication ID

问题描述

我有带有 GUI (JavaFX) 的 RCP E4 应用程序。它还包含几个没有 GUI 的 IApplication 实例。问题是,有一些自动运行的 DS 服务,我想检测从这些 DS 服务中启动的应用程序(IApplication/产品 ID)。这可能吗?我能得到什么信息?

标签: osgieclipse-rcpequinoxefxclipse

解决方案


IApplicationContext包含许多方法来告诉您它所谓的“品牌应用程序” 。

getBrandingApplication为您提供正在运行的应用程序的 ID(例如,对于 e4,总是 org.eclipse.e4.ui.workbench.swt.E4Application`)。

getBrandingId是产品编号。

getBrandingName是为产品指定的名称。

在 e4 应用程序中,您只需注入IApplicationContext. IApplication应用程序被赋予 cpntext 作为 start 方法的参数。也可以通过搜索 OSGi 服务找到:

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;
}

(以上代码改编自org.eclipse.core.internal.runtimeInternalPlatform


推荐阅读