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.

AbstractTextualDateConnector.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.datefield;
  17. import com.google.gwt.i18n.client.TimeZone;
  18. import com.google.gwt.i18n.client.TimeZoneInfo;
  19. import com.vaadin.client.annotations.OnStateChange;
  20. import com.vaadin.client.communication.StateChangeEvent;
  21. import com.vaadin.client.ui.VAbstractTextualDate;
  22. import com.vaadin.shared.ui.datefield.AbstractTextualDateFieldState;
  23. /**
  24. * Abstract base class for date fields with textual date representation.
  25. *
  26. * @author Vaadin Ltd
  27. * @since 8.0
  28. *
  29. * @param <R>
  30. * resolution type
  31. */
  32. public abstract class AbstractTextualDateConnector<R extends Enum<R>>
  33. extends AbstractDateFieldConnector<R> {
  34. @Override
  35. public VAbstractTextualDate<R> getWidget() {
  36. return (VAbstractTextualDate<R>) super.getWidget();
  37. }
  38. @Override
  39. public AbstractTextualDateFieldState getState() {
  40. return (AbstractTextualDateFieldState) super.getState();
  41. }
  42. @OnStateChange("timeZoneJSON")
  43. private void onTimeZoneJSONChange() {
  44. TimeZone timeZone;
  45. String timeZoneJSON = getState().timeZoneJSON;
  46. if (timeZoneJSON != null) {
  47. TimeZoneInfo timeZoneInfo = TimeZoneInfo
  48. .buildTimeZoneData(timeZoneJSON);
  49. timeZone = TimeZone.createTimeZone(timeZoneInfo);
  50. } else {
  51. timeZone = null;
  52. }
  53. getWidget().setTimeZone(timeZone);
  54. }
  55. @Override
  56. public void onStateChanged(StateChangeEvent stateChangeEvent) {
  57. VAbstractTextualDate<R> widget = getWidget();
  58. AbstractTextualDateFieldState state = getState();
  59. R origRes = widget.getCurrentResolution();
  60. String oldLocale = widget.getCurrentLocale();
  61. super.onStateChanged(stateChangeEvent);
  62. if (origRes != widget.getCurrentResolution()
  63. || oldLocale != widget.getCurrentLocale()) {
  64. // force recreating format string
  65. widget.setFormatString(null);
  66. }
  67. if (state.format != widget.getFormatString()) {
  68. widget.setFormatString(state.format);
  69. }
  70. widget.lenient = state.lenient;
  71. // may be excessively called on every state change
  72. widget.buildDate();
  73. // not a FocusWidget -> needs own tabindex handling
  74. widget.text.setTabIndex(state.tabIndex);
  75. if (widget.isReadonly()) {
  76. widget.text.addStyleDependentName("readonly");
  77. } else {
  78. widget.text.removeStyleDependentName("readonly");
  79. }
  80. }
  81. }