比如擴(kuò)展ECLIPSE的視圖:




當(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)一步研究:)