SWT: prevent Tree from expanding by doubleclick?

为君一笑 提交于 2019-12-06 22:11:36

If you are using TreeViewer, you could make use of IOpenListener

treeViewer.addOpenListener(new IOpenListener() {

      @Override
      public void open(OpenEvent event) {
}
}

I find the above answers to be rather bogus. The following worked for me:

treeViewer.getControl().addListener(SWT.MeasureItem, new Listener(){
    @Override
    public void handleEvent(Event event) {
    }});

I know, it does not make any sense; for an explanation of the real cause of the problem, and why the above is a fix, see this discussion in the Eclipse Community Forums: Disabling Treeviewer doubleclick expand/collapse.

There is another solution which works much better.

The problem with the solution from 'sambi reddy' was, that the tree was prevented from expanding by doubleclick, but it was prevented from expanding by clickling on the left handside cross as well.

My solution (that works well), was easy: I added a TreeListener, which listens to expanding/collapsing the tree and removed the expanding/collpasing implementation from the MouseDoubleClick-Listener.

No JFace TreeViewer - it works fine.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!