您的位置:首页 >> 编程开发 >> Java >> Java基础 >> Eclipse >> 正文
Eclipse RSS
 

自己动手编写Eclipse扩展点

http://www.rdxx.com 04年09月15日 12:12 Blog 我要投稿

关键词: 扩展 , Eclipse , IP

      </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());

9 7 3 1 2 3 4 5 6 7 4 8 :


 
 
标签: 扩展 , Eclipse , IP 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站