如何在Eclipse e4应用程序中获取视图部件实例?

时间:2012-05-11 15:19:00

标签: eclipse

我正在尝试在Eclipse e4应用程序中获取视图部件的实例,但我找不到PlatformUI类。自Eclipse 3以来名称是否已更改,或者它位于不同的包中?

2 个答案:

答案 0 :(得分:10)

查看Eclipse e4 Parts

e4 parts

371405这样的错误可能很有启发性:

org.eclipse.ui.presentations

  

此API不再适用于4.2,我们从不打算使其正常工作   它与4.2中的可插入渲染故事不兼容。可以由演示文稿扩展程序做出的决定现在取决于渲染器。

     

需要弃用的受影响的API:

     
      
  • 整个API包:org.eclipse.ui.presentations
  •   
  • 扩展点:org.eclipse.ui.presentationFactories
  •   
    org.eclipse.ui.IWorkbenchPreferenceConstants#PRESENTATION_FACTORY_ID
    org.eclipse.ui.IWorkbenchWindowConfigurer#getPresentationFactory
    org.eclipse.ui.IWorkbenchWindowConfigurer#setPresentationFactory

教程的其余部分解释了如何声明“部分”(编辑或视图)


OP August Karlstrom提及:

  

这曾经有用:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("‌​some view");

使用像PlatformUI这样的单例是一种不好的做法,也是e4中引入 Context 的原因之一。见presentation on Context


Paul Webster(IBM Eclipse Platform团队成员)评论:

  

在Eclipse4中,您可以使用org.eclipse.e4.ui.workbench.modeling.EPartService.findPart(String)按ID查找MPart   MPart在其object属性中包含注入的部分。

正如页面Workbench_Services详细信息:

  

在e4中,工作台页面的概念将不存在    part service API 基本上是现有3.x IPartServiceWorkbenchPage接口的合并。


请注意,这并不理想,因为bug 372488说明了(this thread之后):

  

使用MPart创建MPartDescriptor的{​​{1}},其中descriptor_id是EPartService.createPart(descriptor_id)的标识符。
  如果只有一个,可以使用MPartDescriptor - 再次找到此部分。

     

问题是,可能需要为一个EPartService.findPart(descriptor_id)创建多个MPart
  编辑器可能是一个例子:人们可能想要编辑同一种类的不同实例。

     

可以为给定的MPartDescriptor创建多个MPart,但没有方便的方法来查找这些部分。
  MPartDescriptor会返回为特定EPartService.findPart(descriptor_id)创建的第一个MPart,即使有多个MPartDescriptor。   因此对于给定的MPartDescriptor有三个问题:

     
      
  1. EPartService.findPart(id)并未说明有多个MPart
  2.   
  3. 没有方便的方法来获取此描述符的所有MParts
  4.   
  5. 没有API方式来获取给定描述符和“content”或“reference”的特定MPart
  6.         

    目前的方法是使用EPartService.getParts(),遗憾的是   返回所有MPart s,而不仅仅是与一个特定对应的那些MPartDescriptor   MPart
      然后,我们需要检查具有特定“内容”的特定MPartDescriptor是否有一个MPart

         

    所以缺少一些可以找到给定MPartDescriptor {{1}}的内容   特别是“内容”或“参考”。

答案 1 :(得分:5)

只是有同样的问题。找到这个帖子并尝试:

MPart mPart = epartService.findPart("MyPart");

MyPart myPart = (MyPart)mPart.getObject();

然后我得到了我的观点。