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.

InlineDateTimeFieldConnector.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2000-2021 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.datefield;
  17. import java.util.Date;
  18. import com.vaadin.client.DateTimeService;
  19. import com.vaadin.client.ui.VDateTimeCalendarPanel;
  20. import com.vaadin.client.ui.VDateTimeFieldCalendar;
  21. import com.vaadin.shared.ui.Connect;
  22. import com.vaadin.shared.ui.datefield.DateTimeResolution;
  23. import com.vaadin.ui.InlineDateTimeField;
  24. /**
  25. * The client-side connector for InlineDateTimeField.
  26. *
  27. * @author Vaadin Ltd
  28. * @since 8.0
  29. */
  30. @Connect(InlineDateTimeField.class)
  31. public class InlineDateTimeFieldConnector extends
  32. AbstractInlineDateFieldConnector<VDateTimeCalendarPanel, DateTimeResolution> {
  33. @Override
  34. protected boolean isResolutionMonthOrHigher() {
  35. return getWidget().getCurrentResolution()
  36. .compareTo(DateTimeResolution.MONTH) >= 0;
  37. }
  38. @Override
  39. public VDateTimeFieldCalendar getWidget() {
  40. return (VDateTimeFieldCalendar) super.getWidget();
  41. }
  42. @SuppressWarnings("deprecation")
  43. @Override
  44. protected void updateListeners() {
  45. super.updateListeners();
  46. if (getWidget().getCurrentResolution()
  47. .compareTo(DateTimeResolution.DAY) < 0) {
  48. getWidget().calendarPanel
  49. .setTimeChangeListener((hour, min, sec, msec) -> {
  50. Date d = getWidget().getDate();
  51. if (d == null) {
  52. // date currently null, use the value from
  53. // calendarPanel
  54. // (~ client time at the init of the widget)
  55. d = (Date) getWidget().calendarPanel.getDate()
  56. .clone();
  57. }
  58. d.setHours(hour);
  59. d.setMinutes(min);
  60. d.setSeconds(sec);
  61. DateTimeService.setMilliseconds(d, msec);
  62. // Always update time changes to the server
  63. getWidget().calendarPanel.setDate(d);
  64. getWidget().updateValueFromPanel();
  65. });
  66. }
  67. }
  68. }