首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> Java 程式設計 >> Java 相關知識

Eclipse Perspective 透視圖兩種定義與佈局方法:程式碼 vs plugin.xml

     編輯:Java 相關知識

方法一:程式碼實作 IPerspectiveFactory

  1. 在 plugin.xml 擴充 org.eclipse.ui.perspectives,指定實作類別(如 com.test.blog.core.ui.perspective.Perspective)。
  2. 實作類別實作 IPerspectiveFactory,覆寫 createInitialLayout(IPageLayout layout):
public void createInitialLayout(IPageLayout layout) {
  layout.setEditorAreaVisible(false);
  String editorArea = layout.getEditorArea();
  layout.addView(JobInformationView.ID, IPageLayout.LEFT, 0.45f, editorArea);
  layout.addView(DetailLogsView.ID, IPageLayout.BOTTOM, 0.4f, editorArea);
  String folderId = "position.statlog";
  IFolderLayout bottomFolder = layout.createFolder(folderId, IPageLayout.BOTTOM, 0.5f, JobInformationView.ID);
  bottomFolder.addView(SimpleStatsView.ID);
  bottomFolder.addView(DetailStatsView.ID);
  // 設定不可關閉
  layout.getViewLayout(JobInformationView.ID).setCloseable(false);
  layout.getViewLayout(SimpleStatsView.ID).setCloseable(false);
  layout.getViewLayout(DetailStatsView.ID).setCloseable(false);
}

方法二:plugin.xml 宣式式擴充 org.eclipse.ui.perspectiveExtensions

無需修改 Java 類別,直接在 plugin.xml 定義:

<extension point="org.eclipse.ui.perspectiveExtensions">
  <perspectiveExtension targetID="com.test.blog.core.ui.perspective.Perspective">
    <view id="com.test.blog.core.ui.views.jobinfo.JobInformationView"
          relative="org.eclipse.ui.editorss" relationship="left" ratio="0.45" closeable="false"/>
    <view id="com.test.blog.core.ui.views.detaillog.DetailLogsView"
          relative="org.eclipse.ui.editorss" relationship="bottom" ratio="0.4"/>
    <view id="com.test.blog.core.ui.views.statinfo.SimpleStatsView"
          relative="com.test.blog.core.ui.views.jobinfo.JobInformationView" relationship="bottom" ratio="0.5" closeable="false"/>
    <view id="com.test.blog.core.ui.views.statinfo.DetailStatsView"
          relative="com.test.blog.core.ui.views.statinfo.SimpleStatsView" relationship="stack" closeable="false"/>
  </perspectiveExtension>
</extension>

比較與建議

  • 程式碼方式:邏輯集中、支援動態計算、適合複雜條件佈局。
  • plugin.xml 方式:宣告式、無需編譯、易於維護、適合靜態佈局。
  • 兩者可混用:基礎佈局用 XML,動態調整用程式碼。

Perspective 佈局效果圖

圖 1:Perspective 佈局效果圖

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved