summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java74
-rw-r--r--uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerLongEventTest.java55
-rw-r--r--uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerTestUI.java8
3 files changed, 81 insertions, 56 deletions
diff --git a/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java b/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java
index fcaabcc079..2f51b21f7c 100644
--- a/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java
+++ b/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java
@@ -249,71 +249,33 @@ public class ContainerEventProvider implements CalendarEditableEventProvider,
@Override
public List<CalendarEvent> getEvents(Date startDate, Date endDate) {
eventCache.clear();
-
- int[] rangeIndexes = getFirstAndLastEventIndex(startDate, endDate);
- for (int i = rangeIndexes[0]; i <= rangeIndexes[1]
- && i < container.size(); i++) {
- eventCache.add(getEvent(i));
- }
- return Collections.unmodifiableList(eventCache);
- }
-
- /**
- * Get the first event for a date
- *
- * @param date
- * The date to search for, NUll returns first event in container
- * @return Returns an array where the first item is the start index and the
- * second item is the end item
- */
- private int[] getFirstAndLastEventIndex(Date start, Date end) {
- int startIndex = 0;
int size = container.size();
assert size >= 0;
- int endIndex = size - 1;
- if (start != null) {
- /*
- * Iterating from the start of the container, if range is in the end
- * of the container then this will be slow TODO This could be
- * improved by using some sort of divide and conquer algorithm
- */
- while (startIndex < size) {
- Object id = container.getIdByIndex(startIndex);
- Item item = container.getItem(id);
- Date d = (Date) item.getItemProperty(startDateProperty)
+ for (int i = 0; i < size; i++) {
+ Object id = container.getIdByIndex(i);
+ Item item = container.getItem(id);
+ boolean add = true;
+ if (startDate != null) {
+ Date eventEnd = (Date) item.getItemProperty(endDateProperty)
.getValue();
- if (d.compareTo(start) >= 0) {
- break;
+ if (eventEnd.compareTo(startDate) < 0) {
+ add = false;
}
- startIndex++;
}
- }
-
- if (end != null) {
- /*
- * Iterate from the start index until range ends
- */
- endIndex = startIndex;
- while (endIndex < size - 1) {
- Object id = container.getIdByIndex(endIndex);
- Item item = container.getItem(id);
- Date d = (Date) item.getItemProperty(endDateProperty)
- .getValue();
- if (d == null) {
- // No end date present, use start date
- d = (Date) item.getItemProperty(startDateProperty)
- .getValue();
+ if (add && endDate != null) {
+ Date eventStart = (Date) item
+ .getItemProperty(startDateProperty).getValue();
+ if (eventStart.compareTo(endDate) >= 0) {
+ break; // because container is sorted, all further events
+ // will be even later
}
- if (d.compareTo(end) >= 0) {
- endIndex--;
- break;
- }
- endIndex++;
+ }
+ if (add) {
+ eventCache.add(getEvent(i));
}
}
-
- return new int[] { startIndex, endIndex };
+ return Collections.unmodifiableList(eventCache);
}
/*
diff --git a/uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerLongEventTest.java b/uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerLongEventTest.java
new file mode 100644
index 0000000000..0ec196f266
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerLongEventTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.components.calendar;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Tests if long event which began before the view period is shown (#15242)
+ */
+public class BeanItemContainerLongEventTest extends MultiBrowserTest {
+
+ @Override
+ protected String getDeploymentPath() {
+ return "/run/BeanItemContainerTestUI?restartApplication";
+ }
+
+ @Test
+ public void testEventDisplayedInWeekView() {
+ openTestURL();
+ WebElement target = driver.findElements(
+ By.className("v-calendar-week-number")).get(1);
+ target.click();
+ target = driver.findElement(By.className("v-calendar-event"));
+ Assert.assertEquals("Wrong event name", "Long event", target.getText());
+ }
+
+ @Test
+ public void testEventDisplayedInDayView() {
+ openTestURL();
+ WebElement target = driver.findElements(
+ By.className("v-calendar-day-number")).get(5);
+ target.click();
+ target = driver.findElement(By.className("v-calendar-event"));
+ Assert.assertEquals("Wrong event name", "Long event", target.getText());
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerTestUI.java b/uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerTestUI.java
index 83fc4a03cb..bda3b34875 100644
--- a/uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerTestUI.java
+++ b/uitest/src/com/vaadin/tests/components/calendar/BeanItemContainerTestUI.java
@@ -17,6 +17,7 @@ package com.vaadin.tests.components.calendar;
import java.util.Arrays;
import java.util.Date;
+import java.util.GregorianCalendar;
import com.vaadin.data.fieldgroup.FieldGroup;
import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
@@ -69,6 +70,13 @@ public class BeanItemContainerTestUI extends UI {
table.setVisibleColumns(new Object[] { "caption", "description",
"start", "end" });
content.addComponent(table);
+
+ BasicEvent longEvent = new BasicEvent();
+ longEvent.setCaption("Long event");
+ longEvent.setAllDay(true);
+ longEvent.setStart(new GregorianCalendar(2000, 1, 3).getTime());
+ longEvent.setEnd(new GregorianCalendar(2000, 2, 5).getTime());
+ events.addBean(longEvent);
}
/**