選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Listing.java 3.5KB

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