有没有更好的方法来使用 ILazyTreeContentProvider 进行排序和过滤
显然,如果使用 ILazyTree(TreePath)ContentProvider
,TreeViewers
不支持排序和过滤。因此,为 TreeView 设置 ViewerFilters
或 Sorters/Comparators
不会有任何好处。也许这与不知道所有元素有关,包括那些目前不可见的元素。
支持此声明的是来自 org.eclipse.jface.viewers.TreeViewer 类的 javadoc 摘录:
如果内容提供商是
ILazyTreeContentProvider
或ILazyTreePathContentProvider
,底层 Tree 必须是 使用 {@link SWT#VIRTUAL} 样式位创建,树查看器不会 支持排序或过滤,并且必须通过调用启用哈希查找 {@link #setUseHashlookup(boolean)}。
目前我看到的唯一解决方案是获取已订购的每个节点的子节点。如果您需要动态排序,即能够在运行时按降序或升序切换排序顺序,那么您需要为此提出自己的解决方案,例如在填充和更新子项时监视排序的布尔标志。
您是否知道可能有更好的解决方案,也许涉及更多 jface API?
Apparently if using ILazyTree(TreePath)ContentProvider
sorting and filtering is not supported by TreeViewers
. So setting ViewerFilters
or Sorters/Comparators
to your TreeView won't do any good. Perhaps this is related to not knowing all elements, including those not visible at the moment.
In support to this statement here is javadoc excerpt from org.eclipse.jface.viewers.TreeViewer
class:
If the content provider is an
ILazyTreeContentProvider
or anILazyTreePathContentProvider
, the underlying Tree must be
created using the {@link SWT#VIRTUAL} style bit, the tree viewer will not
support sorting or filtering, and hash lookup must be enabled by calling
{@link #setUseHashlookup(boolean)}.
The only solution I see at the moment is to get the children for each node already ordered. If you need dynamic sorting, i.e., being able to switch sorting order in desc or asc order during run time, then you need to come up with your own solution for this, monitoring a boolean flag of sorts when filling and updating children for example.
Are you aware possibly of better solutions, perhaps more jface API involving?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,无论您使用
IStructuredContentProvider
还是惰性提供程序,VIRTUAL-TreeViewer
都无法进行排序,如 此线程:事情可能e4 中的更改(来自 2009 年 6 月的此消息):
现在:
Indeed, sorting is not possible for a
VIRTUAL-TreeViewer
whether you use aIStructuredContentProvider
or a lazy one, as noted in this thread:Things may change in e4 (from this message in June 2009):
Right now: