diff options
author | Denis Anisimov <denis@vaadin.com> | 2016-09-27 10:41:37 +0300 |
---|---|---|
committer | Denis Anisimov <denis@vaadin.com> | 2016-09-30 06:56:18 +0000 |
commit | d36d63fefa3ab9f4908f97772bcc6499e4f52532 (patch) | |
tree | d2189db8f44601925a96435dedec031459eeed57 | |
parent | db3a91c9b4d8d0451c8f1c5e875f4c6f6f50324a (diff) | |
download | vaadin-framework-d36d63fefa3ab9f4908f97772bcc6499e4f52532.tar.gz vaadin-framework-d36d63fefa3ab9f4908f97772bcc6499e4f52532.zip |
Make AbstractDateField based on LocalDate (#125).
Change-Id: I33a4a4f0f3437a8d1733031a131afbe844c12afb
92 files changed, 543 insertions, 2068 deletions
diff --git a/client/src/main/java/com/vaadin/client/DateTimeService.java b/client/src/main/java/com/vaadin/client/DateTimeService.java index 6c20282f97..bfb8533f39 100644 --- a/client/src/main/java/com/vaadin/client/DateTimeService.java +++ b/client/src/main/java/com/vaadin/client/DateTimeService.java @@ -20,8 +20,8 @@ import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; -import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.LocaleInfo; +import com.google.gwt.i18n.shared.DateTimeFormat; import com.vaadin.shared.ui.datefield.Resolution; /** @@ -235,15 +235,9 @@ public class DateTimeService { start += s.getHours() * 10000l; end += e.getHours() * 10000l; target += date.getHours() * 10000l; - if (resolution == Resolution.HOUR) { - return (start <= target && end >= target); - } start += s.getMinutes() * 100l; end += e.getMinutes() * 100l; target += date.getMinutes() * 100l; - if (resolution == Resolution.MINUTE) { - return (start <= target && end >= target); - } start += s.getSeconds(); end += e.getSeconds(); target += date.getSeconds(); diff --git a/client/src/main/java/com/vaadin/client/ui/VCalendarPanel.java b/client/src/main/java/com/vaadin/client/ui/VCalendarPanel.java index 57750b8fbb..2a03b91d2b 100644 --- a/client/src/main/java/com/vaadin/client/ui/VCalendarPanel.java +++ b/client/src/main/java/com/vaadin/client/ui/VCalendarPanel.java @@ -23,11 +23,8 @@ import com.google.gwt.aria.client.Roles; import com.google.gwt.aria.client.SelectedValue; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.dom.client.Node; import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; -import com.google.gwt.event.dom.client.ChangeEvent; -import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.DomEvent; @@ -48,9 +45,7 @@ import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.FlexTable; -import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.InlineHTML; -import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.BrowserInfo; import com.vaadin.client.DateTimeService; @@ -97,14 +92,6 @@ public class VCalendarPanel extends FocusableFlexTable implements } /** - * Dispatches an event when the panel when time is changed - */ - public interface TimeChangeListener { - - void changed(int hour, int min, int sec, int msec); - } - - /** * Represents a Date button in the calendar */ private class VEventButton extends Button { @@ -169,8 +156,6 @@ public class VCalendarPanel extends FocusableFlexTable implements private VEventButton nextMonth; - private VTime time; - private FlexTable days = new FlexTable(); private Resolution resolution = Resolution.YEAR; @@ -197,8 +182,6 @@ public class VCalendarPanel extends FocusableFlexTable implements private FocusChangeListener focusChangeListener; - private TimeChangeListener timeChangeListener; - private boolean hasFocus = false; private VDateField parent; @@ -238,8 +221,7 @@ public class VCalendarPanel extends FocusableFlexTable implements */ private void focusDay(Date date) { // Only used when calender body is present - if (resolution.getCalendarField() > Resolution.MONTH - .getCalendarField()) { + if (isDay(getResolution())) { if (focusedDay != null) { focusedDay.removeStyleDependentName(CN_FOCUSED); } @@ -265,6 +247,10 @@ public class VCalendarPanel extends FocusableFlexTable implements } } + private boolean isDay(Resolution resolution) { + return Resolution.DAY.equals(resolution); + } + /** * Sets the selection highlight to a given day in the current view * @@ -344,10 +330,6 @@ public class VCalendarPanel extends FocusableFlexTable implements public void setResolution(Resolution resolution) { this.resolution = resolution; - if (time != null) { - time.removeFromParent(); - time = null; - } } private boolean isReadonly() { @@ -685,8 +667,7 @@ public class VCalendarPanel extends FocusableFlexTable implements if (day > 6) { day = 0; } - if (getResolution().getCalendarField() > Resolution.MONTH - .getCalendarField()) { + if (isDay(getResolution())) { days.setHTML(headerRow, firstWeekdayColumn + i, "<strong>" + getDateTimeService().getShortDay(day) + "</strong>"); } else { @@ -772,16 +753,6 @@ public class VCalendarPanel extends FocusableFlexTable implements } /** - * Do we need the time selector - * - * @return True if it is required - */ - private boolean isTimeSelectorNeeded() { - return getResolution().getCalendarField() > Resolution.DAY - .getCalendarField(); - } - - /** * Updates the calendar and text field with the selected dates. */ public void renderCalendar() { @@ -812,31 +783,19 @@ public class VCalendarPanel extends FocusableFlexTable implements displayedMonth = new FocusedDate(now.getYear(), now.getMonth(), 1); } - if (updateDate && getResolution().getCalendarField() <= Resolution.MONTH - .getCalendarField() && focusChangeListener != null) { + if (updateDate && !isDay(getResolution()) + && focusChangeListener != null) { focusChangeListener.focusChanged(new Date(focusedDate.getTime())); } - final boolean needsMonth = getResolution() - .getCalendarField() > Resolution.YEAR.getCalendarField(); - boolean needsBody = getResolution().getCalendarField() >= Resolution.DAY - .getCalendarField(); + final boolean needsMonth = !getResolution().equals(Resolution.YEAR); + boolean needsBody = isDay(getResolution()); buildCalendarHeader(needsMonth); clearCalendarBody(!needsBody); if (needsBody) { buildCalendarBody(); } - if (isTimeSelectorNeeded()) { - time = new VTime(); - setWidget(2, 0, time); - getFlexCellFormatter().setColSpan(2, 0, 5); - getFlexCellFormatter().setStyleName(2, 0, - parent.getStylePrimaryName() + "-calendarpanel-time"); - } else if (time != null) { - remove(time); - } - initialRenderDone = true; } @@ -1105,23 +1064,6 @@ public class VCalendarPanel extends FocusableFlexTable implements * The keydown/keypress event */ private void handleKeyPress(DomEvent<?> event) { - // Special handling for events from time ListBoxes. - if (time != null && time.getElement().isOrHasChild( - (Node) event.getNativeEvent().getEventTarget().cast())) { - int nativeKeyCode = event.getNativeEvent().getKeyCode(); - if (nativeKeyCode == getSelectKey()) { - onSubmit(); // submit if enter key hit down on listboxes - event.preventDefault(); - event.stopPropagation(); - } - if (nativeKeyCode == getCloseKey()) { - onCancel(); // cancel if ESC key hit down on listboxes - event.preventDefault(); - event.stopPropagation(); - } - return; - } - // Check tabs int keycode = event.getNativeEvent().getKeyCode(); if (keycode == KeyCodes.KEY_TAB @@ -1610,8 +1552,7 @@ public class VCalendarPanel extends FocusableFlexTable implements // confusion, but this is only needed (and allowed) when we have // a day // resolution - if (getResolution().getCalendarField() >= Resolution.DAY - .getCalendarField()) { + if (isDay(getResolution())) { value = null; } } else { @@ -1624,19 +1565,14 @@ public class VCalendarPanel extends FocusableFlexTable implements 1); } - // Re-render calendar if the displayed month is changed, - // or if a time selector is needed but does not exist. - if ((isTimeSelectorNeeded() && time == null) - || oldDisplayedMonth == null || value == null + // Re-render calendar if the displayed month is changed. + if (oldDisplayedMonth == null || value == null || oldDisplayedMonth.getYear() != value.getYear() || oldDisplayedMonth.getMonth() != value.getMonth()) { renderCalendar(); } else { focusDay(focusedDate); selectFocused(); - if (isTimeSelectorNeeded()) { - time.updateTimes(); - } } if (!hasFocus) { @@ -1645,282 +1581,6 @@ public class VCalendarPanel extends FocusableFlexTable implements } /** - * TimeSelector is a widget consisting of list boxes that modifie the Date - * object that is given for. - * - */ - public class VTime extends FlowPanel implements ChangeHandler { - - private ListBox hours; - - private ListBox mins; - - private ListBox sec; - - private ListBox ampm; - - /** - * Constructor - */ - public VTime() { - super(); - setStyleName(VDateField.CLASSNAME + "-time"); - buildTime(); - } - - private ListBox createListBox() { - ListBox lb = new ListBox(); - lb.setStyleName("v-select"); - lb.addChangeHandler(this); - lb.addBlurHandler(VCalendarPanel.this); - lb.addFocusHandler(VCalendarPanel.this); - return lb; - } - - /** - * Constructs the ListBoxes and updates their value - * - * @param redraw - * Should new instances of the listboxes be created - */ - private void buildTime() { - clear(); - - hours = createListBox(); - if (getDateTimeService().isTwelveHourClock()) { - hours.addItem("12"); - for (int i = 1; i < 12; i++) { - hours.addItem((i < 10) ? "0" + i : "" + i); - } - } else { - for (int i = 0; i < 24; i++) { - hours.addItem((i < 10) ? "0" + i : "" + i); - } - } - - hours.addChangeHandler(this); - if (getDateTimeService().isTwelveHourClock()) { - ampm = createListBox(); - final String[] ampmText = getDateTimeService().getAmPmStrings(); - ampm.addItem(ampmText[0]); - ampm.addItem(ampmText[1]); - ampm.addChangeHandler(this); - } - - if (getResolution().getCalendarField() >= Resolution.MINUTE - .getCalendarField()) { - mins = createListBox(); - for (int i = 0; i < 60; i++) { - mins.addItem((i < 10) ? "0" + i : "" + i); - } - mins.addChangeHandler(this); - } - if (getResolution().getCalendarField() >= Resolution.SECOND - .getCalendarField()) { - sec = createListBox(); - for (int i = 0; i < 60; i++) { - sec.addItem((i < 10) ? "0" + i : "" + i); - } - sec.addChangeHandler(this); - } - - final String delimiter = getDateTimeService().getClockDelimeter(); - if (isReadonly()) { - int h = 0; - if (value != null) { - h = value.getHours(); - } - if (getDateTimeService().isTwelveHourClock()) { - h -= h < 12 ? 0 : 12; - } - add(new VLabel(h < 10 ? "0" + h : "" + h)); - } else { - add(hours); - } - - if (getResolution().getCalendarField() >= Resolution.MINUTE - .getCalendarField()) { - add(new VLabel(delimiter)); - if (isReadonly()) { - final int m = mins.getSelectedIndex(); - add(new VLabel(m < 10 ? "0" + m : "" + m)); - } else { - add(mins); - } - } - if (getResolution().getCalendarField() >= Resolution.SECOND - .getCalendarField()) { - add(new VLabel(delimiter)); - if (isReadonly()) { - final int s = sec.getSelectedIndex(); - add(new VLabel(s < 10 ? "0" + s : "" + s)); - } else { - add(sec); - } - } - if (getResolution() == Resolution.HOUR) { - add(new VLabel(delimiter + "00")); // o'clock - } - if (getDateTimeService().isTwelveHourClock()) { - add(new VLabel(" ")); - if (isReadonly()) { - int i = 0; - if (value != null) { - i = (value.getHours() < 12) ? 0 : 1; - } - add(new VLabel(ampm.getItemText(i))); - } else { - add(ampm); - } - } - - if (isReadonly()) { - return; - } - - // Update times - updateTimes(); - - ListBox lastDropDown = getLastDropDown(); - lastDropDown.addKeyDownHandler(new KeyDownHandler() { - @Override - public void onKeyDown(KeyDownEvent event) { - boolean shiftKey = event.getNativeEvent().getShiftKey(); - if (shiftKey) { - return; - } else { - int nativeKeyCode = event.getNativeKeyCode(); - if (nativeKeyCode == KeyCodes.KEY_TAB) { - onTabOut(event); - } - } - } - }); - - } - - private ListBox getLastDropDown() { - int i = getWidgetCount() - 1; - while (i >= 0) { - Widget widget = getWidget(i); - if (widget instanceof ListBox) { - return (ListBox) widget; - } - i--; - } - return null; - } - - /** - * Updates the valus to correspond to the values in value - */ - public void updateTimes() { - if (value == null) { - value = new Date(); - } - if (getDateTimeService().isTwelveHourClock()) { - int h = value.getHours(); - ampm.setSelectedIndex(h < 12 ? 0 : 1); - h -= ampm.getSelectedIndex() * 12; - hours.setSelectedIndex(h); - } else { - hours.setSelectedIndex(value.getHours()); - } - if (getResolution().getCalendarField() >= Resolution.MINUTE - .getCalendarField()) { - mins.setSelectedIndex(value.getMinutes()); - } - if (getResolution().getCalendarField() >= Resolution.SECOND - .getCalendarField()) { - sec.setSelectedIndex(value.getSeconds()); - } - if (getDateTimeService().isTwelveHourClock()) { - ampm.setSelectedIndex(value.getHours() < 12 ? 0 : 1); - } - - hours.setEnabled(isEnabled()); - if (mins != null) { - mins.setEnabled(isEnabled()); - } - if (sec != null) { - sec.setEnabled(isEnabled()); - } - if (ampm != null) { - ampm.setEnabled(isEnabled()); - } - - } - - private DateTimeService getDateTimeService() { - if (dateTimeService == null) { - dateTimeService = new DateTimeService(); - } - return dateTimeService; - } - - /* - * (non-Javadoc) VT - * - * @see - * com.google.gwt.event.dom.client.ChangeHandler#onChange(com.google.gwt - * .event.dom.client.ChangeEvent) - */ - @Override - public void onChange(ChangeEvent event) { - /* - * Value from dropdowns gets always set for the value. Like year and - * month when resolution is month or year. - */ - if (event.getSource() == hours) { - int h = hours.getSelectedIndex(); - if (getDateTimeService().isTwelveHourClock()) { - h = h + ampm.getSelectedIndex() * 12; - } - value.setHours(h); - if (timeChangeListener != null) { - timeChangeListener.changed(h, value.getMinutes(), - value.getSeconds(), - DateTimeService.getMilliseconds(value)); - } - event.preventDefault(); - event.stopPropagation(); - } else if (event.getSource() == mins) { - final int m = mins.getSelectedIndex(); - value.setMinutes(m); - if (timeChangeListener != null) { - timeChangeListener.changed(value.getHours(), m, - value.getSeconds(), - DateTimeService.getMilliseconds(value)); - } - event.preventDefault(); - event.stopPropagation(); - } else if (event.getSource() == sec) { - final int s = sec.getSelectedIndex(); - value.setSeconds(s); - if (timeChangeListener != null) { - timeChangeListener.changed(value.getHours(), - value.getMinutes(), s, - DateTimeService.getMilliseconds(value)); - } - event.preventDefault(); - event.stopPropagation(); - } else if (event.getSource() == ampm) { - final int h = hours.getSelectedIndex() - + (ampm.getSelectedIndex() * 12); - value.setHours(h); - if (timeChangeListener != null) { - timeChangeListener.changed(h, value.getMinutes(), - value.getSeconds(), - DateTimeService.getMilliseconds(value)); - } - event.preventDefault(); - event.stopPropagation(); - } - } - - } - - /** * A widget representing a single day in the calendar panel. */ private class Day extends InlineHTML { @@ -1989,15 +1649,6 @@ public class VCalendarPanel extends FocusableFlexTable implements } /** - * The time change listener is triggered when the user changes the time. - * - * @param listener - */ - public void setTimeChangeListener(TimeChangeListener listener) { - timeChangeListener = listener; - } - - /** * Returns the submit listener that listens to selection made from the panel * * @return The listener or NULL if no listener has been set @@ -2083,17 +1734,6 @@ public class VCalendarPanel extends FocusableFlexTable implements } return SUBPART_DAY + id; } - } else if (time != null) { - if (contains(time.hours, subElement)) { - return SUBPART_HOUR_SELECT; - } else if (contains(time.mins, subElement)) { - return SUBPART_MINUTE_SELECT; - } else if (contains(time.sec, subElement)) { - return SUBPART_SECS_SELECT; - } else if (contains(time.ampm, subElement)) { - return SUBPART_AMPM_SELECT; - - } } else if (getCellFormatter().getElement(0, 2) .isOrHasChild(subElement)) { return SUBPART_MONTH_YEAR_HEADER; @@ -2132,18 +1772,6 @@ public class VCalendarPanel extends FocusableFlexTable implements if (SUBPART_PREV_YEAR.equals(subPart)) { return prevYear.getElement(); } - if (SUBPART_HOUR_SELECT.equals(subPart)) { - return time.hours.getElement(); - } - if (SUBPART_MINUTE_SELECT.equals(subPart)) { - return time.mins.getElement(); - } - if (SUBPART_SECS_SELECT.equals(subPart)) { - return time.sec.getElement(); - } - if (SUBPART_AMPM_SELECT.equals(subPart)) { - return time.ampm.getElement(); - } if (subPart.startsWith(SUBPART_DAY)) { // Zero or negative ids map to days in the preceding month, // past-the-end-of-month ids to days in the following month diff --git a/client/src/main/java/com/vaadin/client/ui/VDateField.java b/client/src/main/java/com/vaadin/client/ui/VDateField.java index d94252c0a6..ef7a131a77 100644 --- a/client/src/main/java/com/vaadin/client/ui/VDateField.java +++ b/client/src/main/java/com/vaadin/client/ui/VDateField.java @@ -37,24 +37,8 @@ public class VDateField extends FlowPanel implements Field, HasEnabled { /** For internal use only. May be removed or replaced in the future. */ public boolean immediate; - @Deprecated - public static final Resolution RESOLUTION_YEAR = Resolution.YEAR; - @Deprecated - public static final Resolution RESOLUTION_MONTH = Resolution.MONTH; - @Deprecated - public static final Resolution RESOLUTION_DAY = Resolution.DAY; - @Deprecated - public static final Resolution RESOLUTION_HOUR = Resolution.HOUR; - @Deprecated - public static final Resolution RESOLUTION_MIN = Resolution.MINUTE; - @Deprecated - public static final Resolution RESOLUTION_SEC = Resolution.SECOND; - /** For internal use only. May be removed or replaced in the future. */ public static String resolutionToString(Resolution res) { - if (res.getCalendarField() > Resolution.DAY.getCalendarField()) { - return "full"; - } if (res == Resolution.DAY) { return "day"; } @@ -89,37 +73,20 @@ public class VDateField extends FlowPanel implements Field, HasEnabled { } /** - * We need this redundant native function because Java's Date object doesn't - * have a setMilliseconds method. - * <p> * For internal use only. May be removed or replaced in the future. */ - public static native double getTime(int y, int m, int d, int h, int mi, - int s, int ms) - /*-{ - try { - var date = new Date(2000,1,1,1); // don't use current date here - if(y && y >= 0) date.setFullYear(y); - if(m && m >= 1) date.setMonth(m-1); - if(d && d >= 0) date.setDate(d); - if(h >= 0) date.setHours(h); - if(mi >= 0) date.setMinutes(mi); - if(s >= 0) date.setSeconds(s); - if(ms >= 0) date.setMilliseconds(ms); - return date.getTime(); - } catch (e) { - // TODO print some error message on the console - //console.log(e); - return (new Date()).getTime(); - } - }-*/; - - public int getMilliseconds() { - return DateTimeService.getMilliseconds(date); - } - - public void setMilliseconds(int ms) { - DateTimeService.setMilliseconds(date, ms); + public static Date getTime(int year, int month, int day) { + Date date = new Date(2000 - 1900, 0, 1); + if (year >= 0) { + date.setYear(year - 1900); + } + if (month >= 0) { + date.setMonth(month - 1); + } + if (day >= 0) { + date.setDate(day); + } + return date; } public Resolution getCurrentResolution() { diff --git a/client/src/main/java/com/vaadin/client/ui/VDateFieldCalendar.java b/client/src/main/java/com/vaadin/client/ui/VDateFieldCalendar.java index 0970cc81ef..d09de9a771 100644 --- a/client/src/main/java/com/vaadin/client/ui/VDateFieldCalendar.java +++ b/client/src/main/java/com/vaadin/client/ui/VDateFieldCalendar.java @@ -19,7 +19,6 @@ package com.vaadin.client.ui; import java.util.Date; import com.google.gwt.event.dom.client.DomEvent; -import com.vaadin.client.DateTimeService; import com.vaadin.client.ui.VCalendarPanel.FocusOutListener; import com.vaadin.client.ui.VCalendarPanel.SubmitListener; import com.vaadin.shared.ui.datefield.Resolution; @@ -79,40 +78,12 @@ public class VDateFieldCalendar extends VDateField { setCurrentDate((Date) date2.clone()); getClient().updateVariable(getId(), "year", date2.getYear() + 1900, false); - if (getCurrentResolution().getCalendarField() > Resolution.YEAR - .getCalendarField()) { + if (getCurrentResolution().compareTo(Resolution.YEAR) < 0) { getClient().updateVariable(getId(), "month", date2.getMonth() + 1, false); - if (getCurrentResolution().getCalendarField() > Resolution.MONTH - .getCalendarField()) { + if (getCurrentResolution().compareTo(Resolution.MONTH) < 0) { getClient().updateVariable(getId(), "day", date2.getDate(), false); - if (getCurrentResolution() - .getCalendarField() > Resolution.DAY - .getCalendarField()) { - getClient().updateVariable(getId(), "hour", - date2.getHours(), false); - if (getCurrentResolution() - .getCalendarField() > Resolution.HOUR - .getCalendarField()) { - getClient().updateVariable(getId(), "min", - date2.getMinutes(), false); - if (getCurrentResolution() - .getCalendarField() > Resolution.MINUTE - .getCalendarField()) { - getClient().updateVariable(getId(), "sec", - date2.getSeconds(), false); - if (getCurrentResolution() - .getCalendarField() > Resolution.SECOND - .getCalendarField()) { - getClient().updateVariable(getId(), - "msec", DateTimeService - .getMilliseconds(date2), - false); - } - } - } - } } } if (isImmediate()) { diff --git a/client/src/main/java/com/vaadin/client/ui/VPopupCalendar.java b/client/src/main/java/com/vaadin/client/ui/VPopupCalendar.java index cc7d1a9820..f56228f26e 100644 --- a/client/src/main/java/com/vaadin/client/ui/VPopupCalendar.java +++ b/client/src/main/java/com/vaadin/client/ui/VPopupCalendar.java @@ -51,7 +51,7 @@ import com.vaadin.client.VConsole; import com.vaadin.client.ui.VCalendarPanel.FocusOutListener; import com.vaadin.client.ui.VCalendarPanel.SubmitListener; import com.vaadin.client.ui.aria.AriaHelper; -import com.vaadin.shared.ui.datefield.PopupDateFieldState; +import com.vaadin.shared.ui.datefield.DateFieldState; import com.vaadin.shared.ui.datefield.Resolution; /** @@ -130,7 +130,7 @@ public class VPopupCalendar extends VTextualDate // Description of the usage of the widget for assisitve device users descriptionForAssisitveDevicesElement = DOM.createDiv(); descriptionForAssisitveDevicesElement.setInnerText( - PopupDateFieldState.DESCRIPTION_FOR_ASSISTIVE_DEVICES); + DateFieldState.DESCRIPTION_FOR_ASSISTIVE_DEVICES); AriaHelper.ensureHasId(descriptionForAssisitveDevicesElement); Roles.getTextboxRole().setAriaDescribedbyProperty(text.getElement(), Id.of(descriptionForAssisitveDevicesElement)); @@ -222,32 +222,12 @@ public class VPopupCalendar extends VTextualDate setCurrentDate((Date) newDate.clone()); getClient().updateVariable(getId(), "year", newDate.getYear() + 1900, false); - if (getCurrentResolution().getCalendarField() > Resolution.YEAR - .getCalendarField()) { + if (getCurrentResolution().compareTo(Resolution.YEAR) < 0) { getClient().updateVariable(getId(), "month", newDate.getMonth() + 1, false); - if (getCurrentResolution().getCalendarField() > Resolution.MONTH - .getCalendarField()) { + if (getCurrentResolution().compareTo(Resolution.MONTH) < 0) { getClient().updateVariable(getId(), "day", newDate.getDate(), false); - if (getCurrentResolution() - .getCalendarField() > Resolution.DAY - .getCalendarField()) { - getClient().updateVariable(getId(), "hour", - newDate.getHours(), false); - if (getCurrentResolution() - .getCalendarField() > Resolution.HOUR - .getCalendarField()) { - getClient().updateVariable(getId(), "min", - newDate.getMinutes(), false); - if (getCurrentResolution() - .getCalendarField() > Resolution.MINUTE - .getCalendarField()) { - getClient().updateVariable(getId(), "sec", - newDate.getSeconds(), false); - } - } - } } } } diff --git a/client/src/main/java/com/vaadin/client/ui/VTextualDate.java b/client/src/main/java/com/vaadin/client/ui/VTextualDate.java index 45221dfce0..9577698194 100644 --- a/client/src/main/java/com/vaadin/client/ui/VTextualDate.java +++ b/client/src/main/java/com/vaadin/client/ui/VTextualDate.java @@ -132,30 +132,6 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, String frmString = LocaleService .getDateFormat(currentLocale); frmString = cleanFormat(frmString); - // String delim = LocaleService - // .getClockDelimiter(currentLocale); - if (currentResolution.getCalendarField() >= Resolution.HOUR - .getCalendarField()) { - if (dts.isTwelveHourClock()) { - frmString += " hh"; - } else { - frmString += " HH"; - } - if (currentResolution - .getCalendarField() >= Resolution.MINUTE - .getCalendarField()) { - frmString += ":mm"; - if (currentResolution - .getCalendarField() >= Resolution.SECOND - .getCalendarField()) { - frmString += ":ss"; - } - } - if (dts.isTwelveHourClock()) { - frmString += " aaa"; - } - - } formatStr = frmString; } catch (LocaleNotLoadedException e) { @@ -283,47 +259,24 @@ public class VTextualDate extends VDateField implements Field, ChangeHandler, getClient().updateVariable(getId(), "year", currentDate != null ? currentDate.getYear() + 1900 : -1, currentResolution == Resolution.YEAR && immediate); - if (currentResolution.getCalendarField() >= Resolution.MONTH - .getCalendarField()) { + if (currentResolution.compareTo(Resolution.MONTH) <= 0) { getClient().updateVariable(getId(), "month", currentDate != null ? currentDate.getMonth() + 1 : -1, currentResolution == Resolution.MONTH && immediate); } - if (currentResolution.getCalendarField() >= Resolution.DAY - .getCalendarField()) { + if (currentResolution.compareTo(Resolution.DAY) <= 0) { getClient().updateVariable(getId(), "day", currentDate != null ? currentDate.getDate() : -1, currentResolution == Resolution.DAY && immediate); } - if (currentResolution.getCalendarField() >= Resolution.HOUR - .getCalendarField()) { - getClient().updateVariable(getId(), "hour", - currentDate != null ? currentDate.getHours() : -1, - currentResolution == Resolution.HOUR && immediate); - } - if (currentResolution.getCalendarField() >= Resolution.MINUTE - .getCalendarField()) { - getClient().updateVariable(getId(), "min", - currentDate != null ? currentDate.getMinutes() : -1, - currentResolution == Resolution.MINUTE && immediate); - } - if (currentResolution.getCalendarField() >= Resolution.SECOND - .getCalendarField()) { - getClient().updateVariable(getId(), "sec", - currentDate != null ? currentDate.getSeconds() : -1, - currentResolution == Resolution.SECOND && immediate); - } - } private String cleanFormat(String format) { // Remove unnecessary d & M if resolution is too low - if (currentResolution.getCalendarField() < Resolution.DAY - .getCalendarField()) { + if (currentResolution.compareTo(Resolution.DAY) > 0) { format = format.replaceAll("d", ""); } - if (currentResolution.getCalendarField() < Resolution.MONTH - .getCalendarField()) { + if (currentResolution.compareTo(Resolution.MONTH) > 0) { format = format.replaceAll("M", ""); } diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java index 0992b79b80..9d9bdb4d7a 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/AbstractDateFieldConnector.java @@ -15,8 +15,6 @@ */ package com.vaadin.client.ui.datefield; -import java.util.Date; - import com.vaadin.client.ApplicationConnection; import com.vaadin.client.LocaleNotLoadedException; import com.vaadin.client.Paintable; @@ -24,6 +22,7 @@ import com.vaadin.client.UIDL; import com.vaadin.client.VConsole; import com.vaadin.client.ui.AbstractFieldConnector; import com.vaadin.client.ui.VDateField; +import com.vaadin.client.ui.VTextualDate; import com.vaadin.shared.ui.datefield.DateFieldConstants; import com.vaadin.shared.ui.datefield.Resolution; @@ -65,13 +64,7 @@ public class AbstractDateFieldConnector extends AbstractFieldConnector && getWidget().dts.getFirstDayOfWeek() == 1); Resolution newResolution; - if (uidl.hasVariable("sec")) { - newResolution = Resolution.SECOND; - } else if (uidl.hasVariable("min")) { - newResolution = Resolution.MINUTE; - } else if (uidl.hasVariable("hour")) { - newResolution = Resolution.HOUR; - } else if (uidl.hasVariable("day")) { + if (uidl.hasVariable("day")) { newResolution = Resolution.DAY; } else if (uidl.hasVariable("month")) { newResolution = Resolution.MONTH; @@ -95,21 +88,14 @@ public class AbstractDateFieldConnector extends AbstractFieldConnector final Resolution resolution = getWidget().getCurrentResolution(); final int year = uidl.getIntVariable("year"); - final int month = (resolution.getCalendarField() >= Resolution.MONTH - .getCalendarField()) ? uidl.getIntVariable("month") : -1; - final int day = (resolution.getCalendarField() >= Resolution.DAY - .getCalendarField()) ? uidl.getIntVariable("day") : -1; - final int hour = (resolution.getCalendarField() >= Resolution.HOUR - .getCalendarField()) ? uidl.getIntVariable("hour") : 0; - final int min = (resolution.getCalendarField() >= Resolution.MINUTE - .getCalendarField()) ? uidl.getIntVariable("min") : 0; - final int sec = (resolution.getCalendarField() >= Resolution.SECOND - .getCalendarField()) ? uidl.getIntVariable("sec") : 0; + final int month = resolution.compareTo(Resolution.MONTH) <= 0 + ? uidl.getIntVariable("month") : -1; + final int day = resolution.compareTo(Resolution.DAY) <= 0 + ? uidl.getIntVariable("day") : -1; // Construct new date for this datefield (only if not null) if (year > -1) { - getWidget().setCurrentDate(new Date((long) getWidget().getTime(year, - month, day, hour, min, sec, 0))); + getWidget().setCurrentDate(VTextualDate.getTime(year, month, day)); } else { getWidget().setCurrentDate(null); } diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/DateFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/DateFieldConnector.java index c7a2b50388..c5972c9f61 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/DateFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/DateFieldConnector.java @@ -22,14 +22,12 @@ import com.google.gwt.event.logical.shared.CloseEvent; import com.google.gwt.event.logical.shared.CloseHandler; import com.google.gwt.user.client.ui.PopupPanel; import com.vaadin.client.ApplicationConnection; -import com.vaadin.client.DateTimeService; import com.vaadin.client.UIDL; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.VCalendarPanel.FocusChangeListener; -import com.vaadin.client.ui.VCalendarPanel.TimeChangeListener; import com.vaadin.client.ui.VPopupCalendar; import com.vaadin.shared.ui.Connect; -import com.vaadin.shared.ui.datefield.PopupDateFieldState; +import com.vaadin.shared.ui.datefield.DateFieldState; import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.ui.AbstractDateField; @@ -106,7 +104,7 @@ public class DateFieldConnector extends TextualDateConnector { } if (getWidget().getCurrentResolution() - .getCalendarField() <= Resolution.MONTH.getCalendarField()) { + .compareTo(Resolution.MONTH) >= 0) { getWidget().calendar .setFocusChangeListener(new FocusChangeListener() { @Override @@ -123,35 +121,6 @@ public class DateFieldConnector extends TextualDateConnector { getWidget().calendar.setFocusChangeListener(null); } - if (getWidget().getCurrentResolution() - .getCalendarField() > Resolution.DAY.getCalendarField()) { - getWidget().calendar - .setTimeChangeListener(new TimeChangeListener() { - @Override - public void changed(int hour, int min, int sec, - int msec) { - Date d = getWidget().getDate(); - if (d == null) { - // date currently null, use the value from - // calendarPanel - // (~ client time at the init of the widget) - d = (Date) getWidget().calendar.getDate() - .clone(); - } - d.setHours(hour); - d.setMinutes(min); - d.setSeconds(sec); - DateTimeService.setMilliseconds(d, msec); - - // Always update time changes to the server - getWidget().updateValue(d); - - // Update text field - getWidget().buildDate(); - } - }); - } - if (getWidget().isReadonly()) { getWidget().calendarToggle.addStyleName( VPopupCalendar.CLASSNAME + "-button-readonly"); @@ -172,8 +141,8 @@ public class DateFieldConnector extends TextualDateConnector { } @Override - public PopupDateFieldState getState() { - return (PopupDateFieldState) super.getState(); + public DateFieldState getState() { + return (DateFieldState) super.getState(); } @Override diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/InlineDateFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/InlineDateFieldConnector.java index 234160292b..add25ae99b 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/InlineDateFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/InlineDateFieldConnector.java @@ -18,11 +18,9 @@ package com.vaadin.client.ui.datefield; import java.util.Date; import com.vaadin.client.ApplicationConnection; -import com.vaadin.client.DateTimeService; import com.vaadin.client.UIDL; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.VCalendarPanel.FocusChangeListener; -import com.vaadin.client.ui.VCalendarPanel.TimeChangeListener; import com.vaadin.client.ui.VDateFieldCalendar; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.datefield.InlineDateFieldState; @@ -54,34 +52,7 @@ public class InlineDateFieldConnector extends AbstractDateFieldConnector { } if (getWidget().getCurrentResolution() - .getCalendarField() > Resolution.DAY.getCalendarField()) { - getWidget().calendarPanel - .setTimeChangeListener(new TimeChangeListener() { - @Override - public void changed(int hour, int min, int sec, - int msec) { - Date d = getWidget().getDate(); - if (d == null) { - // date currently null, use the value from - // calendarPanel - // (~ client time at the init of the widget) - d = (Date) getWidget().calendarPanel.getDate() - .clone(); - } - d.setHours(hour); - d.setMinutes(min); - d.setSeconds(sec); - DateTimeService.setMilliseconds(d, msec); - - // Always update time changes to the server - getWidget().calendarPanel.setDate(d); - getWidget().updateValueFromPanel(); - } - }); - } - - if (getWidget().getCurrentResolution() - .getCalendarField() <= Resolution.MONTH.getCalendarField()) { + .compareTo(Resolution.MONTH) >= 0) { getWidget().calendarPanel .setFocusChangeListener(new FocusChangeListener() { @Override diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VCalendarPanel.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VCalendarPanel.java index fd1edda55d..bd0cab400a 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VCalendarPanel.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VCalendarPanel.java @@ -58,8 +58,8 @@ import com.vaadin.client.VConsole; import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.FocusableFlexTable; import com.vaadin.client.ui.SubPartAware; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.shared.util.SharedUtil; +import com.vaadin.v7.shared.ui.datefield.Resolution; @SuppressWarnings("deprecation") public class VCalendarPanel extends FocusableFlexTable implements diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VDateField.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VDateField.java index eca4273e24..23ad279b66 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VDateField.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VDateField.java @@ -23,7 +23,7 @@ import com.google.gwt.user.client.ui.HasEnabled; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.DateTimeService; import com.vaadin.client.ui.Field; -import com.vaadin.shared.ui.datefield.Resolution; +import com.vaadin.v7.shared.ui.datefield.Resolution; public class VDateField extends FlowPanel implements Field, HasEnabled { diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VDateFieldCalendar.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VDateFieldCalendar.java index 16f6b90a5d..12141f7445 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VDateFieldCalendar.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VDateFieldCalendar.java @@ -20,9 +20,9 @@ import java.util.Date; import com.google.gwt.event.dom.client.DomEvent; import com.vaadin.client.DateTimeService; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.v7.client.ui.VCalendarPanel.FocusOutListener; import com.vaadin.v7.client.ui.VCalendarPanel.SubmitListener; +import com.vaadin.v7.shared.ui.datefield.Resolution; /** * A client side implementation for InlineDateField diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VPopupCalendar.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VPopupCalendar.java index a21cfea4ab..c8d3ece2d3 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VPopupCalendar.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VPopupCalendar.java @@ -52,10 +52,10 @@ import com.vaadin.client.ui.Field; import com.vaadin.client.ui.SubPartAware; import com.vaadin.client.ui.VOverlay; import com.vaadin.client.ui.aria.AriaHelper; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.v7.client.ui.VCalendarPanel.FocusOutListener; import com.vaadin.v7.client.ui.VCalendarPanel.SubmitListener; import com.vaadin.v7.shared.ui.datefield.PopupDateFieldState; +import com.vaadin.v7.shared.ui.datefield.Resolution; /** * Represents a date selection component with a text field and a popup date diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VTextualDate.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VTextualDate.java index 329382d605..c9204478b4 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VTextualDate.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VTextualDate.java @@ -41,7 +41,7 @@ import com.vaadin.client.ui.aria.HandlesAriaCaption; import com.vaadin.client.ui.aria.HandlesAriaInvalid; import com.vaadin.client.ui.aria.HandlesAriaRequired; import com.vaadin.shared.EventId; -import com.vaadin.shared.ui.datefield.Resolution; +import com.vaadin.v7.shared.ui.datefield.Resolution; public class VTextualDate extends VDateField implements Field, ChangeHandler, Focusable, SubPartAware, HandlesAriaCaption, HandlesAriaInvalid, diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/AbstractDateFieldConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/AbstractDateFieldConnector.java index bd9ba1c90d..1c4932e6a4 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/AbstractDateFieldConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/AbstractDateFieldConnector.java @@ -22,10 +22,10 @@ import com.vaadin.client.LocaleNotLoadedException; import com.vaadin.client.Paintable; import com.vaadin.client.UIDL; import com.vaadin.client.VConsole; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.v7.client.ui.AbstractFieldConnector; import com.vaadin.v7.client.ui.VDateField; import com.vaadin.v7.shared.ui.datefield.DateFieldConstants; +import com.vaadin.v7.shared.ui.datefield.Resolution; public class AbstractDateFieldConnector extends AbstractFieldConnector implements Paintable { diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/DateFieldConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/DateFieldConnector.java index 2b961cf9ac..746af3043d 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/DateFieldConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/DateFieldConnector.java @@ -26,11 +26,11 @@ import com.vaadin.client.DateTimeService; import com.vaadin.client.UIDL; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.shared.ui.Connect; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.v7.client.ui.VCalendarPanel.FocusChangeListener; import com.vaadin.v7.client.ui.VCalendarPanel.TimeChangeListener; import com.vaadin.v7.client.ui.VPopupCalendar; import com.vaadin.v7.shared.ui.datefield.PopupDateFieldState; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.ui.DateField; @Connect(DateField.class) diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/InlineDateFieldConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/InlineDateFieldConnector.java index 39d8e575d7..ddf72a0705 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/InlineDateFieldConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/InlineDateFieldConnector.java @@ -22,11 +22,11 @@ import com.vaadin.client.DateTimeService; import com.vaadin.client.UIDL; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.shared.ui.Connect; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.v7.client.ui.VCalendarPanel.FocusChangeListener; import com.vaadin.v7.client.ui.VCalendarPanel.TimeChangeListener; import com.vaadin.v7.client.ui.VDateFieldCalendar; import com.vaadin.v7.shared.ui.datefield.InlineDateFieldState; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.ui.InlineDateField; @Connect(InlineDateField.class) diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/TextualDateConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/TextualDateConnector.java index 85b3664923..a41fca521f 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/TextualDateConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/datefield/TextualDateConnector.java @@ -18,8 +18,8 @@ package com.vaadin.v7.client.ui.datefield; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.UIDL; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.v7.client.ui.VTextualDate; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.shared.ui.datefield.TextualDateFieldState; public class TextualDateConnector extends AbstractDateFieldConnector { diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/DateField.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/DateField.java index 14d0145730..befdc26998 100644 --- a/compatibility-server/src/main/java/com/vaadin/v7/ui/DateField.java +++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/DateField.java @@ -34,7 +34,6 @@ import com.vaadin.event.FieldEvents.FocusEvent; import com.vaadin.event.FieldEvents.FocusListener; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.ui.Component; import com.vaadin.ui.LegacyComponent; import com.vaadin.ui.declarative.DesignAttributeHandler; @@ -46,6 +45,7 @@ import com.vaadin.v7.data.util.converter.Converter; import com.vaadin.v7.data.validator.DateRangeValidator; import com.vaadin.v7.event.FieldEvents; import com.vaadin.v7.shared.ui.datefield.DateFieldConstants; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.shared.ui.datefield.TextualDateFieldState; /** diff --git a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/DateFieldConverterTest.java b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/DateFieldConverterTest.java index a5166f9373..35e8a93929 100644 --- a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/DateFieldConverterTest.java +++ b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/DateFieldConverterTest.java @@ -22,10 +22,10 @@ import java.util.Locale; import org.junit.Before; import org.junit.Test; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.v7.data.Property; import com.vaadin.v7.data.util.ObjectProperty; import com.vaadin.v7.data.util.converter.Converter; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.ui.DateField; public class DateFieldConverterTest { @@ -35,7 +35,7 @@ public class DateFieldConverterTest { @Before public void setUp() { - date = new ObjectProperty<Long>(0L); + date = new ObjectProperty<>(0L); datefield = new DateField(); datefield.setBuffered(false); datefield.setConverter(new Converter<Date, Long>() { diff --git a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/LegacyDateFieldDeclarativeTest.java b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/LegacyDateFieldDeclarativeTest.java index e001a3327f..e9b7ac7959 100644 --- a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/LegacyDateFieldDeclarativeTest.java +++ b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/LegacyDateFieldDeclarativeTest.java @@ -21,8 +21,8 @@ import java.util.TimeZone; import org.junit.Test; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.ui.DateField; /** diff --git a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java index e6316cec3f..7bfe4adf4a 100644 --- a/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java +++ b/compatibility-server/src/test/java/com/vaadin/v7/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java @@ -19,8 +19,8 @@ import java.util.Date; import org.junit.Test; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.ui.PopupDateField; /** diff --git a/compatibility-shared/src/main/java/com/vaadin/v7/shared/ui/datefield/Resolution.java b/compatibility-shared/src/main/java/com/vaadin/v7/shared/ui/datefield/Resolution.java new file mode 100644 index 0000000000..155c43b5a6 --- /dev/null +++ b/compatibility-shared/src/main/java/com/vaadin/v7/shared/ui/datefield/Resolution.java @@ -0,0 +1,84 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.v7.shared.ui.datefield; + +import java.util.ArrayList; +import java.util.List; + +/** + * Resolutions for DateFields + * + * @author Vaadin Ltd. + * @since 7.0 + */ +public enum Resolution { + // Values from Calendar.SECOND etc. Set as ints to avoid Calendar dependency + // (does not exist on the client side) + SECOND(13), MINUTE(12), HOUR(11), DAY(5), MONTH(2), YEAR(1); + + private int calendarField; + + private Resolution(int calendarField) { + this.calendarField = calendarField; + } + + /** + * Returns the field in java.util.Calendar that corresponds to this + * resolution. + * + * @return one of the field numbers used by Calendar + */ + public int getCalendarField() { + return calendarField; + } + + /** + * Returns the resolutions that are higher or equal to the given resolution, + * starting from the given resolution. In other words passing DAY to this + * methods returns DAY,MONTH,YEAR + * + * @param r + * The resolution to start from + * @return An iterable for the resolutions higher or equal to r + */ + public static Iterable<Resolution> getResolutionsHigherOrEqualTo( + Resolution r) { + List<Resolution> resolutions = new ArrayList<>(); + Resolution[] values = Resolution.values(); + for (int i = r.ordinal(); i < values.length; i++) { + resolutions.add(values[i]); + } + return resolutions; + } + + /** + * Returns the resolutions that are lower than the given resolution, + * starting from the given resolution. In other words passing DAY to this + * methods returns HOUR,MINUTE,SECOND. + * + * @param r + * The resolution to start from + * @return An iterable for the resolutions lower than r + */ + public static List<Resolution> getResolutionsLowerThan(Resolution r) { + List<Resolution> resolutions = new ArrayList<>(); + Resolution[] values = Resolution.values(); + for (int i = r.ordinal() - 1; i >= 0; i--) { + resolutions.add(values[i]); + } + return resolutions; + } +} diff --git a/documentation/datamodel/datamodel-fields.asciidoc b/documentation/datamodel/datamodel-fields.asciidoc index 651def13a6..ac39c7fda0 100644 --- a/documentation/datamodel/datamodel-fields.asciidoc +++ b/documentation/datamodel/datamodel-fields.asciidoc @@ -25,7 +25,7 @@ Button sayHelloButton = new Button("Say hello", clickEvent -> { }); ---- -Each field implementation has its own specific value type – the type of a [classname]#TextField# is [classname]#String#, the type of a [classname]#Slider# is [classname]#Double#, the type of a [classname]#PopupDateField# is [classname]#LocalDate#, and so on. +Each field implementation has its own specific value type – the type of a [classname]#TextField# is [classname]#String#, the type of a [classname]#Slider# is [classname]#Double#, the type of a [classname]#DateField# is [classname]#LocalDate#, and so on. == Reacting to Value Changes diff --git a/documentation/datamodel/datamodel-forms.asciidoc b/documentation/datamodel/datamodel-forms.asciidoc index 3c2dd95bb5..8772f0d770 100644 --- a/documentation/datamodel/datamodel-forms.asciidoc +++ b/documentation/datamodel/datamodel-forms.asciidoc @@ -200,12 +200,12 @@ We can save the binding to a local variable and trigger a revalidation when anot [source, java] ---- -PopupDateField departing = new PopupDateField("Departing"); -PopupDateField returning = new PopupDateField("Returning"); +DateField departing = new DateField("Departing"); +DateField returning = new DateField("Returning"); // Store return date binding so we can revalidate it later -Binding<Trip, Date, Date> returnBinding = binder.forField(returning) - .withValidator(returnDate -> !returnDate.before(departing.getValue()), +Binding<Trip, LocalDate, LocalDate> returnBinding = binder.forField(returning) + .withValidator(returnDate -> !returnDate.isBefore(departing.getValue()), "Cannot return before departing"); returnBinding.bind(Trip::getReturnDate, Trip::setReturnDate); diff --git a/server/src/main/java/com/vaadin/ui/AbstractDateField.java b/server/src/main/java/com/vaadin/ui/AbstractDateField.java index ab0aed1b0c..6ac135b354 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractDateField.java +++ b/server/src/main/java/com/vaadin/ui/AbstractDateField.java @@ -16,20 +16,21 @@ package com.vaadin.ui; import java.text.SimpleDateFormat; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneOffset; import java.util.Calendar; -import java.util.Comparator; import java.util.Date; import java.util.EventObject; import java.util.HashMap; import java.util.Locale; import java.util.Map; -import java.util.TimeZone; import java.util.logging.Logger; import org.jsoup.nodes.Element; import com.vaadin.data.Result; -import com.vaadin.data.validator.RangeValidator; +import com.vaadin.data.validator.DateRangeValidator; import com.vaadin.event.FieldEvents.BlurEvent; import com.vaadin.event.FieldEvents.BlurListener; import com.vaadin.event.FieldEvents.BlurNotifier; @@ -47,20 +48,20 @@ import com.vaadin.ui.declarative.DesignAttributeHandler; import com.vaadin.ui.declarative.DesignContext; /** - * A date editor component with <code>java.util.Date</code> as an input value. + * A date editor component with {@link LocalDate} as an input value. * * @author Vaadin Ltd * * @since 8.0 * */ -public abstract class AbstractDateField extends AbstractField<Date> +public abstract class AbstractDateField extends AbstractField<LocalDate> implements LegacyComponent, FocusNotifier, BlurNotifier { /** * Value of the field. */ - private Date value; + private LocalDate value; /** * Specified smallest modifiable unit for the date field. @@ -68,11 +69,6 @@ public abstract class AbstractDateField extends AbstractField<Date> private Resolution resolution = Resolution.DAY; /** - * The internal calendar to be used in java.utl.Date conversions. - */ - private transient Calendar calendar; - - /** * Overridden format string */ private String dateFormat; @@ -96,8 +92,6 @@ public abstract class AbstractDateField extends AbstractField<Date> private String defaultParseErrorMessage = "Date format not recognized"; - private TimeZone timeZone = null; - private static Map<Resolution, String> variableNameForResolution = new HashMap<>(); private String dateOutOfRangeMessage = "Date is out of allowed range"; @@ -110,9 +104,6 @@ public abstract class AbstractDateField extends AbstractField<Date> private boolean preventValueChangeEvent; static { - variableNameForResolution.put(Resolution.SECOND, "sec"); - variableNameForResolution.put(Resolution.MINUTE, "min"); - variableNameForResolution.put(Resolution.HOUR, "hour"); variableNameForResolution.put(Resolution.DAY, "day"); variableNameForResolution.put(Resolution.MONTH, "month"); variableNameForResolution.put(Resolution.YEAR, "year"); @@ -143,9 +134,9 @@ public abstract class AbstractDateField extends AbstractField<Date> * @param caption * the caption <code>String</code> for the editor. * @param value - * the Date value. + * the LocalDate value. */ - public AbstractDateField(String caption, Date value) { + public AbstractDateField(String caption, LocalDate value) { setValue(value); setCaption(caption); } @@ -166,7 +157,7 @@ public abstract class AbstractDateField extends AbstractField<Date> } if (getDateFormat() != null) { - target.addAttribute("format", dateFormat); + target.addAttribute("format", getDateFormat()); } if (!isLenient()) { @@ -181,9 +172,7 @@ public abstract class AbstractDateField extends AbstractField<Date> * app or refresh. */ - // Gets the calendar - final Calendar calendar = getCalendar(); - final Date currentDate = getValue(); + final LocalDate currentDate = getValue(); // Only paint variables for the resolution and up, e.g. Resolution DAY // paints DAY,MONTH,YEAR @@ -191,11 +180,7 @@ public abstract class AbstractDateField extends AbstractField<Date> .getResolutionsHigherOrEqualTo(resolution)) { int value = -1; if (currentDate != null) { - value = calendar.get(res.getCalendarField()); - if (res == Resolution.MONTH) { - // Calendar month is zero based - value++; - } + value = getDateValue(currentDate, res); } target.addVariable(this, variableNameForResolution.get(res), value); } @@ -211,14 +196,12 @@ public abstract class AbstractDateField extends AbstractField<Date> if (!isReadOnly() && (variables.containsKey("year") || variables.containsKey("month") - || variables.containsKey("day") || variables.containsKey("hour") - || variables.containsKey("min") || variables.containsKey("sec") - || variables.containsKey("msec") + || variables.containsKey("day") || variables.containsKey("dateString"))) { // Old and new dates - final Date oldDate = getValue(); - Date newDate = null; + final LocalDate oldDate = getValue(); + LocalDate newDate = null; // this enables analyzing invalid input on the server final String newDateString = (String) variables.get("dateString"); @@ -226,55 +209,37 @@ public abstract class AbstractDateField extends AbstractField<Date> // Gets the new date in parts boolean hasChanges = false; - Map<Resolution, Integer> calendarFieldChanges = new HashMap<>(); + Map<Resolution, Integer> calendarFields = new HashMap<>(); - for (Resolution r : Resolution - .getResolutionsHigherOrEqualTo(resolution)) { + for (Resolution resolution : Resolution + .getResolutionsHigherOrEqualTo(getResolution())) { // Only handle what the client is allowed to send. The same // resolutions that are painted - String variableName = variableNameForResolution.get(r); + String variableName = variableNameForResolution.get(resolution); + Integer value = getDateValue(oldDate, resolution); if (variables.containsKey(variableName)) { - Integer value = (Integer) variables.get(variableName); - if (r == Resolution.MONTH) { - // Calendar MONTH is zero based - value--; - } - if (value >= 0) { + Integer newValue = (Integer) variables.get(variableName); + if (newValue >= 0) { hasChanges = true; - calendarFieldChanges.put(r, value); + value = newValue; } } + calendarFields.put(resolution, value); } // If no new variable values were received, use the previous value if (!hasChanges) { newDate = null; } else { - // Clone the calendar for date operation - final Calendar cal = getCalendar(); - - // Update the value based on the received info - // Must set in this order to avoid invalid dates (or wrong - // dates if lenient is true) in calendar - for (int r = Resolution.YEAR.ordinal(); r >= 0; r--) { - Resolution res = Resolution.values()[r]; - if (calendarFieldChanges.containsKey(res)) { - - // Field resolution should be included. Others are - // skipped so that client can not make unexpected - // changes (e.g. day change even though resolution is - // year). - Integer newValue = calendarFieldChanges.get(res); - cal.set(res.getCalendarField(), newValue); - } - } - newDate = cal.getTime(); + newDate = LocalDate.of(calendarFields.get(Resolution.YEAR), + calendarFields.getOrDefault(Resolution.MONTH, 1), + calendarFields.getOrDefault(Resolution.DAY, 1)); } if (newDate == null && dateString != null && !dateString.isEmpty()) { - Result<Date> parsedDate = handleUnparsableDateString( + Result<LocalDate> parsedDate = handleUnparsableDateString( dateString); if (parsedDate.isError()) { @@ -365,17 +330,15 @@ public abstract class AbstractDateField extends AbstractField<Date> * @param startDate * - the allowed range's start date */ - public void setRangeStart(Date startDate) { - if (startDate != null && getState().rangeEnd != null - && startDate.after(getState().rangeEnd)) { + public void setRangeStart(LocalDate startDate) { + Date date = convertLocalDate(startDate); + if (date != null && getState().rangeEnd != null + && date.after(getState().rangeEnd)) { throw new IllegalStateException( "startDate cannot be later than endDate"); } - // Create a defensive copy against issues when using java.sql.Date (and - // also against mutable Date). - getState().rangeStart = startDate != null - ? new Date(startDate.getTime()) : null; + getState().rangeStart = date; } /** @@ -431,35 +394,33 @@ public abstract class AbstractDateField extends AbstractField<Date> * - the allowed range's end date (inclusive, based on the * current resolution) */ - public void setRangeEnd(Date endDate) { - if (endDate != null && getState().rangeStart != null - && getState().rangeStart.after(endDate)) { + public void setRangeEnd(LocalDate endDate) { + Date date = convertLocalDate(endDate); + if (date != null && getState().rangeStart != null + && getState().rangeStart.after(date)) { throw new IllegalStateException( "endDate cannot be earlier than startDate"); } - // Create a defensive copy against issues when using java.sql.Date (and - // also against mutable Date). - getState().rangeEnd = endDate != null ? new Date(endDate.getTime()) - : null; + getState().rangeEnd = date; } /** * Returns the precise rangeStart used. * - * @return the precise rangeStart used + * @return the precise rangeStart used, may be null. */ - public Date getRangeStart() { - return getState(false).rangeStart; + public LocalDate getRangeStart() { + return convertDate(getState(false).rangeStart); } /** * Returns the precise rangeEnd used. * - * @return the precise rangeEnd used + * @return the precise rangeEnd used, may be null. */ - public Date getRangeEnd() { - return getState(false).rangeEnd; + public LocalDate getRangeEnd() { + return convertDate(getState(false).rangeEnd); } /** @@ -519,12 +480,12 @@ public abstract class AbstractDateField extends AbstractField<Date> } @Override - public Date getValue() { + public LocalDate getValue() { return value; } @Override - public void setValue(Date value) { + public void setValue(LocalDate value) { /* * First handle special case when the client side component have a date * string but value is null (e.g. unparsable date string typed in by the @@ -567,64 +528,6 @@ public abstract class AbstractDateField extends AbstractField<Date> } /** - * Returns new instance calendar used in Date conversions. - * - * Returns new clone of the calendar object initialized using the the - * current date (if available) - * - * If this is no calendar is assigned the <code>Calendar.getInstance</code> - * is used. - * - * @return the Calendar. - * @see #setCalendar(Calendar) - */ - private Calendar getCalendar() { - - // Makes sure we have an calendar instance - if (calendar == null) { - calendar = Calendar.getInstance(); - // Start by a zeroed calendar to avoid having values for lower - // resolution variables e.g. time when resolution is day - int min, field; - for (Resolution r : Resolution - .getResolutionsLowerThan(resolution)) { - field = r.getCalendarField(); - min = calendar.getActualMinimum(field); - calendar.set(field, min); - } - calendar.set(Calendar.MILLISECOND, 0); - } - - // Clone the instance - final Calendar newCal = (Calendar) calendar.clone(); - - final TimeZone currentTimeZone = getTimeZone(); - if (currentTimeZone != null) { - newCal.setTimeZone(currentTimeZone); - } - - final Date currentDate = getValue(); - if (currentDate != null) { - newCal.setTime(currentDate); - } - return newCal; - } - - /** - * Gets the time zone used by this field. The time zone is used to convert - * the absolute time in a Date object to a logical time displayed in the - * selector and to convert the select time back to a Date object. - * - * If {@code null} is returned, the current default time zone returned by - * {@code TimeZone.getDefault()} is used. - * - * @return the current time zone - */ - public TimeZone getTimeZone() { - return timeZone; - } - - /** * Return the error message that is shown if the user inputted value can't * be parsed into a Date object. If * {@link #handleUnparsableDateString(String)} is overridden and it throws a @@ -655,23 +558,6 @@ public abstract class AbstractDateField extends AbstractField<Date> defaultParseErrorMessage = parsingErrorMessage; } - /** - * Sets the time zone used by this date field. The time zone is used to - * convert the absolute time in a Date object to a logical time displayed in - * the selector and to convert the select time back to a Date object. - * - * If no time zone has been set, the current default time zone returned by - * {@code TimeZone.getDefault()} is used. - * - * @see #getTimeZone() - * @param timeZone - * the time zone to use for time calculations. - */ - public void setTimeZone(TimeZone timeZone) { - this.timeZone = timeZone; - markAsDirty(); - } - @Override public Registration addFocusListener(FocusListener listener) { addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener, @@ -704,14 +590,14 @@ public abstract class AbstractDateField extends AbstractField<Date> public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); if (design.hasAttr("value") && !design.attr("value").isEmpty()) { - Date date = DesignAttributeHandler.getFormatter() - .parse(design.attr("value"), Date.class); + LocalDate date = DesignAttributeHandler.getFormatter() + .parse(design.attr("value"), LocalDate.class); // formatting will return null if it cannot parse the string if (date == null) { Logger.getLogger(AbstractDateField.class.getName()).info( "cannot parse " + design.attr("value") + " as date"); } - setValue(date); + doSetValue(date); } } @@ -750,7 +636,7 @@ public abstract class AbstractDateField extends AbstractField<Date> * date string to handle * @return result that contains parsed Date as a value or an error */ - protected Result<Date> handleUnparsableDateString(String dateString) { + protected Result<LocalDate> handleUnparsableDateString(String dateString) { return Result.error(getParseErrorMessage()); } @@ -765,7 +651,7 @@ public abstract class AbstractDateField extends AbstractField<Date> } @Override - protected void doSetValue(Date value) { + protected void doSetValue(LocalDate value) { // Also set the internal dateString if (value != null) { dateString = value.toString(); @@ -780,87 +666,61 @@ public abstract class AbstractDateField extends AbstractField<Date> uiHasValidDateString = true; setComponentError(new UserError(currentParseErrorMessage)); } else { - RangeValidator<Date> validator = new RangeValidator<>( - getDateOutOfRangeMessage(), Comparator.naturalOrder(), - getRangeStart(getResolution()), - getRangeEnd(getResolution())); - Result<Date> result = validator.apply(value); + DateRangeValidator validator = new DateRangeValidator( + getDateOutOfRangeMessage(), + getDate(getRangeStart(), getResolution()), + getDate(getRangeEnd(), getResolution())); + Result<LocalDate> result = validator.apply(value); if (result.isError()) { setComponentError(new UserError(getDateOutOfRangeMessage())); } } } - /** - * Gets the start range for a certain resolution. The range is inclusive, so - * if <code>rangeStart</code> is set to one millisecond before year n and - * resolution is set to YEAR, any date in year n - 1 will be accepted. - * Lowest supported resolution is DAY. - * - * @param forResolution - * - the range conforms to the resolution - * @return - */ - private Date getRangeStart(Resolution forResolution) { - if (getState(false).rangeStart == null) { + private LocalDate getDate(LocalDate date, Resolution forResolution) { + if (date == null) { return null; } - Calendar startCal = Calendar.getInstance(); - startCal.setTime(getState(false).rangeStart); - if (forResolution == Resolution.YEAR) { - startCal.set(startCal.get(Calendar.YEAR), 0, 1, 0, 0, 0); + return date.withDayOfYear(1); } else if (forResolution == Resolution.MONTH) { - startCal.set(startCal.get(Calendar.YEAR), - startCal.get(Calendar.MONTH), 1, 0, 0, 0); + return date.withDayOfMonth(1); } else { - startCal.set(startCal.get(Calendar.YEAR), - startCal.get(Calendar.MONTH), startCal.get(Calendar.DATE), - 0, 0, 0); + return date; } - - startCal.set(Calendar.MILLISECOND, 0); - return startCal.getTime(); } - /** - * Gets the end range for a certain resolution. The range is inclusive, so - * if rangeEnd is set to zero milliseconds past year n and resolution is set - * to YEAR, any date in year n will be accepted. Resolutions lower than DAY - * will be interpreted on a DAY level. That is, everything below DATE is - * cleared - * - * @param forResolution - * - the range conforms to the resolution - * @return - */ - private Date getRangeEnd(Resolution forResolution) { - // We need to set the correct resolution for the dates, - // otherwise the range validator will complain + private int getDateValue(LocalDate date, Resolution resolution) { + LocalDate value = date; + if (value == null) { + value = LocalDate.of(1, 1, 1); + } + switch (resolution) { + case DAY: + return value.getDayOfMonth(); + case MONTH: + return value.getMonthValue(); + case YEAR: + return value.getYear(); + default: + assert false : "Unexpected resolution argument " + resolution; + return -1; + } + } - Date rangeEnd = getState(false).rangeEnd; - if (rangeEnd == null) { + private Date convertLocalDate(LocalDate date) { + if (date == null) { return null; } + return Date.from(date.atStartOfDay(ZoneOffset.UTC).toInstant()); + } - Calendar endCal = Calendar.getInstance(); - endCal.setTime(rangeEnd); - - if (forResolution == Resolution.YEAR) { - // Adding one year (minresolution) and clearing the rest. - endCal.set(endCal.get(Calendar.YEAR) + 1, 0, 1, 0, 0, 0); - } else if (forResolution == Resolution.MONTH) { - // Adding one month (minresolution) and clearing the rest. - endCal.set(endCal.get(Calendar.YEAR), - endCal.get(Calendar.MONTH) + 1, 1, 0, 0, 0); - } else { - endCal.set(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH), - endCal.get(Calendar.DATE) + 1, 0, 0, 0); + private LocalDate convertDate(Date date) { + if (date == null) { + return null; } - // removing one millisecond will now get the endDate to return to - // current resolution's set time span (year or month) - endCal.set(Calendar.MILLISECOND, -1); - return endCal.getTime(); + return Instant.ofEpochMilli(date.getTime()).atZone(ZoneOffset.UTC) + .toLocalDate(); } } diff --git a/server/src/main/java/com/vaadin/ui/DateField.java b/server/src/main/java/com/vaadin/ui/DateField.java index 00e71a6eff..04b32f66a0 100644 --- a/server/src/main/java/com/vaadin/ui/DateField.java +++ b/server/src/main/java/com/vaadin/ui/DateField.java @@ -15,11 +15,11 @@ */ package com.vaadin.ui; -import java.util.Date; +import java.time.LocalDate; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; -import com.vaadin.shared.ui.datefield.PopupDateFieldState; +import com.vaadin.shared.ui.datefield.DateFieldState; /** * A date entry component, which displays the actual date selector as a popup. @@ -34,27 +34,27 @@ public class DateField extends AbstractDateField { private String inputPrompt = null; /** - * Constructs an empty <code>PopupDateField</code> with no caption. + * Constructs an empty <code>DateField</code> with no caption. */ public DateField() { super(); } /** - * Constructs a new <code>PopupDateField</code> with the given caption and + * Constructs a new <code>DateField</code> with the given caption and * initial text contents. * * @param caption * the caption <code>String</code> for the editor. * @param value - * the Date value. + * the LocalDate value. */ - public DateField(String caption, Date value) { + public DateField(String caption, LocalDate value) { super(caption, value); } /** - * Constructs an empty <code>PopupDateField</code> with caption. + * Constructs an empty <code>DateField</code> with caption. * * @param caption * the caption of the datefield. @@ -94,19 +94,19 @@ public class DateField extends AbstractDateField { } @Override - protected PopupDateFieldState getState() { - return (PopupDateFieldState) super.getState(); + protected DateFieldState getState() { + return (DateFieldState) super.getState(); } @Override - protected PopupDateFieldState getState(boolean markAsDirty) { - return (PopupDateFieldState) super.getState(markAsDirty); + protected DateFieldState getState(boolean markAsDirty) { + return (DateFieldState) super.getState(markAsDirty); } /** * Checks whether the text field is enabled (default) or not. * - * @see PopupDateField#setTextFieldEnabled(boolean); + * @see #setTextFieldEnabled(boolean) * * @return <b>true</b> if the text field is enabled, <b>false</b> otherwise. */ diff --git a/server/src/main/java/com/vaadin/ui/InlineDateField.java b/server/src/main/java/com/vaadin/ui/InlineDateField.java index 8fd6656c2f..a1610949f1 100644 --- a/server/src/main/java/com/vaadin/ui/InlineDateField.java +++ b/server/src/main/java/com/vaadin/ui/InlineDateField.java @@ -15,7 +15,7 @@ */ package com.vaadin.ui; -import java.util.Date; +import java.time.LocalDate; /** * A date entry component, which displays the actual date selector inline. @@ -28,27 +28,27 @@ import java.util.Date; public class InlineDateField extends AbstractDateField { /** - * Constructs an empty <code>DateField</code> with no caption. + * Constructs an empty <code>InlineDateField</code> with no caption. */ public InlineDateField() { super(); } /** - * Constructs a new <code>DateField</code> with the given caption and + * Constructs a new <code>InlineDateField</code> with the given caption and * initial text contents. * * @param caption * the caption <code>String</code> for the editor. * @param value - * the Date value. + * the LocalDate value. */ - public InlineDateField(String caption, Date value) { + public InlineDateField(String caption, LocalDate value) { super(caption, value); } /** - * Constructs an empty <code>DateField</code> with caption. + * Constructs an empty <code>InlineDateField</code> with caption. * * @param caption * the caption of the datefield. diff --git a/server/src/main/java/com/vaadin/ui/declarative/DesignFormatter.java b/server/src/main/java/com/vaadin/ui/declarative/DesignFormatter.java index 203954dd27..64430470d4 100644 --- a/server/src/main/java/com/vaadin/ui/declarative/DesignFormatter.java +++ b/server/src/main/java/com/vaadin/ui/declarative/DesignFormatter.java @@ -20,6 +20,7 @@ import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; +import java.time.LocalDate; import java.util.Collections; import java.util.Date; import java.util.Locale; @@ -39,6 +40,7 @@ import com.vaadin.event.ShortcutAction; import com.vaadin.server.Resource; import com.vaadin.ui.declarative.converters.DesignDateConverter; import com.vaadin.ui.declarative.converters.DesignEnumConverter; +import com.vaadin.ui.declarative.converters.DesignLocalDateConverter; import com.vaadin.ui.declarative.converters.DesignObjectConverter; import com.vaadin.ui.declarative.converters.DesignResourceConverter; import com.vaadin.ui.declarative.converters.DesignShortcutActionConverter; @@ -170,6 +172,7 @@ public class DesignFormatter implements Serializable { converterMap.put(char.class, charConverter); converterMap.put(Date.class, new DesignDateConverter()); + converterMap.put(LocalDate.class, new DesignLocalDateConverter()); converterMap.put(ShortcutAction.class, new DesignShortcutActionConverter()); converterMap.put(Resource.class, new DesignResourceConverter()); diff --git a/server/src/main/java/com/vaadin/ui/declarative/converters/DesignLocalDateConverter.java b/server/src/main/java/com/vaadin/ui/declarative/converters/DesignLocalDateConverter.java new file mode 100644 index 0000000000..188516b431 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/declarative/converters/DesignLocalDateConverter.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.ui.declarative.converters; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.Locale; + +import com.vaadin.data.Result; +import com.vaadin.data.util.converter.Converter; +import com.vaadin.ui.declarative.DesignAttributeHandler; + +/** + * A {@link LocalDate} converter to be used by {@link DesignAttributeHandler}. + * Provides ISO-compliant way of storing date and time. + * + * @since 8.0 + * @author Vaadin Ltd + */ +public class DesignLocalDateConverter implements Converter<String, LocalDate> { + + @Override + public Result<LocalDate> convertToModel(String value, Locale locale) { + for (String pattern : new String[] { "yyyy-MM-dd", "yyyy-MM", + "yyyy" }) { + try { + Locale effectiveLocale = locale == null ? Locale.ENGLISH + : locale; + LocalDate date = DateTimeFormatter + .ofPattern(pattern, effectiveLocale) + .parse(value, LocalDate::from); + return Result.ok(date); + } catch (DateTimeParseException e) { + // not parseable, ignore and try another format + } + } + return Result.error("Could not parse date value: " + value); + } + + @Override + public String convertToPresentation(LocalDate value, Locale locale) { + return DateTimeFormatter.ofPattern("yyyy-MM-dd", + locale == null ? Locale.ENGLISH : locale).format(value); + } + +} diff --git a/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java b/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java index 41c9806165..0b55bc8cad 100644 --- a/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java +++ b/server/src/test/java/com/vaadin/data/BinderBookOfVaadinTest.java @@ -15,8 +15,7 @@ */ package com.vaadin.data; -import java.util.Calendar; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import java.util.Locale; import java.util.concurrent.atomic.AtomicReference; @@ -33,9 +32,9 @@ import com.vaadin.data.util.converter.StringToIntegerConverter; import com.vaadin.data.validator.EmailValidator; import com.vaadin.server.AbstractErrorMessage; import com.vaadin.ui.Button; +import com.vaadin.ui.DateField; import com.vaadin.ui.Label; import com.vaadin.ui.Notification; -import com.vaadin.ui.DateField; import com.vaadin.ui.Slider; import com.vaadin.ui.TextField; @@ -116,13 +115,13 @@ public class BinderBookOfVaadinTest { } public static class Trip { - private Date returnDate; + private LocalDate returnDate; - public Date getReturnDate() { + public LocalDate getReturnDate() { return returnDate; } - public void setReturnDate(Date returnDate) { + public void setReturnDate(LocalDate returnDate) { this.returnDate = returnDate; } } @@ -304,20 +303,18 @@ public class BinderBookOfVaadinTest { DateField departing = new DateField("Departing"); DateField returning = new DateField("Returning"); - Binding<Trip, Date, Date> returnBinding = binder.forField(returning) - .withValidator( - returnDate -> !returnDate.before(departing.getValue()), + Binding<Trip, LocalDate, LocalDate> returnBinding = binder + .forField(returning).withValidator( + returnDate -> !returnDate + .isBefore(departing.getValue()), "Cannot return before departing"); returnBinding.bind(Trip::getReturnDate, Trip::setReturnDate); departing.addValueChangeListener(event -> returnBinding.validate()); - Calendar calendar = Calendar.getInstance(); - Date past = calendar.getTime(); - calendar.add(1, Calendar.DAY_OF_YEAR); - Date before = calendar.getTime(); - calendar.add(1, Calendar.DAY_OF_YEAR); - Date after = calendar.getTime(); + LocalDate past = LocalDate.now(); + LocalDate before = past.plusDays(1); + LocalDate after = before.plusDays(1); departing.setValue(before); returning.setValue(after); @@ -359,25 +356,23 @@ public class BinderBookOfVaadinTest { DateField departing = new DateField("Departing"); DateField returning = new DateField("Returning"); - Binding<Trip, Date, Date> returnBinding = binder.forField(returning) - .withValidator( - returnDate -> !returnDate.before(departing.getValue()), + Binding<Trip, LocalDate, LocalDate> returnBinding = binder + .forField(returning).withValidator( + returnDate -> !returnDate + .isBefore(departing.getValue()), "Cannot return before departing"); returnBinding.bind(Trip::getReturnDate, Trip::setReturnDate); departing.addValueChangeListener(event -> returnBinding.validate()); - Calendar calendar = Calendar.getInstance(); - Date past = calendar.getTime(); - calendar.add(1, Calendar.DAY_OF_YEAR); - Date before = calendar.getTime(); - calendar.add(1, Calendar.DAY_OF_YEAR); - Date after = calendar.getTime(); + LocalDate past = LocalDate.now(); + LocalDate before = past.plusDays(1); + LocalDate after = before.plusDays(1); departing.setValue(before); returning.setValue(after); - ValidationStatus<Date> result = returnBinding.validate(); + ValidationStatus<LocalDate> result = returnBinding.validate(); Assert.assertFalse(result.isError()); Assert.assertNull(departing.getComponentError()); @@ -465,8 +460,7 @@ public class BinderBookOfVaadinTest { @Test public void binder_saveIfValid() { - BeanBinder<BookPerson> binder = new BeanBinder<BookPerson>( - BookPerson.class); + BeanBinder<BookPerson> binder = new BeanBinder<>(BookPerson.class); // Phone or email has to be specified for the bean Validator<BookPerson> phoneOrEmail = Validator.from( diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java index 9d6e57b207..0448bf5697 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java @@ -15,11 +15,10 @@ */ package com.vaadin.tests.server.component.datefield; -import java.util.Date; +import java.time.LocalDate; import org.junit.Test; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.design.DeclarativeTestBase; import com.vaadin.ui.AbstractDateField; import com.vaadin.ui.DateField; @@ -31,20 +30,18 @@ import com.vaadin.ui.DateField; * @since 7.4 * @author Vaadin Ltd */ -public class DateFieldDeclarativeTest - extends DeclarativeTestBase<DateField> { +public class DateFieldDeclarativeTest extends DeclarativeTestBase<DateField> { private String getBasicDesign() { - return "<vaadin-date-field assistive-text='at' text-field-enabled='false' show-iso-week-numbers resolution=\"MINUTE\" range-end=\"2019-01-15\" input-prompt=\"Pick a day\" value=\"2003-02-27 07:15\"></vaadin-date-field>"; + return "<vaadin-date-field assistive-text='at' text-field-enabled='false' show-iso-week-numbers range-end=\"2019-01-15\" input-prompt=\"Pick a day\" value=\"2003-02-27\"></vaadin-date-field>"; } private DateField getBasicExpected() { DateField pdf = new DateField(); pdf.setShowISOWeekNumbers(true); - pdf.setResolution(Resolution.MINUTE); - pdf.setRangeEnd(new Date(2019 - 1900, 1 - 1, 15)); + pdf.setRangeEnd(LocalDate.of(2019, 01, 15)); pdf.setInputPrompt("Pick a day"); - pdf.setValue(new Date(2003 - 1900, 2 - 1, 27, 7, 15)); + pdf.setValue(LocalDate.of(2003, 2, 27)); pdf.setTextFieldEnabled(false); pdf.setAssistiveText("at"); return pdf; diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java index 70309c7e7d..c947641986 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java @@ -17,18 +17,18 @@ package com.vaadin.tests.server.component.datefield; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.text.SimpleDateFormat; +import java.time.LocalDate; import org.junit.Test; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.design.DeclarativeTestBase; import com.vaadin.ui.AbstractDateField; import com.vaadin.ui.InlineDateField; import com.vaadin.ui.declarative.Design; /** - * Tests the declarative support for implementations of {@link AbstractDateField}. + * Tests the declarative support for implementations of + * {@link AbstractDateField}. * * @since 7.4 * @author Vaadin Ltd @@ -39,13 +39,10 @@ public class InlineDateFieldDeclarativeTest @Test public void testInlineDateFieldToFromDesign() throws Exception { InlineDateField field = new InlineDateField("Day is", - new SimpleDateFormat("yyyy-MM-dd").parse("2003-02-27")); - field.setResolution(Resolution.DAY); + LocalDate.of(2003, 2, 27)); field.setShowISOWeekNumbers(true); - field.setRangeStart( - new SimpleDateFormat("yyyy-MM-dd").parse("2001-02-27")); - field.setRangeEnd( - new SimpleDateFormat("yyyy-MM-dd").parse("2011-02-27")); + field.setRangeStart(LocalDate.of(2001, 2, 27)); + field.setRangeEnd(LocalDate.of(20011, 2, 27)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); Design.write(field, bos); diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/ResolutionTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/ResolutionTest.java index 2fb7702aeb..cb8b6f4914 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/datefield/ResolutionTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/ResolutionTest.java @@ -31,35 +31,12 @@ public class ResolutionTest { } @Test - public void testResolutionLowerThanDay() { - Iterable<Resolution> higherOrEqual = Resolution - .getResolutionsLowerThan(Resolution.DAY); - ArrayList<Resolution> expected = new ArrayList<>(); - expected.add(Resolution.HOUR); - expected.add(Resolution.MINUTE); - expected.add(Resolution.SECOND); - TestUtil.assertIterableEquals(expected, higherOrEqual); - - } - - @Test - public void testResolutionLowerThanSecond() { - Iterable<Resolution> higherOrEqual = Resolution - .getResolutionsLowerThan(Resolution.SECOND); - ArrayList<Resolution> expected = new ArrayList<>(); - TestUtil.assertIterableEquals(expected, higherOrEqual); - } - - @Test public void testResolutionLowerThanYear() { Iterable<Resolution> higherOrEqual = Resolution .getResolutionsLowerThan(Resolution.YEAR); ArrayList<Resolution> expected = new ArrayList<>(); expected.add(Resolution.MONTH); expected.add(Resolution.DAY); - expected.add(Resolution.HOUR); - expected.add(Resolution.MINUTE); - expected.add(Resolution.SECOND); TestUtil.assertIterableEquals(expected, higherOrEqual); } diff --git a/server/src/test/java/com/vaadin/ui/DateFieldTestCase.java b/server/src/test/java/com/vaadin/ui/DateFieldTestCase.java index b7b7dfd9f9..8abb16af6c 100644 --- a/server/src/test/java/com/vaadin/ui/DateFieldTestCase.java +++ b/server/src/test/java/com/vaadin/ui/DateFieldTestCase.java @@ -4,21 +4,22 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNull.nullValue; -import java.util.Date; +import java.time.LocalDate; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class DateFieldTestCase { private AbstractDateField dateField; - private Date date; + private LocalDate date; @Before public void setup() { dateField = new AbstractDateField() { }; - date = new Date(); + date = LocalDate.now(); } @Test @@ -29,13 +30,17 @@ public class DateFieldTestCase { } @Test - public void rangeStartIsImmutable() { - long expectedTime = date.getTime(); - + public void rangeStartIsAcceptedAsValue() { dateField.setRangeStart(date); - date.setTime(expectedTime + 1); + dateField.setValue(date); + Assert.assertNull(dateField.getComponentError()); + } - assertThat(dateField.getRangeStart().getTime(), is(expectedTime)); + @Test + public void belowRangeStartIsNotAcceptedAsValue() { + dateField.setRangeStart(date); + dateField.setValue(date.minusDays(1)); + Assert.assertNotNull(dateField.getComponentError()); } @Test @@ -46,12 +51,16 @@ public class DateFieldTestCase { } @Test - public void rangeEndIsImmutable() { - long expectedTime = date.getTime(); - + public void rangeEndIsAcceptedAsValue() { dateField.setRangeEnd(date); - date.setTime(expectedTime + 1); + dateField.setValue(date); + Assert.assertNull(dateField.getComponentError()); + } - assertThat(dateField.getRangeEnd().getTime(), is(expectedTime)); + @Test + public void aboveRangeEndIsNotAcceptedAsValue() { + dateField.setRangeEnd(date); + dateField.setValue(date.plusDays(1)); + Assert.assertNotNull(dateField.getComponentError()); } } diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/PopupDateFieldState.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/DateFieldState.java index 3489346564..f71d33fb3a 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/datefield/PopupDateFieldState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/datefield/DateFieldState.java @@ -17,7 +17,7 @@ package com.vaadin.shared.ui.datefield; import com.vaadin.shared.annotations.NoLayout; -public class PopupDateFieldState extends TextualDateFieldState { +public class DateFieldState extends TextualDateFieldState { public static final String DESCRIPTION_FOR_ASSISTIVE_DEVICES = "Arrow down key opens calendar element for choosing the date"; { diff --git a/shared/src/main/java/com/vaadin/shared/ui/datefield/Resolution.java b/shared/src/main/java/com/vaadin/shared/ui/datefield/Resolution.java index 93dbb7ab83..0fc5da4803 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/datefield/Resolution.java +++ b/shared/src/main/java/com/vaadin/shared/ui/datefield/Resolution.java @@ -25,25 +25,7 @@ import java.util.List; * @since 7.0 */ public enum Resolution { - // Values from Calendar.SECOND etc. Set as ints to avoid Calendar dependency - // (does not exist on the client side) - SECOND(13), MINUTE(12), HOUR(11), DAY(5), MONTH(2), YEAR(1); - - private int calendarField; - - private Resolution(int calendarField) { - this.calendarField = calendarField; - } - - /** - * Returns the field in java.util.Calendar that corresponds to this - * resolution. - * - * @return one of the field numbers used by Calendar - */ - public int getCalendarField() { - return calendarField; - } + DAY, MONTH, YEAR; /** * Returns the resolutions that are higher or equal to the given resolution, @@ -81,4 +63,5 @@ public enum Resolution { } return resolutions; } + } diff --git a/uitest/src/main/java/com/vaadin/tests/RandomLayoutStress.java b/uitest/src/main/java/com/vaadin/tests/RandomLayoutStress.java index f15263203e..474ebc9988 100644 --- a/uitest/src/main/java/com/vaadin/tests/RandomLayoutStress.java +++ b/uitest/src/main/java/com/vaadin/tests/RandomLayoutStress.java @@ -16,6 +16,7 @@ package com.vaadin.tests; +import java.time.LocalDate; import java.util.Random; import com.vaadin.server.ExternalResource; @@ -184,13 +185,13 @@ public class RandomLayoutStress extends com.vaadin.server.LegacyApplication { // Datefield result = new TestDateField(); ((AbstractDateField) result).setStyleName("calendar"); - ((AbstractDateField) result).setValue(new java.util.Date()); + ((AbstractDateField) result).setValue(LocalDate.now()); result.setCaption("Calendar component " + caption); break; case 7: // Datefield result = new TestDateField(); - ((AbstractDateField) result).setValue(new java.util.Date()); + ((AbstractDateField) result).setValue(LocalDate.now()); result.setCaption("Calendar component " + caption); break; } diff --git a/uitest/src/main/java/com/vaadin/tests/components/TestDateField.java b/uitest/src/main/java/com/vaadin/tests/components/TestDateField.java index 26353e192b..6a3004ed65 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/TestDateField.java +++ b/uitest/src/main/java/com/vaadin/tests/components/TestDateField.java @@ -15,7 +15,7 @@ */ package com.vaadin.tests.components; -import java.util.Date; +import java.time.LocalDate; import com.vaadin.ui.AbstractDateField; @@ -48,9 +48,9 @@ public class TestDateField extends AbstractDateField { * @param caption * the caption <code>String</code> for the editor. * @param value - * the Date value. + * the {@link LocalDate} value. */ - public TestDateField(String caption, Date value) { + public TestDateField(String caption, LocalDate value) { setValue(value); setCaption(caption); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java b/uitest/src/main/java/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java index 399174b2f6..7324f46d3c 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/abstractfield/AbstractFieldTest.java @@ -1,10 +1,10 @@ package com.vaadin.tests.components.abstractfield; -import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.Locale; import com.vaadin.data.HasValue.ValueChange; @@ -137,13 +137,13 @@ public abstract class AbstractFieldTest<T extends AbstractField<V>, V> // Distinguish between null and 'null' String value = "null"; if (o != null) { - if (o instanceof Date) { - Date d = (Date) o; - // Dec 31, 2068 23:09:26.531 - String pattern = "MMM d, yyyy HH:mm:ss.SSS"; - SimpleDateFormat format = new SimpleDateFormat(pattern, - new Locale("en", "US")); - value = format.format(d); + if (o instanceof LocalDate) { + LocalDate date = (LocalDate) o; + // Dec 31, 2068 + String pattern = "MMM d, yyyy"; + DateTimeFormatter format = DateTimeFormatter.ofPattern(pattern, + Locale.ENGLISH); + value = format.format(date); } else { value = "'" + o.toString() + "'"; } diff --git a/uitest/src/main/java/com/vaadin/tests/components/calendar/BeanItemContainerTestUI.java b/uitest/src/main/java/com/vaadin/tests/components/calendar/BeanItemContainerTestUI.java index e9d50a3a7e..0f468ae979 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/calendar/BeanItemContainerTestUI.java +++ b/uitest/src/main/java/com/vaadin/tests/components/calendar/BeanItemContainerTestUI.java @@ -21,7 +21,6 @@ import java.util.GregorianCalendar; import com.vaadin.event.Action; import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.ui.FormLayout; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalSplitPanel; @@ -31,6 +30,7 @@ import com.vaadin.v7.data.fieldgroup.FieldGroup; import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException; import com.vaadin.v7.data.util.BeanItem; import com.vaadin.v7.data.util.BeanItemContainer; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.ui.Calendar; import com.vaadin.v7.ui.DateField; import com.vaadin.v7.ui.Table; diff --git a/uitest/src/main/java/com/vaadin/tests/components/calendar/CalendarTest.java b/uitest/src/main/java/com/vaadin/tests/components/calendar/CalendarTest.java index 2b7fe664cd..b099de70e5 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/calendar/CalendarTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/calendar/CalendarTest.java @@ -27,7 +27,6 @@ import com.vaadin.data.Binder; import com.vaadin.data.ValidationException; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.MarginInfo; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; @@ -48,6 +47,7 @@ import com.vaadin.v7.data.fieldgroup.FieldGroup; import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException; import com.vaadin.v7.data.util.BeanItem; import com.vaadin.v7.shared.ui.combobox.FilteringMode; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.ui.Calendar; import com.vaadin.v7.ui.Calendar.TimeFormat; import com.vaadin.v7.ui.ComboBox; diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/AbstractDateFieldTest.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/AbstractDateFieldTest.java index 0d0e88b3cb..2e39af99d1 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/AbstractDateFieldTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/AbstractDateFieldTest.java @@ -2,8 +2,7 @@ package com.vaadin.tests.components.datefield; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; +import java.time.LocalDate; import java.util.LinkedHashMap; import java.util.Locale; @@ -13,7 +12,7 @@ import com.vaadin.tests.components.abstractfield.AbstractFieldTest; import com.vaadin.ui.AbstractDateField; public class AbstractDateFieldTest<T extends AbstractDateField> - extends AbstractFieldTest<T, Date> { + extends AbstractFieldTest<T, LocalDate> { @SuppressWarnings("unchecked") @Override @@ -21,10 +20,10 @@ public class AbstractDateFieldTest<T extends AbstractDateField> return (Class<T>) TestDateField.class; } - private Command<T, Date> setValue = new Command<T, Date>() { + private Command<T, LocalDate> setValue = new Command<T, LocalDate>() { @Override - public void execute(T c, Date value, Object data) { + public void execute(T c, LocalDate value, Object data) { c.setValue(value); } }; @@ -43,18 +42,10 @@ public class AbstractDateFieldTest<T extends AbstractDateField> } private void createSetValueAction(String category) { - LinkedHashMap<String, Date> options = new LinkedHashMap<>(); + LinkedHashMap<String, LocalDate> options = new LinkedHashMap<>(); options.put("(null)", null); - options.put("(current time)", new Date()); - Calendar c = Calendar.getInstance(new Locale("fi", "FI")); - c.clear(); - c.set(2010, 12 - 1, 12, 12, 0, 0); - c.set(Calendar.MILLISECOND, 0); - options.put("2010-12-12 12:00:00.000", c.getTime()); - c.clear(); - c.set(2000, 1 - 1, 2, 3, 4, 5); - c.set(Calendar.MILLISECOND, 6); - options.put("2000-01-02 03:04:05.006", c.getTime()); + options.put("(current time)", LocalDate.now()); + options.put("2010-12-12", LocalDate.of(2010, 12, 12)); createMultiClickAction("Set value", category, options, setValue, null); } @@ -103,9 +94,6 @@ public class AbstractDateFieldTest<T extends AbstractDateField> options.put("Year", Resolution.YEAR); options.put("Month", Resolution.MONTH); options.put("Day", Resolution.DAY); - options.put("Hour", Resolution.HOUR); - options.put("Min", Resolution.MINUTE); - options.put("Sec", Resolution.SECOND); createSelectAction("Resolution", category, options, "Year", resolutionCommand); diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormat.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormat.java index aa32fd3c4f..511b7fe3d4 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormat.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormat.java @@ -1,6 +1,6 @@ package com.vaadin.tests.components.datefield; -import java.util.Calendar; +import java.time.LocalDate; import java.util.Locale; import com.vaadin.shared.ui.datefield.Resolution; @@ -12,20 +12,16 @@ public class CustomDateFormat extends TestBase { @Override protected void setup() { - Locale locale = new Locale("fi", "FI"); - Calendar cal = Calendar.getInstance(); - cal.set(2010, 0, 1); - AbstractDateField df = new TestDateField(); df.setResolution(Resolution.DAY); df.setLocale(locale); df.setWidth("300px"); - String pattern = "d. MMMM'ta 'yyyy 'klo 'H.mm.ss"; + String pattern = "d. MMMM'ta 'yyyy 'klo"; df.setDateFormat(pattern); - df.setValue(cal.getTime()); + df.setValue(LocalDate.of(2010, 1, 1)); addComponent(df); diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormatEEE.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormatEEE.java index afbd6e828f..45828486cf 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormatEEE.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormatEEE.java @@ -15,7 +15,7 @@ */ package com.vaadin.tests.components.datefield; -import java.util.Calendar; +import java.time.LocalDate; import java.util.Locale; import com.vaadin.server.VaadinRequest; @@ -29,9 +29,6 @@ public class CustomDateFormatEEE extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { - Calendar cal = Calendar.getInstance(); - cal.set(2014, 2, 14); // Friday - AbstractDateField df = new TestDateField( "Should display 14/03/2014 Fri"); df.setResolution(Resolution.DAY); @@ -39,7 +36,7 @@ public class CustomDateFormatEEE extends AbstractTestUI { String pattern = "dd/MM/yyyy EEE"; df.setDateFormat(pattern); - df.setValue(cal.getTime()); + df.setValue(LocalDate.of(2014, 3, 14)); // Friday df.setWidth("200px"); VerticalLayout layout = new VerticalLayout(); diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java index 91a76f5269..f28ad7b104 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java @@ -2,7 +2,8 @@ package com.vaadin.tests.components.datefield; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.Calendar; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.HashSet; import java.util.Locale; import java.util.Set; @@ -137,9 +138,6 @@ public class CustomDateFormats extends TestBase { private void addDateField(GridLayout gridLayout, String pattern, Locale locale, String expectedDateFormat) { - Calendar cal = Calendar.getInstance(); - cal.set(2010, 1, 1); - Label serversideValueLabel = new Label(); AbstractDateField df = new TestDateField(); @@ -158,16 +156,16 @@ public class CustomDateFormats extends TestBase { usedDebugIds.add(debugId); df.setData(new Data(serversideValueLabel, pattern)); - df.setValue(cal.getTime()); + df.setValue(LocalDate.of(2010, 2, 1)); df.addValueChangeListener(event -> updateServerSideLabel( (AbstractDateField) event.getConnector())); Label patternLabel = new Label(pattern); patternLabel.setWidth(null); - SimpleDateFormat expDateFormat = new SimpleDateFormat( - expectedDateFormat, locale); + DateTimeFormatter expDateFormat = DateTimeFormatter + .ofPattern(expectedDateFormat, locale); - Label expectedLabel = new Label(expDateFormat.format(cal.getTime())); + Label expectedLabel = new Label(expDateFormat.format(df.getValue())); if (!pattern.equals(expectedDateFormat)) { expectedLabel .setValue(expectedLabel.getValue() + " (differs from JDK)"); diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldChangeResolution.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldChangeResolution.java index ba8da59dfb..3305f9e229 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldChangeResolution.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldChangeResolution.java @@ -18,13 +18,13 @@ package com.vaadin.tests.components.datefield; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbstractDateField; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.AbstractDateField; +import com.vaadin.ui.DateField; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; -import com.vaadin.ui.DateField; public class DateFieldChangeResolution extends AbstractTestUI { diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java index 2e4d899f16..8fce5df8d3 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java @@ -1,9 +1,7 @@ package com.vaadin.tests.components.datefield; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.TimeZone; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.datefield.Resolution; @@ -14,16 +12,15 @@ import com.vaadin.ui.Label; public class DateFieldDayResolutionOffset extends AbstractTestUI { - private final String initialDateString = "09/01/2014 00:00:00"; + private final String initialDateString = "09/01/2014"; @Override protected void setup(VaadinRequest request) { final Label dateValue = new Label(initialDateString); dateValue.setId("dateValue"); - final TimeZone timezone = TimeZone.getTimeZone("GMT"); - final SimpleDateFormat dateformat = getDateFormat(timezone); - final AbstractDateField dateField = getDateField(timezone, dateformat); + final DateTimeFormatter dateformat = getDateFormat(); + final AbstractDateField dateField = getDateField(dateformat); addComponent(dateValue); addComponent(dateField); @@ -32,24 +29,18 @@ public class DateFieldDayResolutionOffset extends AbstractTestUI { .setValue(dateformat.format(dateField.getValue()))); } - private AbstractDateField getDateField(TimeZone timezone, - SimpleDateFormat dateformat) { + private AbstractDateField getDateField(DateTimeFormatter dateformat) { final AbstractDateField dateField = new TestDateField(); - try { - Date initialDate = dateformat.parse(initialDateString); - dateField.setResolution(Resolution.DAY); - dateField.setTimeZone(timezone); - dateField.setValue(initialDate); - } catch (ParseException e) { - e.printStackTrace(); - } + LocalDate initialDate = dateformat.parse(initialDateString, + LocalDate::from); + dateField.setResolution(Resolution.DAY); + dateField.setValue(initialDate); return dateField; } - private SimpleDateFormat getDateFormat(TimeZone timezone) { - final SimpleDateFormat dateformat = new SimpleDateFormat( - "MM/dd/yyyy HH:mm:ss"); - dateformat.setTimeZone(timezone); + private DateTimeFormatter getDateFormat() { + final DateTimeFormatter dateformat = DateTimeFormatter + .ofPattern("MM/dd/yyyy"); return dateformat; } diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldEmptyValid.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldEmptyValid.java index 5e9df766d2..318634bcbe 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldEmptyValid.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldEmptyValid.java @@ -4,7 +4,6 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.Log; @@ -15,6 +14,7 @@ import com.vaadin.ui.Label; import com.vaadin.v7.data.Property.ValueChangeEvent; import com.vaadin.v7.data.Property.ValueChangeListener; import com.vaadin.v7.data.util.ObjectProperty; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.ui.PopupDateField; @SuppressWarnings("serial") diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldExtendedRange.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldExtendedRange.java index 2a9b71ccaa..b75fb761d2 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldExtendedRange.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldExtendedRange.java @@ -1,27 +1,22 @@ package com.vaadin.tests.components.datefield; -import java.util.Calendar; +import java.time.LocalDate; import java.util.Locale; +import java.util.stream.Stream; import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.AbstractDateField; +import com.vaadin.ui.Button; +import com.vaadin.ui.DateField; import com.vaadin.ui.GridLayout; import com.vaadin.ui.InlineDateField; -import com.vaadin.ui.DateField; @SuppressWarnings("serial") public class DateFieldExtendedRange extends TestBase { - private Calendar date = Calendar.getInstance(); - @Override protected void setup() { - date.set(2011, 0, 1); - GridLayout layout = new GridLayout(2, 3); layout.setWidth("600px"); layout.setSpacing(true); @@ -49,15 +44,8 @@ public class DateFieldExtendedRange extends TestBase { addComponent(layout); - addComponent(new Button("Change date", new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - date.set(2010, 1, 16); - for (AbstractDateField f : fields) { - f.setValue(date.getTime()); - } - } - })); + addComponent(new Button("Change date", event -> Stream.of(fields) + .forEach(field -> field.setValue(LocalDate.of(2010, 2, 16))))); } @Override @@ -72,9 +60,10 @@ public class DateFieldExtendedRange extends TestBase { private AbstractDateField makeDateField(boolean isPopup, Locale locale, String caption) { - AbstractDateField df = isPopup ? new DateField() : new InlineDateField(); + AbstractDateField df = isPopup ? new DateField() + : new InlineDateField(); df.setResolution(Resolution.DAY); - df.setValue(date.getTime()); + df.setValue(LocalDate.of(2011, 1, 1)); df.setLocale(locale); df.setCaption(caption); return df; diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldIsValid.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldIsValid.java index f38e641b8b..0542961260 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldIsValid.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldIsValid.java @@ -1,7 +1,7 @@ package com.vaadin.tests.components.datefield; -import java.text.SimpleDateFormat; -import java.util.Date; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUIWithLog; @@ -22,7 +22,7 @@ public class DateFieldIsValid extends AbstractTestUIWithLog { } private String pattern = "dd/MM/yy"; - private SimpleDateFormat format = new SimpleDateFormat(pattern); + private DateTimeFormatter format = DateTimeFormatter.ofPattern(pattern); @Override protected void setup(VaadinRequest request) { @@ -45,7 +45,7 @@ public class DateFieldIsValid extends AbstractTestUIWithLog { * @param value * @return */ - protected String format(Date value) { + protected String format(LocalDate value) { if (value != null) { return format.format(value); } else { diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldKeyboardInput.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldKeyboardInput.java index 24b75d0603..b92ca393c9 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldKeyboardInput.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldKeyboardInput.java @@ -15,23 +15,19 @@ */ package com.vaadin.tests.components.datefield; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.Locale; +import java.time.LocalDate; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Label; import com.vaadin.ui.DateField; +import com.vaadin.ui.Label; public class DateFieldKeyboardInput extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { - Calendar c = new GregorianCalendar(Locale.ENGLISH); - c.set(2014, 0, 15); final DateField dateField = new DateField("Select date", - c.getTime()); + LocalDate.of(2014, 1, 15)); dateField.setDateFormat("dd.MM.yyyy"); addComponent(dateField); dateField.addValueChangeListener( diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldLocale.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldLocale.java index cf524f375c..1224b6aa73 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldLocale.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldLocale.java @@ -1,6 +1,6 @@ package com.vaadin.tests.components.datefield; -import java.util.Date; +import java.time.LocalDate; import java.util.Locale; import com.vaadin.shared.ui.datefield.Resolution; @@ -18,7 +18,7 @@ public class DateFieldLocale extends TestBase { final AbstractDateField dateField = new TestDateField("DateField"); dateField.setLocale(new Locale("fi", "FI")); dateField.setCaption(dateField.getLocale().toString()); - dateField.setValue(new Date(2013 - 1900, 7 - 1, 27)); + dateField.setValue(LocalDate.of(2013, 7, 27)); dateField.setResolution(Resolution.DAY); addComponent(new Button("Change locale", new ClickListener() { diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldMinResolution.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldMinResolution.java deleted file mode 100644 index 9b6faf201a..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldMinResolution.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.vaadin.tests.components.datefield; - -import java.text.SimpleDateFormat; -import java.util.Calendar; - -import com.vaadin.shared.ui.datefield.Resolution; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.components.TestDateField; -import com.vaadin.ui.AbstractDateField; -import com.vaadin.ui.InlineDateField; -import com.vaadin.ui.Label; - -public class DateFieldMinResolution extends TestBase { - - @Override - protected void setup() { - - final SimpleDateFormat dformat = new SimpleDateFormat( - "dd/MM/yyyy HH:mm"); - - Calendar cal = Calendar.getInstance(); - cal.set(2019, 1, 1, 1, 1); - - AbstractDateField df = new TestDateField("foo"); - df.setResolution(Resolution.MINUTE); - df.setDateFormat(dformat.toPattern()); - df.setValue(cal.getTime()); - df.setImmediate(true); - - addComponent(df); - - final Label lbl = new Label(dformat.format(cal.getTime())); - lbl.setCaption("Selected date"); - - InlineDateField idf = new InlineDateField("bar"); - idf.setResolution(Resolution.MINUTE); - idf.setDateFormat(dformat.toPattern()); - idf.setValue(cal.getTime()); - idf.setImmediate(true); - - idf.addValueChangeListener( - event -> lbl.setValue(dformat.format(event.getValue()))); - - addComponent(idf); - addComponent(lbl); - } - - @Override - protected String getDescription() { - return "When the time controls are visible the time should be directed directly to the textfield"; - } - - @Override - protected Integer getTicketNumber() { - return 5387; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.java index afcc5295e4..165a62b6e2 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.java @@ -1,9 +1,8 @@ package com.vaadin.tests.components.datefield; -import java.util.Date; +import java.time.LocalDate; import java.util.Locale; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.AbstractTestCase; import com.vaadin.tests.components.TestDateField; import com.vaadin.ui.AbstractDateField; @@ -59,10 +58,9 @@ public class DateFieldPopupOffScreen extends AbstractTestCase { private AbstractDateField createDateField() { AbstractDateField df = new TestDateField(); df.setLocale(new Locale("fi")); - df.setResolution(Resolution.SECOND); df.setDescription( "This is a long, multiline tooltip.<br/>It should always be on screen so it can be read."); - df.setValue(new Date(1000000L)); + df.setValue(LocalDate.of(2000, 1, 1)); return df; } } diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRangeValidation.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRangeValidation.java index 7a1717cdb6..dceb6f1bb9 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRangeValidation.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRangeValidation.java @@ -4,7 +4,6 @@ import java.util.Date; import java.util.Locale; import com.vaadin.data.HasValue; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.CheckBoxWithPropertyDataSource; import com.vaadin.ui.CheckBox; @@ -119,7 +118,6 @@ public class DateFieldRangeValidation extends TestBase { private PopupDateField createDateField() { PopupDateField df = new PopupDateField(); df.setLocale(new Locale("en", "US")); - df.setResolution(Resolution.DAY); df.setBuffered(false); df.setImmediate(true); return df; diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRanges.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRanges.java index 5db5b815e4..7b8e547701 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRanges.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRanges.java @@ -1,5 +1,6 @@ package com.vaadin.tests.components.datefield; +import java.time.LocalDate; import java.util.Calendar; import java.util.Date; import java.util.Locale; @@ -54,9 +55,6 @@ public class DateFieldRanges extends AbstractTestUI { } private void initializeControlFields() { - resoSelect.addItem(Resolution.MINUTE); - resoSelect.addItem(Resolution.SECOND); - resoSelect.addItem(Resolution.HOUR); resoSelect.addItem(Resolution.DAY); resoSelect.addItem(Resolution.MONTH); resoSelect.addItem(Resolution.YEAR); @@ -225,9 +223,9 @@ public class DateFieldRanges extends AbstractTestUI { } private void updateValuesForDateField(AbstractDateField df) { - Date fromVal = fromRange.getValue(); - Date toVal = toRange.getValue(); - Date value = valueDF.getValue(); + LocalDate fromVal = fromRange.getValue(); + LocalDate toVal = toRange.getValue(); + LocalDate value = valueDF.getValue(); Resolution r = (Resolution) resoSelect.getValue(); boolean immediate = immediateCB.getValue(); diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldReadOnly.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldReadOnly.java index 84ac1c6106..513bb11f9e 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldReadOnly.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldReadOnly.java @@ -1,10 +1,9 @@ package com.vaadin.tests.components.datefield; -import java.util.Calendar; +import java.time.LocalDate; import java.util.Locale; import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.components.TestDateField; import com.vaadin.ui.AbstractDateField; @@ -28,8 +27,6 @@ public class DateFieldReadOnly extends AbstractTestUI { protected void setup(VaadinRequest request) { final AbstractDateField timeField = new TestDateField( "A read-only datefield"); - timeField.setResolution(Resolution.SECOND); - timeField.setDateFormat("HH:mm:ss"); timeField.setCaption(null); timeField.setIcon(null); timeField.setWidth("8em"); @@ -37,10 +34,7 @@ public class DateFieldReadOnly extends AbstractTestUI { timeField.setLocale(new Locale("fi")); // Set date so that testing always has same time - Calendar c = Calendar.getInstance(Locale.ENGLISH); - c.set(2009, 05, 12, 0, 0, 0); - - timeField.setValue(c.getTime()); + timeField.setValue(LocalDate.of(2009, 6, 12)); timeField.setReadOnly(true); addComponent(timeField); diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldTest.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldTest.java index 01e6500d35..4bff1505c0 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldTest.java @@ -39,14 +39,6 @@ public class DateFieldTest extends AbstractDateFieldTest<DateField> { private void createTextEnabledAction(String category) { this.createBooleanAction("Text field enabled", category, true, - new Command<DateField, Boolean>() { - - @Override - public void execute(DateField c, Boolean value, - Object data) { - c.setTextFieldEnabled(value); - } - - }); + (field, value, data) -> field.setTextFieldEnabled(value)); } } diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldTimezone.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldTimezone.java deleted file mode 100644 index 19120be547..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldTimezone.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.vaadin.tests.components.datefield; - -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; - -import com.vaadin.shared.ui.datefield.Resolution; -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.components.TestDateField; -import com.vaadin.tests.util.Log; -import com.vaadin.ui.AbstractDateField; -import com.vaadin.v7.data.Property; -import com.vaadin.v7.data.Property.ValueChangeEvent; -import com.vaadin.v7.shared.ui.combobox.FilteringMode; -import com.vaadin.v7.ui.ComboBox; - -public class DateFieldTimezone extends TestBase { - - private static final TimeZone UTC = TimeZone.getTimeZone("UTC"); - private static final Locale EN = Locale.ENGLISH; - private final Log log = new Log(5); - private final AbstractDateField dateField = new TestDateField(); - private static final String nullValue = ""; - - @Override - protected void setup() { - dateField.setResolution(Resolution.SECOND); - - ArrayList<String> timeZoneCodes = new ArrayList<>(); - timeZoneCodes.add(nullValue); - timeZoneCodes.addAll(Arrays.asList(TimeZone.getAvailableIDs())); - ComboBox timezoneSelector = new ComboBox("Select time zone", - timeZoneCodes) { - @Override - public String getItemCaption(Object itemId) { - if (itemId == nullValue || itemId == null) { - TimeZone timeZone = TimeZone.getDefault(); - return "Default time zone (" + timeZone.getDisplayName() - + ")"; - } else { - TimeZone timeZone = TimeZone.getTimeZone((String) itemId); - return itemId + " (" + timeZone.getDisplayName() + ")"; - } - } - }; - timezoneSelector.setValue("UTC"); - timezoneSelector.setImmediate(true); - timezoneSelector.setNullSelectionAllowed(true); - timezoneSelector.setNullSelectionItemId(nullValue); - timezoneSelector.setFilteringMode(FilteringMode.CONTAINS); - timezoneSelector.addListener(new Property.ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - Object value = event.getProperty().getValue(); - TimeZone timeZone; - if (value == nullValue || value == null) { - timeZone = null; - log.log("Change to default time zone " - + TimeZone.getDefault().getID()); - } else { - timeZone = TimeZone.getTimeZone((String) value); - log.log("Changed to time zone " + timeZone.getID()); - } - dateField.setTimeZone(timeZone); - } - }); - - Calendar cal = Calendar.getInstance(UTC); - cal.set(2010, 0, 1, 0, 0, 0); - cal.set(Calendar.MILLISECOND, 0); - - dateField.setValue(cal.getTime()); - dateField.setImmediate(true); - dateField.setTimeZone(cal.getTimeZone()); - dateField.setLocale(EN); - dateField.addValueChangeListener(event -> { - Date date = dateField.getValue(); - DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, - DateFormat.LONG, EN); - format.setTimeZone(UTC); - log.log("Date changed to " + format.format(date)); - }); - - addComponent(timezoneSelector); - addComponent(log); - addComponent(dateField); - } - - @Override - protected String getDescription() { - return "Tests the operation of the date field with different time zones"; - } - - @Override - protected Integer getTicketNumber() { - return Integer.valueOf(6066); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldUnparsableDate.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldUnparsableDate.java index 17c9f47c35..53f8bb1cb2 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldUnparsableDate.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldUnparsableDate.java @@ -1,6 +1,6 @@ package com.vaadin.tests.components.datefield; -import java.util.Date; +import java.time.LocalDate; import com.vaadin.data.Result; import com.vaadin.tests.components.TestBase; @@ -10,7 +10,7 @@ import com.vaadin.v7.data.util.converter.Converter; public class DateFieldUnparsableDate extends TestBase { public class MyDateField extends AbstractDateField { - Date oldDate = null; + LocalDate oldDate = null; public MyDateField(String caption) { super(caption); @@ -18,8 +18,8 @@ public class DateFieldUnparsableDate extends TestBase { } @Override - protected Result<Date> handleUnparsableDateString(String dateString) - throws Converter.ConversionException { + protected Result<LocalDate> handleUnparsableDateString( + String dateString) throws Converter.ConversionException { return Result.ok(oldDate); } } @@ -30,8 +30,8 @@ public class DateFieldUnparsableDate extends TestBase { } @Override - protected Result<Date> handleUnparsableDateString(String dateString) - throws Converter.ConversionException { + protected Result<LocalDate> handleUnparsableDateString( + String dateString) throws Converter.ConversionException { return Result.ok(null); } } @@ -42,8 +42,8 @@ public class DateFieldUnparsableDate extends TestBase { } @Override - protected Result<Date> handleUnparsableDateString(String dateString) - throws Converter.ConversionException { + protected Result<LocalDate> handleUnparsableDateString( + String dateString) throws Converter.ConversionException { return Result.error("You should not enter invalid dates!"); } } @@ -54,10 +54,10 @@ public class DateFieldUnparsableDate extends TestBase { } @Override - protected Result<Date> handleUnparsableDateString(String dateString) - throws Converter.ConversionException { + protected Result<LocalDate> handleUnparsableDateString( + String dateString) throws Converter.ConversionException { if (dateString != null && dateString.equals("today")) { - return Result.ok(new Date()); + return Result.ok(LocalDate.now()); } return Result.error("You should not enter invalid dates!"); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldValueChangeEvents.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldValueChangeEvents.java deleted file mode 100644 index b100cd4c23..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldValueChangeEvents.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -/** - * - */ -package com.vaadin.tests.components.datefield; - -import java.util.Arrays; -import java.util.Calendar; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.datefield.Resolution; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.components.TestDateField; -import com.vaadin.ui.AbstractDateField; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.v7.data.Property.ValueChangeEvent; -import com.vaadin.v7.data.Property.ValueChangeListener; -import com.vaadin.v7.ui.NativeSelect; - -/** - * - * @since - * @author Vaadin Ltd - */ -public class DateFieldValueChangeEvents extends AbstractTestUIWithLog { - - private int count = 0; - - /* - * (non-Javadoc) - * - * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server. - * VaadinRequest) - */ - @Override - protected void setup(VaadinRequest request) { - - HorizontalLayout hl = new HorizontalLayout(); - addComponent(hl); - - Calendar calendar = Calendar.getInstance(); - calendar.set(2010, 1, 1, 18, 19, 20); - - final AbstractDateField df = new TestDateField(null, - calendar.getTime()); - df.setResolution(Resolution.SECOND); - df.setImmediate(true); - hl.addComponent(df); - - NativeSelect resolution = new NativeSelect(null, - Arrays.asList(Resolution.values())); - resolution.setImmediate(true); - resolution.setValue(df.getResolution()); - hl.addComponent(resolution); - resolution.addValueChangeListener(new ValueChangeListener() { - - @Override - public void valueChange(ValueChangeEvent event) { - df.setResolution((Resolution) event.getProperty().getValue()); - } - }); - - df.addValueChangeListener(event -> log("Value changes: " + (++count))); - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() - */ - @Override - protected String getTestDescription() { - return "DateField Time resolution fields should only send events when focus is removed"; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber() - */ - @Override - protected Integer getTicketNumber() { - return 6252; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldWhenChangingValueAndEnablingParent.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldWhenChangingValueAndEnablingParent.java index 6a7550d0c8..0e19ed9490 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldWhenChangingValueAndEnablingParent.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldWhenChangingValueAndEnablingParent.java @@ -1,6 +1,6 @@ package com.vaadin.tests.components.datefield; -import java.util.Date; +import java.time.LocalDate; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; @@ -40,12 +40,12 @@ public class DateFieldWhenChangingValueAndEnablingParent main.addComponent(sub); chk.addValueChangeListener(event -> { - df1.setValue(new Date()); - df2.setValue(new Date()); - pdf1.setValue(new Date()); - pdf2.setValue(new Date()); - pdf3.setValue(new Date()); - pdf4.setValue(new Date()); + df1.setValue(LocalDate.now()); + df2.setValue(LocalDate.now()); + pdf1.setValue(LocalDate.now()); + pdf2.setValue(LocalDate.now()); + pdf3.setValue(LocalDate.now()); + pdf4.setValue(LocalDate.now()); sub.setEnabled(chk.getValue()); }); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFields.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFields.java index ac77215245..6d6ab7c6a5 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFields.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateFields.java @@ -1,6 +1,6 @@ package com.vaadin.tests.components.datefield; -import java.sql.Date; +import java.time.LocalDate; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -42,10 +42,9 @@ public class DateFields extends ComponentTestCase<DateField> { private DateField createPopupDateField(String caption, String width, Locale locale) { - DateField pd = new DateField( - caption + "(" + locale.toString() + ")"); + DateField pd = new DateField(caption + "(" + locale.toString() + ")"); pd.setWidth(width); - pd.setValue(new Date(12312312313L)); + pd.setValue(LocalDate.of(1970, 05, 23)); pd.setLocale(locale); pd.setResolution(Resolution.YEAR); @@ -70,19 +69,8 @@ public class DateFields extends ComponentTestCase<DateField> { options.put("Year", Resolution.YEAR); options.put("Month", Resolution.MONTH); options.put("Day", Resolution.DAY); - options.put("Hour", Resolution.HOUR); - options.put("Min", Resolution.MINUTE); - options.put("Sec", Resolution.SECOND); return createSelectAction("Resolution", options, "Year", - new Command<DateField, Resolution>() { - - @Override - public void execute(DateField c, Resolution value, - Object data) { - c.setResolution(value); - - } - }); + (field, value, data) -> field.setResolution(value)); } private Component createInputPromptSelectAction() { diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DatePopupStyleName.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DatePopupStyleName.java index 4e1c59c4a6..d08194681e 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DatePopupStyleName.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DatePopupStyleName.java @@ -1,9 +1,8 @@ package com.vaadin.tests.components.datefield; -import java.util.Date; +import java.time.LocalDate; import com.vaadin.server.UserError; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.components.TestDateField; import com.vaadin.ui.AbstractDateField; @@ -14,8 +13,7 @@ public class DatePopupStyleName extends TestBase { setTheme("reindeer-tests"); final AbstractDateField df = new TestDateField(); - df.setValue(new Date(1203910239L)); - df.setResolution(Resolution.SECOND); + df.setValue(LocalDate.of(1970, 1, 15)); df.setWidth("200px"); df.setRequired(true); df.setComponentError(new UserError("abc")); diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateRangeWithSqlDate.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DateRangeWithSqlDate.java deleted file mode 100644 index eb4044c4ae..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DateRangeWithSqlDate.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.datefield; - -import java.util.Locale; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.AbstractDateField; -import com.vaadin.ui.InlineDateField; - -public class DateRangeWithSqlDate extends AbstractTestUI { - - // 2014-12-01 - private static final java.sql.Date startDate = new java.sql.Date( - 1417467822699L); - - // 2014-12-02 - private static final java.sql.Date endDate = new java.sql.Date( - 1417554763317L); - - @Override - protected void setup(VaadinRequest request) { - AbstractDateField df = new InlineDateField(); - df.setLocale(Locale.US); - df.setRangeStart(startDate); - df.setRangeEnd(endDate); - - df.setValue(startDate); - - addComponent(df); - } - - @Override - protected String getTestDescription() { - return "Test that java.sql.Date can be given to specify date range start and end dates."; - } - - @Override - protected Integer getTicketNumber() { - return 15342; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledInlineDateField.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledInlineDateField.java index 1669f3da22..855c90fa53 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledInlineDateField.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledInlineDateField.java @@ -15,8 +15,7 @@ */ package com.vaadin.tests.components.datefield; -import java.util.Calendar; -import java.util.Date; +import java.time.LocalDate; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; @@ -25,22 +24,16 @@ import com.vaadin.ui.InlineDateField; public class DisabledInlineDateField extends AbstractTestUI { - private static final Date testDate; - static { - Calendar cal = Calendar.getInstance(); - cal.set(2014, 5, 5); - testDate = cal.getTime(); - } - @Override protected void setup(VaadinRequest request) { AbstractDateField df = new InlineDateField("Disabled"); - df.setValue(testDate); + LocalDate date = LocalDate.of(2014, 6, 5); + df.setValue(date); df.setEnabled(false); addComponent(df); df = new InlineDateField("Read-only"); - df.setValue(testDate); + df.setValue(date); df.setReadOnly(true); addComponent(df); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/DynamicallyChangeDateRange.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/DynamicallyChangeDateRange.java index b280f751fd..18dd47c392 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/DynamicallyChangeDateRange.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/DynamicallyChangeDateRange.java @@ -1,15 +1,15 @@ package com.vaadin.tests.components.datefield; -import java.util.Date; +import java.time.LocalDate; import java.util.Locale; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.AbstractDateField; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.AbstractDateField; -import com.vaadin.ui.InlineDateField; import com.vaadin.ui.DateField; +import com.vaadin.ui.InlineDateField; import com.vaadin.ui.VerticalLayout; /** @@ -26,12 +26,12 @@ public class DynamicallyChangeDateRange extends AbstractTestUI { setContent(layout); final DateField df = new DateField(); - df.setValue(new Date(2012 - 1900, 5 - 1, 12)); + df.setValue(LocalDate.of(2012, 5, 12)); setRange(df, 5); layout.addComponent(df); final InlineDateField df2 = new InlineDateField(); - df2.setValue(new Date(2012 - 1900, 11 - 1, 16)); + df2.setValue(LocalDate.of(2012, 11, 16)); setRange(df2, 5); // layout.addComponent(df2); @@ -57,16 +57,9 @@ public class DynamicallyChangeDateRange extends AbstractTestUI { layout.addComponent(button2); } - /** - * @since - * @param df - * @param i - */ private void setRange(AbstractDateField df, int days) { - df.setRangeStart( - new Date(df.getValue().getTime() - days * 24 * 60 * 60 * 1000)); - df.setRangeEnd( - new Date(df.getValue().getTime() + days * 24 * 60 * 60 * 1000)); + df.setRangeStart(df.getValue().minusDays(days)); + df.setRangeEnd(df.getValue().plusDays(days)); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/InlineDateFields.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/InlineDateFields.java index 2c5f387292..19a44774a6 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/InlineDateFields.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/InlineDateFields.java @@ -1,6 +1,6 @@ package com.vaadin.tests.components.datefield; -import java.sql.Date; +import java.time.LocalDate; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -49,7 +49,7 @@ public class InlineDateFields extends ComponentTestCase<InlineDateField> { InlineDateField pd = new InlineDateField( caption + "(" + locale.toString() + ")"); pd.setWidth(width); - pd.setValue(new Date(12312312313L)); + pd.setValue(LocalDate.of(1970, 05, 23)); pd.setLocale(locale); pd.setResolution(Resolution.YEAR); @@ -74,19 +74,8 @@ public class InlineDateFields extends ComponentTestCase<InlineDateField> { options.put("Year", Resolution.YEAR); options.put("Month", Resolution.MONTH); options.put("Day", Resolution.DAY); - options.put("Hour", Resolution.HOUR); - options.put("Min", Resolution.MINUTE); - options.put("Sec", Resolution.SECOND); return createSelectAction("Resolution", options, "Year", - new Command<InlineDateField, Resolution>() { - - @Override - public void execute(InlineDateField c, Resolution value, - Object data) { - c.setResolution(value); - - } - }); + (field, value, data) -> field.setResolution(value)); } private Component createLocaleSelectAction() { diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldRanges.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldRanges.java index 36e58e0b13..05a7c6aa3d 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldRanges.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldRanges.java @@ -6,7 +6,6 @@ import java.util.Locale; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.MarginInfo; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; @@ -17,6 +16,7 @@ import com.vaadin.ui.Label; import com.vaadin.ui.VerticalLayout; import com.vaadin.v7.data.Property.ValueChangeEvent; import com.vaadin.v7.data.Property.ValueChangeListener; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.ui.DateField; import com.vaadin.v7.ui.InlineDateField; import com.vaadin.v7.ui.NativeSelect; diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldTest.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldTest.java index 8d42f1a561..fa95971870 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldTest.java @@ -7,8 +7,8 @@ import java.util.Date; import java.util.LinkedHashMap; import java.util.Locale; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.abstractfield.LegacyAbstractFieldTest; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.ui.DateField; public class LegacyDateFieldTest<T extends DateField> diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java index 1e108fca15..a9d978c9e4 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java @@ -1,6 +1,6 @@ package com.vaadin.tests.components.datefield; -import java.util.Date; +import java.time.LocalDate; import java.util.Locale; import com.vaadin.data.HasValue.ValueChange; @@ -11,7 +11,8 @@ import com.vaadin.tests.components.TestDateField; import com.vaadin.ui.AbstractDateField; import com.vaadin.ui.Button; -public class LenientMode extends TestBase implements ValueChangeListener<Date> { +public class LenientMode extends TestBase + implements ValueChangeListener<LocalDate> { private static final long serialVersionUID = -9064553409580072387L; @@ -28,8 +29,7 @@ public class LenientMode extends TestBase implements ValueChangeListener<Date> { @Override protected void setup() { - @SuppressWarnings("deprecation") - Date d = new Date(2009 - 1900, 12 - 1, 31, 23, 59, 59); + LocalDate d = LocalDate.of(2009, 12, 31); AbstractDateField df = new TestDateField("Lenient "); df.setLocale(new Locale("fi")); @@ -76,7 +76,7 @@ public class LenientMode extends TestBase implements ValueChangeListener<Date> { } @Override - public void accept(ValueChange<Date> event) { + public void accept(ValueChange<LocalDate> event) { getMainWindow().showNotification("New value" + event.getValue()); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/LocaleChange.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/LocaleChange.java deleted file mode 100644 index 71e4db4076..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/LocaleChange.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.datefield; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.datefield.Resolution; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.components.TestDateField; -import com.vaadin.ui.AbstractDateField; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; - -public class LocaleChange extends AbstractTestUI { - - private final Locale locale12hClock = Locale.US; - private final Locale locale24hClock = Locale.FRANCE; - - private final String caption = "Switch to %s hour clock"; - private static final Date dateValue; - static { - try { - dateValue = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss") - .parse("2014-05-22 20:00:00"); - } catch (ParseException e) { - throw new ExceptionInInitializerError("Should never happen."); - } - } - - @Override - protected void setup(VaadinRequest request) { - final AbstractDateField df = new TestDateField(); - df.setLocale(locale24hClock); - df.setResolution(Resolution.SECOND); - df.setValue(dateValue); - - Button button = new Button(String.format(caption, "12")); - button.addClickListener(new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - if (locale12hClock.equals(df.getLocale())) { - df.setLocale(locale24hClock); - event.getButton().setCaption(String.format(caption, "12")); - } else { - df.setLocale(locale12hClock); - event.getButton().setCaption(String.format(caption, "24")); - } - } - }); - - addComponent(df); - addComponent(button); - } - - @Override - protected String getTestDescription() { - return "Testing locale change from one with 24h clock to a 12h clock locale."; - } - - @Override - protected Integer getTicketNumber() { - return 13722; - } -}
\ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/LowResolution.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/LowResolution.java index c5a1d371b4..da2fad276c 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/LowResolution.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/LowResolution.java @@ -1,11 +1,13 @@ package com.vaadin.tests.components.datefield; +import java.time.LocalDate; + import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Button; import com.vaadin.ui.CheckBox; -import com.vaadin.ui.InlineDateField; import com.vaadin.ui.DateField; +import com.vaadin.ui.InlineDateField; @SuppressWarnings("serial") public class LowResolution extends TestBase { @@ -13,7 +15,7 @@ public class LowResolution extends TestBase { @Override protected void setup() { final DateField dateField = new DateField(); - dateField.setValue(new java.util.Date()); + dateField.setValue(LocalDate.now()); dateField.setResolution(Resolution.MONTH); dateField.addValueChangeListener(event -> getMainWindow() .showNotification("Date now" + event.getValue())); @@ -29,7 +31,7 @@ public class LowResolution extends TestBase { getLayout().addComponent(dateField3); final InlineDateField dateField2 = new InlineDateField(); - dateField2.setValue(new java.util.Date()); + dateField2.setValue(LocalDate.now()); dateField2.setResolution(Resolution.MONTH); dateField2.addValueChangeListener(event -> getMainWindow() .showNotification("Date now" + event.getValue())); diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupClosingWithEsc.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupClosingWithEsc.java index 64c24beec9..0bd2191587 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupClosingWithEsc.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupClosingWithEsc.java @@ -26,10 +26,6 @@ public class PopupClosingWithEsc extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { - AbstractDateField df0 = new TestDateField("Minute"); - df0.setId("minute"); - df0.setResolution(Resolution.MINUTE); - AbstractDateField df1 = new TestDateField("Day"); df1.setId("day"); df1.setResolution(Resolution.DAY); @@ -45,7 +41,7 @@ public class PopupClosingWithEsc extends AbstractTestUI { VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); layout.setSpacing(true); - layout.addComponents(df0, df1, df2, df3); + layout.addComponents(df1, df2, df3); setContent(layout); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldExtendedRange.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldExtendedRange.java index ed4b2d8d77..4a65358516 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldExtendedRange.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldExtendedRange.java @@ -1,25 +1,20 @@ package com.vaadin.tests.components.datefield; -import java.util.Calendar; +import java.time.LocalDate; import java.util.Locale; +import java.util.stream.Stream; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.DateField; @SuppressWarnings("serial") public class PopupDateFieldExtendedRange extends AbstractTestUI { - private Calendar date = Calendar.getInstance(); - @Override protected void setup(VaadinRequest request) { - date.set(2011, 0, 1); - getLayout().setSpacing(true); final DateField[] fields = new DateField[3]; @@ -41,15 +36,8 @@ public class PopupDateFieldExtendedRange extends AbstractTestUI { addComponent(f); } - addComponent(new Button("Change date", new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - date.set(2010, 1, 16); - for (DateField f : fields) { - f.setValue(date.getTime()); - } - } - })); + addComponent(new Button("Change date", event -> Stream.of(fields) + .forEach(field -> field.setValue(LocalDate.of(2010, 2, 16))))); } @Override @@ -65,7 +53,7 @@ public class PopupDateFieldExtendedRange extends AbstractTestUI { private DateField makeDateField() { DateField pdf = new DateField(); pdf.setResolution(Resolution.DAY); - pdf.setValue(date.getTime()); + pdf.setValue(LocalDate.of(2011, 1, 1)); return pdf; } } diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldLocaleTest.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldLocaleTest.java deleted file mode 100644 index 5ea0eb0e70..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldLocaleTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.vaadin.tests.components.datefield; - -import java.util.Calendar; -import java.util.Locale; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.datefield.Resolution; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.DateField; - -public class PopupDateFieldLocaleTest extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - // Set a specific time for the PopupDateField - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, 2000); - cal.set(Calendar.DAY_OF_YEAR, 1); - cal.set(Calendar.HOUR_OF_DAY, 1); - cal.set(Calendar.MINUTE, 1); - cal.set(Calendar.SECOND, 1); - cal.set(Calendar.MILLISECOND, 1); - - final DateField pdf = new DateField(); - pdf.setLocale(Locale.ENGLISH); - pdf.setValue(cal.getTime()); - pdf.setImmediate(true); - pdf.setResolution(Resolution.SECOND); - addComponent(pdf); - - pdf.addValueChangeListener(event -> pdf.setLocale(Locale.FRENCH)); - } - - @Override - protected String getTestDescription() { - return "Changing the locale while the popupdatefield is visible can " - + "result in the locale remaining at the previous value; the locale " - + "is only changed once the current month is changed."; - } - - @Override - protected Integer getTicketNumber() { - return 12135; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldPopup.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldPopup.java deleted file mode 100644 index a2d276fde3..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldPopup.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.vaadin.tests.components.datefield; - -import java.util.Calendar; -import java.util.Locale; - -import com.vaadin.shared.ui.datefield.Resolution; -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.DateField; - -public class PopupDateFieldPopup extends TestBase { - - @Override - protected void setup() { - // Set a specific time for the PopupDateField - Calendar cal = Calendar.getInstance(); - cal.set(Calendar.YEAR, 2000); - cal.set(Calendar.DAY_OF_YEAR, 1); - cal.set(Calendar.HOUR_OF_DAY, 1); - cal.set(Calendar.MINUTE, 1); - cal.set(Calendar.SECOND, 1); - cal.set(Calendar.MILLISECOND, 1); - - DateField pdf = new DateField(); - pdf.setLocale(Locale.US); - pdf.setValue(cal.getTime()); - pdf.setImmediate(true); - pdf.setResolution(Resolution.SECOND); - addComponent(pdf); - } - - @Override - protected String getDescription() { - return "Changing the minute, second and millisecond parts should also result in an update of the PopupDateField popup contents."; - } - - @Override - protected Integer getTicketNumber() { - return 8391; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldStates.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldStates.java index bcfb00e88c..d094b058eb 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldStates.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/PopupDateFieldStates.java @@ -1,13 +1,11 @@ package com.vaadin.tests.components.datefield; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; +import java.time.LocalDate; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.GridLayout; import com.vaadin.ui.DateField; +import com.vaadin.ui.GridLayout; @SuppressWarnings("serial") public class PopupDateFieldStates extends AbstractTestUI { @@ -39,14 +37,7 @@ public class PopupDateFieldStates extends AbstractTestUI { final boolean textFieldEnabled) { final DateField popupDatefield = new DateField(); - Calendar cal = GregorianCalendar.getInstance(); - cal.set(Calendar.DATE, 3); - cal.set(Calendar.MONTH, Calendar.SEPTEMBER); - cal.set(Calendar.YEAR, 2014); - cal.set(Calendar.HOUR_OF_DAY, 8); - final Date currentDate = cal.getTime(); - - popupDatefield.setValue(currentDate); + popupDatefield.setValue(LocalDate.of(2014, 9, 3)); popupDatefield.setCaption("Enabled: " + enabled + ", Text field enabled: " + textFieldEnabled); popupDatefield.setEnabled(enabled); diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/TestDatefieldYear.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/TestDatefieldYear.java index da8860c111..997f04fac4 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/TestDatefieldYear.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/TestDatefieldYear.java @@ -1,6 +1,6 @@ package com.vaadin.tests.components.datefield; -import java.util.Date; +import java.time.LocalDate; import java.util.Locale; import com.vaadin.shared.ui.datefield.Resolution; @@ -24,7 +24,7 @@ public class TestDatefieldYear extends TestBase { protected void setup() { @SuppressWarnings("deprecation") AbstractDateField df = new TestDateField("Year", - new Date(2009 - 1900, 4 - 1, 1)); + LocalDate.of(2009, 4, 1)); df.setLocale(new Locale("en", "US")); df.setResolution(Resolution.YEAR); df.setResolution(Resolution.MONTH); diff --git a/uitest/src/main/java/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.java b/uitest/src/main/java/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.java index 6c83ee4b0e..0f253edce4 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.java +++ b/uitest/src/main/java/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.java @@ -1,8 +1,7 @@ package com.vaadin.tests.components.datefield; -import java.util.Date; +import java.time.LocalDate; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.components.TestDateField; import com.vaadin.ui.AbstractDateField; @@ -15,8 +14,7 @@ public class WidthRecalculationOnEnableStateChange extends TestBase { setTheme("reindeer-tests"); final AbstractDateField df = new TestDateField(); - df.setValue(new Date(1203910239L)); - df.setResolution(Resolution.SECOND); + df.setValue(LocalDate.of(1970, 1, 15)); df.setWidth("200px"); df.addStyleName("enabled-readonly-styled"); addComponent(df); diff --git a/uitest/src/main/java/com/vaadin/tests/components/uitest/components/DatesCssTest.java b/uitest/src/main/java/com/vaadin/tests/components/uitest/components/DatesCssTest.java index c6dbd4e025..26e45e7541 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/uitest/components/DatesCssTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/uitest/components/DatesCssTest.java @@ -1,7 +1,6 @@ package com.vaadin.tests.components.uitest.components; -import java.util.Calendar; -import java.util.GregorianCalendar; +import java.time.LocalDate; import com.vaadin.tests.components.TestDateField; import com.vaadin.tests.components.uitest.TestSampler; @@ -17,7 +16,7 @@ public class DatesCssTest extends GridLayout { private TestSampler parent; private int debugIdCounter = 0; - private Calendar cal = new GregorianCalendar(2012, 8, 11, 18, 00, 00); + private LocalDate date = LocalDate.of(2012, 9, 11); public DatesCssTest(TestSampler parent) { super(5, 2); @@ -31,12 +30,12 @@ public class DatesCssTest extends GridLayout { AbstractDateField df = new DateField("Popup date field"); df.setId("datefield" + debugIdCounter++); - df.setValue(cal.getTime()); + df.setValue(date); addComponent(df); df = new InlineDateField("Inline date field"); df.setId("datefield" + debugIdCounter++); - df.setValue(cal.getTime()); + df.setValue(date); addComponent(df); createDateFieldWith(null, null, "130px"); @@ -50,7 +49,7 @@ public class DatesCssTest extends GridLayout { String width) { AbstractDateField df = new TestDateField("Date field"); df.setId("datefield" + debugIdCounter++); - df.setValue(cal.getTime()); + df.setValue(date); if (caption != null) { df.setCaption(caption); diff --git a/uitest/src/main/java/com/vaadin/tests/themes/valo/CalendarTest.java b/uitest/src/main/java/com/vaadin/tests/themes/valo/CalendarTest.java index bd3473246e..d8d7d73d7c 100644 --- a/uitest/src/main/java/com/vaadin/tests/themes/valo/CalendarTest.java +++ b/uitest/src/main/java/com/vaadin/tests/themes/valo/CalendarTest.java @@ -11,7 +11,6 @@ import com.vaadin.data.Binder; import com.vaadin.data.ValidationException; import com.vaadin.navigator.View; import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; -import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.components.calendar.CalendarTestEvent; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; @@ -34,6 +33,7 @@ import com.vaadin.v7.data.fieldgroup.FieldGroup; import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException; import com.vaadin.v7.data.util.BeanItem; import com.vaadin.v7.shared.ui.combobox.FilteringMode; +import com.vaadin.v7.shared.ui.datefield.Resolution; import com.vaadin.v7.ui.Calendar; import com.vaadin.v7.ui.Calendar.TimeFormat; import com.vaadin.v7.ui.ComboBox; diff --git a/uitest/src/main/java/com/vaadin/tests/themes/valo/DateFields.java b/uitest/src/main/java/com/vaadin/tests/themes/valo/DateFields.java index c9797709da..4346d1c64b 100644 --- a/uitest/src/main/java/com/vaadin/tests/themes/valo/DateFields.java +++ b/uitest/src/main/java/com/vaadin/tests/themes/valo/DateFields.java @@ -15,7 +15,7 @@ */ package com.vaadin.tests.themes.valo; -import java.util.Date; +import java.time.LocalDate; import java.util.Locale; import com.vaadin.navigator.View; @@ -77,7 +77,7 @@ public class DateFields extends VerticalLayout implements View { Button today = new Button("Today", new ClickListener() { @Override public void buttonClick(ClickEvent event) { - date2.setValue(new Date()); + date2.setValue(LocalDate.now()); } }); group.addComponent(today); @@ -88,27 +88,6 @@ public class DateFields extends VerticalLayout implements View { date.setWidth("260px"); date.setHeight("60px"); - date = new TestDateField("Second resolution"); - setDate(date); - date.setResolution(Resolution.SECOND); - row.addComponent(date); - - date = new TestDateField("Minute resolution"); - setDate(date); - date.setResolution(Resolution.MINUTE); - row.addComponent(date); - - date = new TestDateField("Hour resolution"); - setDate(date); - date.setResolution(Resolution.HOUR); - row.addComponent(date); - - date = new TestDateField("Disabled"); - setDate(date); - date.setResolution(Resolution.HOUR); - date.setEnabled(false); - row.addComponent(date); - date = new TestDateField("Day resolution"); setDate(date); date.setResolution(Resolution.DAY); @@ -167,12 +146,6 @@ public class DateFields extends VerticalLayout implements View { date.setShowISOWeekNumbers(true); row.addComponent(date); - date = new TestDateField("US locale"); - setDate(date); - date.setResolution(Resolution.SECOND); - date.setLocale(new Locale("en", "US")); - row.addComponent(date); - date = new TestDateField("Custom format"); setDate(date); date.setDateFormat("E dd/MM/yyyy"); @@ -218,20 +191,19 @@ public class DateFields extends VerticalLayout implements View { private void setDateRange(AbstractDateField date) { date.setRangeStart(getDefaultDate()); - Date endDate = getDefaultDate(); - endDate.setMonth(endDate.getMonth() + 1); - date.setRangeEnd(endDate); + LocalDate endDate = getDefaultDate(); + date.setRangeEnd(endDate.plusMonths(1)); } private void setDate(AbstractDateField date) { date.setValue(getDefaultDate()); } - private Date getDefaultDate() { + private LocalDate getDefaultDate() { if (ValoThemeUI.isTestMode()) { - return new Date(2014 - 1900, 5, 7); + return LocalDate.of(2014, 6, 7); } else { - return new Date(); + return LocalDate.now(); } } diff --git a/uitest/src/main/java/com/vaadin/tests/themes/valo/Forms.java b/uitest/src/main/java/com/vaadin/tests/themes/valo/Forms.java index a47e3af78b..b6eb923cb3 100644 --- a/uitest/src/main/java/com/vaadin/tests/themes/valo/Forms.java +++ b/uitest/src/main/java/com/vaadin/tests/themes/valo/Forms.java @@ -15,7 +15,7 @@ */ package com.vaadin.tests.themes.valo; -import java.util.Date; +import java.time.LocalDate; import com.vaadin.navigator.View; import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; @@ -71,7 +71,7 @@ public class Forms extends VerticalLayout implements View { form.addComponent(name); AbstractDateField birthday = new TestDateField("Birthday"); - birthday.setValue(new Date(80, 0, 31)); + birthday.setValue(LocalDate.of(1980, 1, 31)); form.addComponent(birthday); TextField username = new TextField("Username"); diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldChangeResolutionTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldChangeResolutionTest.java index 23aca038ae..975bb93d2f 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldChangeResolutionTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldChangeResolutionTest.java @@ -31,8 +31,7 @@ import com.vaadin.tests.tb3.MultiBrowserTest; public class DateFieldChangeResolutionTest extends MultiBrowserTest { private WebElement dateFieldButton, textField; - private WebElement resolutionSecond, resolutionMinute, resolutionHour, - resolutionDay, resolutionMonth, resolutionYear; + private WebElement resolutionDay, resolutionMonth, resolutionYear; @Test public void changeResolutionBetweenYearAndMonth() throws Exception { @@ -44,15 +43,6 @@ public class DateFieldChangeResolutionTest extends MultiBrowserTest { } @Test - public void changeResolutionBetweenYearAndSecond() throws Exception { - initialize(); - click(resolutionSecond); - checkHeaderAndBody(Resolution.SECOND, true); - click(resolutionYear); - checkHeaderAndBody(Resolution.YEAR, true); - } - - @Test public void changeResolutionToDayThenMonth() throws Exception { initialize(); checkHeaderAndBody(Resolution.YEAR, true); // check the initial state @@ -75,12 +65,8 @@ public class DateFieldChangeResolutionTest extends MultiBrowserTest { textField.getAttribute("value").isEmpty()); // Change resolutions and check that the selected date is not lost and // that the calendar has the correct resolution. - click(resolutionHour); - checkHeaderAndBody(Resolution.HOUR, false); click(resolutionYear); checkHeaderAndBody(Resolution.YEAR, false); - click(resolutionMinute); - checkHeaderAndBody(Resolution.MINUTE, false); } private void initialize() { @@ -90,9 +76,6 @@ public class DateFieldChangeResolutionTest extends MultiBrowserTest { .findElement(By.className("v-datefield-button")); textField = dateField .findElement(By.className("v-datefield-textfield")); - resolutionSecond = driver.findElement(By.id(BUTTON_BASE_ID + "second")); - resolutionMinute = driver.findElement(By.id(BUTTON_BASE_ID + "minute")); - resolutionHour = driver.findElement(By.id(BUTTON_BASE_ID + "hour")); resolutionDay = driver.findElement(By.id(BUTTON_BASE_ID + "day")); resolutionMonth = driver.findElement(By.id(BUTTON_BASE_ID + "month")); resolutionYear = driver.findElement(By.id(BUTTON_BASE_ID + "year")); @@ -105,14 +88,12 @@ public class DateFieldChangeResolutionTest extends MultiBrowserTest { sleep(100); // Open the popup calendar, perform checks and close the popup. openPopupDateField(); - if (resolution.getCalendarField() >= Resolution.MONTH - .getCalendarField()) { + if (resolution.compareTo(Resolution.MONTH) <= 0) { checkMonthHeader(); } else { checkYearHeader(); } - if (resolution.getCalendarField() >= Resolution.DAY - .getCalendarField()) { + if (resolution.compareTo(Resolution.DAY) <= 0) { assertTrue( "A calendar with the chosen resolution should have a body", calendarHasBody()); diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java index ffe8239da1..62ba7b293e 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java @@ -21,7 +21,7 @@ public class DateFieldDayResolutionOffsetTest extends MultiBrowserTest { select2ndOfSeptember(); LabelElement dateValue = $(LabelElement.class).id("dateValue"); - assertThat(dateValue.getText(), is("09/02/2014 00:00:00")); + assertThat(dateValue.getText(), is("09/02/2014")); } private void select2ndOfSeptember() { @@ -35,7 +35,8 @@ public class DateFieldDayResolutionOffsetTest extends MultiBrowserTest { } private void openDatePicker() { - AbstractDateFieldElement dateField = $(AbstractDateFieldElement.class).first(); + AbstractDateFieldElement dateField = $(AbstractDateFieldElement.class) + .first(); dateField.findElement(By.tagName("button")).click(); } diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldReadOnlyTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldReadOnlyTest.java index 0791b3dd9c..0d1ceb4545 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldReadOnlyTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldReadOnlyTest.java @@ -17,15 +17,15 @@ public class DateFieldReadOnlyTest extends MultiBrowserTest { throws IOException, InterruptedException { openTestURL(); - compareScreen("initial"); + compareScreen("initial-date"); toggleReadOnly(); openPopup(); - compareScreen("readwrite-popup"); + compareScreen("readwrite-popup-date"); closePopup(); toggleReadOnly(); - compareScreen("readonly"); + compareScreen("readonly-date"); } private void closePopup() { @@ -36,8 +36,8 @@ public class DateFieldReadOnlyTest extends MultiBrowserTest { private void openPopup() { // waiting for openPopup() in TB4 beta1: // http://dev.vaadin.com/ticket/13766 - $(AbstractDateFieldElement.class).first().findElement(By.tagName("button")) - .click(); + $(AbstractDateFieldElement.class).first() + .findElement(By.tagName("button")).click(); } private void toggleReadOnly() { diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldValueChangeEventsTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldValueChangeEventsTest.java deleted file mode 100644 index 5f6373ee57..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldValueChangeEventsTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.datefield; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; -import org.openqa.selenium.support.ui.Select; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.customelements.AbstractDateFieldElement; -import com.vaadin.testbench.elements.LabelElement; -import com.vaadin.testbench.elements.NativeSelectElement; -import com.vaadin.tests.tb3.MultiBrowserTest; - -public class DateFieldValueChangeEventsTest extends MultiBrowserTest { - - @Test - public void tb2test() throws Exception { - openTestURL(); - getPopUpButton().click(); - getCalendarDayElement(2, 1).click(); - Assert.assertEquals("1. Value changes: 1", getLogRow(0)); - getPopUpButton().click(); - new Select(getHoursSelect()).selectByValue("01"); - new Select(getMinutesSelect()).selectByValue("02"); - new Select(getSecondsSelect()).selectByValue("03"); - new Actions(driver).sendKeys(getSecondsSelect(), Keys.ENTER).perform(); - $(LabelElement.class).first().click(); - Assert.assertEquals("2. Value changes: 2", getLogRow(0)); - getResolutionSelect().selectByText("Month"); - getPopUpButton().click(); - getNextMonthButton().click(); - getNextYearButton().click(); - getNextMonthButton().click(); - getNextMonthButton().sendKeys(Keys.ENTER); - Assert.assertEquals("3. Value changes: 3", getLogRow(0)); - } - - public WebElement getPopUpButton() { - AbstractDateFieldElement datefield = $(AbstractDateFieldElement.class).first(); - return datefield.findElement((By.className("v-datefield-button"))); - } - - public WebElement getCalendarDayElement(int row, int col) { - return findElement(By - .xpath("//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[2]/td/table/tbody/tr[" - + (row + 2) + "]/td[" + (col + 2) + "]/span")); - } - - public WebElement getHoursSelect() { - return findElement(By.xpath( - "//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[3]/td/div/select")); - } - - public WebElement getMinutesSelect() { - return findElement(By.xpath( - "//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[3]/td/div/select[2]")); - } - - public WebElement getSecondsSelect() { - return findElement(By.xpath( - "//table[@id='PID_VAADIN_POPUPCAL']/tbody/tr[3]/td/div/select[3]")); - } - - public NativeSelectElement getResolutionSelect() { - return $(NativeSelectElement.class).first(); - } - - public WebElement getNextMonthButton() { - return findElement((By.className("v-button-nextmonth"))); - } - - public WebElement getNextYearButton() { - return findElement((By.className("v-button-nextyear"))); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateRangeWithSqlDateTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/DateRangeWithSqlDateTest.java deleted file mode 100644 index 3e5c380b52..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/DateRangeWithSqlDateTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.datefield; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import com.vaadin.tests.tb3.MultiBrowserTest; - -public class DateRangeWithSqlDateTest extends MultiBrowserTest { - - @Test - public void testDateRange() { - openTestURL(); - - // Get all cells of the inline datefield. - List<WebElement> cells = driver.findElements( - By.className("v-inline-datefield-calendarpanel-day")); - - // Verify the range is rendered correctly. - assertCell(cells.get(0), "30", true); - assertCell(cells.get(1), "1", false); - assertCell(cells.get(2), "2", false); - assertCell(cells.get(3), "3", true); - } - - private void assertCell(WebElement cell, String text, - boolean outsideRange) { - assertEquals(text, cell.getText()); - assertEquals(outsideRange, - cell.getAttribute("class").contains("outside-range")); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/LocaleChangeTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/LocaleChangeTest.java deleted file mode 100644 index 16f6e046db..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/LocaleChangeTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.tests.components.datefield; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.parallel.BrowserUtil; -import com.vaadin.tests.tb3.MultiBrowserTest; - -public class LocaleChangeTest extends MultiBrowserTest { - - @Test - public void testLocaleChange() { - openTestURL(); - - // Check the initial value and that popup can be opened. - assertEquals("22/05/14 20:00:00", getDateValue()); - toggleDatePopup(); - assertPopupOpen(true); - - // Close the popup and change the locale. - toggleDatePopupWorkaroundClosePopupIE(); - assertPopupOpen(false); - driver.findElement(By.className("v-button")).click(); // Locale change. - - // Check that the value has changed and the popup can still be opened - // without problems. - assertEquals("5/22/14 08:00:00 PM", getDateValue()); - toggleDatePopup(); - assertPopupOpen(true); - } - - private void assertPopupOpen(boolean open) { - assertEquals("Date popup was not " + (open ? "open" : "closed") + ".", - (open ? 1 : 0), - driver.findElements(By.className("v-datefield-popup")).size()); - } - - private void toggleDatePopup() { - driver.findElement(By.className("v-datefield-button")).click(); - } - - /* - * Work around bug reported in ticket #14086. Delete this method once fixed - * andd use toggleDatePopup() instead. - */ - private void toggleDatePopupWorkaroundClosePopupIE() { - if (!BrowserUtil.isIE(getDesiredCapabilities())) { - driver.findElement(By.className("v-datefield-button")).click(); - } else { - boolean popupOpen = driver - .findElements(By.className("v-datefield-popup")) - .size() == 1; - if (popupOpen) { - driver.findElement( - By.className("v-datefield-calendarpanel-day-selected")) - .click(); - } else { - driver.findElement(By.className("v-datefield-button")).click(); - } - } - } - - private String getDateValue() { - return driver.findElement(By.className("v-datefield-textfield")) - .getAttribute("value"); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupClosingWithEscTest.java b/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupClosingWithEscTest.java index 8f91e6cc5b..49ca030eb4 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupClosingWithEscTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/datefield/PopupClosingWithEscTest.java @@ -21,28 +21,12 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; import com.vaadin.tests.tb3.MultiBrowserTest; public class PopupClosingWithEscTest extends MultiBrowserTest { @Test - public void testPopupClosingFromTimeSelect() { - openTestURL(); - - openPopup("minute"); - assertTrue(isPopupVisible()); - - // Send ESC to the select element to simulate user being - // focused on the select while hitting the ESC key. - WebElement select = driver.findElement( - By.cssSelector(".v-datefield-popup select:first-child")); - select.sendKeys(Keys.ESCAPE); - assertFalse(isPopupVisible()); - } - - @Test public void testPopupClosingDayResolution() { testPopupClosing("day"); } |