有没有更好的方法来使用 ILazyTreeContentProvider 进行排序和过滤

发布于 2024-08-12 17:39:55 字数 674 浏览 7 评论 0原文

显然,如果使用 ILazyTree(TreePath)ContentProviderTreeViewers 不支持排序和过滤。因此,为 TreeView 设置 ViewerFiltersSorters/Comparators 不会有任何好处。也许这与不知道所有元素有关,包括那些目前不可见的元素。

支持此声明的是来自 org.eclipse.jface.viewers.TreeViewer 类的 javadoc 摘录:

如果内容提供商是 ILazyTreeContentProviderILazyTreePathContentProvider,底层 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 an
ILazyTreePathContentProvider, 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜兔 2024-08-19 17:39:55

事实上,无论您使用 IStructuredContentProvider 还是惰性提供程序,VIRTUAL-TreeViewer 都无法进行排序,如 此线程

您必须自己进行排序(在您的模型中)。
基本假设是这些元素甚至可能不在内存中。

事情可能e4 中的更改(来自 2009 年 6 月的此消息):

恕我直言,JFace 虚拟表和树实现不如非虚拟表和树实现 - 好吧,我远离它并且不在我的项目中使用它。

[...] 拥有虚拟表是毫无意义的,因为从 UI 设计的角度来看,向用户展示 10.000 个元素是毫无意义的,甚至更重要,因为模型
留在您的记忆中,显示带有 JFace 的大表可能会被吃掉
你所有的堆空间
我们希望在 E4 中提出一组重新设计的查看器来解决此类问题)。
请参阅此项目错误 260451
(更一般的错误:167436262160)

现在:

我们正在表请求后在查看器中创建强引用。

恕我直言,最好给用户提供:
- 寻呼
- 智能过滤的可能性

而不是显示数百万个结果,然后例如在CDO(连接数据对象)的情况下使用新的查询 API 在服务器上进行过滤。

Indeed, sorting is not possible for a VIRTUAL-TreeViewer whether you use a IStructuredContentProvider or a lazy one, as noted in this thread:

You will have to do the sorting yourself (in your model).
The underlying assumption is that the elements might not even be in memory.

Things may change in e4 (from this message in June 2009):

IMHO the JFace Virtual Table and Tree implementation is not as good as the none virtual one - well I stay away from it and use it in none of my projects.

[...] its senseless to have virtual tables because from an UI-Design point of view it is senseless to show an user 10.000s of elements and even more important because the model
stays resident in your memory showing big tables with JFace might eat up
all your heapspace
(We hope to come up with a redesigned set of Viewers in E4 who fix such problems).
See this project and bug 260451.
(more genral bugs: 167436 and 262160)

Right now:

we are creating a strong reference in the viewer after the table requested it.

IMHO its much better to give the user:
- paging
- intelligent filtering possibilities

instead of showing million of results and then e.g. in case of CDO (Connected Data Objects) the filtering happens on the server using their new query-API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文