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 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.tokka.server.communication.data;
  17. import java.io.Serializable;
  18. import java.util.Collection;
  19. import com.vaadin.server.ClientConnector;
  20. import com.vaadin.tokka.event.Event;
  21. import com.vaadin.tokka.server.ListingExtension;
  22. import com.vaadin.tokka.ui.components.HasValue;
  23. import com.vaadin.tokka.ui.components.Listing;
  24. import com.vaadin.ui.Component;
  25. /**
  26. * Generic selection model interface.
  27. *
  28. * @since
  29. * @param <T>
  30. * type of selected values
  31. */
  32. public interface SelectionModel<T> extends Serializable, ListingExtension<T> {
  33. public class SelectionEvent<T> extends Event<T> {
  34. public SelectionEvent(ClientConnector source, T value,
  35. boolean userOriginated) {
  36. super(source, value, userOriginated);
  37. }
  38. }
  39. /**
  40. * Selection model for selection a single value.
  41. *
  42. * @param <T>
  43. * type of selected values
  44. */
  45. public interface Single<T> extends SelectionModel<T>, HasValue<T> {
  46. }
  47. /**
  48. * Selection model for selection multiple values.
  49. *
  50. * @param <T>
  51. * type of selected values
  52. */
  53. public interface Multi<T>
  54. extends SelectionModel<T>, HasValue<Collection<T>> {
  55. }
  56. /**
  57. * Get current selection.
  58. *
  59. * @return selection
  60. */
  61. Collection<T> getSelected();
  62. /**
  63. * Add this extension to the target listing component. SelectionModel can
  64. * only extend {@link Component}s that implement {@link Listing} interface.
  65. * This method should only be called from a listing component when changing
  66. * the selection model.
  67. *
  68. * @param target
  69. * listing component to extend.
  70. *
  71. * @throws IllegalArgumentException
  72. */
  73. void setParentListing(Listing<T> target);
  74. /**
  75. * Selects the given object.
  76. *
  77. * @param value
  78. * selected value
  79. */
  80. void select(T value);
  81. /**
  82. * Deselects the given object.
  83. *
  84. * @param value
  85. * deselected value
  86. */
  87. void deselect(T value);
  88. }