Topic: jface treeview的问题 |
Print this page |
1.jface treeview的问题 | Copy to clipboard |
Posted by: kabbesy Posted on: 2005-06-29 11:12 就是想借着tutorial弄个完整的资源管理器,做为学习范例 但是资源管理器左侧树部分的操作死活不对 ——双击文件夹,将树的该结点展开 按理说treeview实现这个是很简单的,但我这里死活就是不对 网上jface资料少,教程更少,会的人不知道哪儿去找 只能求助于这里了>__< 下面是代码部分 =========================== public class Explorer extends ApplicationWindow { protected Control createContents(Composite parent) { final TreeViewer treeViewer = new TreeViewer(sashForm, SWT.BORDER); treeViewer.setContentProvider(new FileTreeContentProvider()); treeViewer.setInput(new File("C:\\")); treeViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent e) { System.out.println("Double Clicked :" + e.getSelection()); treeViewer.setExpandedElements(new Object[]{new File(e.getSelection().toString())}); // treeViewer.setExpandedElements(new Object[]{new File("C:\\code")}); } }); ........ } 下面是treeview的provider ============================================= public class FileTreeContentProvider implements ITreeContentProvider { public void dispose() { } public Object[] getChildren(Object element) { return ((File) element).listFiles(); } public Object[] getElements(Object element) { return getChildren(element); } public Object getParent(Object element) { return ((File) element).getParentFile(); } public boolean hasChildren(Object element) { Object[] obj = getChildren(element); return obj == null ? false : obj.length > 0; } public void inputChanged(Viewer arg0, Object arg1, Object arg2) { } } 执行这段代码,我发现contentProvider的getParent被反复进入了若干此 直到获得tree的跟结点为止(也就是C:\) 也就没有expand(可以说,就是expand了C:\,所以没效果) JFace封装的这些provider我也没法进去追踪,又木有源码 卡死在这里两天了,哪位可以指导下? |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |