で新しいタブ/パーツを追加します。のEclipse RCP 4は、私は、このコードとして新しいタブ/パーツを追加することができ、通常のコマンドハンドラではIEventBrokerのhandleEvent
@Execute
public void execute(Shell shell, EPartService partService, MApplication application,EModelService modelService) throws URISyntaxException{
MPart part = MBasicFactory.INSTANCE.createPart();
part.setLabel("New file ");
part.setCloseable(true);
part.setContributionURI("bundleclass://com.xxx.rcp.app.item_editor/com.xxx.rcp.app.item_editor.parts.ItemEditorPart");
List<MPartStack> stacks = modelService.findElements(application, "com.xxx.rcp.app.partstack.2", MPartStack.class, null);
stacks.get(0).getChildren().add(part);
partService.showPart(part, PartState.ACTIVATE);
}
今、私は新しいタブ/パーツを追加したいです1つのIEventBroker handleEventです。
まず、私はアクティベーターで話題を登録します。
@Override
public void start(BundleContext context) throws Exception {
IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(context);
IEventBroker eventBroker = serviceContext.get(IEventBroker.class);
eventBroker.subscribe("MY_TOPIC", ContextInjectionFactory.make(OpenItemEditorHandler2.class, serviceContext));
}
その後、私はのhandleEventのタブ/パーツを追加します。
public class OpenItemEditorHandler2 implements EventHandler {
// @Inject
// private IEclipseContext serviceContext;
// @Inject
// EPartService partService;
// @Inject
// MApplication application;
@Inject
IEclipseContext serviceContext;
// @Inject
// EModelService modelService;
// @Inject
// private ECommandService commandService;
//
// @Inject
// private EHandlerService handlerService;
@Override
public void handleEvent(Event event) {
MPart part = MBasicFactory.INSTANCE.createPart();
part.setLabel("New file ");
part.setCloseable(true);
part.setContributionURI("bundleclass://com.xxx.rcp.app.item_editor/com.xxx.rcp.app.item_editor.parts.ItemEditorPart");
// get the part stack and show created part
EModelService modelService = serviceContext.get(EModelService.class);
MApplication application = serviceContext.get(MApplication.class);
List<MPartStack> stacks = modelService.findElements(application, "com.xxx.rcp.app.partstack.2", MPartStack.class, null);
}
私はすべてのためにヌルでそれらのサービスにアクセスしたり、注入することはできません。どうして?私はオブジェクトOpenItemEditorHandler2
をActivator
に注射しました。
または、新しいタブ/パートを追加するための他の解決策についてのヒントを教えてください。
ありがとうございました!
私は、アプリケーションモデルに新しいアドオンを追加しました。バンドルクラスでは、 'Activator'のようにコードを追加しました。しかし、 'handleEvent'は呼び出されませんでした。 'LifeCycle'については、これらのコードは別のRCPアプリのプラグインにあります。 'LifeCycle'を追加するには?ありがとう! – aviit
メインのRCPプラグインでのみLifeCycleを使用できます。 AddOnのコードは、 'EclipseContextFactory.getServiceContext'を使用していない** IEclipseContextを直接注入するべきです。更新された回答を参照 –
ありがとう、greg!コードが機能しました。しかし、問題があります。「MyAddon」では、これらのサービスをメソッド/コンストラクタに注入するだけで、フィールドに注入することができます。 – aviit