Posted on 2007-05-06 18:03
xiaoxiaoleemin 閱讀(775)
評論(0) 編輯 收藏
上個帖子介紹了如何顯示PropertySheet視圖,這里繼續介紹如何顯示Outline視圖,還是只關心與顯示大綱視圖相關的代碼:
public class MySchoolEditor extends EditorPart implements ISelectionListener {
...
protected IContentOutlinePage contentOutlinePage;
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
...
contentOutlinePage = getContentOutlinePage();
}
public ContentOutlinePage getContentOutlinePage() {
if (contentOutlinePage == null) {
contentOutlinePage = new MyContentOutlinePage();
}
return (ContentOutlinePage) contentOutlinePage;
public Object getAdapter(Class key) {
if (key.equals(IContentOutlinePage.class))
return getContentOutlinePage();
else
return super.getAdapter(key);
}
class MyContentOutlinePage extends ContentOutlinePage {
TreeViewer contentOutlineViewer;
public void createControl(Composite parent) {
super.createControl(parent);
contentOutlineViewer = getTreeViewer();
// Set up the tree viewer.
contentOutlineViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
contentOutlineViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
contentOutlineViewer.setInput(school);
}
}
}
ContentOutlinePage類是一個抽象類,不能直接創建對象,所以我們要繼承它實現自己的大綱頁,主要任務是為它的treeViewer設置一些屬性值。