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 でアノテーションが付けられたメソッドにこのコードを入れることはできません。これに対する解決策を提案できますか?
================ グレッグが提案した解決策に従って、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 を注入できません。