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();
}
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();
}
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;
}
})));
}
}
Aggregations