Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TwinColSelect.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.ui;
  17. import java.util.Collection;
  18. import com.vaadin.data.HasDataProvider;
  19. import com.vaadin.data.provider.DataProvider;
  20. import com.vaadin.shared.ui.twincolselect.TwinColSelectState;
  21. /**
  22. * Multiselect component with two lists: left side for available items and right
  23. * side for selected items.
  24. *
  25. * @author Vaadin Ltd
  26. *
  27. * @param <T>
  28. * item type
  29. */
  30. public class TwinColSelect<T> extends AbstractMultiSelect<T>
  31. implements HasDataProvider<T> {
  32. /**
  33. * Constructs a new TwinColSelect.
  34. */
  35. public TwinColSelect() {
  36. }
  37. /**
  38. * Constructs a new TwinColSelect with the given caption.
  39. *
  40. * @param caption
  41. * the caption to set, can be {@code null}
  42. */
  43. public TwinColSelect(String caption) {
  44. this();
  45. setCaption(caption);
  46. }
  47. /**
  48. * Constructs a new TwinColSelect with caption and data provider for
  49. * options.
  50. *
  51. * @param caption
  52. * the caption to set, can be {@code null}
  53. * @param dataProvider
  54. * the data provider, not {@code null}
  55. * @since 8.0
  56. */
  57. public TwinColSelect(String caption, DataProvider<T, ?> dataProvider) {
  58. this(caption);
  59. setDataProvider(dataProvider);
  60. }
  61. /**
  62. * Constructs a new TwinColSelect with caption and the given options.
  63. *
  64. * @param caption
  65. * the caption to set, can be {@code null}
  66. * @param options
  67. * the options, cannot be {@code null}
  68. */
  69. public TwinColSelect(String caption, Collection<T> options) {
  70. this(caption, DataProvider.ofCollection(options));
  71. }
  72. /**
  73. * Returns the number of rows in the selects.
  74. *
  75. * @return the number of rows visible
  76. */
  77. public int getRows() {
  78. return getState(false).rows;
  79. }
  80. /**
  81. * Sets the number of rows in the selects. If the number of rows is set to 0
  82. * or less, the actual number of displayed rows is determined implicitly by
  83. * the selects.
  84. * <p>
  85. * If a height if set (using {@link #setHeight(String)} or
  86. * {@link #setHeight(float, Unit)}) it overrides the number of rows. Leave
  87. * the height undefined to use this method.
  88. *
  89. * @param rows
  90. * the number of rows to set.
  91. */
  92. public void setRows(int rows) {
  93. if (rows < 0) {
  94. rows = 0;
  95. }
  96. if (getState(false).rows != rows) {
  97. getState().rows = rows;
  98. }
  99. }
  100. /**
  101. * Sets the text shown above the right column. {@code null} clears the
  102. * caption.
  103. *
  104. * @param rightColumnCaption
  105. * The text to show, {@code null} to clear
  106. */
  107. public void setRightColumnCaption(String rightColumnCaption) {
  108. getState().rightColumnCaption = rightColumnCaption;
  109. }
  110. /**
  111. * Returns the text shown above the right column.
  112. *
  113. * @return The text shown or {@code null} if not set.
  114. */
  115. public String getRightColumnCaption() {
  116. return getState(false).rightColumnCaption;
  117. }
  118. /**
  119. * Sets the text shown above the left column. {@code null} clears the
  120. * caption.
  121. *
  122. * @param leftColumnCaption
  123. * The text to show, {@code null} to clear
  124. */
  125. public void setLeftColumnCaption(String leftColumnCaption) {
  126. getState().leftColumnCaption = leftColumnCaption;
  127. markAsDirty();
  128. }
  129. /**
  130. * Returns the text shown above the left column.
  131. *
  132. * @return The text shown or {@code null} if not set.
  133. */
  134. public String getLeftColumnCaption() {
  135. return getState(false).leftColumnCaption;
  136. }
  137. @Override
  138. protected TwinColSelectState getState() {
  139. return (TwinColSelectState) super.getState();
  140. }
  141. @Override
  142. protected TwinColSelectState getState(boolean markAsDirty) {
  143. return (TwinColSelectState) super.getState(markAsDirty);
  144. }
  145. @Override
  146. public DataProvider<T, ?> getDataProvider() {
  147. return internalGetDataProvider();
  148. }
  149. @Override
  150. public void setDataProvider(DataProvider<T, ?> dataProvider) {
  151. internalSetDataProvider(dataProvider);
  152. }
  153. }