Posted on 2007-05-06 18:03
xiaoxiaoleemin 阅读(766)
评论(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设置一些属性值。