picker.setSelectedDate(d);
return picker;
}
private Widget stylingPicker() {
final DatePicker picker = new DatePicker();
HorizontalPanel panel = new HorizontalPanel();
panel.add(picker);
VerticalPanel styling = new VerticalPanel();
panel.add(styling);
// 5th of each month is red.
RenderingHandler redHandler = new RenderingHandler() {
public void onRendered(RenderingEvent event) {
Date shown = picker.getDateShown();
Date d = new Date();
d.setYear(shown.getYear());
d.setMonth(shown.getMonth());
d.setDate(5);
picker.addVisibleDateStyle(d, "red-date");
}
};
styling.add(toggleHandler("5th of the month will be red", picker,
redHandler));
// Random style adder.
ChangeHandler<Date> randomStyles = new ChangeHandler<Date>() {
String[] styles = {
"blue-background", "green-border", "red-text", "big-text",
"green-background", "underlined-and-bold-text", "yellow-background"};
int styleIndex = 0;
public void onChange(ChangeEvent<Date> event) {
if (event.getNewValue() != null) {
styleIndex = ++styleIndex % styles.length;
String styling = styles[styleIndex];
Log.info(event.getNewValue() + " has style " + styling, "styling");
picker.addGlobalDateStyle(event.getNewValue(), styling);
}
}
};
styling.add(toggleHandler("Add random style to selected date", picker,
randomStyles));
// Visibly disable selected date.
ChangeHandler<Date> disabler = new ChangeHandler<Date>() {
public void onChange(ChangeEvent<Date> event) {
if (event.getNewValue() != null) {
picker.setVisibleDateEnabled(event.getNewValue(), false);
}
}
};
styling.add(toggleHandler("Disable selected date", picker, disabler));
return panel;