Get busy living or get busy dying!

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            1 隨筆 :: 13 文章 :: 0 評論 :: 0 Trackbacks
          ECLIPSE的擴展主要體現在EXTENTION-POINT和EXTENTION上。
          比如擴展ECLIPSE的視圖:
          <extension point="org.eclipse.ui.view"/>
               擴展ECLIPSE的編輯器:
          <extension point="org.eclipse.ui.editors">
                擴展ECLIPSE的透視圖:
          <extension point="org.eclipse.ui.perspective">
          而這些擴展都是建立在已經有:
          <extension-point="org.eclipse.ui.*">
          的基礎上的。ECLIPSE會在加載extension-point時查找其相應的插件,當然要對應ID,從而實現擴展。
          當然,也可以自己編寫擴展點:
          下面,我們要在net.softapp.worklist插件中定義workList擴展點。
           1. 擴展點的定義文件按照Eclipse的存放方式,一般存放在schema目錄下,我們把文件命名為worklist.exsd。內容如下,此內容由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"/>
                   <!--通過這個定義,我們可以看出,定義的擴展點的id是 net.softapp.worklist.workList,以后引用時要注意,同時注意大小寫-->
                </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時,必須指出應用的id,而name給出了一個可供顯示的直觀的名字-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                   <attribute name="parentCategory" type="string"><!--定義父category,也就是說我們的category可以嵌套形成樹狀結構-->
                      <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,可供顯示的直觀的圖標-->
                      <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,實現功能的類名稱-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                         <appInfo>
                            <meta.attribute kind="java"/>
                         </appInfo>
                      </annotation>
                   </attribute>
                   <attribute name="id" type="string" use="required"><!--定義worklist/id,唯一標志-->
                      <annotation>
                         <documentation>                 
                         </documentation>
                      </annotation>
                   </attribute>
                </complexType>
             </element>

             <!--以下內容為PDE自動生成,與我們的編程無關-->
             <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>
            這樣我們就定義好了擴展的屬性。
            然后在plugin.xml加入:
               <extension-point id="workList" name="workList" schema="schema/workList.exsd"/>
            就定義好了!
          2. 實現擴展
            定義完擴展之后,接下來要編寫解析此擴展的相關代碼。可喜的是,Eclipse為我們提供了大量的API可以調用,省下了若干代碼的編寫。另外我們還可以借鑒Eclipse實現的其他代碼,通過模仿來編寫我們自己的解析代碼。本例參考了View的解析部分。同View,我們定義了WorkListDescriptor,WorkListRegistry,WorkListRegistryReader.其中WorkListDescriptor完成對上述定義的解析,WorkListRegistry存放了其他插件對workList擴展的相關信息,WorkListRegistryReader則從WorkListRegistry讀取信息供我們使用。
            此處代碼從略,具體請參考View實現部分的ViewDescriptor,ViewRegistry,ViewRegistryReader相關代碼。
          3. 編寫界面部分
             在類里面編寫代碼就行。
          可見,自己編寫擴展點有點復雜,好要等進一步研究:)

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

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


          網站導航:
           
          主站蜘蛛池模板: 遂平县| 牙克石市| 东阳市| 岐山县| 阳泉市| 习水县| 怀柔区| 清水河县| 北流市| 遂宁市| 大港区| 谷城县| 夏邑县| 修水县| 云和县| 竹溪县| 上犹县| 淮南市| 乌拉特前旗| 慈溪市| 平山县| 水城县| 阳谷县| 淮安市| 西城区| 南皮县| 宜宾市| 平陆县| 仲巴县| 南昌市| 保山市| 砀山县| 田东县| 宽城| 海盐县| 昌乐县| 林州市| 美姑县| 会宁县| 湘西| 夏河县|