]> source.dussan.org Git - vaadin-framework.git/commitdiff
Rename TypedDataGenerator to DataGenerator
authorJohannes Dahlström <johannesd@vaadin.com>
Tue, 30 Aug 2016 12:30:13 +0000 (15:30 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 31 Aug 2016 07:37:02 +0000 (07:37 +0000)
Also add a no-op default implementation to destroyData,
making DataGenerator a functional interface.

Change-Id: I546f443150da23debd4a2691003e435367469439

server/src/main/java/com/vaadin/server/data/DataCommunicator.java
server/src/main/java/com/vaadin/server/data/DataGenerator.java [new file with mode: 0644]
server/src/main/java/com/vaadin/server/data/TypedDataGenerator.java [deleted file]
server/src/main/java/com/vaadin/ui/AbstractListing.java
server/src/main/java/com/vaadin/ui/Grid.java
server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingTest.java

index 9bfc8e248fc595f684492bbcebeaff6d89b71b79..7bf9707741b0c351555d05e589d3dd8450fd9120 100644 (file)
@@ -42,7 +42,7 @@ import elemental.json.JsonObject;
 
 /**
  * DataProvider base class. This class is the base for all DataProvider
- * communication implementations. It uses {@link TypedDataGenerator}s to write
+ * communication implementations. It uses {@link DataGenerator}s to write
  * {@link JsonObject}s representing each data object to be sent to the
  * client-side.
  *
@@ -81,10 +81,10 @@ public class DataCommunicator<T> extends AbstractExtension {
      * {@link #addActiveData(Collection)} and {@link #cleanUp(Collection)} are
      * called with the same parameter. In the clean up method any dropped data
      * objects that are not in the given collection will be cleaned up and
-     * {@link TypedDataGenerator#destroyData(Object)} will be called for them.
+     * {@link DataGenerator#destroyData(Object)} will be called for them.
      */
     protected class ActiveDataHandler
-            implements Serializable, TypedDataGenerator<T> {
+            implements Serializable, DataGenerator<T> {
 
         /**
          * Set of key strings for currently active data objects
@@ -173,7 +173,7 @@ public class DataCommunicator<T> extends AbstractExtension {
         }
     }
 
-    private Collection<TypedDataGenerator<T>> generators = new LinkedHashSet<>();
+    private Collection<DataGenerator<T>> generators = new LinkedHashSet<>();
     private ActiveDataHandler handler = new ActiveDataHandler();
 
     private DataSource<T> dataSource;
@@ -266,7 +266,7 @@ public class DataCommunicator<T> extends AbstractExtension {
      * @param generator
      *            the data generator to add, not null
      */
-    public void addDataGenerator(TypedDataGenerator<T> generator) {
+    public void addDataGenerator(DataGenerator<T> generator) {
         Objects.requireNonNull(generator, "generator cannot be null");
         generators.add(generator);
     }
@@ -278,7 +278,7 @@ public class DataCommunicator<T> extends AbstractExtension {
      * @param generator
      *            the data generator to remove, not null
      */
-    public void removeDataGenerator(TypedDataGenerator<T> generator) {
+    public void removeDataGenerator(DataGenerator<T> generator) {
         Objects.requireNonNull(generator, "generator cannot be null");
         generators.remove(generator);
     }
@@ -327,7 +327,7 @@ public class DataCommunicator<T> extends AbstractExtension {
     protected JsonObject getDataObject(T data) {
         JsonObject dataObject = Json.createObject();
 
-        for (TypedDataGenerator<T> generator : generators) {
+        for (DataGenerator<T> generator : generators) {
             generator.generateData(data, dataObject);
         }
 
@@ -336,7 +336,7 @@ public class DataCommunicator<T> extends AbstractExtension {
 
     /**
      * Drops data objects identified by given keys from memory. This will invoke
-     * {@link TypedDataGenerator#destroyData} for each of those objects.
+     * {@link DataGenerator#destroyData} for each of those objects.
      *
      * @param droppedKeys
      *            collection of dropped keys
@@ -348,7 +348,7 @@ public class DataCommunicator<T> extends AbstractExtension {
             T data = getKeyMapper().get(key);
             assert data != null : "Bookkeepping failure. No data object to match key";
 
-            for (TypedDataGenerator<T> g : generators) {
+            for (DataGenerator<T> g : generators) {
                 g.destroyData(data);
             }
         }
diff --git a/server/src/main/java/com/vaadin/server/data/DataGenerator.java b/server/src/main/java/com/vaadin/server/data/DataGenerator.java
new file mode 100644 (file)
index 0000000..8eda632
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.server.data;
+
+import java.io.Serializable;
+
+import elemental.json.JsonObject;
+
+/**
+ * A data generator for {@link DataCommunicator}. Used to inject custom data to
+ * data items sent to the client for extension purposes.
+ *
+ * @author Vaadin Ltd.
+ * 
+ * @param <T>
+ *            the data type
+ * 
+ * @since
+ */
+@FunctionalInterface
+public interface DataGenerator<T> extends Serializable {
+
+    /**
+     * Adds custom data for the given item to its serialized {@code JsonObject}
+     * representation. This JSON object will be sent to client-side DataSource.
+     *
+     * @param item
+     *            the data item being serialized
+     * @param jsonObject
+     *            the JSON object being sent to the client
+     */
+    void generateData(T item, JsonObject jsonObject);
+
+    /**
+     * Informs the {@code DataGenerator} that the given data item has been
+     * dropped and is no longer needed. This method should clean up any unneeded
+     * information stored for this item.
+     *
+     * @param item
+     *            the dropped data item
+     */
+    public default void destroyData(T item) {
+    }
+}
diff --git a/server/src/main/java/com/vaadin/server/data/TypedDataGenerator.java b/server/src/main/java/com/vaadin/server/data/TypedDataGenerator.java
deleted file mode 100644 (file)
index 1303921..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.server.data;
-
-import java.io.Serializable;
-
-import elemental.json.JsonObject;
-
-/**
- * Simple typed data generator for {@link DataCommunicator}.
- *
- * @since
- */
-public interface TypedDataGenerator<T> extends Serializable {
-
-    /**
-     * Adds data for given object to {@link JsonObject}. This JsonObject will be
-     * sent to client-side DataSource.
-     *
-     * @param data
-     *            data object
-     * @param jsonObject
-     *            json object being sent to the client
-     */
-    void generateData(T data, JsonObject jsonObject);
-
-    /**
-     * Informs the {@link TypedDataGenerator} that given data has been dropped
-     * and is no longer needed. This method should clean up any unneeded
-     * information stored for this data.
-     *
-     * @param data
-     *            dropped data
-     */
-    public void destroyData(T data);
-}
\ No newline at end of file
index 1167e645055023278615706bb1b30b02392d8683..58117e6df8336fd3625713f0b900151caa6ba4f2 100644 (file)
@@ -21,8 +21,8 @@ import com.vaadin.data.Listing;
 import com.vaadin.data.selection.SelectionModel;
 import com.vaadin.server.AbstractExtension;
 import com.vaadin.server.data.DataCommunicator;
+import com.vaadin.server.data.DataGenerator;
 import com.vaadin.server.data.DataSource;
-import com.vaadin.server.data.TypedDataGenerator;
 
 /**
  * A base class for listing components. Provides common handling for fetching
@@ -45,7 +45,7 @@ public abstract class AbstractListing<T, SELECTIONMODEL extends SelectionModel<T
      *            the listing item type
      */
     public abstract static class AbstractListingExtension<T>
-            extends AbstractExtension implements TypedDataGenerator<T> {
+            extends AbstractExtension implements DataGenerator<T> {
 
         /**
          * Adds this extension to the given parent listing.
@@ -154,7 +154,7 @@ public abstract class AbstractListing<T, SELECTIONMODEL extends SelectionModel<T
      * @param generator
      *            the data generator to add, not null
      */
-    protected void addDataGenerator(TypedDataGenerator<T> generator) {
+    protected void addDataGenerator(DataGenerator<T> generator) {
         getDataCommunicator().addDataGenerator(generator);
     }
 
@@ -165,7 +165,7 @@ public abstract class AbstractListing<T, SELECTIONMODEL extends SelectionModel<T
      * @param generator
      *            the data generator to remove, not null
      */
-    protected void removeDataGenerator(TypedDataGenerator<T> generator) {
+    protected void removeDataGenerator(DataGenerator<T> generator) {
         getDataCommunicator().removeDataGenerator(generator);
     }
 
index 1a30b0f3fc60c8d9cd45eec223cd407880297769..47335e446236af3acdde11c67c9fbf7408c250de 100644 (file)
@@ -36,7 +36,7 @@ import com.vaadin.server.AbstractExtension;
 import com.vaadin.server.KeyMapper;
 import com.vaadin.server.data.DataSource;
 import com.vaadin.server.data.SortOrder;
-import com.vaadin.server.data.TypedDataGenerator;
+import com.vaadin.server.data.DataGenerator;
 import com.vaadin.shared.MouseEventDetails;
 import com.vaadin.shared.data.DataCommunicatorConstants;
 import com.vaadin.shared.data.sort.SortDirection;
@@ -301,7 +301,7 @@ public class Grid<T> extends AbstractListing<T, SelectionModel<T>>
      *            the column value type
      */
     public static class Column<T, V> extends AbstractExtension
-            implements TypedDataGenerator<T> {
+            implements DataGenerator<T> {
 
         private Function<T, V> valueProvider;
         private Function<SortDirection, Stream<SortOrder<String>>> sortOrderProvider;
index 3ec889f30191880eeb184a4083c3a950d803111c..f29d1dd00b5b7f58cd1d3bcc31d17c7523855144 100644 (file)
@@ -13,10 +13,10 @@ import org.junit.Test;
 
 import com.vaadin.data.selection.SelectionModel;
 import com.vaadin.server.data.BackEndDataSource;
+import com.vaadin.server.data.DataGenerator;
 import com.vaadin.server.data.DataSource;
 import com.vaadin.server.data.ListDataSource;
 import com.vaadin.server.data.Query;
-import com.vaadin.server.data.TypedDataGenerator;
 import com.vaadin.ui.AbstractListing;
 import com.vaadin.ui.AbstractListing.AbstractListingExtension;
 
@@ -48,12 +48,12 @@ public class AbstractListingTest {
         }
 
         @Override
-        public void addDataGenerator(TypedDataGenerator<String> generator) {
+        public void addDataGenerator(DataGenerator<String> generator) {
             super.addDataGenerator(generator);
         }
 
         @Override
-        public void removeDataGenerator(TypedDataGenerator<String> generator) {
+        public void removeDataGenerator(DataGenerator<String> generator) {
             super.removeDataGenerator(generator);
         }