如何访问兼容性层IViewPart的(e4)MPart

如何访问兼容性层IViewPart的(e4)MPart

问题描述:

我正在将现有的Eclipse插件移植到e4.我想从未移植的 IViewPart 内部访问视图的相应e4 MPart ,但无法可靠地执行以下操作:

I am porting an existing Eclipse plug-in to e4. From within a non-ported IViewPart I would like to access the view’s corresponding e4 MPart but couldn’t get the following to work reliably:

EPartService partService = (EPartService) PlatformUI.getWorkbench().getService(EPartService.class);
MPart part = partService.findPart(getSite().getId());

放置在 createPartControlComposite)中有时我会收到 IllegalStateException (应用程序没有活动的窗口").

Placed in createPartControlComposite) I sometimes get an IllegalStateException ("Application does not have an active window").

避免从工作台使用零件服务,因为只有在有活动窗口的情况下,此服务才起作用.

Avoid using the part service from the workbench as this only works when there is an active window.

请对当前窗口(可能未激活)使用零件服务.您可以使用以下方法在IViewPart中获取它:

Instead use the part service for the current window (which might not be active). You can get this in the IViewPart using:

EPartService partService = getSite().getService(EPartService.class);

MPart part = partService.findPart(getSite().getId());