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.

DataGenerator.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.server.data;
  17. import java.io.Serializable;
  18. import elemental.json.JsonObject;
  19. /**
  20. * A data generator for {@link DataCommunicator}. Used to inject custom data to
  21. * data items sent to the client for extension purposes.
  22. *
  23. * @author Vaadin Ltd.
  24. *
  25. * @param <T>
  26. * the data type
  27. *
  28. * @since 8.0
  29. */
  30. @FunctionalInterface
  31. public interface DataGenerator<T> extends Serializable {
  32. /**
  33. * Adds custom data for the given item to its serialized {@code JsonObject}
  34. * representation. This JSON object will be sent to client-side DataSource.
  35. *
  36. * @param item
  37. * the data item being serialized
  38. * @param jsonObject
  39. * the JSON object being sent to the client
  40. */
  41. void generateData(T item, JsonObject jsonObject);
  42. /**
  43. * Informs the {@code DataGenerator} that the given data item has been
  44. * dropped and is no longer needed. This method should clean up any unneeded
  45. * information stored for this item.
  46. *
  47. * @param item
  48. * the dropped data item
  49. */
  50. public default void destroyData(T item) {
  51. }
  52. }