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