]> source.dussan.org Git - vaadin-framework.git/commitdiff
Significant speedup. Added more generated data.
authorMarc Englund <marc.englund@itmill.com>
Wed, 17 Oct 2007 14:19:14 +0000 (14:19 +0000)
committerMarc Englund <marc.englund@itmill.com>
Wed, 17 Oct 2007 14:19:14 +0000 (14:19 +0000)
svn changeset:2543/svn branch:trunk

src/com/itmill/toolkit/demo/reservation/SampleDB.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ICalendar.java

index 7f2225eee164fcacb7f7fea898c56799a0e9d33f..764b7d997772e75bd9fb29ad60a2e23f6fd7b592 100644 (file)
@@ -376,7 +376,7 @@ public class SampleDB {
        }
 
        public void generateReservations() {
-               int days = 10;
+               int days = 30;
                String descriptions[] = {
                                "Picking up guests from airport",
                                "Sightseeing with the guests",
@@ -396,6 +396,9 @@ public class SampleDB {
                        Container resources = getResources(c);
                        Collection rIds = resources.getItemIds();
                        Calendar cal = Calendar.getInstance();
+                       cal.set(Calendar.MINUTE, 0);
+                       cal.set(Calendar.SECOND, 0);
+                       cal.set(Calendar.MILLISECOND, 0);
                        //cal.add(Calendar.DAY_OF_MONTH, -days);
                        for (int i = 0;i<days;i++) {
                                for (Iterator rit = rIds.iterator();rit.hasNext();) {
@@ -406,9 +409,8 @@ public class SampleDB {
                                        Date start = new Date(cal.getTimeInMillis());
                                        start.setHours(s);
                                        Date end = new Date(cal.getTimeInMillis());
-                                       start.setHours(e);
+                                       end.setHours(e);
                                        addReservation(resource, 0, start, end, descriptions[(int)Math.floor(Math.random()*descriptions.length)]);
-                                       break;
                                }
                                cal.add(Calendar.DAY_OF_MONTH, 1);
                        }
@@ -426,7 +428,7 @@ public class SampleDB {
                                                "w/ company logo. 12m3 storage space.", "Turku",
                                                new Double(60.452171), new Double(22.2995) },
                                { "03", "03 Saab 93",
-                                               "Cabriolet<br/>Keys from the rental desk.", "Turku",
+                                               "CabrioletKeys from the rental desk.", "Turku",
                                                new Double(60.4507), new Double(22.295551) },
                                { "04", "04 Volvo S60", "Key from the rental desk.", "Turku",
                                                new Double(60.434722), new Double(22.224398) },
index 8ba19ab790d75a2d7478b4624ca7915e001c1761..9afbb2cfbbf2146b13e700c6d438f21eccc26f59 100644 (file)
@@ -194,7 +194,7 @@ public class ICalendar extends IDateField {
 \r
        private class EntrySource implements CalendarPanel.CalendarEntrySource {\r
 \r
-               private HashMap items = new HashMap();\r
+               private HashMap dates = new HashMap();\r
 \r
                public void addItem(UIDL item) {\r
                        String styleName = item.getStringAttribute("styleName");\r
@@ -207,16 +207,34 @@ public class ICalendar extends IDateField {
                        String title = item.getStringAttribute("title");\r
                        String desc = item.getStringAttribute("description");\r
                        boolean notime = item.getBooleanAttribute("notime");\r
-                       if (items.containsKey(id)) {\r
-                               items.remove(id);\r
+                       CalendarEntry entry = new CalendarEntry(styleName, startDate,\r
+                                       endDate, title, desc, notime);\r
+\r
+                       // TODO should remove+readd if the same entry (id) is added again\r
+                       \r
+                       for (Date d = entry.getStart(); d.getYear() <= entry.getEnd()\r
+                                       .getYear()\r
+                                       && d.getMonth() <= entry.getEnd().getYear()\r
+                                       && d.getDate() <= entry.getEnd().getDate(); d.setTime(d\r
+                                       .getTime() + 86400000)) {\r
+                               String key = d.getYear() + "" + d.getMonth() + "" + d.getDate();\r
+                               ArrayList l = (ArrayList) dates.get(key);\r
+                               if (l == null) {\r
+                                       l = new ArrayList();\r
+                                       dates.put(key, l);\r
+                               }\r
+                               l.add(entry);\r
                        }\r
-                       items.put(id, new CalendarEntry(styleName, startDate, endDate,\r
-                                       title, desc, notime));\r
                }\r
 \r
                public List getEntries(Date date, int resolution) {\r
+                       List entries = (List) dates.get(date.getYear() + "" + date.getMonth() + ""\r
+                                       + date.getDate());\r
                        ArrayList res = new ArrayList();\r
-                       for (Iterator it = this.items.values().iterator(); it.hasNext();) {\r
+                       if (entries == null) {\r
+                               return res;\r
+                       }\r
+                       for (Iterator it = entries.iterator(); it.hasNext();) {\r
                                CalendarEntry item = (CalendarEntry) it.next();\r
                                if (DateTimeService.isInRange(date, item.getStart(), item\r
                                                .getEnd(), resolution)) {\r
@@ -228,7 +246,7 @@ public class ICalendar extends IDateField {
                }\r
 \r
                public void clear() {\r
-                       items.clear();\r
+                       dates.clear();\r
                }\r
 \r
        }\r