a) 說明:EMF.edit位於EMF.editor和EMF.Ecore之間,他起了一個中介者的作用。他負責把來自EMF.editor的UI相關的請求轉換成符合EMF.Ecore的UI無關的調用。他需要提供以下四個功能:實現用於支援Viewer顯示的ContentProvider和LabelProvider;實現用於支援屬性顯示的IPropertySource;實現用於支援對模型進行操作的CommandFramework;實現用於支援修改通知的Framework。
b) ContentProvider和LabelProvider
i. 圖:
ii. 說明:當TreeViewer需要顯示內容時,調用她的IContentProvider的getChildren(Object obj)方法。這個方法會被轉寄到AdapterFactoryContentProvider內部。她通過她所引用的ItemProviderAdapterFactory來擷取一個對obj的ITreeItemContentProvider類型的Adapter,這個Adapter是由EMF產生的對應於ECore模型的一個ItemProviderAdapter(這裡為TeacherItemProvider),最後由這個TeacherItemProvider負責產生所需要顯示的子節點列表。
iii. 代碼:
public classAdapterFactoryContentProvider implements ITreeContentProvider {
ii. 說明:當PropertySheetPage需要顯示內容內容時,他訪問他的IPropertySourceProvider的getPropertySource(Object obj)方法。這個方法會被轉寄到AdapterFactoryContentProvider內部。她通過她所引用的ItemProviderAdapterFactory來擷取一個對obj的IItemPropertySource類型的Adapter,這個Adapter是由EMF產生的對應於ECore模型的一個ItemProviderAdapter(這裡為TeacherItemProvider),最後由這個TeacherItemProvider負責產生所需要顯示的屬性列表。
iii. 代碼:
public classAdapterFactoryContentProvider implements IPropertySourceProvider{
public IPropertySource getPropertySource(Object object){
ii. 說明:由於EMF.editor並不瞭解底層的模型細節,因此他不能直接對模型進行操作,他需要產生一些用於操作模型的Command對象。當editor需要對模型進行修改時,他通過調用他的createCommand(EditingDomain domain)方法,建立用於進行模型操作的Command對象,該方法最後會被轉寄到domain的createCommand(),然後domain會根據他所引用的ItemProviderAdapterFactory來擷取一個IEditingDomainItemProvider的適配器,由他來最後產生用於對模型進行操作的Command對象。
iii. 代碼:
public class DeleteAction extendsCommandActionHandler{
public CommandcreateCommand(Collection selection){
returnRemoveCommand.create(domain, selection);
}
}
public class RemoveCommand extendsAbstractOverrideableCommand{
public static Commandcreate(…){
return domain.createCommand(…);
}
}
public classAdapterFactoryEditingDomain implements EditingDomain{