BasicEvent event = new BasicEvent(); event.setCaption("My Event"); event.setDescription("My Event Description"); event.setStart(start);
event.setEnd(end);
events.add(event);
}
public void addEvent(CalendarEvent BasicEvent) { events.add(BasicEvent);
}
public List<CalendarEvent> getEvents(Date startDate, Date endDate) {
return events;
}
}
After these changes, the user can move events around as earlier, but dropping an event, the start and end dates are checked by the server. Note that as the server-side must move the event in order for it to render to the place it was dropped. The server can also reject moves by not doing anything when the event is received.
18.9.8. Handling Drag Selection
Drag selection works both in the monthly and weekly views. To listen for drag selection, you can add a RangeSelectListener to the Calendar. There is no default handler for range select.
In the code example below, we create an new event when any date range is selected. Drag selection opens a window where the user is asked for a caption for the new event. After confirming, the new event is be passed to the event provider and calendar is updated. Note that as our example event provider and event classes do not implement the event change interface, we must refresh the Calendar manually after changing the events.
cal.setHandler(new RangeSelectHandler() {
public void rangeSelect(RangeSelectEvent event) { BasicEvent calendarEvent = new BasicEvent(); calendarEvent.setStart(event.getStart()); calendarEvent.setEnd(event.getEnd());
// Create popup window and add a form in it. VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); layout.setSpacing(true);
final Window w = new Window(null, layout);
...
//Wrap the calendar event to a BeanItem
//and pass it to the form
final BeanItem<CalendarEvent> item =
new BeanItem<CalendarEvent>(myEvent);
final Form form = new Form(); form.setItemDataSource(item);
...
layout.addComponent(form);
HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true);
buttons.addComponent(new Button("OK", new ClickListener() {