邋遢居

          我的Java天堂

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            61 Posts :: 2 Stories :: 90 Comments :: 0 Trackbacks

          EMF不光為我們生成了模型類的代碼。還為我們提供了一個默認(rèn)的模型編輯器。要看到這個模型編輯器我們只需要運行一下就可以看到了(用Eclipse Application的方式)。

          他默認(rèn)的編輯器如下圖所示viewer.gif

          共有三個部:

          1.         編輯器的主體。包括六種呈現(xiàn)方式。

          a)         Selection.

          b)        Parent.

          c)        List.

          d)        Tree

          e)         Table

          f)         Tree With Columns.

          2.         Outline部分。

          Properties,會根據(jù)選擇不同的對象而改變顯示的內(nèi)容。關(guān)于Jface部分的工作模式我在《Table View 的合作類的模式》一文中有提到,不過需要說明的是,在Jface中的Viewer他們的ContentProvider可能不一樣的。

          要完成這部分的功能emf的產(chǎn)生代碼中分別放到了兩個插件里實現(xiàn)了他們分別是editeditor

          Edit提供了Item Provider,他存在的意義就在于把邏輯對象和UI分割開。而Editor通過使用edit提供的Provider實現(xiàn)了一個編輯器的UICommand部分,他是正真的用戶界面部分。

          下面我們就先來看看edit中的類。

          好了,首先edit中使用的是adapt模型。所以edit中的插件對象會實現(xiàn)所有的viewer,Properties所需要的接口。

          Emf為我們實現(xiàn)通用的接口。所以這絕對是一個學(xué)習(xí)的好機會。

          廢話不多說了,來看代碼把。

          首先看聲明:

          public class FamilyItemProvider
              
          extends ItemProviderAdapter
              
          implements    
                  IEditingDomainItemProvider,    
                  IStructuredItemContentProvider,    
                  ITreeItemContentProvider,    
                  IItemLabelProvider,    
                  IItemPropertySource {
          他的繼承關(guān)系可以用下圖來表示:
          providerh.gif

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

          itemprivdelayer.gif
          AdapterImpl是為了實現(xiàn)Adapter模式而設(shè)定.

          ItemProviderAdapter完成一些基本功能。下面就分別從不同的接口來說明

          1.         ResourceLocator:該接口是用來進行資源定位的。

          2.         IDisposable emf框架提供的一種析構(gòu)接口。

          3.         IChangeNotifier 為"Notification and Adapters"模式提供必需的方法。

          CreateChildCommand.Helper

          最下面的EMF根據(jù)我們的模型產(chǎn)生的Provider的了。他實現(xiàn)了5個接口。

           

          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 itemsit is the same as IpropertySourceexcept that the object is          passed as the first parameter for each method.

          這一篇還只是edit部分剛開一個頭。

          下一期會介紹一下他的command部分。

          posted on 2005-12-25 13:36 Jet Geng 閱讀(1748) 評論(0)  編輯  收藏 所屬分類: EMF
          主站蜘蛛池模板: 兰考县| 清徐县| 怀来县| 玉屏| 梅河口市| 屯昌县| 通化县| 桂平市| 庆城县| 梨树县| 绥滨县| 青神县| 英吉沙县| 密山市| 浑源县| 交口县| 离岛区| 威宁| 都安| 鲁甸县| 泊头市| 云南省| 博爱县| 苏尼特右旗| 普格县| 阳谷县| 林州市| 左云县| 陆河县| 客服| 龙山县| 镇沅| 建德市| 图们市| 重庆市| 江阴市| 柘荣县| 江北区| 乾安县| 岢岚县| 五河县|