【发布时间】:2011-07-25 14:47:32
【问题描述】:
我想根据某些编辑框中的文本(在文本更改时)从 vaadin 树中隐藏叶子。 即,如果编辑框中的文本是“ab”,我只想显示以“ab”开头的文本的叶子。 如果文本为空,我想显示所有叶子。
我该怎么做?
【问题讨论】:
标签: java tree filtering vaadin
我想根据某些编辑框中的文本(在文本更改时)从 vaadin 树中隐藏叶子。 即,如果编辑框中的文本是“ab”,我只想显示以“ab”开头的文本的叶子。 如果文本为空,我想显示所有叶子。
我该怎么做?
【问题讨论】:
标签: java tree filtering vaadin
您必须过滤附加到树的数据容器。
6.6.0 版中引入了一个新的过滤器 API,它允许您创建自定义过滤器。我还没有尝试过新的 API,但在你的情况下它应该像这样工作:
textField.addListener(new FieldEvents.TextChangeListener() {
void textChange(FieldEvents.TextChangeEvent event) {
// Remove existing filter (if any).
// This is OK if you don't use any other filters, otherwise you'll have to store the previous filter and use removeContainerFilter(filter)
dataContainer.removeAllContainerFilters();
// Create a new filter which ignores case and only matches String prefix
SimpleStringFilter filter = new SimpleStringFilter(propertyId, event.getText(), true, true);
// Add the new filter
dataContainer.addContainerFilter(filter);
}
});
其中 textField 是您的“编辑框”,dataContainer 是附加到树的数据容器,properyId 是属性 ID包含要过滤的文本的容器字段。
请注意,以上代码未经测试,因为我目前无法访问相应的开发工具。
【讨论】: