]> source.dussan.org Git - vaadin-framework.git/commitdiff
All day property support is added to ContainerEventProvider (#14178).
authorDenis Anisimov <denis@vaadin.com>
Sun, 17 Aug 2014 15:04:11 +0000 (18:04 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 20 Aug 2014 13:31:50 +0000 (13:31 +0000)
Change-Id: I8d5580895a218440a8295ed79453d6cbe24195b1

server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java
server/tests/src/com/vaadin/tests/server/component/calendar/ContainerEventProviderTest.java [new file with mode: 0644]

index a8804caedb3b673b69abfa5f55e300ba0ff6955d..8dff224627cd4f5d96b34f1121187a023b2b09aa 100644 (file)
@@ -61,6 +61,7 @@ public class ContainerEventProvider implements CalendarEditableEventProvider,
     public static final String STARTDATE_PROPERTY = "start";
     public static final String ENDDATE_PROPERTY = "end";
     public static final String STYLENAME_PROPERTY = "styleName";
+    public static final String ALL_DAY_PROPERTY = "allDay";
 
     /**
      * Internal class to keep the container index which item this event
@@ -106,6 +107,7 @@ public class ContainerEventProvider implements CalendarEditableEventProvider,
     private Object startDateProperty = STARTDATE_PROPERTY;
     private Object endDateProperty = ENDDATE_PROPERTY;
     private Object styleNameProperty = STYLENAME_PROPERTY;
+    private Object allDayProperty = ALL_DAY_PROPERTY;
 
     /**
      * Constructor
@@ -227,6 +229,11 @@ public class ContainerEventProvider implements CalendarEditableEventProvider,
                 basicEvent.setStyleName(String.valueOf(item.getItemProperty(
                         styleNameProperty).getValue()));
             }
+            if (allDayProperty != null
+                    && item.getItemPropertyIds().contains(allDayProperty)) {
+                basicEvent.setAllDay((Boolean) item.getItemProperty(
+                        allDayProperty).getValue());
+            }
             event = basicEvent;
         }
         return event;
@@ -433,6 +440,20 @@ public class ContainerEventProvider implements CalendarEditableEventProvider,
         this.styleNameProperty = styleNameProperty;
     }
 
+    /**
+     * Set the all day property for the event
+     */
+    public void setAllDayProperty(Object allDayProperty) {
+        this.allDayProperty = allDayProperty;
+    }
+
+    /**
+     * Get the all day property for the event
+     */
+    public Object getAllDayProperty() {
+        return allDayProperty;
+    }
+
     /*
      * (non-Javadoc)
      * 
diff --git a/server/tests/src/com/vaadin/tests/server/component/calendar/ContainerEventProviderTest.java b/server/tests/src/com/vaadin/tests/server/component/calendar/ContainerEventProviderTest.java
new file mode 100644 (file)
index 0000000..63749a2
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.calendar;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.ui.components.calendar.ContainerEventProvider;
+import com.vaadin.ui.components.calendar.event.CalendarEvent;
+
+/**
+ * 
+ * @author Vaadin Ltd
+ */
+public class ContainerEventProviderTest {
+
+    @Test
+    public void testDefaultAllDayProperty() {
+        ContainerEventProvider provider = new ContainerEventProvider(null);
+        Assert.assertEquals(ContainerEventProvider.ALL_DAY_PROPERTY,
+                provider.getAllDayProperty());
+
+    }
+
+    @Test
+    public void testSetAllDayProperty() {
+        ContainerEventProvider provider = new ContainerEventProvider(null);
+        Object prop = new Object();
+        provider.setAllDayProperty(prop);
+        Assert.assertEquals(prop, provider.getAllDayProperty());
+    }
+
+    @Test
+    public void testGetEvents() {
+        BeanItemContainer<EventBean> container = new BeanItemContainer<EventBean>(
+                EventBean.class);
+        EventBean bean = new EventBean();
+        container.addBean(bean);
+        ContainerEventProvider provider = new ContainerEventProvider(container);
+        List<CalendarEvent> events = provider.getEvents(bean.getStart(),
+                bean.getEnd());
+        Assert.assertTrue(events.get(0).isAllDay());
+    }
+
+    public static class EventBean {
+
+        public boolean isAllDay() {
+            return true;
+        }
+
+        public void setAllDay(boolean allDay) {
+        }
+
+        public Date getStart() {
+            return Calendar.getInstance().getTime();
+        }
+
+        public Date getEnd() {
+            Calendar calendar = Calendar.getInstance();
+            calendar.add(Calendar.MINUTE, 10);
+            return calendar.getTime();
+        }
+
+        public void setStart(Date date) {
+        }
+
+        public void setEnd(Date date) {
+        }
+    }
+}