如何在 E4 中使用 Eclipse 3.x 视图?

How to use Eclipse 3.x views in E4?

我有 Eclipse 3.x 开发经验,现在想开发 E4 应用程序。因此,我测试了一个简单的示例,以便开始使用新事物。

我是按照 this tutorial 一步一步来的,但它导致了同样的错误。但是,他没有收到这些错误。

我正在使用 Eclipse Luna (4.4.2) 并安装了 E4 Tools (0.17)。 我创建了一个新的 Eclipse 4 应用程序,并使用 Import 3x -> View as CompatibilityView 添加到 Application.e4xmi Common Resource Navigator (Project Explorer) 作为 Shared Part。然后我添加了一个 Placeholder 来引用共享部分。我已将所有必要的插件添加到产品的依赖项中。我还添加了兼容性插件。

但是,当我启动应用程序时,我在 InjectorImpl#internalMake()#331 处得到一个 InjectionException,它只是:

if (unresolved(actualArgs) != -1) continue;

调试unresolved()让我到以下几点(InjectorImpl#489):

Creatable creatableAnnotation = desiredClass.getAnnotation(Creatable.class);

其中 desiredClass 是 class org.eclipse.ui.internal.ViewReference。 然后函数 returns 1 导致继续大写和异常。堆栈跟踪如下 (full here):

!ENTRY org.eclipse.e4.ui.workbench 4 0 2015-05-06 13:00:05.899
!MESSAGE Unable to create class 'org.eclipse.ui.internal.e4.compatibility.CompatibilityView' from bundle '96'
!STACK 0
org.eclipse.e4.core.di.InjectionException: Could not find satisfiable constructor in org.eclipse.ui.internal.e4.compatibility.CompatibilityView
    at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:346)
    at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:258)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
...

为了解决这个问题,我不得不遵循this awesome tutorial。正如 @greg-449 已经提到的,您必须使用 3.x RCP 并在其上放置一个 e4 aware 产品。然后将初始化兼容层。因此,您必须执行以下操作(教程中有详细说明):

  1. 创建一个适用于 Eclipse 3.5 或更高版本
  2. 的 Ecliplse 插件
  3. 勾选将为UI
  4. 做出贡献
  5. 使用 Hello World RCP 生成所需的扩展点
  6. Ctrl+N -> Eclipse 4 -> 模型 -> 新建应用程序模型
  7. 添加扩展点
  8. Ctrl+N -> 插件开发 -> 产品配置

其余内容在链接教程中进行了描述。不要不要忘记将-clearPersistedState添加到产品的启动选项中。所以你会看到你的应用程序模型的增量。如果您打算使用基于功能的产品,您应该创建一个功能插件,它引用您的 RCP 插件并将其添加为产品的依赖项。因此,您不必按照教程中的说明更改 运行 配置。

根据我到今天为止的搜索,您不能在纯 e4 应用程序 (org.eclipse.e4.ui.workbench.swt.E4Application) 中使用现有的 Eclipse UI 插件,如 org.eclipse.debug.uiorg.eclipse.ui.console 等.因此,如果您需要使用现有的 UI 组件,您必须创建一个 3.x 应用程序(实现 IApplication、引用 ApplicationWorkbenchAdvisorPlatformUI 等)。所以从今天开始,如果你想使用现有的 UI 插件,你必须创建一个 3.x RCP,它在兼容层上运行新的 4.x 运行时。这很简单,但几乎没有在任何地方写清楚,我不得不花一些时间来弄清楚。令人沮丧的 Eclipse RCP 介绍。