private Widget dateRange() {
VerticalPanel v = new VerticalPanel();
HorizontalPanel p = new HorizontalPanel();
v.add(p);
start = new DateBox();
final DateBox end = new DateBox();
start.addKeyDownHandler(new KeyDownHandler() {
public void onKeyDown(KeyDownEvent e) {
if (e.getKeyCode() == KEY_RIGHT
&& start.getCursorPos() == start.getText().length()) {
start.hideDatePicker();
end.setFocus(true);
}
}
});
end.addKeyDownHandler(new KeyDownHandler() {
public void onKeyDown(KeyDownEvent e) {
if ((e.getKeyCode() == KEY_LEFT) && end.getCursorPos() == 0) {
start.setFocus(true);
end.hideDatePicker();
}
}
});
end.getDatePicker().addChangeHandler(new ChangeHandler<Date>() {
public void onChange(ChangeEvent<Date> event) {
start.removeStyleName("user-modified");
}
});
start.showDate(new Date());
p.add(start);
Label l = new Label(" - ");
l.setStyleName("filler");
p.add(l);
p.add(end);
HorizontalPanel h2 = new HorizontalPanel();
v.add(h2);
h2.add(new Button("Short format", new ClickListener() {
public void onClick(Widget sender) {
start.setDateFormat(DateTimeFormat.getShortDateFormat());
end.setDateFormat(DateTimeFormat.getShortDateFormat());
}
}));
h2.add(new Button("Long format", new ClickListener() {
public void onClick(Widget sender) {
start.setDateFormat(DateTimeFormat.getLongDateFormat());
end.setDateFormat(DateTimeFormat.getLongDateFormat());
}
}));
return v;
}