Example usage for com.vaadin.data Result getMessage

List of usage examples for com.vaadin.data Result getMessage

Introduction

In this page you can find the example usage for com.vaadin.data Result getMessage.

Prototype

public Optional<String> getMessage();

Source Link

Document

Returns an Optional of the result message, or an empty Optional if none.

Usage

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;//w  w w  .  j  ava2s  .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);
                }
            }
        }
    }
}