我有一个TwinColSelect和一个Textfield我用它来过滤表的内容,它运行得很好,但问题是过滤器过滤了TwinColSelect的两个列的内容,我想知道它是否可能它只影响左栏。
我的代码现在看起来像这样:
final TwinColSelect select = new TwinColSelect();
select.setItemCaptionPropertyId(PersistenceLoinc.CORPUS_NOMBRE);
TextField filtro = new TextField();
filtro.addTextChangeListener(new TextChangeListener() {
private static final long serialVersionUID = 1L;
SimpleStringFilter filter = null;
@Override
public void textChange(TextChangeEvent event) {
Filterable f = (Filterable) select.getContainerDataSource();
if (filter != null) {
f.removeContainerFilter(filter);
}
filter = new SimpleStringFilter(select.getItemCaptionPropertyId(), event.getText(), true, false);
f.addContainerFilter(filter);
}
});
谢谢, 克里斯。
答案 0 :(得分:0)
我在问题的评论部分中遵循了@andreSchild的建议,并开发了以下完美运作的类:
public class TwinColSelectStringFilter implements Container.Filter {
final SimpleStringFilter spf;
final TwinColSelect select;
final Object propertyId;
public TwinColSelectStringFilter(Object propertyId, String filterString, boolean ignoreCase, boolean onlyMatchPrefix, TwinColSelect select) {
spf = new SimpleStringFilter(propertyId, filterString, ignoreCase, onlyMatchPrefix);
this.select = select;
this.propertyId=propertyId;
}
@Override
public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
if(select.getValue() != null && (select.getValue() instanceof Collection)) {
if (((Collection<Integer>) select.getValue()).contains(itemId)) {
return true;
}
}
return spf.passesFilter(itemId, item);
}
@Override
public boolean appliesToProperty(Object propertyId) {
return spf.appliesToProperty(propertyId);
}
}