Eclipse Modeling Framework (EMF) 能從 Ecore 模型生成代碼及基礎編輯器,但默認屬性視圖扁平羅列所有屬性,缺乏分組、分頁、條件顯示等企業級建模能力。Topcased(Airbus 開源)基於 EMF/GMF,提供 Tabbed Properties View 實現屬性視圖的靈活定製。
創建 Empty EMF Project,定義 Ecore 模型:BookLib(圖書館)→ Category(分類)→ Book(圖書)、User(用戶)。生成 GenModel 並 Generate All,產生 4 個插件項目。
Gen Model 屬性指向導入的 GenModel。
Tabbed View (根)
└── Category (類別,如「基本信息」「業務屬性」)
└── Tab (標籤頁,如「圖書詳情」「庫存管理」)
├── Single Feature Section (單屬性編輯)
├── Advanced Section (多屬性組合編輯)
└── Multiple Feature Section (尚未完全支援)
Section 關鍵屬性:Feature 指向 Ecore 模型中的具體屬性(如 Book 的 title、author、isbn)。
右鍵 .propertiesconfigurator 文件 → Topcased → Generation → Properties View。生成獨立插件項目(如 demo.bookmanage.propertysheetpage)。
修改生成的 ModelEditor 類:
// 1. 替換屬性頁實現
public IPropertySheetPage getPropertySheetPage() {
if (propertySheetPage == null) {
propertySheetPage = new ModelPropertySheetPage(this);
}
return propertySheetPage;
}
// 2. 實現 ITabbbedPropertySheetPageContributor 接口
public String getContributorId() {
return "demo.bookmanage.propertysheetpage.contributorID"; // 對應 plugin.xml 中擴展點 ID
}