如何在 JFace TreeViewer 中显示根元素?
我有一个 JFace Treeviewer,但是它不显示作为输入传递的“根”元素。仅显示根的子级。 是否也可以显示根?
I have a JFace Treeviewer, however it does not display the 'root' element that is passed as input. Only the children of the root are shown.
Is it possible to display the root too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
输入未确定为 TreeViewer 的根。事实上,树查看器不知道哪一个是根,哪一个不是。它由 contentprovider.getElements() 方法。我猜您很有可能在该方法内调用 getChildren() 。这会导致返回根元素的子元素,而不是返回根元素本身。
The input is not decided as the root of the TreeViewer. Infact the treeviewer doesn't know which one is root and which one is not. Its decided by the contentprovider.getElements() methods. With most probability, I guess you are calling the getChildren() inside that method. That leads to returning the children of the root elements rather than returning the root elements themselves.
不应显示 TreeViewer 的输入元素。问题可以这样解决:
在 ContentProvider 中:
The TreeViewer's input element should not be displayed. The problem can be solved like this:
And in the ContentProvider:
我遇到了完全相同的问题,并通过使用布尔字段
treeInputSet
解决了它,如下所示,其中Model
是要在树中显示的域类:I ran into exactly the same problem and solved it by using a boolean field
treeInputSet
as follows in whichModel
is the domain class you want to display in the tree: