Search in sources :

Example 1 with Buffered

use of com.vaadin.v7.data.Buffered in project SORMAS-Project by hzi-braunschweig.

the class CommitDiscardWrapperComponent method discard.

@Override
public void discard() {
    if (fieldGroups != null) {
        for (FieldGroup fieldGroup : fieldGroups) {
            fieldGroup.discard();
        }
    } else if (wrappedComponent instanceof Buffered) {
        ((Buffered) wrappedComponent).discard();
    } else {
    // NOOP
    }
    dirty = false;
    onDiscard();
    onDone();
}
Also used : FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) Buffered(com.vaadin.v7.data.Buffered)

Example 2 with Buffered

use of com.vaadin.v7.data.Buffered in project SORMAS-Project by hzi-braunschweig.

the class CommitDiscardWrapperComponent method doCommit.

private void doCommit() throws InvalidValueException, SourceException, CommitRuntimeException {
    if (fieldGroups != null) {
        if (fieldGroups.size() > 1) {
            List<InvalidValueException> invalidValueExceptions = fieldGroups.stream().filter(fieldGroup -> !fieldGroup.isValid()).map(fieldGroup -> {
                try {
                    // all invalid fieldGroups are committed to fetch the CommitExceptions
                    fieldGroup.commit();
                } catch (CommitException e) {
                    return e;
                }
                // when the fieldGroup did not throw a CommitException, it is invalid and committed
                throw new IllegalStateException();
            }).map(e -> {
                // keep invalid value exceptions, throw the rest
                Throwable c = e.getCause();
                if (c instanceof InvalidValueException) {
                    return (InvalidValueException) c;
                } else if (c instanceof SourceException) {
                    throw (SourceException) c;
                } else {
                    throw new CommitRuntimeException(e);
                }
            }).collect(Collectors.toList());
            if (invalidValueExceptions.isEmpty()) {
            // NOOP
            } else if (invalidValueExceptions.size() == 1) {
                throw invalidValueExceptions.get(0);
            } else {
                throw new InvalidValueException(null, invalidValueExceptions.stream().map(InvalidValueException::getCauses).flatMap(Arrays::stream).toArray(InvalidValueException[]::new));
            }
        }
        try {
            for (FieldGroup fieldGroup : fieldGroups) {
                fieldGroup.commit();
            }
        } catch (CommitException e) {
            Throwable c = e.getCause();
            if (c instanceof InvalidValueException) {
                throw (InvalidValueException) c;
            } else if (c instanceof SourceException) {
                throw (SourceException) c;
            } else {
                throw new CommitRuntimeException(e);
            }
        }
    } else if (wrappedComponent instanceof Buffered) {
        ((Buffered) wrappedComponent).commit();
    } else {
    // NOOP
    }
    dirty = false;
    onCommit();
    commited = true;
    onDone();
}
Also used : InvalidValueException(com.vaadin.v7.data.Validator.InvalidValueException) Panel(com.vaadin.ui.Panel) EventDataForm(de.symeda.sormas.ui.events.EventDataForm) Arrays(java.util.Arrays) ClickListener(com.vaadin.ui.Button.ClickListener) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) VerticalLayout(com.vaadin.ui.VerticalLayout) Alignment(com.vaadin.ui.Alignment) Notifier(com.vaadin.event.Action.Notifier) ArrayUtils(org.apache.commons.lang3.ArrayUtils) AccessibleTextField(de.symeda.sormas.ui.location.AccessibleTextField) PersonDto(de.symeda.sormas.api.person.PersonDto) ArrayList(java.util.ArrayList) Buffered(com.vaadin.v7.data.Buffered) DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) Notification(com.vaadin.ui.Notification) RichTextArea(com.vaadin.v7.ui.RichTextArea) Page(com.vaadin.server.Page) KeyCode(com.vaadin.event.ShortcutAction.KeyCode) AbstractLegacyComponent(com.vaadin.v7.ui.AbstractLegacyComponent) CannotProceedException(javax.naming.CannotProceedException) ValoTheme(com.vaadin.ui.themes.ValoTheme) LocationDto(de.symeda.sormas.api.location.LocationDto) ClickEvent(com.vaadin.ui.Button.ClickEvent) Collection(java.util.Collection) Field(com.vaadin.v7.ui.Field) EventDto(de.symeda.sormas.api.event.EventDto) InvalidValueException(com.vaadin.v7.data.Validator.InvalidValueException) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) List(java.util.List) Button(com.vaadin.ui.Button) Stream(java.util.stream.Stream) Type(com.vaadin.ui.Notification.Type) PersonEditForm(de.symeda.sormas.ui.person.PersonEditForm) HorizontalLayout(com.vaadin.ui.HorizontalLayout) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) TextArea(com.vaadin.v7.ui.TextArea) CommitException(com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException) Descriptions(de.symeda.sormas.api.i18n.Descriptions) Objects.nonNull(java.util.Objects.nonNull) Strings(de.symeda.sormas.api.i18n.Strings) Component(com.vaadin.ui.Component) CommitException(com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) Buffered(com.vaadin.v7.data.Buffered)

Example 3 with Buffered

use of com.vaadin.v7.data.Buffered in project SORMAS-Project by hzi-braunschweig.

the class CommitDiscardWrapperComponent method addDirtyHandler.

@SuppressWarnings("deprecation")
protected void addDirtyHandler(FieldGroup[] fieldGroups) {
    if (fieldGroups != null) {
        Stream.of(fieldGroups).forEach(fg -> fg.getFields().forEach(f -> f.addValueChangeListener(ev -> {
            final Object source = ((Field.ValueChangeEvent) ev).getSource();
            // moving it to a separate method breaks the logic at least on my dev system
            if (source instanceof PersonEditForm) {
                final PersonEditForm personEditForm = (PersonEditForm) source;
                final LocationEditForm locationEditForm = personEditForm.getField(PersonDto.ADDRESS);
                if (atLeastOneFieldModified(locationEditForm.getField(LocationDto.LATITUDE), locationEditForm.getField(LocationDto.LONGITUDE), locationEditForm.getField(LocationDto.LAT_LON_ACCURACY))) {
                    dirty = true;
                } else if (locationEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
                    dirty = true;
                } else if (personEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
                    dirty = true;
                }
            } else if (source instanceof EventDataForm) {
                final EventDataForm eventDataForm = (EventDataForm) source;
                final LocationEditForm locationEditForm = eventDataForm.getField(EventDto.EVENT_LOCATION);
                if (atLeastOneFieldModified(locationEditForm.getField(LocationDto.LATITUDE), locationEditForm.getField(LocationDto.LONGITUDE), locationEditForm.getField(LocationDto.LAT_LON_ACCURACY))) {
                    dirty = true;
                } else if (locationEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
                    dirty = true;
                } else if (eventDataForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
                    dirty = true;
                }
            } else if (source instanceof LocationEditForm) {
                final LocationEditForm locationEditForm = (LocationEditForm) source;
                if (atLeastOneFieldModified(locationEditForm.getField(LocationDto.LATITUDE), locationEditForm.getField(LocationDto.LONGITUDE), locationEditForm.getField(LocationDto.LAT_LON_ACCURACY))) {
                    dirty = true;
                } else if (locationEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
                    dirty = true;
                }
            } else if (source instanceof AccessibleTextField) {
                final AccessibleTextField accessibleTextField = (AccessibleTextField) source;
                if (accessibleTextField.isModified()) {
                    dirty = true;
                }
            } else {
                dirty = true;
            }
        })));
    }
}
Also used : Panel(com.vaadin.ui.Panel) EventDataForm(de.symeda.sormas.ui.events.EventDataForm) Arrays(java.util.Arrays) ClickListener(com.vaadin.ui.Button.ClickListener) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) VerticalLayout(com.vaadin.ui.VerticalLayout) Alignment(com.vaadin.ui.Alignment) Notifier(com.vaadin.event.Action.Notifier) ArrayUtils(org.apache.commons.lang3.ArrayUtils) AccessibleTextField(de.symeda.sormas.ui.location.AccessibleTextField) PersonDto(de.symeda.sormas.api.person.PersonDto) ArrayList(java.util.ArrayList) Buffered(com.vaadin.v7.data.Buffered) DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) Notification(com.vaadin.ui.Notification) RichTextArea(com.vaadin.v7.ui.RichTextArea) Page(com.vaadin.server.Page) KeyCode(com.vaadin.event.ShortcutAction.KeyCode) AbstractLegacyComponent(com.vaadin.v7.ui.AbstractLegacyComponent) CannotProceedException(javax.naming.CannotProceedException) ValoTheme(com.vaadin.ui.themes.ValoTheme) LocationDto(de.symeda.sormas.api.location.LocationDto) ClickEvent(com.vaadin.ui.Button.ClickEvent) Collection(java.util.Collection) Field(com.vaadin.v7.ui.Field) EventDto(de.symeda.sormas.api.event.EventDto) InvalidValueException(com.vaadin.v7.data.Validator.InvalidValueException) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) List(java.util.List) Button(com.vaadin.ui.Button) Stream(java.util.stream.Stream) Type(com.vaadin.ui.Notification.Type) PersonEditForm(de.symeda.sormas.ui.person.PersonEditForm) HorizontalLayout(com.vaadin.ui.HorizontalLayout) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) TextArea(com.vaadin.v7.ui.TextArea) CommitException(com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException) Descriptions(de.symeda.sormas.api.i18n.Descriptions) Objects.nonNull(java.util.Objects.nonNull) Strings(de.symeda.sormas.api.i18n.Strings) Component(com.vaadin.ui.Component) AccessibleTextField(de.symeda.sormas.ui.location.AccessibleTextField) PersonEditForm(de.symeda.sormas.ui.person.PersonEditForm) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) EventDataForm(de.symeda.sormas.ui.events.EventDataForm) Buffered(com.vaadin.v7.data.Buffered)

Aggregations

Buffered (com.vaadin.v7.data.Buffered)3 FieldGroup (com.vaadin.v7.data.fieldgroup.FieldGroup)3 Notifier (com.vaadin.event.Action.Notifier)2 KeyCode (com.vaadin.event.ShortcutAction.KeyCode)2 Page (com.vaadin.server.Page)2 Alignment (com.vaadin.ui.Alignment)2 Button (com.vaadin.ui.Button)2 ClickEvent (com.vaadin.ui.Button.ClickEvent)2 ClickListener (com.vaadin.ui.Button.ClickListener)2 Component (com.vaadin.ui.Component)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Notification (com.vaadin.ui.Notification)2 Type (com.vaadin.ui.Notification.Type)2 Panel (com.vaadin.ui.Panel)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 ValoTheme (com.vaadin.ui.themes.ValoTheme)2 InvalidValueException (com.vaadin.v7.data.Validator.InvalidValueException)2 CommitException (com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException)2 AbstractLegacyComponent (com.vaadin.v7.ui.AbstractLegacyComponent)2 Field (com.vaadin.v7.ui.Field)2