比如擴展ECLIPSE的視圖:




當然,也可以自己編寫擴展點:
下面,我們要在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. 編寫界面部分
在類里面編寫代碼就行。
可見,自己編寫擴展點有點復雜,好要等進一步研究:)