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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 java.util.Collection;
  18. import com.vaadin.server.PaintException;
  19. import com.vaadin.server.PaintTarget;
  20. import com.vaadin.v7.data.Container;
  21. import com.vaadin.v7.shared.ui.twincolselect.TwinColSelectConstants;
  22. import com.vaadin.v7.shared.ui.twincolselect.TwinColSelectState;
  23. /**
  24. * Multiselect component with two lists: left side for available items and right
  25. * side for selected items.
  26. *
  27. * @deprecated As of 8.0 replaced by {@link com.vaadin.ui.TwinColSelect} based
  28. * on the new data binding API
  29. */
  30. @SuppressWarnings("serial")
  31. @Deprecated
  32. public class TwinColSelect extends AbstractSelect {
  33. private int columns = 0;
  34. private int rows = 0;
  35. private String leftColumnCaption;
  36. private String rightColumnCaption;
  37. /**
  38. *
  39. */
  40. public TwinColSelect() {
  41. super();
  42. setMultiSelect(true);
  43. }
  44. /**
  45. * @param caption
  46. */
  47. public TwinColSelect(String caption) {
  48. super(caption);
  49. setMultiSelect(true);
  50. }
  51. /**
  52. * @param caption
  53. * @param dataSource
  54. */
  55. public TwinColSelect(String caption, Container dataSource) {
  56. super(caption, dataSource);
  57. setMultiSelect(true);
  58. }
  59. /**
  60. * Sets the width of the component so that it displays approximately the
  61. * given number of letters in each of the two selects.
  62. * <p>
  63. * Calling {@code setColumns(10);} is roughly equivalent to calling
  64. * {@code setWidth((10*2+4)+"10em");}
  65. * </p>
  66. *
  67. * @deprecated As of 7.0. "Columns" does not reflect the exact number of
  68. * characters that will be displayed. It is better to use
  69. * setWidth together with "em" to control the width of the
  70. * field.
  71. * @param columns
  72. * the number of columns to set.
  73. */
  74. @Deprecated
  75. public void setColumns(int columns) {
  76. if (columns < 0) {
  77. columns = 0;
  78. }
  79. if (this.columns != columns) {
  80. this.columns = columns;
  81. markAsDirty();
  82. }
  83. }
  84. /**
  85. * Gets the number of columns for the component.
  86. *
  87. * @see #setColumns(int)
  88. * @deprecated As of 7.0. "Columns" does not reflect the exact number of
  89. * characters that will be displayed. It is better to use
  90. * setWidth together with "em" to control the width of the
  91. * field.
  92. */
  93. @Deprecated
  94. public int getColumns() {
  95. return columns;
  96. }
  97. public int getRows() {
  98. return rows;
  99. }
  100. /**
  101. * Sets the number of rows in the editor. If the number of rows is set to 0,
  102. * the actual number of displayed rows is determined implicitly by the
  103. * adapter.
  104. * <p>
  105. * If a height if set (using {@link #setHeight(String)} or
  106. * {@link #setHeight(float, int)}) it overrides the number of rows. Leave
  107. * the height undefined to use this method. This is the opposite of how
  108. * {@link #setColumns(int)} work.
  109. *
  110. *
  111. * @param rows
  112. * the number of rows to set.
  113. */
  114. public void setRows(int rows) {
  115. if (rows < 0) {
  116. rows = 0;
  117. }
  118. if (this.rows != rows) {
  119. this.rows = rows;
  120. markAsDirty();
  121. }
  122. }
  123. /**
  124. * @param caption
  125. * @param options
  126. */
  127. public TwinColSelect(String caption, Collection<?> options) {
  128. super(caption, options);
  129. setMultiSelect(true);
  130. }
  131. @Override
  132. public void paintContent(PaintTarget target) throws PaintException {
  133. target.addAttribute("type", "twincol");
  134. // Adds the number of columns
  135. if (columns != 0) {
  136. target.addAttribute("cols", columns);
  137. }
  138. // Adds the number of rows
  139. if (rows != 0) {
  140. target.addAttribute("rows", rows);
  141. }
  142. // Right and left column captions and/or icons (if set)
  143. String lc = getLeftColumnCaption();
  144. String rc = getRightColumnCaption();
  145. if (lc != null) {
  146. target.addAttribute(TwinColSelectConstants.ATTRIBUTE_LEFT_CAPTION,
  147. lc);
  148. }
  149. if (rc != null) {
  150. target.addAttribute(TwinColSelectConstants.ATTRIBUTE_RIGHT_CAPTION,
  151. rc);
  152. }
  153. super.paintContent(target);
  154. }
  155. /**
  156. * Sets the text shown above the right column.
  157. *
  158. * @param rightColumnCaption
  159. * The text to show
  160. */
  161. public void setRightColumnCaption(String rightColumnCaption) {
  162. this.rightColumnCaption = rightColumnCaption;
  163. markAsDirty();
  164. }
  165. /**
  166. * Returns the text shown above the right column.
  167. *
  168. * @return The text shown or null if not set.
  169. */
  170. public String getRightColumnCaption() {
  171. return rightColumnCaption;
  172. }
  173. /**
  174. * Sets the text shown above the left column.
  175. *
  176. * @param leftColumnCaption
  177. * The text to show
  178. */
  179. public void setLeftColumnCaption(String leftColumnCaption) {
  180. this.leftColumnCaption = leftColumnCaption;
  181. markAsDirty();
  182. }
  183. /**
  184. * Returns the text shown above the left column.
  185. *
  186. * @return The text shown or null if not set.
  187. */
  188. public String getLeftColumnCaption() {
  189. return leftColumnCaption;
  190. }
  191. @Override
  192. protected TwinColSelectState getState() {
  193. return (TwinColSelectState) super.getState();
  194. }
  195. }