2016-10-04 65 views
2

我有一個TwinColSelect和一個Textfield,用於過濾表格的內容,它工作的很好,但問題是過濾器過濾了TwinColSelect的兩個列的內容,而我想知道它是否可能隻影響左欄。Vaadin 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); 
     } 
    }); 

感謝, 克里斯。

+1

的唯一途徑是建立一個過濾器,其不不過濾已分配列表中的項目 –

+0

@AndréSchild嗯,好主意,男人,好主意,確實!謝謝! – crigore

回答

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); 
} 

}