You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VDateTimeFieldCalendar.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui;
  17. import static com.vaadin.shared.ui.datefield.DateTimeResolution.DAY;
  18. import static com.vaadin.shared.ui.datefield.DateTimeResolution.HOUR;
  19. import static com.vaadin.shared.ui.datefield.DateTimeResolution.MINUTE;
  20. import static com.vaadin.shared.ui.datefield.DateTimeResolution.MONTH;
  21. import static com.vaadin.shared.ui.datefield.DateTimeResolution.SECOND;
  22. import static com.vaadin.shared.ui.datefield.DateTimeResolution.YEAR;
  23. import java.util.Date;
  24. import java.util.Map;
  25. import com.google.gwt.core.client.GWT;
  26. import com.vaadin.shared.ui.datefield.DateTimeResolution;
  27. /**
  28. * A client side implementation for inline date/time field.
  29. *
  30. * @author Vaadin Ltd
  31. * @since 8.0
  32. *
  33. */
  34. public class VDateTimeFieldCalendar extends
  35. VAbstractDateFieldCalendar<VDateTimeCalendarPanel, DateTimeResolution> {
  36. public VDateTimeFieldCalendar() {
  37. super(GWT.create(VDateTimeCalendarPanel.class), MINUTE);
  38. }
  39. @Override
  40. public void updateBufferedValues() {
  41. // If field is invisible at the beginning, client can still be null when
  42. // this function is called.
  43. if (getClient() == null) {
  44. return;
  45. }
  46. Date date2 = calendarPanel.getDate();
  47. Date currentDate = getCurrentDate();
  48. DateTimeResolution resolution = getCurrentResolution();
  49. if (currentDate == null || date2.getTime() != currentDate.getTime()) {
  50. setCurrentDate((Date) date2.clone());
  51. bufferedResolutions.put(YEAR, date2.getYear() + 1900);
  52. if (resolution.compareTo(YEAR) < 0) {
  53. bufferedResolutions.put(MONTH, date2.getMonth() + 1);
  54. if (resolution.compareTo(MONTH) < 0) {
  55. bufferedResolutions.put(DAY, date2.getDate());
  56. if (resolution.compareTo(DAY) < 0) {
  57. bufferedResolutions.put(HOUR, date2.getHours());
  58. if (resolution.compareTo(HOUR) < 0) {
  59. bufferedResolutions.put(MINUTE, date2.getMinutes());
  60. if (resolution.compareTo(MINUTE) < 0) {
  61. bufferedResolutions.put(SECOND,
  62. date2.getSeconds());
  63. }
  64. }
  65. }
  66. }
  67. }
  68. }
  69. }
  70. @Override
  71. public void updateValueFromPanel() {
  72. updateBufferedValues();
  73. if (bufferedResolutions != null) {
  74. sendBufferedValues();
  75. }
  76. }
  77. @Override
  78. public String resolutionAsString() {
  79. if (getCurrentResolution().compareTo(DAY) >= 0) {
  80. return getResolutionVariable(getCurrentResolution());
  81. }
  82. return "full";
  83. }
  84. @Override
  85. public boolean isYear(DateTimeResolution resolution) {
  86. return YEAR.equals(resolution);
  87. }
  88. @Override
  89. protected Date getDate(Map<DateTimeResolution, Integer> dateValues) {
  90. return VPopupTimeCalendar.makeDate(dateValues);
  91. }
  92. @Override
  93. protected DateTimeResolution[] doGetResolutions() {
  94. return DateTimeResolution.values();
  95. }
  96. @Override
  97. protected boolean supportsTime() {
  98. return true;
  99. }
  100. }