/**
* 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.
*
* {@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
}
}
- private Collection<TypedDataGenerator<T>> generators = new LinkedHashSet<>();
+ private Collection<DataGenerator<T>> generators = new LinkedHashSet<>();
private ActiveDataHandler handler = new ActiveDataHandler();
private DataSource<T> dataSource;
* @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);
}
* @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);
}
protected JsonObject getDataObject(T data) {
JsonObject dataObject = Json.createObject();
- for (TypedDataGenerator<T> generator : generators) {
+ for (DataGenerator<T> generator : generators) {
generator.generateData(data, dataObject);
}
/**
* 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
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);
}
}
--- /dev/null
+/*
+ * 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) {
+ }
+}
+++ /dev/null
-/*
- * 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
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
* 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.
* @param generator
* the data generator to add, not null
*/
- protected void addDataGenerator(TypedDataGenerator<T> generator) {
+ protected void addDataGenerator(DataGenerator<T> generator) {
getDataCommunicator().addDataGenerator(generator);
}
* @param generator
* the data generator to remove, not null
*/
- protected void removeDataGenerator(TypedDataGenerator<T> generator) {
+ protected void removeDataGenerator(DataGenerator<T> generator) {
getDataCommunicator().removeDataGenerator(generator);
}
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;
* 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;
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;
}
@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);
}