如何访问兼容性层IViewPart的(e4)MPart [英] How to access an compatibility layer IViewPart’s (e4) MPart

查看:68
本文介绍了如何访问兼容性层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());

这篇关于如何访问兼容性层IViewPart的(e4)MPart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆