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 /client | |
parent | db3a91c9b4d8d0451c8f1c5e875f4c6f6f50324a (diff) | |
download | vaadin-framework-d36d63fefa3ab9f4908f97772bcc6499e4f52532.tar.gz vaadin-framework-d36d63fefa3ab9f4908f97772bcc6499e4f52532.zip |
Make AbstractDateField based on LocalDate (#125).
Change-Id: I33a4a4f0f3437a8d1733031a131afbe844c12afb
Diffstat (limited to 'client')
9 files changed, 48 insertions, 629 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 |