[英]SortController: how to use a dynamic filter
The JXTable
from the SwingX project has a method to set a RowFilter
directly on the JXTable
(see JXTable#setRowFilter
). SwingX 项目中的
JXTable
有一个方法可以直接在JXTable
上设置RowFilter
(参见JXTable#setRowFilter
)。
It is unclear to me what you need to do when the filter implementation is dynamic.我不清楚当过滤器实现是动态的时你需要做什么。
To compare: in the JDK they introduced the RowSorter
interface in JDK1.6, and this interface allows to attach a RowSorterListener
.比较:在JDK1.6中引入了
RowSorter
接口,该接口允许附加一个RowSorterListener
。 If you have a dynamic RowSorter
(which can also be used for filtering), you can fire an event to those listeners when the filter changes (although this requires that the filter has access to the RowSorter
as there is no such thing as a DynamicRowFilter
or RowFilterEvent
in the JDK).如果您有动态
RowSorter
(也可用于过滤),您可以在过滤器更改时向这些侦听器触发事件(尽管这要求过滤器有权访问RowSorter
因为没有DynamicRowFilter
或JDK 中的RowFilterEvent
)。
What I would expect is that I can set an "observable" RowFilter
on the JXTable
and that I have to do nothing.我期望的是我可以在
JXTable
上设置一个“可观察的” RowFilter
,而我什么都不用做。 But as that seems not to be possible with the current API, what is the next best thing ?但是由于当前的 API 似乎无法实现,那么下一个最好的事情是什么?
JXTable
?JXTable
上设置的实例JXTable
?setRowFilter
method and create your own TableRowSorter
and fall back on the JDK API.setRowFilter
方法并创建自己的TableRowSorter
并依靠 JDK API。The use-case we have is a filter (not a rowfilter) which can be changed to filter out elements of a model, and we have a RowFilter based on that dynamic filter to filter out those elements
我们拥有的用例是一个过滤器(不是 rowfilter),它可以更改以过滤掉模型的元素,并且我们有一个基于该动态过滤器的 RowFilter 来过滤掉这些元素
Repeating my comment: the RowFilter must be immutable.重复我的评论:RowFilter 必须是不可变的。 That was a concious design decision back when sorting/filtering was introduced into core.
当排序/过滤被引入核心时,这是一个有意识的设计决定。 So the approach to implement "dynamic" filtering is to
所以实现“动态”过滤的方法是
Edit编辑
I don't agree with that design, but couldn't sway him
我不同意那个设计,但不能动摇他
should be: I didn't agree - meanwhile, I'm not so sure as I had been ;-)应该是:我不同意- 同时,我不像以前那样确定 ;-)
The advantage of this approach is that the RowFilter is really small coin to implement and highly re-usable - just a simple predicate, nothing else.这种方法的优点是 RowFilter 实现起来真的很小,而且高度可重用——只是一个简单的谓词,没有别的。 That allows simple logic compounding (and/or) of filters.
这允许过滤器的简单逻辑复合(和/或)。 No burden to notify on part of the filter, no burden on part of the sorter (or compound filter) to listen and update itself.
没有负担通知部分过滤器,也没有负担分拣机(或复合过滤器)的一部分来监听和更新自己。 Then taking into account that the "dynamics" of the filter change often comes from user interaction and something has to listen to those user triggers anyway, it's not a big deal to create a new rowFilter vs. updating an existing rowFilter.
再考虑到该更换过滤器的“动态”往往来自于用户交互和东西已经听那些用户触发,无论如何,这不是一个大问题,以创建一个新的RowFilter与更新现有的RowFilter。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.