Eclipse插件开发学习笔记

Posted on 2009-05-13 21:19 eric_xu 阅读(1392) 评论(0)  编辑  收藏 所属分类: Eclipse Plugin

对org.eclipse.ui.popupMenus扩展点

1、  viewerContribution,也就是通过视图的id。这样只有视图id和给定的id一致的时候,它的弹出菜单才会增加我们定义的菜单项。实现类必须实现IObjectActionDelegate接口

2、  objectContribution,通过对象类型。当在视图里选定的对象类型和给定的一致时,在视图的弹出菜单增加我们定义的菜单项。实现类必须实现IViewerActionDelegate接口

 对org.eclipse.ui.viewAction扩展点

       viewContribution 添加视图工具栏与添加视图下拉子菜单。实现类都必须实现IViewActionDelegate接口

创建编辑器的上下文操作,targetID="#TextEditorContext",为eclipse默认文件编辑器的上下文菜单标识符。实现类必须实现IEditorActionDelegate接口



所有视图必须实现org.eclipse.ui.IViewPart接口

IViewPartIEditorPart都继承自IWorkbenchPart

ResourceNavigator即可被实例化,又可以被继承

ContentOutlinePropertySheet视图不能被再次实例化也无法被继承,它们仅有的实例是由工作台创建并管理的,可以被引用。可以通过IWorkbenchPageshowView()方法显示ContentOutlinePropertySheetBookmarkNavigatorTaskList

 

视图模式

VIEW_ACTIVATE
          Show view mode that indicates the view should be made visible and activated.

         激活定义视图的插件并在当前页面中显示视图

VIEW_CREATE
          Show view mode that indicates the view should be made created but not necessarily be made visible.

VIEW_VISIBLE
          Show view mode that indicates the view should be made visible.

         该视图可见,但不会立即显示该视图

 

createPartControl(Composite)定义视图的用户界面。

TableViewer的责任是用特定的对象填充到Table窗体组件中。是我们最终在窗体要看到的对象。

IStructuredContentProviderITableLabelProvider的实现类是用来帮助TableViewer来完成这个任务的。

结构化内容提供者IStructuredContentProvider负责从输入对象中提取对象,并把它们传递给表格查看器进行显示。

标签提供者LabelProvider将获得内容提供者返回的一个表格行对象,并提取要显示到列上的值。

所以,要实现一个在TableView中显示特定对象只需要实现IStructuredContentProvider实现类的getElements方法。和ITableLabelProvidergetColumnTextgetColumnImage方法。

查看器排序器ViewerSorter用于对内容提供者提供的元素进行排序。

视图过滤器

 

获取到的有关当前选择项内容,先查找视图,找到该视图后,调用getSelection()得到当前选择项,然后马上转换为IStructuredSelection,以后的操作就是统一的了,因为有IStructuredSelection接口。如果是在action中遇到这种需求,就将event调用getSelection(),然后转换为IStructuredSelection,后续操作相同。

 

KeyEvent

Character, 就是按键对应字符

stateMask则是用来检测AltShiftCtrl这些键有没有同时被按下。stateMask与这些键的键码进行位与运算,如果得到的结果不是0就说明这些键被按下了,比如如果stateMake & SWT.ALT不为零,我们就可以认为Alt键被按下了。

 

属性视图支持所有实现IResource接口的资源。

Java是一种强类型语言,每个实例都必须有指定的类型。实际上,Java类型有两种声明类型和运行时类型(也可以相应的说是静态类型 和动态类型)

可以把IAdaptable想象为一个能够动态进行类型转换的途径。其实这种机制可以让我们将目标类转换为它并没有实现的接口。

大部分IAdaptable的实现是一些if语句的叠加,实现getAdapter()方法。getAdapter()方法的调用者需要传入一个代表特定接口的Class对象,该方法则会返回一个具有该接口的对象。

 

Eclipse中,比较标准的做法是通过ISelectionProviderISelectionListener来完成的。Eclipse为了解决这个问题,提供了所谓的Site,以及ISelectionService机制,来处理试图之间的简单的交互。简单的说,ViewSite提供了一个交互的中心点,其它ViewViewSite提供选择事件,或者向其注册监听器,而事件的触发与转发则由ViewSite()来完成。

注意SelectionProviderSelectionListener并不直接对应。这个地方有一点容易混淆,就是Eclipse实际上提供有两套与Selection相关的事件与接口:

ISelectionChangedListener <--> ISelectionProvider

这个是JFace中的选择监听机制,对试图或者控件而言,它提供对原始的选择事件的通知与响应。ISelectionProvider需要注册在Site上,以供ISelectionSerivce使用,将选择事件扩散到其他的ISelectionListener中。

ISelectionListener <--> ISelectionService

这个是在Site中使用的,ISelectionService不需要自己实现,已经实现好了,ISelectionListener则需要注册到ISelectionService上,以对其它SelectionProvider的事件响应进行监听。

Eclipse本身的实现中,PropertySheetOutline都使用了这种机制。不过需要注意的是,缺省的PropertySheet需要接受一个IStructuredSelection,而不仅仅是一个ISelection。因此,如果ISeletionProvider需要提供一个能够让PropertySheet进行显示的对象的话,除了除了要实现ISelection接口外,还需要对其进行封装成一个IStructuredSelection。这个比较简单,直接调用StructuredSelection构造函数即可。

 

Protected类型不希望其他类使用该方法。

 

A site maintains the context for a part,
including the part, its pane, active contributions, selection provider, etc.
Together, these components make up the complete behavior for a
part as if it was implemented by one person.

The PartSite lifecycle is as follows ..

  (1) a site is constructed
  (2) a part is constructed and stored in the part
  (3) the site calls part.init()
  (4) a pane is constructed and stored in the site
  (5) the action bars for a part are constructed and stored in the site
  (6) the pane is added to a presentation
  (7) the SWT widgets for the pane and part are created
  (8) the site is activated, causing the actions to become visible


只有注册用户登录后才能发表评论。


网站导航:
 

posts - 37, comments - 5, trackbacks - 0, articles - 0

Copyright © eric_xu