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.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2000-2016 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. @Override
  43. protected void updateListeners() {
  44. super.updateListeners();
  45. if (getWidget().getCurrentResolution()
  46. .compareTo(DateTimeResolution.DAY) < 0) {
  47. getWidget().calendarPanel
  48. .setTimeChangeListener((hour, min, sec, msec) -> {
  49. Date d = getWidget().getDate();
  50. if (d == null) {
  51. // date currently null, use the value from
  52. // calendarPanel
  53. // (~ client time at the init of the widget)
  54. d = (Date) getWidget().calendarPanel.getDate()
  55. .clone();
  56. }
  57. d.setHours(hour);
  58. d.setMinutes(min);
  59. d.setSeconds(sec);
  60. DateTimeService.setMilliseconds(d, msec);
  61. // Always update time changes to the server
  62. getWidget().calendarPanel.setDate(d);
  63. getWidget().updateValueFromPanel();
  64. });
  65. }
  66. }
  67. }