</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. 编写界面部分
根据1对View的扩展,我们需要编写界面部分。此处请参考View插件的编写。我们在此对WorkListPlugin添加了一个方法用以从注册表中读取扩展信息:
public IWorkListRegistry getWorkListRegistry() {
if (workListRegistry == null) {
workListRegistry = new WorkListRegistry();
try {
WorkListRegistryReader reader = new WorkListRegistryReader();
reader.readWorkList(Platform.getExtensionRegistry(), workListRegistry);
} catch (CoreException e) {
// cannot safely show a dialog so log it
WorkbenchPlugin.log("Unable to read workList registry.", e.getStatus()); //$NON-NLS-1$
}
}
return workListRegistry;
}
其中WorkListRegistryReader.readWorkList定义如下:
/**
* Read the workList extensions within a registry.
*/
public void readWorkList(IExtensionRegistry in, WorkListRegistry out)
throws CoreException {
// this does not seem to really ever be throwing an the exception
workListRegistry = out;
readRegistry(in, WorkListPlugin.getDefault().getPluginId(), "workList");
out.mapWorkListToCategories();
}
可见,我们不需要编写复杂的代码就可以读取注册表中存放的扩展信息!
我们对workList扩展的显示是采用了TreeView,代码如下(WorkListView):
protected TreeViewer createViewer(Composite parent) {
TreeViewer viewer =
new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setUseHashlookup(true);
viewer.setContentProvider(new WorkListContentProvider());
viewer.setLabelProvider(new WorkListLabelProvider());






