Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

TextField.java 4.6KB

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