final List entries = entrySource.getEntries(date,
DateTimeService.RESOLUTION_DAY);
int currentCol = 1;
for (final Iterator it = entries.iterator(); it.hasNext();) {
final CalendarEntry entry = (CalendarEntry) it.next();
int start = 0;
int hours = 24;
if (!entry.isNotime()) {
Date d = entry.getStart();
// TODO consider month&year as well
start = (d.getDate() < date.getDate() ? 0 : d.getHours());
d = entry.getEnd();
hours = (d.getDate() > date.getDate() ? 24 : d.getHours())
- start;
if (hours < 1) {
// We can't draw entries smaller than
// one
hours = 1;
}
}
int col = currentCol;
if (col > 1) {
while (!hourTable.isCellPresent(start, col - 1)) {
col--;
}
}
hourTable.setHTML(start, col, "<span>"
+ (entry.getTitle() != null ? entry.getTitle() : " ")
+ "</span>");
hourTable.getFlexCellFormatter().setRowSpan(start, col, hours);
hourTable.getFlexCellFormatter().setStyleName(start, col,
CLASSNAME + "-entry");
final String sn = entry.getStyleName();
if (sn != null && !sn.equals("")) {
hourTable.getFlexCellFormatter().addStyleName(start, col,
CLASSNAME + "-" + entry.getStyleName());
}
final Element el = hourTable.getFlexCellFormatter().getElement(
start, col);
String tooltip;
if (DateTimeService.isSameDay(entry.getStart(), entry.getEnd())) {
tooltip = (start < 10 ? "0" : "") + start + ":00";
if (dts.isTwelveHourClock()) {
final String ampm = (start < 12 ? "am" : "pm");
tooltip = (start <= 12 ? start : start - 12) + ":00 "
+ ampm;
}
tooltip += " (" + hours + "h) ";
if (entry.getTitle() != null) {
tooltip += entry.getTitle() + "\n ";
}
} else {
tooltip = entry.getStringForDate(entry.getEnd()) + "\n ";
}
if (entry.getDescription() != null) {
tooltip += "\"" + entry.getDescription() + "\"";
}
DOM.setElementProperty(el, "title", tooltip);
currentCol++;
}