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.

SelectionModel.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright 2000-2014 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.server.communication.data.typed;
  17. import java.io.Serializable;
  18. import java.util.Collection;
  19. import java.util.Collections;
  20. import java.util.List;
  21. import com.vaadin.event.handler.Handler;
  22. import com.vaadin.event.handler.Registration;
  23. import com.vaadin.server.ListingExtension;
  24. import com.vaadin.ui.Component;
  25. import com.vaadin.ui.components.HasValue;
  26. import com.vaadin.ui.components.Listing;
  27. /**
  28. * Generic selection model interface.
  29. *
  30. * @since
  31. * @param <T>
  32. * type of selected values
  33. */
  34. public interface SelectionModel<T> extends Serializable, ListingExtension<T> {
  35. /**
  36. * Selection model for selection a single value.
  37. *
  38. * @param <T>
  39. * type of selected values
  40. */
  41. public interface Single<T> extends SelectionModel<T>, HasValue<T> {
  42. }
  43. /**
  44. * Selection model for selection multiple values.
  45. *
  46. * @param <T>
  47. * type of selected values
  48. */
  49. public interface Multi<T> extends SelectionModel<T>,
  50. HasValue<Collection<T>> {
  51. }
  52. /**
  53. * Get current selection.
  54. *
  55. * @return selection
  56. */
  57. Collection<T> getSelected();
  58. /**
  59. * Add this extension to the target listing component. SelectionModel can
  60. * only extend {@link Component}s that implement {@link Listing} interface.
  61. * This method should only be called from a listing component when changing
  62. * the selection model.
  63. *
  64. * @param target
  65. * listing component to extend.
  66. *
  67. * @throws IllegalArgumentException
  68. */
  69. void setParentListing(Listing<T> target);
  70. /**
  71. * Selects the given object.
  72. *
  73. * @param value
  74. * selected value
  75. */
  76. void select(T value);
  77. /**
  78. * Deselects the given object.
  79. *
  80. * @param value
  81. * deselected value
  82. */
  83. void deselect(T value);
  84. /**
  85. * Dummy selection model.
  86. *
  87. * @param <T>
  88. * selected data type
  89. */
  90. public static class NullSelection<T> extends AbstractSelectionModel<T>
  91. implements SelectionModel.Single<T> {
  92. @Override
  93. public void setValue(T value) {
  94. // NO-OP
  95. }
  96. @Override
  97. public T getValue() {
  98. return null;
  99. }
  100. @Override
  101. public Registration onChange(Handler<T> onChange) {
  102. return () -> {
  103. // NO-OP
  104. };
  105. }
  106. @Override
  107. public List<T> getSelected() {
  108. return Collections.emptyList();
  109. }
  110. @Override
  111. public void select(T value) {
  112. // NO-OP
  113. }
  114. @Override
  115. public void deselect(T value) {
  116. // NO-OP
  117. }
  118. }
  119. }