Get busy living or get busy dying!

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            1 隨筆 :: 13 文章 :: 0 評論 :: 0 Trackbacks
          ECLIPSE的擴(kuò)展主要體現(xiàn)在EXTENTION-POINT和EXTENTION上。
          比如擴(kuò)展ECLIPSE的視圖:
          <extension point="org.eclipse.ui.view"/>
               擴(kuò)展ECLIPSE的編輯器:
          <extension point="org.eclipse.ui.editors">
                擴(kuò)展ECLIPSE的透視圖:
          <extension point="org.eclipse.ui.perspective">
          而這些擴(kuò)展都是建立在已經(jīng)有:
          <extension-point="org.eclipse.ui.*">
          的基礎(chǔ)上的。ECLIPSE會在加載extension-point時(shí)查找其相應(yīng)的插件,當(dāng)然要對應(yīng)ID,從而實(shí)現(xiàn)擴(kuò)展。
          當(dāng)然,也可以自己編寫擴(kuò)展點(diǎn):
          下面,我們要在net.softapp.worklist插件中定義workList擴(kuò)展點(diǎn)。
           1. 擴(kuò)展點(diǎn)的定義文件按照Eclipse的存放方式,一般存放在schema目錄下,我們把文件命名為worklist.exsd。內(nèi)容如下,此內(nèi)容由PDE生成:
          <?xml version='1.0' encoding='UTF-8'?>
          <!-- Schema file written by PDE -->
          <schema targetNamespace="mtn.esip.worklist">
          <annotation>
                <appInfo>
                   <meta.schema plugin="net.softapp.worklist" id="workList" name="workList"/>
                   <!--通過這個定義,我們可以看出,定義的擴(kuò)展點(diǎn)的id是 net.softapp.worklist.workList,以后引用時(shí)要注意,同時(shí)注意大小寫-->
                </appInfo>
                <documentation>
                   [Enter description of this extension point.]
                </documentation>
             </annotation>

             <element name="extension">
                <complexType>
                   <choice minOccurs="0" maxOccurs="unbounded">
                      <element ref="category" minOccurs="0" maxOccurs="1"/>
                      <element ref="worklist" minOccurs="0" maxOccurs="1"/>
                   </choice>
                   <attribute name="point" type="string" use="required"><!--定義point-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                   <attribute name="id" type="string"><!--定義id-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                   <attribute name="name" type="string"><!--定義name-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                </complexType>
             </element>
           
            <!--定義category-->
             <element name="category">
                <complexType>
                   <attribute name="name" type="string"><!--定義category/name-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                   <attribute name="id" type="string"><!--定義category/id。引用category時(shí),必須指出應(yīng)用的id,而name給出了一個可供顯示的直觀的名字-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                   <attribute name="parentCategory" type="string"><!--定義父category,也就是說我們的category可以嵌套形成樹狀結(jié)構(gòu)-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                </complexType>
             </element>

             <!--定義worklist,注意大小寫-->//必須的
             <element name="worklist">
                <complexType>
                   <attribute name="name" type="string"><!--定義worklist/name,可供顯示的直觀的名字-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                   <attribute name="icon" type="string"><!--定義worklist/icon,可供顯示的直觀的圖標(biāo)-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                   <attribute name="category" type="string">!--定義worklist/category,存放的category位置。如果引用嵌套形式的category,則采用 parent_id/child_id的形式 -->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                   <attribute name="class" type="string"><!--定義worklist/class,實(shí)現(xiàn)功能的類名稱-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                         <appInfo>
                            <meta.attribute kind="java"/>
                         </appInfo>
                      </annotation>
                   </attribute>
                   <attribute name="id" type="string" use="required"><!--定義worklist/id,唯一標(biāo)志-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                </complexType>
             </element>

             <!--以下內(nèi)容為PDE自動生成,與我們的編程無關(guān)-->
             <annotation>
                <appInfo>
                   <meta.section type="since"/>
                </appInfo>
                <documentation>
                   [Enter the first release in which this extension point appears.]
                </documentation>
             </annotation>

             <annotation>
                <appInfo>
                   <meta.section type="examples"/>
                </appInfo>
                <documentation>
                   [Enter extension point usage example here.]
                </documentation>
             </annotation>

             <annotation>
                <appInfo>
                   <meta.section type="apiInfo"/>
                </appInfo>
                <documentation>
                   [Enter API information here.]
                </documentation>
             </annotation>

             <annotation>
                <appInfo>
                   <meta.section type="implementation"/>
                </appInfo>
                <documentation>
                   [Enter information about supplied implementation of this extension point.]
                </documentation>
             </annotation>

             <annotation>
                <appInfo>
                   <meta.section type="copyright"/>
                </appInfo>
                <documentation>        
                </documentation>
             </annotation>

          </schema>
            這樣我們就定義好了擴(kuò)展的屬性。
            然后在plugin.xml加入:
               <extension-point id="workList" name="workList" schema="schema/workList.exsd"/>
            就定義好了!
          2. 實(shí)現(xiàn)擴(kuò)展
            定義完擴(kuò)展之后,接下來要編寫解析此擴(kuò)展的相關(guān)代碼??上驳氖?,Eclipse為我們提供了大量的API可以調(diào)用,省下了若干代碼的編寫。另外我們還可以借鑒Eclipse實(shí)現(xiàn)的其他代碼,通過模仿來編寫我們自己的解析代碼。本例參考了View的解析部分。同View,我們定義了WorkListDescriptor,WorkListRegistry,WorkListRegistryReader.其中WorkListDescriptor完成對上述定義的解析,WorkListRegistry存放了其他插件對workList擴(kuò)展的相關(guān)信息,WorkListRegistryReader則從WorkListRegistry讀取信息供我們使用。
            此處代碼從略,具體請參考View實(shí)現(xiàn)部分的ViewDescriptor,ViewRegistry,ViewRegistryReader相關(guān)代碼。
          3. 編寫界面部分
             在類里面編寫代碼就行。
          可見,自己編寫擴(kuò)展點(diǎn)有點(diǎn)復(fù)雜,好要等進(jìn)一步研究:)

          posted on 2007-06-27 23:04 一條輝 閱讀(221) 評論(0)  編輯  收藏 所屬分類: ECLIPSE

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 鄂尔多斯市| 法库县| 始兴县| 柳州市| 宜春市| 渭南市| 中超| 阳江市| 城市| 唐海县| 漳州市| 苍山县| 桂阳县| 吉木乃县| 阜城县| 桃园县| 清河县| 黄大仙区| 林甸县| 镶黄旗| 门头沟区| 阿拉善右旗| 德阳市| 渭南市| 永顺县| 临漳县| 商洛市| 兴国县| 隆昌县| 迁西县| 漳平市| 射洪县| 民和| 池州市| 奉节县| 镇巴县| 凉山| 承德市| 乌海市| 宁安市| 怀仁县|