From 6dd63c5f38626d63b1741ec3f7875143e903633a Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Mon, 22 Oct 2007 15:08:09 +0000 Subject: [PATCH] CalendarDemo -> com.itmill.toolkit.demo.reservation (#1016) ICalendar bug fixed. svn changeset:2580/svn branch:trunk --- WebContent/WEB-INF/web.xml | 32 +- .../demo/{ => reservation}/CalendarDemo.java | 18 +- .../demo/reservation/CalendarField.java | 13 +- .../terminal/gwt/client/ui/CalendarEntry.java | 4 +- .../terminal/gwt/client/ui/ICalendar.java | 28 +- src/com/itmill/toolkit/ui/CalendarField.java | 315 ------------------ 6 files changed, 61 insertions(+), 349 deletions(-) rename src/com/itmill/toolkit/demo/{ => reservation}/CalendarDemo.java (95%) delete mode 100644 src/com/itmill/toolkit/ui/CalendarField.java diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index c9dde12e94..5d9601c1ec 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -61,6 +61,19 @@ + + CalendarDemo + com.itmill.toolkit.terminal.gwt.server.ApplicationServlet + + application + com.itmill.toolkit.demo.reservation.CalendarDemo + + + widgetset + com.itmill.toolkit.demo.reservation.gwt.WidgetSet + + + SelectDemo com.itmill.toolkit.terminal.gwt.server.ApplicationServlet @@ -151,15 +164,6 @@ - - CalendarDemo - com.itmill.toolkit.terminal.gwt.server.ApplicationServlet - - application - com.itmill.toolkit.demo.CalendarDemo - - - TreeFilesystemContainer com.itmill.toolkit.terminal.gwt.server.ApplicationServlet @@ -273,6 +277,11 @@ /Reservr/* + + CalendarDemo + /CalendarDemo/* + + SelectDemo /SelectDemo/* @@ -328,11 +337,6 @@ /QueryContainerDemo/* - - CalendarDemo - /CalendarDemo/* - - TreeFilesystemContainer /TreeFilesystemContainer/* diff --git a/src/com/itmill/toolkit/demo/CalendarDemo.java b/src/com/itmill/toolkit/demo/reservation/CalendarDemo.java similarity index 95% rename from src/com/itmill/toolkit/demo/CalendarDemo.java rename to src/com/itmill/toolkit/demo/reservation/CalendarDemo.java index 49b3fb7ff1..413e5a36dd 100644 --- a/src/com/itmill/toolkit/demo/CalendarDemo.java +++ b/src/com/itmill/toolkit/demo/reservation/CalendarDemo.java @@ -1,12 +1,12 @@ -package com.itmill.toolkit.demo; +package com.itmill.toolkit.demo.reservation; import java.sql.SQLException; +import java.util.Calendar; import java.util.Date; import com.itmill.toolkit.data.Property.ValueChangeEvent; import com.itmill.toolkit.data.Property.ValueChangeListener; import com.itmill.toolkit.data.util.QueryContainer; -import com.itmill.toolkit.demo.reservation.CalendarField; import com.itmill.toolkit.demo.util.SampleCalendarDatabase; import com.itmill.toolkit.ui.OrderedLayout; import com.itmill.toolkit.ui.Window; @@ -45,12 +45,13 @@ public class CalendarDemo extends com.itmill.toolkit.Application { from.setResolution(CalendarField.RESOLUTION_HOUR); from.setImmediate(true); + to = new CalendarField(); main.addComponent(to); to.setResolution(CalendarField.RESOLUTION_HOUR); to.setEnabled(false); to.setImmediate(true); - + from.addListener(new ValueChangeListener() { public void valueChange(ValueChangeEvent event) { Date fd = (Date) from.getValue(); @@ -68,13 +69,14 @@ public class CalendarDemo extends com.itmill.toolkit.Application { } } }); - + // initialize the sample database and set as calendar datasource sampleDatabase = new SampleCalendarDatabase(); + initCalendars(); - + // Don't allow dates before today - from.setMinimumDate(new Date()); + from.setMinimumDate(Calendar.getInstance().getTime()); } @@ -91,7 +93,7 @@ public class CalendarDemo extends com.itmill.toolkit.Application { } catch (SQLException e) { e.printStackTrace(); } - +/* // Calendar will use the first date property as start if you do not // explicitly specify the property id. Our start -property will be the // first one, so it's intentionally left out. @@ -104,7 +106,7 @@ public class CalendarDemo extends com.itmill.toolkit.Application { to.setItemEndPropertyId(SampleCalendarDatabase.PROPERTY_ID_END); to.setItemTitlePropertyId(SampleCalendarDatabase.PROPERTY_ID_TITLE); to.setItemNotimePropertyId(SampleCalendarDatabase.PROPERTY_ID_NOTIME); - +*/ } } diff --git a/src/com/itmill/toolkit/demo/reservation/CalendarField.java b/src/com/itmill/toolkit/demo/reservation/CalendarField.java index 0dd0c4d94b..a0c217e443 100644 --- a/src/com/itmill/toolkit/demo/reservation/CalendarField.java +++ b/src/com/itmill/toolkit/demo/reservation/CalendarField.java @@ -242,7 +242,7 @@ public class CalendarField extends DateField implements Container.Viewer { if (this.dataSource != null) { target.startTag("items"); - // send one month now, the rest via lazyloading + // TODO send one month now, the rest via lazyloading int month = new Date().getMonth(); Object value = getValue(); if (value != null && value instanceof Date) { @@ -268,14 +268,19 @@ public class CalendarField extends DateField implements Container.Viewer { } } + // TODO half-done lazyloading logic (hence broken) + if (start != null) { if ((start.getMonth() <= month || end.getMonth() >= month)) { target.startTag("item"); // TODO different id? target.addAttribute("id", itemId.hashCode()); - p = item.getItemProperty(this.itemStyleNamePropertyId); - String styleName = (String) p.getValue(); - target.addAttribute("styleName", styleName); + if (this.itemStyleNamePropertyId != null) { + p = item + .getItemProperty(this.itemStyleNamePropertyId); + String styleName = (String) p.getValue(); + target.addAttribute("styleName", styleName); + } target.addAttribute("start", "" + start.getTime()); if (end != start) { target.addAttribute("end", "" + end.getTime()); diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarEntry.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarEntry.java index cebdee2b71..075f68cbf6 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarEntry.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarEntry.java @@ -113,7 +113,9 @@ public class CalendarEntry { } s += " "; } - s += title; + if (title!=null) { + s += title; + } return s; } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java index 9afbb2cfbb..ec429ac4b5 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java @@ -126,13 +126,18 @@ public class ICalendar extends IDateField { 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() + this.hourTable.setHTML(start, col, "" + + (entry.getTitle() != null ? entry.getTitle() : " ") + ""); this.hourTable.getFlexCellFormatter().setRowSpan(start, col, hours); this.hourTable.getFlexCellFormatter().setStyleName(start, col, @@ -155,11 +160,15 @@ public class ICalendar extends IDateField { } tooltip += " (" + hours + "h) "; - tooltip += entry.getTitle() + "\n "; + if (entry.getTitle()!=null) { + tooltip += entry.getTitle() + "\n "; + } } else { tooltip = entry.getStringForDate(entry.getEnd()) + "\n "; } - tooltip += "\"" + entry.getDescription() + "\""; + if (entry.getDescription()!=null) { + tooltip += "\"" + entry.getDescription() + "\""; + } DOM.setElementProperty(el, "title", tooltip); currentCol++; @@ -201,7 +210,12 @@ public class ICalendar extends IDateField { Integer id = new Integer(item.getIntAttribute("id")); long start = Long.parseLong(item.getStringAttribute("start")); Date startDate = new Date(start); - long end = Long.parseLong(item.getStringAttribute("end")); + 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"); @@ -211,7 +225,7 @@ public class ICalendar extends IDateField { 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() @@ -228,8 +242,8 @@ public class ICalendar extends IDateField { } public List getEntries(Date date, int resolution) { - List entries = (List) dates.get(date.getYear() + "" + date.getMonth() + "" - + date.getDate()); + List entries = (List) dates.get(date.getYear() + "" + + date.getMonth() + "" + date.getDate()); ArrayList res = new ArrayList(); if (entries == null) { return res; diff --git a/src/com/itmill/toolkit/ui/CalendarField.java b/src/com/itmill/toolkit/ui/CalendarField.java deleted file mode 100644 index 67e82ea0ee..0000000000 --- a/src/com/itmill/toolkit/ui/CalendarField.java +++ /dev/null @@ -1,315 +0,0 @@ -package com.itmill.toolkit.ui; - -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; - -import com.itmill.toolkit.data.Container; -import com.itmill.toolkit.data.Item; -import com.itmill.toolkit.data.Property; -import com.itmill.toolkit.terminal.PaintException; -import com.itmill.toolkit.terminal.PaintTarget; - -// TODO use Calendar -// TODO lazyLoading -// TODO check date limit when updating variables -// TODO Allow item selection -public class CalendarField extends DateField implements Container.Viewer { - - private Date minDate; - private Date maxDate; - - private Container dataSource; - private Object itemStyleNamePropertyId; - private Object itemStartPropertyId; - private Object itemEndPropertyId; - private Object itemTitlePropertyId; - private Object itemDescriptionPropertyId; - private Object itemNotimePropertyId; - - public CalendarField() { - super(); - init(); - } - - public CalendarField(Property dataSource) throws IllegalArgumentException { - super(dataSource); - init(); - } - - public CalendarField(String caption, Date value) { - super(caption, value); - init(); - } - - public CalendarField(String caption, Property dataSource) { - super(caption, dataSource); - init(); - } - - public CalendarField(String caption) { - super(caption); - init(); - } - - /* - * Gets the components UIDL tag string. Don't add a JavaDoc comment here, we - * use the default documentation from implemented interface. - */ - public String getTag() { - return "calendarfield"; - } - - public void init() { - super.setResolution(RESOLUTION_HOUR); - - } - - /** - * Sets the resolution of the CalendarField. Only RESOLUTION_DAY and - * RESOLUTION_HOUR are supported. - * - * @param resolution - * the resolution to set. - * @see com.itmill.toolkit.ui.DateField#setResolution(int) - */ - public void setResolution(int resolution) { - if (resolution != RESOLUTION_DAY && resolution != RESOLUTION_HOUR) { - throw new IllegalArgumentException(); - } - super.setResolution(resolution); - } - - public void setMinimumDate(Date date) { - this.minDate = date; - requestRepaint(); - } - - public Date getMinimumDate() { - return minDate; - } - - public void setMaximumDate(Date date) { - this.maxDate = date; - requestRepaint(); - } - - public Date getMaximumDate() { - return maxDate; - } - - public Container getContainerDataSource() { - return this.dataSource; - } - - public void setContainerDataSource(Container newDataSource) { - if (newDataSource == null || checkDataSource(newDataSource)) { - this.dataSource = newDataSource; - } else { - // TODO error message - throw new IllegalArgumentException(); - } - requestRepaint(); - } - - private boolean checkDataSource(Container dataSource) { - /* - * if (!(dataSource instanceof Container.Sortable)) { // we really want - * the data source to be sortable return false; } - */ - // Check old propertyIds - if (this.itemEndPropertyId != null) { - Class c = dataSource.getType(this.itemEndPropertyId); - if (!Date.class.isAssignableFrom(c)) { - this.itemEndPropertyId = null; - } - } - if (this.itemNotimePropertyId != null) { - Class c = dataSource.getType(this.itemNotimePropertyId); - if (!Boolean.class.isAssignableFrom(c)) { - this.itemNotimePropertyId = null; - } - } - if (this.itemStartPropertyId != null) { - Class c = dataSource.getType(this.itemStartPropertyId); - if (Date.class.isAssignableFrom(c)) { - // All we _really_ need is one date - return true; - } else { - this.itemStartPropertyId = null; - } - } - // We need at least one Date - Collection ids = dataSource.getContainerPropertyIds(); - for (Iterator it = ids.iterator(); it.hasNext();) { - Object id = it.next(); - Class c = dataSource.getType(id); - if (Date.class.isAssignableFrom(c)) { - this.itemStartPropertyId = id; - return true; - } - } - - return false; - } - - public Object getItemStyleNamePropertyId() { - return itemStyleNamePropertyId; - } - - public void setItemStyleNamePropertyId(Object propertyId) { - this.itemStyleNamePropertyId = propertyId; - } - - public Object getItemStartPropertyId() { - return itemStartPropertyId; - } - - public void setItemStartPropertyId(Object propertyId) { - // TODO nullcheck for property id - if (this.dataSource != null - && !Date.class.isAssignableFrom(dataSource.getType(propertyId))) { - // TODO error message - throw new IllegalArgumentException(); - } - this.itemStartPropertyId = propertyId; - } - - public Object getItemEndPropertyId() { - return itemEndPropertyId; - } - - public void setItemEndPropertyId(Object propertyId) { - // TODO nullcheck for property id - if (this.dataSource != null - && !Date.class.isAssignableFrom(dataSource.getType(propertyId))) { - // TODO error message - throw new IllegalArgumentException(); - } - this.itemEndPropertyId = propertyId; - } - - public Object getItemTitlePropertyId() { - return itemTitlePropertyId; - } - - public void setItemTitlePropertyId(Object propertyId) { - this.itemTitlePropertyId = propertyId; - } - - public Object getItemDescriptionPropertyId() { - return itemDescriptionPropertyId; - } - - public void setItemDescriptionPropertyId(Object propertyId) { - this.itemDescriptionPropertyId = propertyId; - } - - public Object getitemNotimePropertyId() { - return itemNotimePropertyId; - } - - public void setItemNotimePropertyId(Object propertyId) { - // TODO nullcheck for property id - if (this.dataSource != null - && !Boolean.class.isAssignableFrom(dataSource - .getType(propertyId))) { - // TODO error message - throw new IllegalArgumentException(); - } - this.itemNotimePropertyId = propertyId; - } - - /** - * Paints the content of this component. - * - * @param target - * the Paint Event. - * @throws PaintException - * if the paint operation failed. - */ - public void paintContent(PaintTarget target) throws PaintException { - super.paintContent(target); - - if (this.minDate != null) { - target.addAttribute("min", String.valueOf(this.minDate.getTime())); - } - if (this.maxDate != null) { - target.addAttribute("max", String.valueOf(this.maxDate.getTime())); - } - - if (this.dataSource != null) { - target.startTag("items"); - - // send one month now, the rest via lazyloading - int month = new Date().getMonth(); - Object value = getValue(); - if (value != null && value instanceof Date) { - month = ((Date) value).getMonth(); - } - - for (Iterator it = this.dataSource.getItemIds().iterator(); it - .hasNext();) { - Object itemId = it.next(); - Item item = (Item) this.dataSource.getItem(itemId); - Property p = item.getItemProperty(this.itemStartPropertyId); - Date start = (Date) p.getValue(); - Date end = start; // assume same day - if (this.itemEndPropertyId != null) { - p = item.getItemProperty(this.itemEndPropertyId); - end = (Date) p.getValue(); - if (end == null) { - end = start; - } else if (end.before(start)) { - Date tmp = start; - start = end; - end = tmp; - } - } - - if (start != null) { - if ((start.getMonth() <= month || end.getMonth() >= month)) { - target.startTag("item"); - // TODO different id? - target.addAttribute("id", itemId.hashCode()); - p = item.getItemProperty(this.itemStyleNamePropertyId); - String styleName = (String) p.getValue(); - target.addAttribute("styleName", styleName); - target.addAttribute("start", "" + start.getTime()); - if (end != start) { - target.addAttribute("end", "" + end.getTime()); - } - if (this.itemTitlePropertyId != null) { - p = item.getItemProperty(this.itemTitlePropertyId); - Object val = p.getValue(); - if (val != null) { - target.addAttribute("title", val.toString()); - } - } - if (this.itemDescriptionPropertyId != null) { - p = item - .getItemProperty(this.itemDescriptionPropertyId); - Object val = p.getValue(); - if (val != null) { - target.addAttribute("description", val - .toString()); - } - } - if (this.itemNotimePropertyId != null) { - p = item.getItemProperty(this.itemNotimePropertyId); - Object val = p.getValue(); - if (val != null) { - target.addAttribute("notime", ((Boolean) val) - .booleanValue()); - } - } - - target.endTag("item"); - } - } - } - - target.endTag("items"); - } - } -} -- 2.39.5