Calendar ContainerEventProvider needs to show overlap dates

Dear,

I try to show events in the calendar that are bigger then the selected start and end date of my view.
For example:

  • ​My range is set from 01/07/2014 until 31/07/2014
  • My event start date is 16/06/2014 and end 19/08/2014

When i use the basicEventProvider and i at my events to a calendarcomponent the event is shown. [code]
basicEventProvider = new BasicEventProvider();
calendar = new Calendar(basicEventProvider);
calendar.setLocale(Locale.getDefault());
calendar.setImmediate(true);
calendar.setSizeFull();
calendar.setStartDate(new DateTime().dayOfMonth().withMinimumValue().toDate());
calendar.setEndDate(new DateTime().dayOfMonth().withMaximumValue().toDate());

    calendar.addEvent(new BasicEvent("The Event", "Single Event",
            new DateTime().minusMonths(1).minusHours(1).toDate(),
            new DateTime().minusHours(1).toDate()));

    BasicEvent event = new BasicEvent("Wednesday Wonder",
            "Wonderful Event",
            new DateTime().minusHours(1).toDate(),
            new DateTime().plusHours(1).toDate());
    event.setStyleName("blue");
    calendar.addEvent(event);

[/code]
When i use a containerEventProvider with a beanItemContainer/BeanContainer/… my event isn’t shown.
The method in ContainerEventProvider “getFirstAndLastEventIndex” filtered out the events that starts before the calendar startDate en end after the calendar end date.

   final BeanItemContainer<BasicEvent> container = new BeanItemContainer<BasicEvent>(BasicEvent.class);
        container.addBean(new BasicEvent("The Event", "Single Event",
                new DateTime().minusMonths(1).minusHours(1).toDate(),
                new DateTime().minusHours(1).toDate()));

        container.sort(new Object[]{"start"}, new boolean[]
{true});

        BasicEvent event = new BasicEvent("Wednesday Wonder",
                "Wonderful Event",
                new DateTime().minusHours(1).toDate(),
                new DateTime().plusHours(1).toDate());
        event.setStyleName("blue");
        container.sort(new Object[]{"start", "end"}, new boolean[]
{true});
        container.addBean(event);

        container.sort(new Object[]{"start", "end"}, new boolean[]
{true});

        dataSource = new ContainerEventProvider(container);
        calendar = new Calendar(dataSource);
        calendar.setLocale(Locale.getDefault());
        calendar.setImmediate(true);
        calendar.setSizeFull();
        calendar.setStartDate(new DateTime().dayOfMonth().withMinimumValue().toDate());
        calendar.setEndDate(new DateTime().dayOfMonth().withMaximumValue().toDate());

The next line of code must be changed (ContainerEventProvider.java - line:262):

[code]
private int getFirstAndLastEventIndex(Date start, Date end) {
int startIndex = 0;
int size = container.size();
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)
                    .getValue();
            if (d.compareTo(start) >= 0) {
                break;
            }
            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 (d.compareTo(end) >= 0) {
                endIndex--;
                break;
            }
            endIndex++;
        }
    }

[/code]So that it not only returns events that start between the start and end date but also returns the event that overlaps these dates.

Something like (BasicEventProvider - line: 60):

long f = ev.getStart().getTime(); long t = ev.getEnd().getTime(); // Select only events that overlaps with startDate and // endDate. if ((f <= to && f >= from) || (t >= from && t <= to) || (f <= from && t >= to)) { activeEvents.add(ev); } Kind regards,

Ewout Seldeslachts

Also see ticket - http://dev.vaadin.com/ticket/12755?cversion=2&cnum_hist=1