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.

ColumnReorderEvent.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.client.widget.grid.events;
  17. import java.util.List;
  18. import com.google.gwt.event.shared.GwtEvent;
  19. import com.vaadin.client.widgets.Grid.Column;
  20. /**
  21. * An event for notifying that the columns in the Grid have been reordered.
  22. *
  23. * @param <T>
  24. * The row type of the grid. The row type is the POJO type from where
  25. * the data is retrieved into the column cells.
  26. * @since 7.5.0
  27. * @author Vaadin Ltd
  28. */
  29. public class ColumnReorderEvent<T> extends GwtEvent<ColumnReorderHandler<T>> {
  30. /**
  31. * Handler type.
  32. */
  33. private static final Type<ColumnReorderHandler<?>> TYPE = new Type<>();
  34. public static final Type<ColumnReorderHandler<?>> getType() {
  35. return TYPE;
  36. }
  37. private final List<Column<?, T>> oldColumnOrder;
  38. private final List<Column<?, T>> newColumnOrder;
  39. private final boolean userOriginated;
  40. public ColumnReorderEvent(List<Column<?, T>> oldColumnOrder,
  41. List<Column<?, T>> newColumnOrder, boolean userOriginated) {
  42. this.oldColumnOrder = oldColumnOrder;
  43. this.newColumnOrder = newColumnOrder;
  44. this.userOriginated = userOriginated;
  45. }
  46. /**
  47. * Gets the ordering of columns prior to this event.
  48. *
  49. * @return the list of columns in the grid's order prior to this event
  50. */
  51. public List<Column<?, T>> getOldColumnOrder() {
  52. return oldColumnOrder;
  53. }
  54. /**
  55. * Gets the new ordering of columns.
  56. *
  57. * @return the list of columns in the grid's current order
  58. */
  59. public List<Column<?, T>> getNewColumnOrder() {
  60. return newColumnOrder;
  61. }
  62. /**
  63. * Check whether this event originated from the user reordering columns or
  64. * via API call.
  65. *
  66. * @return {@code true} if columns were reordered by the user, {@code false}
  67. * if not
  68. */
  69. public boolean isUserOriginated() {
  70. return userOriginated;
  71. }
  72. @SuppressWarnings({ "rawtypes", "unchecked" })
  73. @Override
  74. public Type<ColumnReorderHandler<T>> getAssociatedType() {
  75. return (Type) TYPE;
  76. }
  77. @Override
  78. protected void dispatch(ColumnReorderHandler<T> handler) {
  79. handler.onColumnReorder(this);
  80. }
  81. }