1 package autotest.afe; 2 3 import autotest.common.table.MultipleListFilter; 4 5 import com.google.gwt.event.dom.client.ChangeEvent; 6 import com.google.gwt.event.dom.client.ChangeHandler; 7 import com.google.gwt.json.client.JSONArray; 8 import com.google.gwt.json.client.JSONString; 9 import com.google.gwt.json.client.JSONValue; 10 import com.google.gwt.user.client.ui.ListBox; 11 import com.google.gwt.user.client.ui.Widget; 12 13 public class LabelFilter extends MultipleListFilter { 14 public static final int VISIBLE_SIZE = 10; 15 private final ListBox platform; 16 LabelFilter()17 public LabelFilter() { 18 super("multiple_labels", VISIBLE_SIZE); 19 setMatchAllText("All labels"); 20 setChoices(AfeUtils.getNonPlatformLabelStrings()); 21 22 String[] platformStrings = AfeUtils.getPlatformStrings(); 23 24 platform = new ListBox(); 25 platform.addItem("All platforms"); 26 for (String platformString : platformStrings) { 27 platform.addItem(platformString); 28 } 29 platform.setStylePrimaryName("filter-box"); 30 platform.addChangeHandler(new ChangeHandler() { 31 public void onChange(ChangeEvent event) { 32 notifyListeners(); 33 } 34 }); 35 } 36 37 @Override getItemText(int index)38 protected String getItemText(int index) { 39 return AfeUtils.decodeLabelName(super.getItemText(index)); 40 } 41 getPlatformWidget()42 public Widget getPlatformWidget() { 43 return platform; 44 } 45 46 @Override getMatchValue()47 public JSONValue getMatchValue() { 48 JSONArray labels = super.getMatchValue().isArray(); 49 50 int selectedIndex = platform.getSelectedIndex(); 51 // Skip the first item ("All platforms") 52 if (selectedIndex > 0) { 53 String platformString = platform.getItemText(selectedIndex); 54 labels.set(labels.size(), new JSONString(platformString)); 55 } 56 57 return labels; 58 } 59 } 60