From 3929d0ac6f8e3d7370412d1d181db1b2361d13e3 Mon Sep 17 00:00:00 2001 From: Ahmed Ashour Date: Fri, 20 Oct 2017 10:54:25 +0200 Subject: AbstractDateField.formatDate() to be abstract (#10186) * AbstractDateField.formatDate to be abstract Remove invalidDateString paramter, as it can be deduced * Fix test * Remove AbstractDateField.getResolutionVariable VAbstractTextualDate: rename updateDateVariables() to updateBufferedResolutions() * Revert to use fixed value of MONDAY. * release notes * updateAndSendBufferedValues() * Missed call to updateAndSendBufferedValues(); * release note --- .../main/java/com/vaadin/ui/AbstractComponent.java | 2 +- .../main/java/com/vaadin/ui/AbstractDateField.java | 106 +++++++++++---------- .../datefield/DateFieldListenersTest.java | 5 + 3 files changed, 60 insertions(+), 53 deletions(-) (limited to 'server/src') diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponent.java b/server/src/main/java/com/vaadin/ui/AbstractComponent.java index 88b42d5757..7a87230125 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractComponent.java +++ b/server/src/main/java/com/vaadin/ui/AbstractComponent.java @@ -91,7 +91,7 @@ public abstract class AbstractComponent extends AbstractClientConnector /** * The internal error message of the component. */ - private ErrorMessage componentError = null; + private ErrorMessage componentError; /** * Locale of this component. diff --git a/server/src/main/java/com/vaadin/ui/AbstractDateField.java b/server/src/main/java/com/vaadin/ui/AbstractDateField.java index 67067bd070..965c2f652a 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractDateField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractDateField.java @@ -77,10 +77,9 @@ public abstract class AbstractDateField resolutions) { - Set resolutionNames = getResolutions() - .map(AbstractDateField.this::getResolutionVariable) + Set resolutionNames = getResolutions().map(Enum::name) .collect(Collectors.toSet()); resolutionNames.retainAll(resolutions.keySet()); if (!isReadOnly() @@ -109,7 +108,8 @@ public abstract class AbstractDateField parsedDate = handleUnparsableDateString( dateString); parsedDate.ifOk(v -> setValue(v, true)); @@ -173,7 +173,7 @@ public abstract class AbstractDateFieldAbstractDateField with no caption and + * Constructs an empty {@code AbstractDateField} with no caption and * specified {@code resolution}. * * @param resolution @@ -185,10 +185,10 @@ public abstract class AbstractDateFieldAbstractDateField with caption. + * Constructs an empty {@code AbstractDateField} with caption. * * @param caption - * the caption of the datefield. + * the caption of the datefield * @param resolution * initial resolution for the field, not {@code null} */ @@ -198,11 +198,11 @@ public abstract class AbstractDateFieldAbstractDateField with the given caption - * and initial text contents. + * Constructs a new {@code AbstractDateField} with the given caption and + * initial text contents. * * @param caption - * the caption String for the editor. + * the caption {@code String} for the editor. * @param value * the date/time value. * @param resolution @@ -227,24 +227,31 @@ public abstract class AbstractDateField variables, + protected T reconstructDateFromFields(Map resolutions, T oldDate) { Map calendarFields = new HashMap<>(); for (R resolution : getResolutionsHigherOrEqualTo(getResolution())) { // Only handle what the client is allowed to send. The same // resolutions that are painted - String variableName = getResolutionVariable(resolution); + String resolutionName = resolution.name(); - Integer newValue = variables.get(variableName); - if (newValue != null) { - calendarFields.put(resolution, newValue); - } else { - calendarFields.put(resolution, - getDatePart(oldDate, resolution)); + Integer newValue = resolutions.get(resolutionName); + if (newValue == null) { + newValue = getDatePart(oldDate, resolution); } + calendarFields.put(resolution, newValue); } return buildDate(calendarFields); } @@ -252,8 +259,8 @@ public abstract class AbstractDateFieldstartDate is set to null, any - * value before endDate will be accepted by the range + * validate. If {@code startDate} is set to {@code null}, any value before + * {@code endDate} will be accepted by the range * * @param startDate * - the allowed range's start date @@ -315,12 +322,12 @@ public abstract class AbstractDateFieldendDate is set to null, any value - * after startDate will be accepted by the range. + * validate. If {@code endDate} is set to {@code null}, any value after + * {@code startDate} will be accepted by the range. * * @param endDate - * - the allowed range's end date (inclusive, based on the - * current resolution) + * the allowed range's end date (inclusive, based on the current + * resolution) */ public void setRangeEnd(T endDate) { Date date = convertToDate(endDate); @@ -336,7 +343,7 @@ public abstract class AbstractDateField validator = getRangeValidator();// TODO move range // check to internal // validator? @@ -717,9 +723,10 @@ public abstract class AbstractDateField getResolutions() { Type resolutionType = GenericTypeReflector.getTypeParameter(getClass(), @@ -776,11 +779,10 @@ public abstract class AbstractDateField clazz = (Class) resolutionType; return Stream.of(clazz.getEnumConstants()) .map(object -> (R) object); - } else { - throw new RuntimeException("Cannot detect resoluton type " - + Optional.ofNullable(resolutionType).map(Type::getTypeName) - .orElse(null)); } + throw new RuntimeException("Cannot detect resoluton type " + + Optional.ofNullable(resolutionType).map(Type::getTypeName) + .orElse(null)); } private Iterable getResolutionsHigherOrEqualTo(R resoution) { diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java index 4edc2a30df..eea1e33137 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java @@ -50,6 +50,11 @@ public class DateFieldListenersTest extends AbstractListenerMethodsTestBase { protected Date convertToDate(LocalDateTime date) { return null; } + + @Override + protected String formatDate(LocalDateTime value) { + return null; + } } @Test -- cgit v1.2.3