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.

SortEvent.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.event;
  17. import java.io.Serializable;
  18. import java.util.List;
  19. import com.vaadin.data.provider.SortOrder;
  20. import com.vaadin.shared.Registration;
  21. import com.vaadin.ui.Component;
  22. /**
  23. * Event describing a change in sorting of a {@link Container}. Fired by
  24. * {@link SortNotifier SortNotifiers}.
  25. *
  26. * @see SortListener
  27. * @see SortOrder
  28. * @param <T>
  29. * the type of the sorting information, usually a String (field id)
  30. * or a {@link java.util.Comparator}.
  31. *
  32. * @since 8.0
  33. * @author Vaadin Ltd
  34. */
  35. public class SortEvent<T> extends Component.Event {
  36. private final List<SortOrder<T>> sortOrder;
  37. private final boolean userOriginated;
  38. /**
  39. * Creates a new sort order change event with a sort order list.
  40. *
  41. * @param source
  42. * the component from which the event originates
  43. * @param sortOrder
  44. * the new sort order list
  45. * @param userOriginated
  46. * <code>true</code> if event is a result of user interaction,
  47. * <code>false</code> if from API call
  48. */
  49. public SortEvent(Component source, List<SortOrder<T>> sortOrder,
  50. boolean userOriginated) {
  51. super(source);
  52. this.sortOrder = sortOrder;
  53. this.userOriginated = userOriginated;
  54. }
  55. /**
  56. * Gets the sort order list.
  57. *
  58. * @return the sort order list
  59. */
  60. public List<SortOrder<T>> getSortOrder() {
  61. return sortOrder;
  62. }
  63. /**
  64. * Returns whether this event originated from actions done by the user.
  65. *
  66. * @return true if sort event originated from user interaction
  67. */
  68. public boolean isUserOriginated() {
  69. return userOriginated;
  70. }
  71. /**
  72. * Listener for sort order change events.
  73. *
  74. * @param <T>
  75. * the type of the sorting information, usually a String (field
  76. * id) or a {@link java.util.Comparator}.
  77. */
  78. @FunctionalInterface
  79. public interface SortListener<T> extends Serializable {
  80. /**
  81. * Called when the sort order has changed.
  82. *
  83. * @param event
  84. * the sort order change event
  85. */
  86. public void sort(SortEvent<T> event);
  87. }
  88. /**
  89. * The interface for adding and removing listeners for {@link SortEvent
  90. * SortEvents}.
  91. *
  92. * @param <T>
  93. * the type of the sorting information, usually a String (field
  94. * id) or a {@link java.util.Comparator}.
  95. */
  96. public interface SortNotifier<T> extends Serializable {
  97. /**
  98. * Adds a sort order change listener that gets notified when the sort
  99. * order changes.
  100. *
  101. * @param listener
  102. * the sort order change listener to add
  103. * @return a registration object for removing the listener
  104. */
  105. public Registration addSortListener(SortListener<T> listener);
  106. }
  107. }