我正在创建 Eclipse RCP 4.x 应用程序。应用由多个视角组成。我想根据某些条件以编程方式打开默认透视图。下面的代码能够加载透视图。
@Execute
public void execute(MApplication app, EPartService partService,
EModelService modelService) {
MPerspective element =
(MPerspective) modelService.find("com.sanyotechnologyindia.desktop.app.perspective.enduser", app);
// now switch perspective
partService.switchPerspective(element);
}
但是我不能把这段代码放在用@PostContextCreate 注释的方法中。你能为此提出任何解决方案吗?
================ 根据 Greg 建议的解决方案,我在 Application Lifecycle 类中尝试了以下代码。
@ProcessAdditions
void processAdditions(MApplication app, EPartService partService,
EModelService modelService){
MPerspective element =
(MPerspective) modelService.find("com.sanyotechnologyindia.desktop.app.perspective.usermanagement", app);
// now switch perspective
partService.switchPerspective(element);
}
现在我在 partService.switchPerspective(element); 行收到以下错误
java.lang.IllegalStateException:应用程序没有活动窗口
================更新:================== 添加 org.eclipse.osgi.services 插件到依赖项。
@PostContextCreate
public void postContextContext(IEventBroker eventBroker)
{
eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE,
new AppStartupCompleteEventHandler());
}
private class AppStartupCompleteEventHandler implements EventHandler
{
@Inject private MApplication app;
@Inject private EPartService partService;
@Inject private EModelService modelService;
@Override
public void handleEvent(Event arg0) {
MPerspective element =
(MPerspective) modelService.find("com.sanyotechnologyindia.desktop.app.perspective.usermanagement", app);
partService.switchPerspective(element);
}
}
但是现在框架无法在 AppStartupCompleteEventHandler 实例中注入 MApplication、EPartService 和 EModelService。