List of usage examples for com.vaadin.data Result ifOk
public default void ifOk(SerializableConsumer<R> consumer)
From source file:com.haulmont.cuba.web.widgets.CubaDateField.java
License:Apache License
@Override protected void updateInternal(String newDateString, Map<String, Integer> resolutions) { // CAUTION: copied from AbstractDateField Set<String> resolutionNames = getResolutions().map(Enum::name).collect(Collectors.toSet()); resolutionNames.retainAll(resolutions.keySet()); if (!isReadOnly() && (!resolutionNames.isEmpty() || newDateString != null)) { // Old and new dates final LocalDate oldDate = getValue(); LocalDate newDate;/*from ww w. ja v a 2s .com*/ String mask = StringUtils.replaceChars(getState(false).dateMask, "#U", "__"); if ("".equals(newDateString) || mask.equals(newDateString)) { newDate = null; } else { newDate = reconstructDateFromFields(resolutions, oldDate); } boolean hasChanges = !Objects.equals(dateString, newDateString) || !Objects.equals(oldDate, newDate); if (hasChanges) { dateString = newDateString; currentParseErrorMessage = null; if (newDateString == null || newDateString.isEmpty() || mask.equals(newDateString)) { setValue(newDate, true); } else { // invalid date string if (resolutions.isEmpty()) { Result<LocalDate> parsedDate = handleUnparsableDateString(dateString); parsedDate.ifOk(v -> setValue(v, true)); if (parsedDate.isError()) { dateString = null; currentParseErrorMessage = parsedDate.getMessage().orElse("Parsing error"); if (!isDifferentValue(null)) { doSetValue(null); } else { setValue(null, true); } } } else { setValue(newDate, true); } } } } }