我有带有GUI(JavaFX(的RCP E4应用程序。它还包含几个没有 GUI 的 IApplication 实例。问题是,有一些 DS 服务会自动运行,我想检测哪个应用程序(IApplication/产品 ID(从这些 DS 服务中启动。这可能吗,我能得到什么信息?
该IApplicationContext
包含许多方法来告诉您它所谓的"品牌应用"。
getBrandingApplication
为您提供正在运行的应用程序的 ID(例如,对于 e4,始终是 org.eclipse.e4.ui.workbench.swt.E4Application'(。
getBrandingId
是产品 ID。
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
(