Tuesday, August 14, 2012

SmartGWT Calendar widget scroll to Current Time in month view

The calendar widget of smartgwt is quite powerful. But it lacks one important functionality, that is, scroll to the current time in case of month view.
But this feature can easily be enabled by working on the Workday feature which smartGWT calendar widget supports.

I wrote a simple function to achieve the same:

private void scrollToCurrentTime() {
int[] workDays = new int[1];
Date now = new Date();
workDays[0] = now.getDay();
int currentHour = now.getHours();
now.setHours(currentHour-1);
String start = DateTimeFormat.getFormat(
PredefinedFormat.TIME_SHORT).format(now);
now.setHours(currentHour+7);
String end = DateTimeFormat.getFormat(
PredefinedFormat.TIME_SHORT).format(now);
calendar.setWorkdays(workDays);
calendar.setWorkdayStart(start);
calendar.setWorkdayEnd(end);
calendar.setScrollToWorkday(true);
calendar.setShowWorkday(true);
}

1 comment:

Building Successful Products in the Maze of a Large Organization

  *Image is generated using AI Large organizations offer a treasure trove of resources and stability for product development. However, navig...