视图不显示

View does not displayed

我制作了 Hello World RCP 应用程序并获得了以下 class 结构:

ApplicationActionBarAdvisor.java 
ApplicationWorkbenchAdvisor.java
ApplicationWorkbenchWindowAdvisor.java
Application.java
Perspective.java

此外,我尝试向透视图添加一些视图。

将扩展点添加到我的 plugin.xml:

<extension point="org.eclipse.ui.views">
  <view
     class="first.rcp.application.MainView"
     id="first.rcp.application.MainView"
     name="name"
     restorable="true">
  </view>
</extension>

并创建了 class MainView.java.

向 Perspective.createInitialLayout() 添加附加代码:

layout.addStandaloneView(MainView.ID, true, IPageLayout.LEFT, 1.0f, layout.getEditorArea());
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
try {
   activePage.showView(MainView.ID);
} catch (PartInitException e) {
   e.printStackTrace();
}

但是视图没有显示。

我在Perspective.createInitialLayout()中设置了断点,发现没有执行

我尝试将 showPerspective() 方法添加到 ApplicationWorkbenchWindowAdvisor() 并将 ApplicationWorkbenchAdvisor 中的 PERSPECTIVE_ID 设置为我的视角 ID。

但是进入 Perspective.createInitialLayout() 的代码仍然没有执行。

应该从哪个点调用?

Eclipse IDE 具有 Java 透视图,默认打开的视图数。 IE。 Java 透视图的 createInitialLayout() 在 eclipse IDE 启动期间被调用。它是如何实施的?可能有一些配置文件?

我的观点宣言是:

<extension point="org.eclipse.ui.perspectives">
  <perspective 
      name="RCP Perspective"
      class="first.rcp.application.Perspective"
      id="first.rcp.application.Perspective">
  </perspective>
</extension>

ApplicationWorkbenchAdvisor.getInitialWindowPerspectiveId()中的代码是:

public String getInitialWindowPerspectiveId() {
   return PERSPECTIVE_ID;
}

private static final String PERSPECTIVE_ID = "first.rcp.application.Perspective";

解决方案 №1.

  1. 通过新建插件项目向导,确保 'would you like to create a rich client application' 设置为是,确保 'Generate an activator, a Java class that controls the plug-in lifecycle' 是在“可用模板”页面上检查并 select 'Hello RCP'。

  2. 转到 MANIFEST.MF,扩展。添加新扩展 'org.eclipse.ui.views',添加适当的 class.

  3. 在视图中添加新扩展 'org.eclipse.ui.perspectiveExtensions'。将view id指定为之前创建的view的id。

解决方案 №2.

通过新建插件项目向导,确保 'would you like to create a rich client application' 设置为是,确保选中 'Generate an activator, a Java class that controls the plug-in lifecycle' 并且 select 'RCP application with a view' 在可用模板页面。