您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

VDateFieldCalendar.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.v7.client.ui;
  17. import java.util.Date;
  18. import com.google.gwt.event.dom.client.DomEvent;
  19. import com.vaadin.client.DateTimeService;
  20. import com.vaadin.v7.client.ui.VCalendarPanel.FocusOutListener;
  21. import com.vaadin.v7.client.ui.VCalendarPanel.SubmitListener;
  22. import com.vaadin.v7.shared.ui.datefield.Resolution;
  23. /**
  24. * A client side implementation for InlineDateField.
  25. */
  26. public class VDateFieldCalendar extends VDateField {
  27. /** For internal use only. May be removed or replaced in the future. */
  28. public final VCalendarPanel calendarPanel;
  29. public VDateFieldCalendar() {
  30. super();
  31. calendarPanel = new VCalendarPanel();
  32. calendarPanel.setParentField(this);
  33. add(calendarPanel);
  34. calendarPanel.setSubmitListener(new SubmitListener() {
  35. @Override
  36. public void onSubmit() {
  37. updateValueFromPanel();
  38. }
  39. @Override
  40. public void onCancel() {
  41. // TODO Auto-generated method stub
  42. }
  43. });
  44. calendarPanel.setFocusOutListener(new FocusOutListener() {
  45. @Override
  46. public boolean onFocusOut(DomEvent<?> event) {
  47. updateValueFromPanel();
  48. return false;
  49. }
  50. });
  51. }
  52. /**
  53. * TODO refactor: almost same method as in VPopupCalendar.updateValue
  54. * <p>
  55. * For internal use only. May be removed or replaced in the future.
  56. */
  57. @SuppressWarnings("deprecation")
  58. public void updateValueFromPanel() {
  59. // If field is invisible at the beginning, client can still be null when
  60. // this function is called.
  61. if (getClient() == null) {
  62. return;
  63. }
  64. Date date2 = calendarPanel.getDate();
  65. Date currentDate = getCurrentDate();
  66. if (currentDate == null || date2.getTime() != currentDate.getTime()) {
  67. setCurrentDate((Date) date2.clone());
  68. getClient().updateVariable(getId(), "year", date2.getYear() + 1900,
  69. false);
  70. if (getCurrentResolution().getCalendarField() > Resolution.YEAR
  71. .getCalendarField()) {
  72. getClient().updateVariable(getId(), "month",
  73. date2.getMonth() + 1, false);
  74. if (getCurrentResolution().getCalendarField() > Resolution.MONTH
  75. .getCalendarField()) {
  76. getClient().updateVariable(getId(), "day", date2.getDate(),
  77. false);
  78. if (getCurrentResolution()
  79. .getCalendarField() > Resolution.DAY
  80. .getCalendarField()) {
  81. getClient().updateVariable(getId(), "hour",
  82. date2.getHours(), false);
  83. if (getCurrentResolution()
  84. .getCalendarField() > Resolution.HOUR
  85. .getCalendarField()) {
  86. getClient().updateVariable(getId(), "min",
  87. date2.getMinutes(), false);
  88. if (getCurrentResolution()
  89. .getCalendarField() > Resolution.MINUTE
  90. .getCalendarField()) {
  91. getClient().updateVariable(getId(), "sec",
  92. date2.getSeconds(), false);
  93. if (getCurrentResolution()
  94. .getCalendarField() > Resolution.SECOND
  95. .getCalendarField()) {
  96. getClient().updateVariable(
  97. getId(), "msec", DateTimeService
  98. .getMilliseconds(date2),
  99. false);
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. if (isImmediate()) {
  107. getClient().sendPendingVariableChanges();
  108. }
  109. }
  110. }
  111. public void setTabIndex(int tabIndex) {
  112. calendarPanel.getElement().setTabIndex(tabIndex);
  113. }
  114. public int getTabIndex() {
  115. return calendarPanel.getElement().getTabIndex();
  116. }
  117. }