I want to use the newly added calendar component to perform the following:
- Like Vaadin demo, select a range of dates by dragging on the calendar that automatically pop-ups event editor and when saved, it saves to Event Entity and updates the calendar.
- Updates my own google or MS outlook calendar in parallel.
I’m stuck at the beginning to create an event. I have a very simple interface called Task to add events.
Here is the exception i am getting:
java.lang.UnsupportedOperationException: Use datasource for changing data items of EntityCalendarEventProvider
at com.haulmont.cuba.gui.components.calendar.EntityCalendarEventProvider.addEvent(EntityCalendarEventProvider.java:83)
at com.company.calendarandgoogle.web.task.TaskEdit.addEvent(TaskEdit.java:72)
at com.company.calendarandgoogle.web.task.TaskEdit.postCommit(TaskEdit.java:56)
at com.haulmont.cuba.gui.components.EditorWindowDelegate.commit(EditorWindowDelegate.java:269)
at com.haulmont.cuba.web.gui.WebWindow$Editor.commitAndClose(WebWindow.java:1578)
at com.haulmont.cuba.gui.components.AbstractEditor.commitAndClose(AbstractEditor.java:110)
at com.haulmont.cuba.gui.components.EditorWindowDelegate$2.actionPerform(EditorWindowDelegate.java:93)
at com.haulmont.cuba.web.gui.components.WebButton.performAction(WebButton.java:44)
at com.haulmont.cuba.web.gui.components.WebButton.lambda$new$61446b05$1(WebButton.java:36)
Here is my Task entity
@Table(name = "CALENDARANDGOOGLE_TASK")
@Entity(name = "calendarandgoogle$Task")
public class Task extends StandardEntity {
private static final long serialVersionUID = -4292269014751733171L;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "EMPLOYEE_ID")
protected Employee employee;
@Column(name = "CAPTION")
protected String caption;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "START_DATE")
protected Date startDate;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "END_DATE")
protected Date endDate;
@Column(name = "DESCRIPTION")
protected String description;
@Column(name = "STYLE_NAME")
protected String styleName;
@Column(name = "ALL_DAY")
protected Boolean allDay;
..........
Here is the Task controller
public class TaskEdit extends AbstractEditor<Task> {
@Named("fieldGroup.allDay")
private CheckBox allDayField;
@Named("fieldGroup.caption")
private TextField captionField;
@Named("fieldGroup.description")
private TextField descriptionField;
@Named("fieldGroup.employee")
private PickerField employeeField;
@Named("fieldGroup.endDate")
private DateField endDateField;
@Named("fieldGroup.startDate")
private DateField startDateField;
@Named("fieldGroup.styleName")
private TextField styleNameField;
@Inject
Calendar calendar;
@Override
public void init(Map<String, Object> params) {
super.init(params);
startDateField.setValue(new Date());
endDateField.setValue(new Date());
captionField.setValue(getMessage("caption"));
descriptionField.setValue(getMessage("description"));
allDayField.setValue(Boolean.FALSE);
}
@Override
protected boolean postCommit(boolean committed, boolean close) {
if (committed) {
addEvent();
}
return super.postCommit(committed, close);
}
public void addEvent() {
SimpleCalendarEvent calendarEvent = new SimpleCalendarEvent();
calendarEvent.setCaption(captionField.getValue());
calendarEvent.setDescription(descriptionField.getValue());
calendarEvent.setStart(startDateField.getValue());
calendarEvent.setEnd(endDateField.getValue());
calendarEvent.setAllDay(allDayField.getValue());
calendarEvent.setStyleName("event-blue");
calendar.getEventProvider().addEvent(calendarEvent);
}
}