]> source.dussan.org Git - vaadin-framework.git/commitdiff
ContainerEventProvider returns style names from container. Fixes #10718
authorMaciej Przepióra <matthew@vaadin.com>
Fri, 11 Apr 2014 20:53:43 +0000 (23:53 +0300)
committerTeemu Suo-Anttila <teemusa@vaadin.com>
Wed, 16 Apr 2014 07:52:18 +0000 (07:52 +0000)
ContainerEventProvider doesn't actually return
style names from container in certain situations
(copy-pasted code). This patch fixes the problem.

Change-Id: I512ea260f34a6db0572b614db393699da152fa8d
(cherry picked from commit 4709b75bb47d28630dacbb240bb43de16d972371)

server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java
server/tests/src/com/vaadin/tests/server/component/calendar/ContainerDataSource.java

index 37ea255d2786e74766fc32dc40e6f22c10ae79fc..b025de6f9a138979f88cdc5ac6ee689823aa1a3d 100644 (file)
@@ -224,8 +224,8 @@ public class ContainerEventProvider implements CalendarEditableEventProvider,
             }
             if (styleNameProperty != null
                     && item.getItemPropertyIds().contains(styleNameProperty)) {
-                basicEvent.setDescription(String.valueOf(item.getItemProperty(
-                        descriptionProperty).getValue()));
+                basicEvent.setStyleName(String.valueOf(item.getItemProperty(
+                        styleNameProperty).getValue()));
             }
             event = basicEvent;
         }
index 2bc95e371c712fa6e31fe5ef4b30dac8e277edbc..d5b0d5d9c8eeff08024c0829c5b70b299505bd95 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Test;
 import com.vaadin.data.Container.Indexed;
 import com.vaadin.data.Container.Sortable;
 import com.vaadin.data.Item;
+import com.vaadin.data.Property;
 import com.vaadin.data.util.BeanItemContainer;
 import com.vaadin.data.util.IndexedContainer;
 import com.vaadin.ui.Calendar;
@@ -327,6 +328,37 @@ public class ContainerDataSource extends TestCase {
         assertEquals(0, calendar.getEvents(start, end).size());
     }
 
+    @Test
+    public void testStyleNamePropertyRetrieved() {
+        IndexedContainer ic = (IndexedContainer) createTestIndexedContainer();
+        ic.addContainerProperty("testStyleName", String.class, "");
+        for (int i = 0; i < 10; i++) {
+            Item item = ic.getItem(ic.getIdByIndex(i));
+            @SuppressWarnings("unchecked")
+            Property<String> itemProperty = item
+                    .getItemProperty("testStyleName");
+            itemProperty.setValue("testStyle");
+        }
+
+        ContainerEventProvider provider = new ContainerEventProvider(ic);
+        provider.setCaptionProperty("testCaption");
+        provider.setDescriptionProperty("testDescription");
+        provider.setStartDateProperty("testStartDate");
+        provider.setEndDateProperty("testEndDate");
+        provider.setStyleNameProperty("testStyleName");
+
+        calendar.setEventProvider(provider);
+        java.util.Calendar cal = java.util.Calendar.getInstance();
+        Date now = cal.getTime();
+        cal.add(java.util.Calendar.DAY_OF_MONTH, 20);
+        Date then = cal.getTime();
+        List<CalendarEvent> events = calendar.getEventProvider().getEvents(now,
+                then);
+        for (CalendarEvent ce : events) {
+            assertEquals("testStyle", ce.getStyleName());
+        }
+    }
+
     private static Indexed createTestBeanItemContainer() {
         BeanItemContainer<CalendarEvent> eventContainer = new BeanItemContainer<CalendarEvent>(
                 CalendarEvent.class);