aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2016-08-30 15:30:13 +0300
committerVaadin Code Review <review@vaadin.com>2016-08-31 07:37:02 +0000
commit8532ed304b73f8d90e254bd9f969d579668981fe (patch)
tree7bf21ea0baf24020f1d2615bc66e210b097fb22c
parent0207cc93e01b0a50817d7164d7d2216ee3bf4c48 (diff)
downloadvaadin-framework-8532ed304b73f8d90e254bd9f969d579668981fe.tar.gz
vaadin-framework-8532ed304b73f8d90e254bd9f969d579668981fe.zip
Rename TypedDataGenerator to DataGenerator
Also add a no-op default implementation to destroyData, making DataGenerator a functional interface. Change-Id: I546f443150da23debd4a2691003e435367469439
-rw-r--r--server/src/main/java/com/vaadin/server/data/DataCommunicator.java18
-rw-r--r--server/src/main/java/com/vaadin/server/data/DataGenerator.java57
-rw-r--r--server/src/main/java/com/vaadin/server/data/TypedDataGenerator.java49
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractListing.java8
-rw-r--r--server/src/main/java/com/vaadin/ui/Grid.java4
-rw-r--r--server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingTest.java6
6 files changed, 75 insertions, 67 deletions
diff --git a/server/src/main/java/com/vaadin/server/data/DataCommunicator.java b/server/src/main/java/com/vaadin/server/data/DataCommunicator.java
index 9bfc8e248f..7bf9707741 100644
--- a/server/src/main/java/com/vaadin/server/data/DataCommunicator.java
+++ b/server/src/main/java/com/vaadin/server/data/DataCommunicator.java
@@ -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
index 0000000000..8eda632167
--- /dev/null
+++ b/server/src/main/java/com/vaadin/server/data/DataGenerator.java
@@ -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
index 1303921f18..0000000000
--- a/server/src/main/java/com/vaadin/server/data/TypedDataGenerator.java
+++ /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
diff --git a/server/src/main/java/com/vaadin/ui/AbstractListing.java b/server/src/main/java/com/vaadin/ui/AbstractListing.java
index 1167e64505..58117e6df8 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractListing.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractListing.java
@@ -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);
}
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java
index 1a30b0f3fc..47335e4462 100644
--- a/server/src/main/java/com/vaadin/ui/Grid.java
+++ b/server/src/main/java/com/vaadin/ui/Grid.java
@@ -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;
diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingTest.java
index 3ec889f301..f29d1dd00b 100644
--- a/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingTest.java
@@ -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);
}