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.

LegacyTextField.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 2000-2014 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.legacy.ui;
  17. import org.jsoup.nodes.Attributes;
  18. import org.jsoup.nodes.Element;
  19. import com.vaadin.data.Property;
  20. import com.vaadin.ui.declarative.DesignAttributeHandler;
  21. import com.vaadin.ui.declarative.DesignContext;
  22. /**
  23. * <p>
  24. * A text editor component that can be bound to any bindable Property. The text
  25. * editor supports both multiline and single line modes, default is one-line
  26. * mode.
  27. * </p>
  28. *
  29. * <p>
  30. * Since <code>TextField</code> extends <code>LegacyAbstractField</code> it
  31. * implements the {@link com.vaadin.data.Buffered} interface. A
  32. * <code>TextField</code> is in write-through mode by default, so
  33. * {@link com.vaadin.legacy.ui.LegacyAbstractField#setWriteThrough(boolean)}
  34. * must be called to enable buffering.
  35. * </p>
  36. *
  37. * @author Vaadin Ltd.
  38. * @since 3.0
  39. */
  40. @SuppressWarnings("serial")
  41. @Deprecated
  42. public class LegacyTextField extends LegacyAbstractTextField {
  43. /**
  44. * Constructs an empty <code>TextField</code> with no caption.
  45. */
  46. public LegacyTextField() {
  47. clear();
  48. }
  49. /**
  50. * Constructs an empty <code>TextField</code> with given caption.
  51. *
  52. * @param caption
  53. * the caption <code>String</code> for the editor.
  54. */
  55. public LegacyTextField(String caption) {
  56. this();
  57. setCaption(caption);
  58. }
  59. /**
  60. * Constructs a new <code>TextField</code> that's bound to the specified
  61. * <code>Property</code> and has no caption.
  62. *
  63. * @param dataSource
  64. * the Property to be edited with this editor.
  65. */
  66. public LegacyTextField(Property dataSource) {
  67. setPropertyDataSource(dataSource);
  68. }
  69. /**
  70. * Constructs a new <code>TextField</code> that's bound to the specified
  71. * <code>Property</code> and has the given caption <code>String</code>.
  72. *
  73. * @param caption
  74. * the caption <code>String</code> for the editor.
  75. * @param dataSource
  76. * the Property to be edited with this editor.
  77. */
  78. public LegacyTextField(String caption, Property dataSource) {
  79. this(dataSource);
  80. setCaption(caption);
  81. }
  82. /**
  83. * Constructs a new <code>TextField</code> with the given caption and
  84. * initial text contents. The editor constructed this way will not be bound
  85. * to a Property unless
  86. * {@link com.vaadin.data.Property.Viewer#setPropertyDataSource(Property)}
  87. * is called to bind it.
  88. *
  89. * @param caption
  90. * the caption <code>String</code> for the editor.
  91. * @param value
  92. * the initial text content of the editor.
  93. */
  94. public LegacyTextField(String caption, String value) {
  95. setValue(value);
  96. setCaption(caption);
  97. }
  98. /*
  99. * (non-Javadoc)
  100. *
  101. * @see com.vaadin.ui.AbstractTextField#readDesign(org.jsoup.nodes.Element,
  102. * com.vaadin.ui.declarative.DesignContext)
  103. */
  104. @Override
  105. public void readDesign(Element design, DesignContext designContext) {
  106. super.readDesign(design, designContext);
  107. Attributes attr = design.attributes();
  108. if (attr.hasKey("value")) {
  109. String newFieldValue = DesignAttributeHandler.readAttribute("value",
  110. attr, String.class);
  111. setValue(newFieldValue, false, true);
  112. }
  113. }
  114. /*
  115. * (non-Javadoc)
  116. *
  117. * @see com.vaadin.ui.AbstractTextField#writeDesign(org.jsoup.nodes.Element
  118. * , com.vaadin.ui.declarative.DesignContext)
  119. */
  120. @Override
  121. public void writeDesign(Element design, DesignContext designContext) {
  122. super.writeDesign(design, designContext);
  123. LegacyAbstractTextField def = (LegacyAbstractTextField) designContext
  124. .getDefaultInstance(this);
  125. Attributes attr = design.attributes();
  126. DesignAttributeHandler.writeAttribute("value", attr, getValue(),
  127. def.getValue(), String.class);
  128. }
  129. /*
  130. * (non-Javadoc)
  131. *
  132. * @see com.vaadin.ui.AbstractField#clear()
  133. */
  134. @Override
  135. public void clear() {
  136. setValue("");
  137. }
  138. }