]> source.dussan.org Git - vaadin-framework.git/commitdiff
eventcalendar updates
authorMarc Englund <marc.englund@itmill.com>
Tue, 9 Oct 2007 12:36:38 +0000 (12:36 +0000)
committerMarc Englund <marc.englund@itmill.com>
Tue, 9 Oct 2007 12:36:38 +0000 (12:36 +0000)
svn changeset:2468/svn branch:trunk

src/com/itmill/toolkit/demo/reservation/ReservationApplication.java
src/com/itmill/toolkit/demo/reservation/gwt/public/reservr/styles.css
src/com/itmill/toolkit/terminal/gwt/client/ui/CalendarEntry.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java

index 2f9d8da7791fda7a493557266e676a119418309f..b5b59c8ba6cab640038958cc027c432cea6fe95f 100644 (file)
@@ -31,7 +31,8 @@ public class ReservationApplication extends Application {
 \r
        private CalendarField reservedFrom;\r
        private static final long DEFAULT_GAP_MILLIS = 3600000; // one hour\r
-       private long currentGapMillis = DEFAULT_GAP_MILLIS;\r
+       private long currentGapMillis = DEFAULT_GAP_MILLIS; // current length of\r
+       // reservation\r
        private CalendarField reservedTo;\r
 \r
        private Label resourceName;\r
@@ -262,6 +263,7 @@ public class ReservationApplication extends Application {
        }\r
 \r
        private void initCalendarFieldPropertyIds(CalendarField cal) {\r
+               cal.setItemStyleNamePropertyId(SampleDB.Resource.PROPERTY_ID_STYLENAME);\r
                cal\r
                                .setItemStartPropertyId(SampleDB.Reservation.PROPERTY_ID_RESERVED_FROM);\r
                cal.setItemEndPropertyId(SampleDB.Reservation.PROPERTY_ID_RESERVED_TO);\r
index 14761b77e106655b9496ff935d9f77004f013cfe..b0e3510e921fa4e951ea80482e30cf5ba3d27161 100644 (file)
@@ -1 +1,90 @@
-@import "googlemap/css/googlemap.css";
\ No newline at end of file
+@import "googlemap/css/googlemap.css";\r
+\r
+.i-datefield-entrycalendar-01 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-02 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-03 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-04 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-05 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-06 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-07 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-08 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-09 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-10 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-11 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-12 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-13 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-14 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-15 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-16 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-17 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-18 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-19 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-20 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-21 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-22 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-23 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-24 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-25 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-26 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-27 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-28 {\r
+       background-color: red;\r
+}\r
+.i-datefield-entrycalendar-29 {\r
+       background-color: red;\r
+}\r
+\r
index 56447949e15ac86a8a9acb070599f65b735f7ba8..cebdee2b715fa437d5b5b573af114b0a4868588a 100644 (file)
@@ -5,14 +5,16 @@ import java.util.Date;
 import com.itmill.toolkit.terminal.gwt.client.DateTimeService;\r
 \r
 public class CalendarEntry {\r
+       private String styleName;\r
        private Date start;\r
        private Date end;\r
        private String title;\r
        private String description;\r
        private boolean notime;\r
 \r
-       public CalendarEntry(Date start, Date end, String title,\r
+       public CalendarEntry(String styleName, Date start, Date end, String title,\r
                        String description, boolean notime) {\r
+               this.styleName = styleName;\r
                if (notime) {\r
                        Date d = new Date(start.getTime());\r
                        d.setSeconds(0);\r
@@ -35,8 +37,13 @@ public class CalendarEntry {
                this.notime = notime;\r
        }\r
 \r
-       public CalendarEntry(Date start, Date end, String title, String description) {\r
-               this(start, end, title, description, false);\r
+       public CalendarEntry(String styleName, Date start, Date end, String title,\r
+                       String description) {\r
+               this(styleName, start, end, title, description, false);\r
+       }\r
+\r
+       public String getStyleName() {\r
+               return styleName;\r
        }\r
 \r
        public Date getStart() {\r
index dea6ee2d54bb2392851705a02fdaf78d97c06ebb..098456ab72f0365c0c21b42307a5b5d5b279d27d 100644 (file)
@@ -6,8 +6,9 @@ import java.util.HashMap;
 import java.util.Iterator;\r
 import java.util.List;\r
 \r
+import com.google.gwt.user.client.DOM;\r
+import com.google.gwt.user.client.Element;\r
 import com.google.gwt.user.client.ui.FlexTable;\r
-import com.google.gwt.user.client.ui.HTMLTable;\r
 import com.google.gwt.user.client.ui.SimplePanel;\r
 import com.google.gwt.user.client.ui.SourcesTableEvents;\r
 import com.google.gwt.user.client.ui.TableListener;\r
@@ -19,7 +20,9 @@ public class ICalendar extends IDateField {
 \r
        private CalendarPanel calPanel;\r
 \r
-       private HTMLTable hourTable;\r
+       private SimplePanel hourPanel;\r
+\r
+       private FlexTable hourTable;\r
 \r
        private EntrySource entrySource;\r
 \r
@@ -75,20 +78,20 @@ public class ICalendar extends IDateField {
        }\r
 \r
        protected void buildDayView(Date date) {\r
-               boolean firstRender = false;\r
-               if (this.hourTable == null) {\r
-                       hourTable = new FlexTable();\r
-                       firstRender = true;\r
-                       hourTable.addTableListener(this.ftListener);\r
-                       SimplePanel p = new SimplePanel();\r
-                       p.add(hourTable);\r
-                       p.setStyleName(CLASSNAME + "-hours");\r
+               if (this.hourPanel == null) {\r
+                       this.hourPanel = new SimplePanel();\r
+                       this.hourPanel.setStyleName(CLASSNAME + "-hours");\r
                        this.calPanel.getFlexCellFormatter().setColSpan(8, 0, 7);\r
-                       this.calPanel.setWidget(8, 0, p);\r
+                       this.calPanel.setWidget(8, 0, this.hourPanel);\r
+               } else {\r
+                       this.hourPanel.clear();\r
                }\r
-               Date curr = new Date(date.getTime());\r
+               this.hourTable = new FlexTable();\r
+               this.hourTable.addTableListener(this.ftListener);\r
+               this.hourPanel.add(this.hourTable);\r
+               this.hourTable.setCellSpacing(1);\r
+\r
                for (int i = 0; i < 24; i++) {\r
-                       curr.setHours(i);\r
                        String style = (i % 2 == 0 ? "even" : "odd");\r
                        if (realResolution >= RESOLUTION_HOUR) {\r
                                if (this.date != null && this.date.getHours() == i) {\r
@@ -97,36 +100,52 @@ public class ICalendar extends IDateField {
                        }\r
                        hourTable.getRowFormatter().setStyleName(i,\r
                                        CLASSNAME + "-row-" + style);\r
-                       if (firstRender) {\r
-                               String hstr = (i < 10 ? "0" : "") + i + ":00";\r
-                               if (this.dts.isTwelveHourClock()) {\r
-                                       String ampm = (i < 12 ? "am" : "pm");\r
-                                       hstr = (i <= 12 ? i : i - 12) + ":00 " + ampm;\r
-                               }\r
-                               hourTable.setHTML(i, 0, "<span>" + hstr + "</span>");\r
-                               hourTable.getCellFormatter().setStyleName(i, 0,\r
-                                               CLASSNAME + "-time");\r
+                       String hstr = (i < 10 ? "0" : "") + i + ":00";\r
+                       if (this.dts.isTwelveHourClock()) {\r
+                               String ampm = (i < 12 ? "am" : "pm");\r
+                               hstr = (i <= 12 ? i : i - 12) + ":00 " + ampm;\r
                        }\r
-                       List entries = this.entrySource.getEntries(curr,\r
-                                       DateTimeService.RESOLUTION_HOUR);\r
-                       String text = "";\r
-                       if (entries != null) {\r
-                               for (Iterator it = entries.iterator(); it.hasNext();) {\r
-                                       CalendarEntry entry = (CalendarEntry) it.next();\r
-                                       String title = entry.getTitle();\r
-                                       String desc = entry.getDescription();\r
-                                       text += (text == "" ? "" : ", ");\r
-                                       String e = "<span"\r
-                                                       + (desc != null ? " title=\"" + desc + "\"" : "")\r
-                                                       + ">";\r
-                                       e += (title != null ? title : "?");\r
-                                       e += "</span>";\r
-                                       text += e;\r
-                               }\r
+                       hourTable.setHTML(i, 0, "<span>" + hstr + "</span>");\r
+                       hourTable.getCellFormatter()\r
+                                       .setStyleName(i, 0, CLASSNAME + "-time");\r
+                       hourTable.getCellFormatter().setWidth(i, 0, "55");\r
+\r
+               }\r
+\r
+               List entries = this.entrySource.getEntries(date,\r
+                               DateTimeService.RESOLUTION_DAY);\r
+               int currentCol = 1;\r
+               for (Iterator it = entries.iterator(); it.hasNext();) {\r
+                       CalendarEntry entry = (CalendarEntry) it.next();\r
+                       int start = 0;\r
+                       int hours = 24;\r
+                       if (!entry.isNotime()) {\r
+                               Date d = entry.getStart();\r
+                               start = (d.getDate() < date.getDate() ? 0 : d.getHours());\r
+                               d = entry.getEnd();\r
+                               hours = (d.getDate() > date.getDate() ? 24 : d.getHours())\r
+                                               - start;\r
+                       }\r
+                       int col = currentCol;\r
+                       if (col > 1) {\r
+                               while (!this.hourTable.isCellPresent(start, col - 1))\r
+                                       col--;\r
                        }\r
-                       hourTable.setHTML(i, 1, text);\r
-                       hourTable.getCellFormatter().setStyleName(i, 1,\r
-                                       CLASSNAME + "-title");\r
+                       this.hourTable.setHTML(start, col, "<span>" + entry.getTitle()\r
+                                       + "</span>");\r
+                       this.hourTable.getFlexCellFormatter().setRowSpan(start, col, hours);\r
+                       this.hourTable.getFlexCellFormatter().setStyleName(start, col,\r
+                                       CLASSNAME + "-entry");\r
+                       String sn = entry.getStyleName();\r
+                       if (sn != null && !sn.equals("")) {\r
+                               this.hourTable.getFlexCellFormatter().addStyleName(start, col,\r
+                                               CLASSNAME + "-" + entry.getStyleName());\r
+                       }\r
+                       Element el = this.hourTable.getFlexCellFormatter().getElement(\r
+                                       start, col);\r
+                       DOM.setElementProperty(el, "title", entry.getDescription());\r
+\r
+                       currentCol++;\r
                }\r
 \r
        }\r
@@ -148,6 +167,7 @@ public class ICalendar extends IDateField {
                private HashMap items = new HashMap();\r
 \r
                public void addItem(UIDL item) {\r
+                       String styleName = item.getStringAttribute("styleName");\r
                        Integer id = new Integer(item.getIntAttribute("id"));\r
                        long start = Long.parseLong(item.getStringAttribute("start"));\r
                        Date startDate = new Date(start);\r
@@ -160,8 +180,8 @@ public class ICalendar extends IDateField {
                        if (items.containsKey(id)) {\r
                                items.remove(id);\r
                        }\r
-                       items.put(id, new CalendarEntry(startDate, endDate, title, desc,\r
-                                       notime));\r
+                       items.put(id, new CalendarEntry(styleName, startDate, endDate,\r
+                                       title, desc, notime));\r
                }\r
 \r
                public List getEntries(Date date, int resolution) {\r