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 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2011 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;
  17. import com.vaadin.client.ApplicationConnection;
  18. import com.vaadin.shared.AbstractFieldState;
  19. public abstract class AbstractFieldConnector extends AbstractComponentConnector {
  20. @Override
  21. public AbstractFieldState getState() {
  22. return (AbstractFieldState) super.getState();
  23. }
  24. @Override
  25. public boolean isReadOnly() {
  26. return super.isReadOnly() || getState().isPropertyReadOnly();
  27. }
  28. public boolean isModified() {
  29. return getState().isModified();
  30. }
  31. /**
  32. * Checks whether the required indicator should be shown for the field.
  33. *
  34. * Required indicators are hidden if the field or its data source is
  35. * read-only.
  36. *
  37. * @return true if required indicator should be shown
  38. */
  39. public boolean isRequired() {
  40. return getState().isRequired() && !isReadOnly();
  41. }
  42. @Override
  43. protected void updateWidgetStyleNames() {
  44. super.updateWidgetStyleNames();
  45. // add / remove modified style name to Fields
  46. setWidgetStyleName(ApplicationConnection.MODIFIED_CLASSNAME,
  47. isModified());
  48. // add / remove error style name to Fields
  49. setWidgetStyleNameWithPrefix(getWidget().getStylePrimaryName(),
  50. ApplicationConnection.REQUIRED_CLASSNAME_EXT, isRequired());
  51. }
  52. }