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.

TwinColSelect.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.ui;
  5. import java.util.Collection;
  6. import com.vaadin.data.Container;
  7. import com.vaadin.terminal.PaintException;
  8. import com.vaadin.terminal.PaintTarget;
  9. import com.vaadin.terminal.gwt.client.ui.VTwinColSelect;
  10. /**
  11. * Multiselect component with two lists: left side for available items and right
  12. * side for selected items.
  13. */
  14. @SuppressWarnings("serial")
  15. @ClientWidget(VTwinColSelect.class)
  16. public class TwinColSelect extends AbstractSelect {
  17. private int columns = 0;
  18. private int rows = 0;
  19. private String leftColumnCaption;
  20. private String rightColumnCaption;
  21. /**
  22. *
  23. */
  24. public TwinColSelect() {
  25. super();
  26. setMultiSelect(true);
  27. }
  28. /**
  29. * @param caption
  30. */
  31. public TwinColSelect(String caption) {
  32. super(caption);
  33. setMultiSelect(true);
  34. }
  35. /**
  36. * @param caption
  37. * @param dataSource
  38. */
  39. public TwinColSelect(String caption, Container dataSource) {
  40. super(caption, dataSource);
  41. setMultiSelect(true);
  42. }
  43. /**
  44. * Sets the number of columns in the editor. If the number of columns is set
  45. * 0, the actual number of displayed columns is determined implicitly by the
  46. * adapter.
  47. * <p>
  48. * The number of columns overrides the value set by setWidth. Only if
  49. * columns are set to 0 (default) the width set using
  50. * {@link #setWidth(float, int)} or {@link #setWidth(String)} is used.
  51. *
  52. * @param columns
  53. * the number of columns to set.
  54. */
  55. public void setColumns(int columns) {
  56. if (columns < 0) {
  57. columns = 0;
  58. }
  59. if (this.columns != columns) {
  60. this.columns = columns;
  61. requestRepaint();
  62. }
  63. }
  64. public int getColumns() {
  65. return columns;
  66. }
  67. public int getRows() {
  68. return rows;
  69. }
  70. /**
  71. * Sets the number of rows in the editor. If the number of rows is set to 0,
  72. * the actual number of displayed rows is determined implicitly by the
  73. * adapter.
  74. * <p>
  75. * If a height if set (using {@link #setHeight(String)} or
  76. * {@link #setHeight(float, int)}) it overrides the number of rows. Leave
  77. * the height undefined to use this method. This is the opposite of how
  78. * {@link #setColumns(int)} work.
  79. *
  80. *
  81. * @param rows
  82. * the number of rows to set.
  83. */
  84. public void setRows(int rows) {
  85. if (rows < 0) {
  86. rows = 0;
  87. }
  88. if (this.rows != rows) {
  89. this.rows = rows;
  90. requestRepaint();
  91. }
  92. }
  93. /**
  94. * @param caption
  95. * @param options
  96. */
  97. public TwinColSelect(String caption, Collection<?> options) {
  98. super(caption, options);
  99. setMultiSelect(true);
  100. }
  101. @Override
  102. public void paintContent(PaintTarget target) throws PaintException {
  103. target.addAttribute("type", "twincol");
  104. // Adds the number of columns
  105. if (columns != 0) {
  106. target.addAttribute("cols", columns);
  107. }
  108. // Adds the number of rows
  109. if (rows != 0) {
  110. target.addAttribute("rows", rows);
  111. }
  112. // Right and left column captions and/or icons (if set)
  113. String lc = getLeftColumnCaption();
  114. String rc = getRightColumnCaption();
  115. if (lc != null) {
  116. target.addAttribute(VTwinColSelect.ATTRIBUTE_LEFT_CAPTION, lc);
  117. }
  118. if (rc != null) {
  119. target.addAttribute(VTwinColSelect.ATTRIBUTE_RIGHT_CAPTION, rc);
  120. }
  121. super.paintContent(target);
  122. }
  123. /**
  124. * Sets the text shown above the right column.
  125. *
  126. * @param caption
  127. * The text to show
  128. */
  129. public void setRightColumnCaption(String rightColumnCaption) {
  130. this.rightColumnCaption = rightColumnCaption;
  131. requestRepaint();
  132. }
  133. /**
  134. * Returns the text shown above the right column.
  135. *
  136. * @return The text shown or null if not set.
  137. */
  138. public String getRightColumnCaption() {
  139. return rightColumnCaption;
  140. }
  141. /**
  142. * Sets the text shown above the left column.
  143. *
  144. * @param caption
  145. * The text to show
  146. */
  147. public void setLeftColumnCaption(String leftColumnCaption) {
  148. this.leftColumnCaption = leftColumnCaption;
  149. requestRepaint();
  150. }
  151. /**
  152. * Returns the text shown above the left column.
  153. *
  154. * @return The text shown or null if not set.
  155. */
  156. public String getLeftColumnCaption() {
  157. return leftColumnCaption;
  158. }
  159. }