EMF不光為我們生成了模型類的代碼。還為我們提供了一個(gè)默認(rèn)的模型編輯器。要看到這個(gè)模型編輯器我們只需要運(yùn)行一下就可以看到了(用Eclipse Application的方式)。
他默認(rèn)的編輯器如下圖所示
共有三個(gè)部:
1. 編輯器的主體。包括六種呈現(xiàn)方式。
a) Selection.
b) Parent.
c) List.
d) Tree
e) Table
f) Tree With Columns.
2. Outline部分。
Properties,會(huì)根據(jù)選擇不同的對(duì)象而改變顯示的內(nèi)容。
關(guān)于Jface部分的工作模式我在《Table View 的合作類的模式》一文中有提到,不過需要說明的是,在Jface中的Viewer他們的ContentProvider可能不一樣的。要完成這部分的功能emf的產(chǎn)生代碼中分別放到了兩個(gè)插件里實(shí)現(xiàn)了他們分別是edit和editor。
Edit提供了Item 的Provider,他存在的意義就在于把邏輯對(duì)象和UI分割開。而Editor通過使用edit提供的Provider實(shí)現(xiàn)了一個(gè)編輯器的UI和Command部分,他是正真的用戶界面部分。
下面我們就先來看看edit中的類。
好了,首先edit中使用的是adapt模型。所以edit中的插件對(duì)象會(huì)實(shí)現(xiàn)所有的viewer,Properties所需要的接口。
Emf為我們實(shí)現(xiàn)通用的接口。所以這絕對(duì)是一個(gè)學(xué)習(xí)的好機(jī)會(huì)。
廢話不多說了,來看代碼把。
首先看聲明:
extends ItemProviderAdapter
implements
IEditingDomainItemProvider,
IStructuredItemContentProvider,
ITreeItemContentProvider,
IItemLabelProvider,
IItemPropertySource {

他們之間的職能以及實(shí)現(xiàn)的接口可用下圖來描述:

AdapterImpl是為了實(shí)現(xiàn)Adapter模式而設(shè)定.
ItemProviderAdapter完成一些基本功能。下面就分別從不同的接口來說明
1. ResourceLocator:該接口是用來進(jìn)行資源定位的。
2. IDisposable 是emf框架提供的一種析構(gòu)接口。
3. IChangeNotifier 為"Notification and Adapters"模式提供必需的方法。
CreateChildCommand.Helper
最下面的EMF根據(jù)我們的模型產(chǎn)生的Provider的了。他實(shí)現(xiàn)了5個(gè)接口。
1. IEditingDomainItemProvider
這部分我還清楚,懷疑和command有關(guān)。
2. IStructuredItemContentProvider
該接口為TableViewer,ListViewer,TreeViewer提供服務(wù)。
This is the interface needed to populate the top level items in a TreeViewer, the items of a ListViewer, or the rows of a TableViewer.
3. ITreeItemContentProvider
This is the interface needed to populate subtrees in a TreeViewer
4. IItemLabelProvider
This is the interface implemented to provide a label text and even a label icon for an item;
it receives delegated calls from ILabelProvider.
5. IItemPropertySource
This is the interface is needed to populate property sheet items。it is the same as IpropertySource。except that the object is passed as the first parameter for each method.這一篇還只是edit部分剛開一個(gè)頭。
下一期會(huì)介紹一下他的command部分。