cal.setHandler(new BasicBackwardHandler() { protected void setDates(BackwardEvent event,
Date start, Date end) {
java.util.Calendar calendar = event.getComponent()
.getInternalCalendar();
if (isThisYear(calendar, end)
&& isThisYear(calendar, start)) { super.setDates(event, start, end);
}
}});
The forward navigation handler can be implemented in the same way. The example handler restricts the dates to the current year.
18.9.4. Date Click Handling
By default, clicking a date either in month or week view switches single-day view. The date click event is handled by a DateClickHandler.
The following example handles click events so that when the user clicks the date header in the weekly view, it will switch to single-day view, and in the single-day view switch back to the weekly view.
cal.setHandler(new BasicDateClickHandler() { public void dateClick(DateClickEvent event) {
Calendar cal = event.getComponent();
long currentCalDateRange = cal.getEndDate().getTime()
- cal.getStartDate().getTime();
if (currentCalDateRange < VCalendar.DAYINMILLIS) {
//Change the date range to the current week cal.setStartDate(cal.getFirstDateForWeek(event.getDate())); cal.setEndDate(cal.getLastDateForWeek(event.getDate()));
}else {
//Default behaviour, change date range to one day super.dateClick(event);
}
}
});
18.9.5. Handling Week Clicks
The monthly view displays week numbers for each week row on the left side of the date grid. The week number are clickable and you can handle the click events by setting a WeekClickHandler for the Calendar object. The default handler changes the date range to be the clicked week.
In the following example, we add a week click handler that changes the date range of the calendar to one week only if the start and end dates of the week are in the current month.
cal.setHandler(new BasicWeekClickHandler() { protected void setDates(WeekClick event,
Date start, Date end) { java.util.Calendar calendar = event.getComponent()
.getInternalCalendar(); if (isThisMonth(calendar, start)
&& isThisMonth(calendar, end)) { super.setDates(event, start, end);
}
}
});