private void updateCalendarEventForm(CalendarEvent event) { BeanItem<CalendarEvent> item = new BeanItem<>(event); scheduleEventFieldLayout.removeAllComponents(); scheduleEventFieldGroup = new FieldGroup(); initFormFields(scheduleEventFieldLayout, event.getClass()); scheduleEventFieldGroup.setBuffered(true); scheduleEventFieldGroup.setItemDataSource(item); scheduledEventBinder.readBean(event); }
/* Adds/updates the event in the data source and fires change event. */ private void commitCalendarEvent() throws CommitException, ValidationException { scheduleEventFieldGroup.commit(); BasicEvent event = getFormCalendarEvent(); scheduledEventBinder.writeBean(event); if (event.getEnd() == null) { event.setEnd(event.getStart()); } if (!dataSource.containsEvent(event)) { dataSource.addEvent(event); } removeWindow(scheduleEventPopup); }
private void initFormFields(Layout formLayout, Class<? extends CalendarEvent> eventClass) { startDateField = createDateField("Start date"); endDateField = createDateField("End date"); final CheckBox allDayField = createCheckBox("All-day"); allDayField.addValueChangeListener( event -> { if (event.getValue()) { setFormDateResolution(Resolution.DAY); } else { setFormDateResolution(Resolution.MINUTE); } }); captionField = createTextField("Caption"); final TextField whereField = createTextField("Where"); final TextArea descriptionField = createTextArea("Description"); descriptionField.setRows(3); final ComboBox styleNameField = createStyleNameComboBox(); formLayout.addComponent(startDateField); formLayout.addComponent(endDateField); formLayout.addComponent(allDayField); formLayout.addComponent(captionField); if (eventClass == CalendarTestEvent.class) { formLayout.addComponent(whereField); } formLayout.addComponent(descriptionField); formLayout.addComponent(styleNameField); scheduleEventFieldGroup.bind(startDateField, "start"); scheduleEventFieldGroup.bind(endDateField, "end"); scheduleEventFieldGroup.bind(captionField, "caption"); scheduleEventFieldGroup.bind(descriptionField, "description"); if (eventClass == CalendarTestEvent.class) { scheduleEventFieldGroup.bind(whereField, "where"); } scheduleEventFieldGroup.bind(styleNameField, "styleName"); scheduledEventBinder.bind(allDayField, CalendarEvent::isAllDay, null); }
private void discardCalendarEvent() { scheduleEventFieldGroup.discard(); scheduledEventBinder.readBean(getFormCalendarEvent()); removeWindow(scheduleEventPopup); }