From: Marc Englund Date: Tue, 23 Oct 2007 06:58:59 +0000 (+0000) Subject: ICalendar -> demo.reservation X-Git-Tag: 6.7.0.beta1~5789 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=81c77001f3209e2860192654128425fb438b5cc9;p=vaadin-framework.git ICalendar -> demo.reservation svn changeset:2581/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/demo/reservation/gwt/client/WidgetSet.java b/src/com/itmill/toolkit/demo/reservation/gwt/client/WidgetSet.java index 6ab247405a..f5a626017e 100644 --- a/src/com/itmill/toolkit/demo/reservation/gwt/client/WidgetSet.java +++ b/src/com/itmill/toolkit/demo/reservation/gwt/client/WidgetSet.java @@ -2,6 +2,7 @@ package com.itmill.toolkit.demo.reservation.gwt.client; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.Widget; +import com.itmill.toolkit.demo.reservation.gwt.client.ui.ICalendar; import com.itmill.toolkit.demo.reservation.gwt.client.ui.IGoogleMap; import com.itmill.toolkit.terminal.gwt.client.DefaultWidgetSet; import com.itmill.toolkit.terminal.gwt.client.UIDL; @@ -12,6 +13,9 @@ public class WidgetSet extends DefaultWidgetSet { if ("com.itmill.toolkit.terminal.gwt.client.ui.IGoogleMap" .equals(className)) { return new IGoogleMap(); + } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ICalendar" + .equals(className)) { + return new ICalendar(); } return super.createWidget(uidl); @@ -22,6 +26,8 @@ public class WidgetSet extends DefaultWidgetSet { String tag = uidl.getTag(); if ("googlemap".equals(tag)) { return "com.itmill.toolkit.terminal.gwt.client.ui.IGoogleMap"; + } else if ("calendarfield".equals(tag)) { + return "com.itmill.toolkit.terminal.gwt.client.ui.ICalendar"; } return super.resolveWidgetTypeName(uidl); diff --git a/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/CalendarEntry.java b/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/CalendarEntry.java new file mode 100644 index 0000000000..424a4ff586 --- /dev/null +++ b/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/CalendarEntry.java @@ -0,0 +1,122 @@ +package com.itmill.toolkit.demo.reservation.gwt.client.ui; + +import java.util.Date; + +import com.itmill.toolkit.terminal.gwt.client.DateTimeService; + +public class CalendarEntry { + private String styleName; + private Date start; + private Date end; + private String title; + private String description; + private boolean notime; + + public CalendarEntry(String styleName, Date start, Date end, String title, + String description, boolean notime) { + this.styleName = styleName; + if (notime) { + Date d = new Date(start.getTime()); + d.setSeconds(0); + d.setMinutes(0); + this.start = d; + if (end != null) { + d = new Date(end.getTime()); + d.setSeconds(0); + d.setMinutes(0); + this.end = d; + } else { + end = start; + } + } else { + this.start = start; + this.end = end; + } + this.title = title; + this.description = description; + this.notime = notime; + } + + public CalendarEntry(String styleName, Date start, Date end, String title, + String description) { + this(styleName, start, end, title, description, false); + } + + public String getStyleName() { + return styleName; + } + + public Date getStart() { + return start; + } + + public void setStart(Date start) { + this.start = start; + } + + public Date getEnd() { + return end; + } + + public void setEnd(Date end) { + this.end = end; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean isNotime() { + return notime; + } + + public void setNotime(boolean notime) { + this.notime = notime; + } + + public String getStringForDate(Date d) { + // TODO format from DateTimeService + String s = ""; + if (!notime) { + if (!DateTimeService.isSameDay(d, start)) { + s += (start.getYear() + 1900) + "." + (start.getMonth() + 1) + + "." + start.getDate() + " "; + } + int i = start.getHours(); + s += (i < 10 ? "0" : "") + i; + s += ":"; + i = start.getMinutes(); + s += (i < 10 ? "0" : "") + i; + if (!start.equals(end)) { + s += " - "; + if (!DateTimeService.isSameDay(start, end)) { + s += (end.getYear() + 1900) + "." + (end.getMonth() + 1) + + "." + end.getDate() + " "; + } + i = end.getHours(); + s += (i < 10 ? "0" : "") + i; + s += ":"; + i = end.getMinutes(); + s += (i < 10 ? "0" : "") + i; + } + s += " "; + } + if (title!=null) { + s += title; + } + return s; + } + +} \ No newline at end of file diff --git a/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/ICalendar.java b/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/ICalendar.java new file mode 100644 index 0000000000..03845a8e22 --- /dev/null +++ b/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/ICalendar.java @@ -0,0 +1,271 @@ +package com.itmill.toolkit.demo.reservation.gwt.client.ui; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Element; +import com.google.gwt.user.client.ui.FlexTable; +import com.google.gwt.user.client.ui.SimplePanel; +import com.google.gwt.user.client.ui.SourcesTableEvents; +import com.google.gwt.user.client.ui.TableListener; +import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; +import com.itmill.toolkit.terminal.gwt.client.DateTimeService; +import com.itmill.toolkit.terminal.gwt.client.UIDL; +import com.itmill.toolkit.terminal.gwt.client.ui.CalendarPanel; +import com.itmill.toolkit.terminal.gwt.client.ui.IDateField; +import com.itmill.toolkit.terminal.gwt.client.ui.CalendarPanel.CalendarEntrySource; + +public class ICalendar extends IDateField { + + private CalendarPanel calPanel; + + private SimplePanel hourPanel; + + private FlexTable hourTable; + + private EntrySource entrySource; + + private TableListener ftListener = new HourTableListener(); + + private int realResolution = RESOLUTION_DAY; + + private static final String CLASSNAME = IDateField.CLASSNAME + + "-entrycalendar"; + + public ICalendar() { + super(); + setStyleName(CLASSNAME); + calPanel = new CalendarPanel(this); + add(calPanel); + this.entrySource = new EntrySource(); + calPanel.setCalendarEntrySource(this.entrySource); + calPanel.addTableListener(new TableListener() { + public void onCellClicked(SourcesTableEvents sender, int row, + int cell) { + buildDayView(date); + } + }); + } + + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { + super.updateFromUIDL(uidl, client); + // We want to draw our own hour list + this.realResolution = currentResolution; + this.currentResolution = RESOLUTION_DAY; + if (uidl.hasAttribute("min")) { + String mins = uidl.getStringAttribute("min"); + long min = (mins != null ? Long.parseLong(mins) : 0); + String maxs = uidl.getStringAttribute("max"); + long max = (maxs != null ? Long.parseLong(maxs) : 0); + Date minDate = (min > 0 ? new Date(min) : null); + Date maxDate = (max > 0 ? new Date(max) : null); + calPanel.setLimits(minDate, maxDate); + } + this.entrySource.clear(); + for (Iterator cit = uidl.getChildIterator(); cit.hasNext();) { + UIDL child = (UIDL) cit.next(); + if (child.getTag().equals("items")) { + for (Iterator iit = child.getChildIterator(); iit.hasNext();) { + UIDL item = (UIDL) iit.next(); + this.entrySource.addItem(item); + } + break; + } + } + calPanel.updateCalendar(); + buildDayView(this.date); + } + + protected void buildDayView(Date date) { + boolean firstRender = true; + if (this.hourPanel == null) { + this.hourPanel = new SimplePanel(); + this.hourPanel.setStyleName(CLASSNAME + "-hours"); + this.calPanel.getFlexCellFormatter().setColSpan(8, 0, 7); + this.calPanel.setWidget(8, 0, this.hourPanel); + } else { + firstRender = false; + this.hourPanel.clear(); + } + this.hourTable = new FlexTable(); + this.hourTable.addTableListener(this.ftListener); + this.hourPanel.add(this.hourTable); + this.hourTable.setCellSpacing(1); + + for (int i = 0; i < 24; i++) { + String style = (i % 2 == 0 ? "even" : "odd"); + if (realResolution >= RESOLUTION_HOUR) { + if (this.date != null && this.date.getHours() == i) { + style = "selected"; + } + } + hourTable.getRowFormatter().setStyleName(i, + CLASSNAME + "-row-" + style); + String hstr = (i < 10 ? "0" : "") + i + ":00"; + if (this.dts.isTwelveHourClock()) { + String ampm = (i < 12 ? "am" : "pm"); + hstr = (i <= 12 ? i : i - 12) + ":00 " + ampm; + } + hourTable.setHTML(i, 0, "" + hstr + ""); + hourTable.getCellFormatter() + .setStyleName(i, 0, CLASSNAME + "-time"); + } + + List entries = this.entrySource.getEntries(date, + DateTimeService.RESOLUTION_DAY); + int currentCol = 1; + for (Iterator it = entries.iterator(); it.hasNext();) { + 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 == 0) { + // We can't draw entries smaller than one + hours = 1; + } + } + int col = currentCol; + if (col > 1) { + while (!this.hourTable.isCellPresent(start, col - 1)) + col--; + } + this.hourTable.setHTML(start, col, "" + + (entry.getTitle() != null ? entry.getTitle() : " ") + + ""); + this.hourTable.getFlexCellFormatter().setRowSpan(start, col, hours); + this.hourTable.getFlexCellFormatter().setStyleName(start, col, + CLASSNAME + "-entry"); + String sn = entry.getStyleName(); + if (sn != null && !sn.equals("")) { + this.hourTable.getFlexCellFormatter().addStyleName(start, col, + CLASSNAME + "-" + entry.getStyleName()); + } + Element el = this.hourTable.getFlexCellFormatter().getElement( + start, col); + + String tooltip; + if (DateTimeService.isSameDay(entry.getStart(), entry.getEnd())) { + tooltip = (start < 10 ? "0" : "") + start + ":00"; + if (this.dts.isTwelveHourClock()) { + 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++; + } + + // int hour = new Date().getHours()+1; // scroll to current hour + int hour = this.date.getHours() + 1; // scroll to selected hour + int h1 = (int) this.hourPanel.getOffsetHeight() / 2; + int oh = this.hourTable.getOffsetHeight(); + int h2 = (int) (hour / 24.0 * oh); + int scrollTop = (int) h2 - h1; + Element el = this.hourPanel.getElement(); + setScrollTop(el, scrollTop); + + } + + private native void setScrollTop(Element el, int scrollTop) /*-{ + el.scrollTop = scrollTop; + }-*/; + + private class HourTableListener implements TableListener { + + public void onCellClicked(SourcesTableEvents sender, int row, int cell) { + if (realResolution < RESOLUTION_HOUR || date == null) { + return; + } + date.setHours(row); + client.updateVariable(id, "hour", row, immediate); + } + + } + + private class EntrySource implements CalendarPanel.CalendarEntrySource { + + private HashMap dates = new HashMap(); + + public void addItem(UIDL item) { + String styleName = item.getStringAttribute("styleName"); + Integer id = new Integer(item.getIntAttribute("id")); + long start = Long.parseLong(item.getStringAttribute("start")); + Date startDate = new Date(start); + long end = -1; + try { + end = Long.parseLong(item.getStringAttribute("end")); + } catch (Exception IGNORED) { + // IGNORED attribute not required + } + Date endDate = (end > 0 && end != start ? new Date(end) : new Date( + start)); + String title = item.getStringAttribute("title"); + String desc = item.getStringAttribute("description"); + boolean notime = item.getBooleanAttribute("notime"); + CalendarEntry entry = new CalendarEntry(styleName, startDate, + endDate, title, desc, notime); + + // TODO should remove+readd if the same entry (id) is added again + + for (Date d = entry.getStart(); d.getYear() <= entry.getEnd() + .getYear() + && d.getMonth() <= entry.getEnd().getYear() + && d.getDate() <= entry.getEnd().getDate(); d.setTime(d + .getTime() + 86400000)) { + String key = d.getYear() + "" + d.getMonth() + "" + d.getDate(); + ArrayList l = (ArrayList) dates.get(key); + if (l == null) { + l = new ArrayList(); + dates.put(key, l); + } + l.add(entry); + } + } + + public List getEntries(Date date, int resolution) { + List entries = (List) dates.get(date.getYear() + "" + + date.getMonth() + "" + date.getDate()); + ArrayList res = new ArrayList(); + if (entries == null) { + return res; + } + for (Iterator it = entries.iterator(); it.hasNext();) { + CalendarEntry item = (CalendarEntry) it.next(); + if (DateTimeService.isInRange(date, item.getStart(), item + .getEnd(), resolution)) { + res.add(item); + } + } + + return res; + } + + public void clear() { + dates.clear(); + } + + } + +} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java index d62a16122e..311ccc3bf4 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java @@ -3,7 +3,6 @@ package com.itmill.toolkit.terminal.gwt.client; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.Widget; import com.itmill.toolkit.terminal.gwt.client.ui.IButton; -import com.itmill.toolkit.terminal.gwt.client.ui.ICalendar; import com.itmill.toolkit.terminal.gwt.client.ui.ICheckBox; import com.itmill.toolkit.terminal.gwt.client.ui.ICustomLayout; import com.itmill.toolkit.terminal.gwt.client.ui.IDateFieldCalendar; @@ -119,9 +118,6 @@ public class DefaultWidgetSet implements WidgetSet { } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IDateFieldCalendar" .equals(className)) { return new IDateFieldCalendar(); - } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ICalendar" - .equals(className)) { - return new ICalendar(); } else if ("com.itmill.toolkit.terminal.gwt.client.ui.ITextualDate" .equals(className)) { return new ITextualDate(); @@ -237,8 +233,6 @@ public class DefaultWidgetSet implements WidgetSet { } else { return "com.itmill.toolkit.terminal.gwt.client.ui.IPopupCalendar"; } - } else if ("calendarfield".equals(tag)) { - return "com.itmill.toolkit.terminal.gwt.client.ui.ICalendar"; } else if ("slider".equals(tag)) { return "com.itmill.toolkit.terminal.gwt.client.ui.ISlider"; } else if ("form".equals(tag)) { diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarEntry.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarEntry.java deleted file mode 100644 index 075f68cbf6..0000000000 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarEntry.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.itmill.toolkit.terminal.gwt.client.ui; - -import java.util.Date; - -import com.itmill.toolkit.terminal.gwt.client.DateTimeService; - -public class CalendarEntry { - private String styleName; - private Date start; - private Date end; - private String title; - private String description; - private boolean notime; - - public CalendarEntry(String styleName, Date start, Date end, String title, - String description, boolean notime) { - this.styleName = styleName; - if (notime) { - Date d = new Date(start.getTime()); - d.setSeconds(0); - d.setMinutes(0); - this.start = d; - if (end != null) { - d = new Date(end.getTime()); - d.setSeconds(0); - d.setMinutes(0); - this.end = d; - } else { - end = start; - } - } else { - this.start = start; - this.end = end; - } - this.title = title; - this.description = description; - this.notime = notime; - } - - public CalendarEntry(String styleName, Date start, Date end, String title, - String description) { - this(styleName, start, end, title, description, false); - } - - public String getStyleName() { - return styleName; - } - - public Date getStart() { - return start; - } - - public void setStart(Date start) { - this.start = start; - } - - public Date getEnd() { - return end; - } - - public void setEnd(Date end) { - this.end = end; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public boolean isNotime() { - return notime; - } - - public void setNotime(boolean notime) { - this.notime = notime; - } - - public String getStringForDate(Date d) { - // TODO format from DateTimeService - String s = ""; - if (!notime) { - if (!DateTimeService.isSameDay(d, start)) { - s += (start.getYear() + 1900) + "." + (start.getMonth() + 1) - + "." + start.getDate() + " "; - } - int i = start.getHours(); - s += (i < 10 ? "0" : "") + i; - s += ":"; - i = start.getMinutes(); - s += (i < 10 ? "0" : "") + i; - if (!start.equals(end)) { - s += " - "; - if (!DateTimeService.isSameDay(start, end)) { - s += (end.getYear() + 1900) + "." + (end.getMonth() + 1) - + "." + end.getDate() + " "; - } - i = end.getHours(); - s += (i < 10 ? "0" : "") + i; - s += ":"; - i = end.getMinutes(); - s += (i < 10 ? "0" : "") + i; - } - s += " "; - } - if (title!=null) { - s += title; - } - return s; - } - -} \ No newline at end of file diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarPanel.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarPanel.java index 0fc60e25dc..6eb7749f26 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarPanel.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarPanel.java @@ -15,6 +15,7 @@ import com.google.gwt.user.client.ui.SourcesMouseEvents; import com.google.gwt.user.client.ui.SourcesTableEvents; import com.google.gwt.user.client.ui.TableListener; import com.google.gwt.user.client.ui.Widget; +import com.itmill.toolkit.demo.reservation.gwt.client.ui.CalendarEntry; import com.itmill.toolkit.terminal.gwt.client.DateTimeService; import com.itmill.toolkit.terminal.gwt.client.LocaleService; diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java deleted file mode 100644 index ec429ac4b5..0000000000 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java +++ /dev/null @@ -1,268 +0,0 @@ -package com.itmill.toolkit.terminal.gwt.client.ui; - -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.Element; -import com.google.gwt.user.client.ui.FlexTable; -import com.google.gwt.user.client.ui.SimplePanel; -import com.google.gwt.user.client.ui.SourcesTableEvents; -import com.google.gwt.user.client.ui.TableListener; -import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; -import com.itmill.toolkit.terminal.gwt.client.DateTimeService; -import com.itmill.toolkit.terminal.gwt.client.UIDL; - -public class ICalendar extends IDateField { - - private CalendarPanel calPanel; - - private SimplePanel hourPanel; - - private FlexTable hourTable; - - private EntrySource entrySource; - - private TableListener ftListener = new HourTableListener(); - - private int realResolution = RESOLUTION_DAY; - - private static final String CLASSNAME = IDateField.CLASSNAME - + "-entrycalendar"; - - public ICalendar() { - super(); - setStyleName(CLASSNAME); - calPanel = new CalendarPanel(this); - add(calPanel); - this.entrySource = new EntrySource(); - calPanel.setCalendarEntrySource(this.entrySource); - calPanel.addTableListener(new TableListener() { - public void onCellClicked(SourcesTableEvents sender, int row, - int cell) { - buildDayView(date); - } - }); - } - - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - super.updateFromUIDL(uidl, client); - // We want to draw our own hour list - this.realResolution = currentResolution; - this.currentResolution = RESOLUTION_DAY; - if (uidl.hasAttribute("min")) { - String mins = uidl.getStringAttribute("min"); - long min = (mins != null ? Long.parseLong(mins) : 0); - String maxs = uidl.getStringAttribute("max"); - long max = (maxs != null ? Long.parseLong(maxs) : 0); - Date minDate = (min > 0 ? new Date(min) : null); - Date maxDate = (max > 0 ? new Date(max) : null); - calPanel.setLimits(minDate, maxDate); - } - this.entrySource.clear(); - for (Iterator cit = uidl.getChildIterator(); cit.hasNext();) { - UIDL child = (UIDL) cit.next(); - if (child.getTag().equals("items")) { - for (Iterator iit = child.getChildIterator(); iit.hasNext();) { - UIDL item = (UIDL) iit.next(); - this.entrySource.addItem(item); - } - break; - } - } - calPanel.updateCalendar(); - buildDayView(this.date); - } - - protected void buildDayView(Date date) { - boolean firstRender = true; - if (this.hourPanel == null) { - this.hourPanel = new SimplePanel(); - this.hourPanel.setStyleName(CLASSNAME + "-hours"); - this.calPanel.getFlexCellFormatter().setColSpan(8, 0, 7); - this.calPanel.setWidget(8, 0, this.hourPanel); - } else { - firstRender = false; - this.hourPanel.clear(); - } - this.hourTable = new FlexTable(); - this.hourTable.addTableListener(this.ftListener); - this.hourPanel.add(this.hourTable); - this.hourTable.setCellSpacing(1); - - for (int i = 0; i < 24; i++) { - String style = (i % 2 == 0 ? "even" : "odd"); - if (realResolution >= RESOLUTION_HOUR) { - if (this.date != null && this.date.getHours() == i) { - style = "selected"; - } - } - hourTable.getRowFormatter().setStyleName(i, - CLASSNAME + "-row-" + style); - String hstr = (i < 10 ? "0" : "") + i + ":00"; - if (this.dts.isTwelveHourClock()) { - String ampm = (i < 12 ? "am" : "pm"); - hstr = (i <= 12 ? i : i - 12) + ":00 " + ampm; - } - hourTable.setHTML(i, 0, "" + hstr + ""); - hourTable.getCellFormatter() - .setStyleName(i, 0, CLASSNAME + "-time"); - } - - List entries = this.entrySource.getEntries(date, - DateTimeService.RESOLUTION_DAY); - int currentCol = 1; - for (Iterator it = entries.iterator(); it.hasNext();) { - 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 == 0) { - // We can't draw entries smaller than one - hours = 1; - } - } - int col = currentCol; - if (col > 1) { - while (!this.hourTable.isCellPresent(start, col - 1)) - col--; - } - this.hourTable.setHTML(start, col, "" - + (entry.getTitle() != null ? entry.getTitle() : " ") - + ""); - this.hourTable.getFlexCellFormatter().setRowSpan(start, col, hours); - this.hourTable.getFlexCellFormatter().setStyleName(start, col, - CLASSNAME + "-entry"); - String sn = entry.getStyleName(); - if (sn != null && !sn.equals("")) { - this.hourTable.getFlexCellFormatter().addStyleName(start, col, - CLASSNAME + "-" + entry.getStyleName()); - } - Element el = this.hourTable.getFlexCellFormatter().getElement( - start, col); - - String tooltip; - if (DateTimeService.isSameDay(entry.getStart(), entry.getEnd())) { - tooltip = (start < 10 ? "0" : "") + start + ":00"; - if (this.dts.isTwelveHourClock()) { - 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++; - } - - // int hour = new Date().getHours()+1; // scroll to current hour - int hour = this.date.getHours() + 1; // scroll to selected hour - int h1 = (int) this.hourPanel.getOffsetHeight() / 2; - int oh = this.hourTable.getOffsetHeight(); - int h2 = (int) (hour / 24.0 * oh); - int scrollTop = (int) h2 - h1; - Element el = this.hourPanel.getElement(); - setScrollTop(el, scrollTop); - - } - - private native void setScrollTop(Element el, int scrollTop) /*-{ - el.scrollTop = scrollTop; - }-*/; - - private class HourTableListener implements TableListener { - - public void onCellClicked(SourcesTableEvents sender, int row, int cell) { - if (realResolution < RESOLUTION_HOUR || date == null) { - return; - } - date.setHours(row); - client.updateVariable(id, "hour", row, immediate); - } - - } - - private class EntrySource implements CalendarPanel.CalendarEntrySource { - - private HashMap dates = new HashMap(); - - public void addItem(UIDL item) { - String styleName = item.getStringAttribute("styleName"); - Integer id = new Integer(item.getIntAttribute("id")); - long start = Long.parseLong(item.getStringAttribute("start")); - Date startDate = new Date(start); - long end = -1; - try { - end = Long.parseLong(item.getStringAttribute("end")); - } catch (Exception IGNORED) { - // IGNORED attribute not required - } - Date endDate = (end > 0 && end != start ? new Date(end) : new Date( - start)); - String title = item.getStringAttribute("title"); - String desc = item.getStringAttribute("description"); - boolean notime = item.getBooleanAttribute("notime"); - CalendarEntry entry = new CalendarEntry(styleName, startDate, - endDate, title, desc, notime); - - // TODO should remove+readd if the same entry (id) is added again - - for (Date d = entry.getStart(); d.getYear() <= entry.getEnd() - .getYear() - && d.getMonth() <= entry.getEnd().getYear() - && d.getDate() <= entry.getEnd().getDate(); d.setTime(d - .getTime() + 86400000)) { - String key = d.getYear() + "" + d.getMonth() + "" + d.getDate(); - ArrayList l = (ArrayList) dates.get(key); - if (l == null) { - l = new ArrayList(); - dates.put(key, l); - } - l.add(entry); - } - } - - public List getEntries(Date date, int resolution) { - List entries = (List) dates.get(date.getYear() + "" - + date.getMonth() + "" + date.getDate()); - ArrayList res = new ArrayList(); - if (entries == null) { - return res; - } - for (Iterator it = entries.iterator(); it.hasNext();) { - CalendarEntry item = (CalendarEntry) it.next(); - if (DateTimeService.isInRange(date, item.getStart(), item - .getEnd(), resolution)) { - res.add(item); - } - } - - return res; - } - - public void clear() { - dates.clear(); - } - - } - -} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IDateField.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IDateField.java index 12635655be..53859ddf6e 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IDateField.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IDateField.java @@ -13,9 +13,9 @@ public class IDateField extends FlowPanel implements Paintable { public static final String CLASSNAME = "i-datefield"; - String id; + protected String id; - ApplicationConnection client; + protected ApplicationConnection client; protected boolean immediate;