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.

Listing.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright 2000-2016 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.data;
  17. import java.io.Serializable;
  18. import java.util.Collection;
  19. import java.util.Set;
  20. import com.vaadin.server.data.DataSource;
  21. import com.vaadin.shared.data.selection.SelectionModel;
  22. /**
  23. * A generic interface for components that show a list of data.
  24. *
  25. * @author Vaadin Ltd.
  26. *
  27. * @param <T>
  28. * the item data type
  29. * @param <SELECTIONMODEL>
  30. * the selection logic supported by this listing
  31. * @since 8.0
  32. */
  33. public interface Listing<T, SELECTIONMODEL extends SelectionModel<T>>
  34. extends Serializable {
  35. /**
  36. * Returns the source of data items used by this listing.
  37. *
  38. * @return the data source, not null
  39. */
  40. DataSource<T> getDataSource();
  41. /**
  42. * Sets the source of data items used by this listing. The data source is
  43. * queried for displayed items as needed.
  44. *
  45. * @param dataSource
  46. * the data source, not null
  47. */
  48. void setDataSource(DataSource<T> dataSource);
  49. /**
  50. * Returns the selection model for this listing.
  51. *
  52. * @return the selection model, not null
  53. */
  54. SELECTIONMODEL getSelectionModel();
  55. /**
  56. * Sets the collection of data items of this listing.
  57. *
  58. * @param items
  59. * the data items to display, not null
  60. *
  61. */
  62. default void setItems(Collection<T> items) {
  63. setDataSource(DataSource.create(items));
  64. }
  65. /**
  66. * Sets the data items of this listing.
  67. *
  68. * @param items
  69. * the data items to display
  70. */
  71. default void setItems(@SuppressWarnings("unchecked") T... items) {
  72. setDataSource(DataSource.create(items));
  73. }
  74. /* SelectionModel helper methods */
  75. /**
  76. * Returns an immutable set of the currently selected items. The iteration
  77. * order of the items in the returned set is specified by the
  78. * {@linkplain #getSelectionModel() selection model} used.
  79. *
  80. * @return the current selection
  81. *
  82. * @see SelectionModel#getSelectedItems
  83. */
  84. default Set<T> getSelectedItems() {
  85. return getSelectionModel().getSelectedItems();
  86. }
  87. /**
  88. * Selects the given item. If the item is already selected, does nothing.
  89. *
  90. * @param item
  91. * the item to select, not null
  92. *
  93. * @see SelectionModel#select
  94. */
  95. default void select(T item) {
  96. getSelectionModel().select(item);
  97. }
  98. /**
  99. * Deselects the given item. If the item is not currently selected, does
  100. * nothing.
  101. *
  102. * @param item
  103. * the item to deselect, not null
  104. *
  105. * @see SelectionModel#deselect
  106. */
  107. default void deselect(T item) {
  108. getSelectionModel().deselect(item);
  109. }
  110. /**
  111. * Returns whether the given item is currently selected.
  112. *
  113. * @param item
  114. * the item to check, not null
  115. * @return {@code true} if the item is selected, {@code false} otherwise
  116. */
  117. default boolean isSelected(T item) {
  118. return getSelectionModel().isSelected(item);
  119. }
  120. }