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.

AbstractFieldConnector.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 com.google.gwt.user.client.ui.Focusable;
  18. import com.vaadin.client.StyleConstants;
  19. import com.vaadin.client.annotations.OnStateChange;
  20. import com.vaadin.client.ui.HasRequiredIndicator;
  21. import com.vaadin.v7.shared.AbstractFieldState;
  22. @Deprecated
  23. public abstract class AbstractFieldConnector
  24. extends AbstractLegacyComponentConnector
  25. implements HasRequiredIndicator {
  26. @Override
  27. public AbstractFieldState getState() {
  28. return (AbstractFieldState) super.getState();
  29. }
  30. @Override
  31. public boolean isReadOnly() {
  32. return super.isReadOnly() || getState().propertyReadOnly;
  33. }
  34. public boolean isModified() {
  35. return getState().modified;
  36. }
  37. /**
  38. * Checks whether the required indicator should be shown for the field.
  39. * Required indicators are hidden if the field or its data source is
  40. * read-only.
  41. * <p>
  42. * NOTE: since 8.0 this only delegates to
  43. * {@link #isRequiredIndicatorVisible()}, and is left for legacy reasons.
  44. *
  45. * @deprecated Use {@link #isRequiredIndicatorVisible()} instead.
  46. *
  47. * @return true if required indicator should be shown
  48. */
  49. @Deprecated
  50. public boolean isRequired() {
  51. return isRequiredIndicatorVisible();
  52. }
  53. /**
  54. * Checks whether the required indicator should be shown for the field.
  55. *
  56. * Required indicators are hidden if the field or its data source is
  57. * read-only.
  58. *
  59. * @return true if required indicator should be shown
  60. */
  61. @Override
  62. public boolean isRequiredIndicatorVisible() {
  63. return getState().required && !isReadOnly();
  64. }
  65. @Override
  66. public boolean isErrorIndicatorVisible() {
  67. return super.isErrorIndicatorVisible() && !getState().hideErrors;
  68. }
  69. @Override
  70. protected void updateWidgetStyleNames() {
  71. super.updateWidgetStyleNames();
  72. // add / remove modified style name to Fields
  73. setWidgetStyleName(StyleConstants.MODIFIED, isModified());
  74. // add / remove error style name to Fields
  75. setWidgetStyleNameWithPrefix(getWidget().getStylePrimaryName(),
  76. StyleConstants.REQUIRED_EXT, isRequiredIndicatorVisible());
  77. getWidget().setStyleName(StyleConstants.REQUIRED,
  78. isRequiredIndicatorVisible());
  79. }
  80. @OnStateChange("tabIndex")
  81. void updateTabIndex() {
  82. // AbstractFieldState is not inheriting TabIndexState because of
  83. // AbstractLegacyComponentState, thus need to set tab index here
  84. // (instead of AbstractComponentConnector)
  85. if (getWidget() instanceof Focusable) {
  86. ((Focusable) getWidget()).setTabIndex(getState().tabIndex);
  87. }
  88. }
  89. }