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.

MultiSelectionModel.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.components.grid;
  17. import com.vaadin.data.Binder;
  18. import com.vaadin.data.provider.DataProvider;
  19. import com.vaadin.event.selection.MultiSelectionListener;
  20. import com.vaadin.event.selection.SelectionListener;
  21. import com.vaadin.shared.Registration;
  22. import com.vaadin.ui.MultiSelect;
  23. /**
  24. * Multiselection model interface for Grid.
  25. *
  26. * @author Vaadin Ltd
  27. * @since 8.0
  28. *
  29. * @param <T>
  30. * the type of items in grid
  31. */
  32. public interface MultiSelectionModel<T>
  33. extends GridSelectionModel<T>, com.vaadin.data.SelectionModel.Multi<T> {
  34. /**
  35. * State for showing the select all checkbox in the grid's default header
  36. * row for the selection column.
  37. * <p>
  38. * Default value is {@link #DEFAULT}, which means that the select all is
  39. * only visible if an in-memory data provider is used
  40. * {@link DataProvider#isInMemory()}.
  41. */
  42. public enum SelectAllCheckBoxVisibility {
  43. /**
  44. * Shows the select all checkbox, regardless of data provider used.
  45. * <p>
  46. * <b>For a lazy data provider, selecting all will result in to all rows
  47. * being fetched from backend to application memory!</b>
  48. */
  49. VISIBLE,
  50. /**
  51. * Never shows the select all checkbox, regardless of data provider
  52. * used.
  53. */
  54. HIDDEN,
  55. /**
  56. * By default select all checkbox depends on the grid's dataprovider.
  57. * <ul>
  58. * <li>Visible, if the data provider is in-memory</li>
  59. * <li>Hidden, if the data provider is NOT in-memory (lazy)</li>
  60. * </ul>
  61. *
  62. * @see DataProvider#isInMemory()}.
  63. */
  64. DEFAULT;
  65. }
  66. /**
  67. * Gets a wrapper to use this multiselection model as a multiselect in
  68. * {@link Binder}.
  69. *
  70. * @return the multiselect wrapper
  71. */
  72. MultiSelect<T> asMultiSelect();
  73. /**
  74. * {@inheritDoc}
  75. * <p>
  76. * Use {@link #addMultiSelectionListener(MultiSelectionListener)} for more
  77. * specific event on multiselection.
  78. *
  79. * @see #addMultiSelectionListener(MultiSelectionListener)
  80. */
  81. @Override
  82. public default Registration addSelectionListener(
  83. SelectionListener<T> listener) {
  84. return addMultiSelectionListener(
  85. event -> listener.selectionChange(event));
  86. }
  87. /**
  88. * Adds a selection listener that will be called when the selection is
  89. * changed either by the user or programmatically.
  90. *
  91. * @param listener
  92. * the value change listener, not {@code null}
  93. * @return a registration for the listener
  94. */
  95. public Registration addMultiSelectionListener(
  96. MultiSelectionListener<T> listener);
  97. /**
  98. * Sets the select all checkbox visibility mode.
  99. * <p>
  100. * The default value is {@link SelectAllCheckBoxVisibility#DEFAULT}, which
  101. * means that the checkbox is only visible if the grid's data provider is
  102. * in- memory.
  103. *
  104. * @param selectAllCheckBoxVisibility
  105. * the visiblity mode to use
  106. * @see SelectAllCheckBoxVisibility
  107. */
  108. public void setSelectAllCheckBoxVisibility(
  109. SelectAllCheckBoxVisibility selectAllCheckBoxVisibility);
  110. /**
  111. * Gets the current mode for the select all checkbox visibility.
  112. *
  113. * @return the select all checkbox visibility mode
  114. * @see SelectAllCheckBoxVisibility
  115. * @see #isSelectAllCheckBoxVisible()
  116. */
  117. public SelectAllCheckBoxVisibility getSelectAllCheckBoxVisibility();
  118. /**
  119. * Returns whether the select all checkbox will be visible with the current
  120. * setting of
  121. * {@link #setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)}.
  122. *
  123. * @return {@code true} if the checkbox will be visible with the current
  124. * settings
  125. * @see SelectAllCheckBoxVisibility
  126. * @see #setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)
  127. */
  128. public boolean isSelectAllCheckBoxVisible();
  129. /**
  130. * Returns whether all items are selected or not.
  131. * <p>
  132. * This is only {@code true} if user has selected all rows with the select
  133. * all checkbox on client side, or if {@link #selectAll()} has been used
  134. * from server side.
  135. *
  136. * @return {@code true} if all selected, {@code false} if not
  137. * @since 8.12.0
  138. */
  139. boolean isAllSelected();
  140. }