Home | History | Annotate | Download | only in table
      1 package autotest.common.table;
      2 
      3 import com.google.gwt.json.client.JSONArray;
      4 import com.google.gwt.json.client.JSONString;
      5 import com.google.gwt.json.client.JSONValue;
      6 
      7 public class MultipleListFilter extends ListFilter {
      8     protected int maxVisibleSize;
      9 
     10     public MultipleListFilter(String fieldName, int maxVisibleSize) {
     11         super(fieldName);
     12         this.maxVisibleSize = maxVisibleSize;
     13     }
     14 
     15     @Override
     16     protected boolean isMultipleSelect() {
     17         return true;
     18     }
     19 
     20     @Override
     21     public JSONValue getMatchValue() {
     22         JSONArray labels = new JSONArray();
     23         // skip first item ("all values")
     24         for (int i = 1; i < select.getItemCount(); i++) {
     25             if (select.isItemSelected(i)) {
     26                 labels.set(labels.size(),
     27                            new JSONString(getItemText(i)));
     28             }
     29         }
     30         return labels;
     31     }
     32 
     33     @Override
     34     public boolean isActive() {
     35         return true;
     36     }
     37 
     38     @Override
     39     public void setChoices(String[] choices) {
     40         super.setChoices(choices);
     41         int visibleSize = Math.min(select.getItemCount(), maxVisibleSize);
     42         select.setVisibleItemCount(visibleSize);
     43         select.setSelectedIndex(0);
     44     }
     45 }
     46