對org.eclipse.ui.popupMenus擴展點
1、 viewerContribution,也就是通過視圖的id。這樣只有視圖id和給定的id一致的時候,它的彈出菜單才會增加我們定義的菜單項。實現類必須實現IObjectActionDelegate接口
2、 objectContribution,通過對象類型。當在視圖里選定的對象類型和給定的一致時,在視圖的彈出菜單增加我們定義的菜單項。實現類必須實現IViewerActionDelegate接口
創建編輯器的上下文操作,targetID="#TextEditorContext",為eclipse默認文件編輯器的上下文菜單標識符。實現類必須實現IEditorActionDelegate接口
所有視圖必須實現org.eclipse.ui.IViewPart接口
IViewPart和IEditorPart都繼承自IWorkbenchPart
ResourceNavigator即可被實例化,又可以被繼承
ContentOutline和PropertySheet視圖不能被再次實例化也無法被繼承,它們僅有的實例是由工作臺創建并管理的,可以被引用。可以通過IWorkbenchPage的showView()方法顯示ContentOutline和PropertySheet。BookmarkNavigator和TaskList
視圖模式
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窗體組件中。是我們最終在窗體要看到的對象。
IStructuredContentProvider和ITableLabelProvider的實現類是用來幫助TableViewer來完成這個任務的。
結構化內容提供者IStructuredContentProvider負責從輸入對象中提取對象,并把它們傳遞給表格查看器進行顯示。
標簽提供者LabelProvider將獲得內容提供者返回的一個表格行對象,并提取要顯示到列上的值。
所以,要實現一個在TableView中顯示特定對象只需要實現IStructuredContentProvider實現類的getElements方法。和ITableLabelProvider的getColumnText和getColumnImage方法。
查看器排序器ViewerSorter用于對內容提供者提供的元素進行排序。
視圖過濾器
獲取到的有關“當前選擇項”內容,先查找視圖,找到該視圖后,調用getSelection()得到當前選擇項,然后馬上轉換為IStructuredSelection,以后的操作就是統一的了,因為有IStructuredSelection接口。如果是在action中遇到這種需求,就將event調用getSelection(),然后轉換為IStructuredSelection,后續操作相同。
KeyEvent
Character, 就是按鍵對應字符
stateMask則是用來檢測Alt,Shift,Ctrl這些鍵有沒有同時被按下。stateMask與這些鍵的鍵碼進行位與運算,如果得到的結果不是0就說明這些鍵被按下了,比如如果stateMake & SWT.ALT不為零,我們就可以認為Alt鍵被按下了。
屬性視圖支持所有實現IResource接口的資源。
Java是一種強類型語言,每個實例都必須有指定的類型。實際上,Java類型有兩種聲明類型和運行時類型(也可以相應的說是靜態類型 和動態類型)。
可以把IAdaptable想象為一個能夠動態進行類型轉換的途徑。其實這種機制可以讓我們將目標類轉換為它并沒有實現的接口。
大部分IAdaptable的實現是一些if語句的疊加,實現getAdapter()方法。getAdapter()方法的調用者需要傳入一個代表特定接口的Class對象,該方法則會返回一個具有該接口的對象。
在Eclipse中,比較標準的做法是通過ISelectionProvider和ISelectionListener來完成的。Eclipse為了解決這個問題,提供了所謂的Site,以及ISelectionService機制,來處理試圖之間的簡單的交互。簡單的說,ViewSite提供了一個交互的中心點,其它View向ViewSite提供選擇事件,或者向其注冊監聽器,而事件的觸發與轉發則由ViewSite()來完成。
注意SelectionProvider和SelectionListener并不直接對應。這個地方有一點容易混淆,就是Eclipse實際上提供有兩套與Selection相關的事件與接口:
ISelectionChangedListener <--> ISelectionProvider
這個是JFace中的選擇監聽機制,對試圖或者控件而言,它提供對原始的選擇事件的通知與響應。ISelectionProvider需要注冊在Site上,以供ISelectionSerivce使用,將選擇事件擴散到其他的ISelectionListener中。
ISelectionListener <--> ISelectionService
這個是在Site中使用的,ISelectionService不需要自己實現,已經實現好了,ISelectionListener則需要注冊到ISelectionService上,以對其它SelectionProvider的事件響應進行監聽。
在Eclipse本身的實現中,PropertySheet和Outline都使用了這種機制。不過需要注意的是,缺省的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