检测 运行 Equinox IApplication ID
Detecting running Equinox IApplication ID
我有带有 GUI (JavaFX) 的 RCP E4 应用程序。它还包含几个没有 GUI 的 IApplication 实例。问题是,有些 DS 服务会自动 运行,我想检测从这些 DS 服务中启动的应用程序(IApplication/product ID)。这可能吗?我可以获得哪些信息?
IApplicationContext
包含许多方法来告诉您它所谓的 'Branding App'。
getBrandingApplication
为您提供 运行 应用程序的 ID(例如,对于 e4 总是 org.eclipse.e4.ui.workbench.swt.E4Application`)。
getBrandingId
是产品编号。
getBrandingName
是为产品指定的名称。
在 e4 应用程序中,您只需注入 IApplicationContext
。 IApplication
应用程序将 cpntext 作为启动方法的参数。也可以通过搜索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
)
我有带有 GUI (JavaFX) 的 RCP E4 应用程序。它还包含几个没有 GUI 的 IApplication 实例。问题是,有些 DS 服务会自动 运行,我想检测从这些 DS 服务中启动的应用程序(IApplication/product ID)。这可能吗?我可以获得哪些信息?
IApplicationContext
包含许多方法来告诉您它所谓的 'Branding App'。
getBrandingApplication
为您提供 运行 应用程序的 ID(例如,对于 e4 总是 org.eclipse.e4.ui.workbench.swt.E4Application`)。
getBrandingId
是产品编号。
getBrandingName
是为产品指定的名称。
在 e4 应用程序中,您只需注入 IApplicationContext
。 IApplication
应用程序将 cpntext 作为启动方法的参数。也可以通过搜索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
)