Eclipse 在e3应用程序中获取e4应用程序模型
我正在考虑在基于Eclipse3.x的大型应用程序中开始使用EclipseRCPE4工具。因此,我没有e4xmi文件 应用程序模型确实存在于兼容层之下,但很难从代码中获得它(请注意,您可以使用依赖项注入获得一切,但只有在说服框架开始为您创建对象之后) 以下是我能找到的获取模型的唯一方法:Eclipse 在e3应用程序中获取e4应用程序模型,eclipse,rcp,e4,Eclipse,Rcp,E4,我正在考虑在基于Eclipse3.x的大型应用程序中开始使用EclipseRCPE4工具。因此,我没有e4xmi文件 应用程序模型确实存在于兼容层之下,但很难从代码中获得它(请注意,您可以使用依赖项注入获得一切,但只有在说服框架开始为您创建对象之后) 以下是我能找到的获取模型的唯一方法: PartSite ps = (PartSite)PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage
PartSite ps = (PartSite)PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getActivePart().getSite();
IEclipseContext iec = ps.getContext();
MApplication ma = iec.get(MApplication.class);
暂时忽略PartSite是内部API这一事实,是否有更简单的方法来获取模型?为什么这么难找到?要想做你想做的事,你可以使用这个片段
IWorkbench workbench = getService(IWorkbench.class, IWorkbench.class);
MApplication mApplication = workbench.getApplication();
EModelService modelService = mApplication.getContext().get(EModelService.class);
这就是我从OSGi获得服务的方式
private <T> T getService(Class<T> pClass, Class pContextClass) {
BundleContext context = FrameworkUtil.getBundle(pContextClass).getBundleContext();
ServiceReference<T> reference = context.getServiceReference(pClass);
if(reference == null){
return null;}
T service = context.getService(reference);
return service;
}
希望这有帮助
Wim您可以使用修剪过的窗口
MTrimmedWindow trimmedWindow = modelService.createModelElement(MTrimmedWindow.class);
trimmedWindow.setX(100);
trimmedWindow.setY(50);
trimmedWindow.setWidth(100);
trimmedWindow.setHeight(50);
window.setLabel("Hello");
window.setVisible(true);
mApplication.getChildren().add(window);
如果使用MWindow
,则可能会出现异常
org.eclipse.e4.core.di.InjectionException:无法处理“WorkbenchWindow.model”
在这种情况下,您需要使用
MTrimmedWindow
很难找到它,因为它并非真正用于3.x样式的应用程序。OK。我意识到我所做的是违反规则的,但是有一些文章讨论了软迁移。显然,从3.x应用程序的深层次开始使用e4设施并不是一种愉快的体验。感谢您的帮助。本月即将发布的Eclipse Luna允许您将e4样式的视图添加到3.x样式的应用程序中-它可以工作-我得到了一个小窗口-但我仍然得到一个异常org.Eclipse.e4.core.di.InjectionException:无法处理“WorkbenchWindow.model”:未找到参数“MTrimmedWindow”的实际值。我发现很难理解幕后发生了什么,但我觉得我在违反一些规则。
MTrimmedWindow trimmedWindow = modelService.createModelElement(MTrimmedWindow.class);
trimmedWindow.setX(100);
trimmedWindow.setY(50);
trimmedWindow.setWidth(100);
trimmedWindow.setHeight(50);
window.setLabel("Hello");
window.setVisible(true);
mApplication.getChildren().add(window);