posts - 97,  comments - 93,  trackbacks - 0

org.eclipse.jface.viewers.TreeViewer

的继承关系是


更多相关参考可见

http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/viewers/TreeViewer.html 

Tree的应用中,尤其是Eclipse RCP的应用,当计算较为耗费资源时我们有时需要在用户点击expend labelarrow或者是双击数据节点时处理计算,然后进行展开等操作。

TreeViewer针对节点对象的双击事件给出了比较好的实现,但并没有直接给出针对expendcollapse labels的事件处理,而给出的addTreeListener(ITreeViewerListener listener)又是处理展开或收缩后的事件。

1 new TreeView().addTreeListener(new ITreeViewerListener(){
2             public void treeCollapsed(TreeExpansionEvent event) {
3                 // TODO Auto-generated method stub
4             }
5             public void treeExpanded(TreeExpansionEvent event) {
6                 // TODO Auto-generated method stub
7             }
8         });
9 

有些网友对于如何解决点击等事件处理问题比较困惑,我最近做的一个项目中也恰好用到单击label后计算并展开、双击节点也做相应的计算并展开(计算后的结果保存提高效率)、根据label得到节点对象。以下贴出相应的主要代码以供参考(原创-版权所有,转载请标明来自http://www.blogjava.net/wqnashqu)。

 1     private void hookClickUnitNavigation() {    
 2         final TreeViewer unitNavigator = this.getTreeViewer();
 3         
 4         unitNavigator.getTree().addListener(SWT.Expand, new Listener() {
 5             public void handleEvent(Event event) {
 6                  (强制转换为放入的数据类型)event.item.getData();
 7                 if (null != selectedTreeItem) {
 8                  
 9                         handleDoubleClick(unitNavigator, selectedTreeItem,
10                                 selectedTreeItem.getAdapter(null));
11                  else
12                     return;
13             }
14         });
15     }
16 private void hookDoubleClickOnUnitNavigator() {
17 final TreeViewer unitNavigator = this.getTreeViewer();
18            unitNavigator.addDoubleClickListener(new IDoubleClickListener(){
19             public void doubleClick(DoubleClickEvent event) {
20                 unitNavigator.getSelection()取得选择的节点
21              相关节点的计算
22            }
23   });
24 }
样例如下


posted on 2008-04-23 00:10 wqwqwqwqwq 阅读(4821) 评论(3)  编辑  收藏 所属分类: IBM Tech

FeedBack:
# re: SWT JFACE .TreeViewer Expand事件及其节点处理方法
2008-05-22 11:40 | 求助
http://www.eclipseworld.org/bbs/read-cec-tid-17144.html

老大帮我看看这个吧万分感谢啊!  回复  更多评论
  
# Vnutrennyaya Optimizaciya
2009-05-18 03:37 | Vnutrennyaya Optimizaciya
Hi everyone. There ain't no free lunches in this country. And don't go spending your whole life commiserating that you got raw deals. You've got to say, 'I think that if I keep working at this and want it bad enough I can have it.'
I am from France and now study English, tell me right I wrote the following sentence: "Our company specialized in seo techniques including advanced seo techniques, seo article archive, web domain ranking, search engine advertising, custom application.Looking to top google? Ethical and creative search engine optimisation service agency based in greenock, near glasgow, scotland."

Best regards :o, Paulina.  回复  更多评论
  
# re: SWT JFACE .TreeViewer Expand事件及其节点处理方法[未登录]
2012-12-24 23:47 | huhu
@求助
非常感谢 解决了问题  回复  更多评论
  

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


网站导航:
 
<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910




常用链接

留言簿(10)

随笔分类(95)

随笔档案(97)

文章档案(10)

相册

J2ME技术网站

java技术相关

mess

搜索

  •  

最新评论

阅读排行榜

校园梦网网络电话,中国最优秀的网络电话