最最最简单的一个GWT的下拉单选框。(对于初学者来说,什么都要从头学起呀。)
lastDays = new SimpleComboBox<String>();
lastDays.setTriggerAction(TriggerAction.ALL);
lastDays.setEditable(false);
lastDays.setForceSelection(true);
lastDays.setFireChangeEventOnSetValue(true);
lastDays.setWidth(70);
lastDays.add("1");
lastDays.add("2");
lastDays.add("10");
lastDays.add("30");
lastDays.add("90");
lastDays.add("All");
lastDays.setSimpleValue("2");
lastDays.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<String>>() {
@Override
public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
String value = se.getSelectedItem().getValue();
if ("All".equals(value)) {
loader.setFilterconfigs(new ArrayList<FilterConfig>());
addDateFilter();
} else {
setDateRange(value);
removeDateFilter();
}
loader.load();
}
private void addDateFilter() {
GridFilters filters = grid.getFilters();
filters.addFilter(new DateFilter(Event.TIMESTAMP));
grid.setFilters(filters);
}
private void removeDateFilter() {
GridFilters filters = grid.getFilters();
if (filters.getFilter(Event.TIMESTAMP) != null) {
filters.getFilter(Event.TIMESTAMP).setActive(false, false);
filters.updateColumnHeadings();
filters.removeFilter(filters.getFilter(Event.TIMESTAMP));
}
grid.setFilters(filters);
}
});