Change-Id: Id44af8373737734dac1149689f0e37bdfd3795d9feature/vaadin8-book
@@ -25,30 +25,30 @@ import com.vaadin.client.data.AbstractRemoteDataSource; | |||
import com.vaadin.client.data.DataSource; | |||
import com.vaadin.client.extensions.AbstractExtensionConnector; | |||
import com.vaadin.shared.data.DataRequestRpc; | |||
import com.vaadin.shared.data.typed.DataProviderClientRpc; | |||
import com.vaadin.shared.data.typed.DataCommunicatorClientRpc; | |||
import com.vaadin.shared.data.typed.DataProviderConstants; | |||
import com.vaadin.shared.ui.Connect; | |||
import com.vaadin.tokka.server.communication.data.DataProvider; | |||
import com.vaadin.tokka.server.communication.data.DataCommunicator; | |||
import elemental.json.Json; | |||
import elemental.json.JsonArray; | |||
import elemental.json.JsonObject; | |||
/** | |||
* A connector for DataProvider class. | |||
* A connector for DataCommunicator class. | |||
* | |||
* @since | |||
*/ | |||
@Connect(DataProvider.class) | |||
public class DataSourceConnector extends AbstractExtensionConnector { | |||
@Connect(DataCommunicator.class) | |||
public class DataCommunicatorConnector extends AbstractExtensionConnector { | |||
public class VaadinDataSource extends AbstractRemoteDataSource<JsonObject> { | |||
private Set<String> droppedKeys = new HashSet<String>(); | |||
protected VaadinDataSource() { | |||
registerRpc(DataProviderClientRpc.class, | |||
new DataProviderClientRpc() { | |||
registerRpc(DataCommunicatorClientRpc.class, | |||
new DataCommunicatorClientRpc() { | |||
@Override | |||
public void reset(int size) { |
@@ -27,7 +27,7 @@ import java.util.stream.Stream; | |||
import com.vaadin.server.AbstractExtension; | |||
import com.vaadin.server.ClientConnector; | |||
import com.vaadin.shared.data.DataRequestRpc; | |||
import com.vaadin.shared.data.typed.DataProviderClientRpc; | |||
import com.vaadin.shared.data.typed.DataCommunicatorClientRpc; | |||
import com.vaadin.shared.data.typed.DataProviderConstants; | |||
import com.vaadin.shared.ui.grid.Range; | |||
import com.vaadin.tokka.event.Registration; | |||
@@ -44,7 +44,7 @@ import elemental.json.JsonObject; | |||
* | |||
* @since | |||
*/ | |||
public class DataProvider<T> extends AbstractExtension { | |||
public class DataCommunicator<T> extends AbstractExtension { | |||
/** | |||
* Simple implementation of collection data provider communication. All data | |||
@@ -72,8 +72,8 @@ public class DataProvider<T> extends AbstractExtension { | |||
* longer needed. Data tracking is based on key string provided by | |||
* {@link DataKeyMapper}. | |||
* <p> | |||
* When the {@link DataProvider} is pushing new data to the client-side via | |||
* {@link DataProvider#pushData(long, Collection)}, | |||
* When the {@link DataCommunicator} is pushing new data to the client-side via | |||
* {@link DataCommunicator#pushData(long, Collection)}, | |||
* {@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 | |||
@@ -170,7 +170,7 @@ public class DataProvider<T> extends AbstractExtension { | |||
private Collection<TypedDataGenerator<T>> generators = new LinkedHashSet<TypedDataGenerator<T>>(); | |||
protected ActiveDataHandler handler = new ActiveDataHandler(); | |||
protected DataProviderClientRpc rpc; | |||
protected DataCommunicatorClientRpc rpc; | |||
protected DataSource<T> dataSource; | |||
private Registration dataChangeHandler; | |||
@@ -181,10 +181,10 @@ public class DataProvider<T> extends AbstractExtension { | |||
private final Set<T> updatedData = new HashSet<T>(); | |||
private Range pushRows = Range.withLength(0, 40); | |||
public DataProvider(DataSource<T> dataSource) { | |||
public DataCommunicator(DataSource<T> dataSource) { | |||
addDataGenerator(handler); | |||
this.dataSource = dataSource; | |||
rpc = getRpcProxy(DataProviderClientRpc.class); | |||
rpc = getRpcProxy(DataCommunicatorClientRpc.class); | |||
registerRpc(createRpc()); | |||
dataChangeHandler = this.dataSource | |||
.addDataChangeHandler(createDataChangeHandler()); | |||
@@ -250,7 +250,7 @@ public class DataProvider<T> extends AbstractExtension { | |||
} | |||
/** | |||
* Adds a {@link TypedDataGenerator} to this {@link DataProvider}. | |||
* Adds a {@link TypedDataGenerator} to this {@link DataCommunicator}. | |||
* | |||
* @param generator | |||
* typed data generator | |||
@@ -260,7 +260,7 @@ public class DataProvider<T> extends AbstractExtension { | |||
} | |||
/** | |||
* Removes a {@link TypedDataGenerator} from this {@link DataProvider}. | |||
* Removes a {@link TypedDataGenerator} from this {@link DataCommunicator}. | |||
* | |||
* @param generator | |||
* typed data generator | |||
@@ -270,7 +270,7 @@ public class DataProvider<T> extends AbstractExtension { | |||
} | |||
/** | |||
* Gets the {@link DataKeyMapper} used by this {@link DataProvider}. Key | |||
* Gets the {@link DataKeyMapper} used by this {@link DataCommunicator}. Key | |||
* mapper can be used to map keys sent to the client-side back to their | |||
* respective data objects. | |||
* | |||
@@ -342,7 +342,7 @@ public class DataProvider<T> extends AbstractExtension { | |||
/** | |||
* Clean up method for removing all listeners attached by the | |||
* {@link DataProvider}. This method is called from {@link #remove()} or | |||
* {@link DataCommunicator}. This method is called from {@link #remove()} or | |||
* when the UI gets detached. | |||
*/ | |||
protected void cleanUp() { | |||
@@ -406,7 +406,7 @@ public class DataProvider<T> extends AbstractExtension { | |||
} | |||
/** | |||
* Creates a {@link DataKeyMapper} to use with this {@link DataProvider}. | |||
* Creates a {@link DataKeyMapper} to use with this {@link DataCommunicator}. | |||
* <p> | |||
* This method is called from the constructor. | |||
* | |||
@@ -417,7 +417,7 @@ public class DataProvider<T> extends AbstractExtension { | |||
} | |||
/** | |||
* Creates a {@link DataRequestRpc} used with this {@link DataProvider}. | |||
* Creates a {@link DataRequestRpc} used with this {@link DataCommunicator}. | |||
* <p> | |||
* This method is called from the constructor. | |||
* |
@@ -20,7 +20,7 @@ import java.io.Serializable; | |||
import elemental.json.JsonObject; | |||
/** | |||
* Simple typed data generator for {@link DataProvider}. | |||
* Simple typed data generator for {@link DataCommunicator}. | |||
* | |||
* @since | |||
*/ |
@@ -20,14 +20,14 @@ import java.util.Set; | |||
import com.vaadin.server.AbstractExtension; | |||
import com.vaadin.tokka.server.ListingExtension; | |||
import com.vaadin.tokka.server.communication.data.DataProvider; | |||
import com.vaadin.tokka.server.communication.data.DataCommunicator; | |||
import com.vaadin.tokka.server.communication.data.SelectionModel; | |||
import com.vaadin.tokka.server.communication.data.TypedDataGenerator; | |||
import com.vaadin.ui.AbstractComponent; | |||
/** | |||
* Base class for Listing components. Provides common handling for | |||
* {@link DataProvider}, {@link SelectionModel} and {@link TypedDataGenerator}s. | |||
* {@link DataCommunicator}, {@link SelectionModel} and {@link TypedDataGenerator}s. | |||
* | |||
* @param <T> | |||
* listing data type | |||
@@ -83,7 +83,7 @@ public abstract class AbstractListing<T> extends AbstractComponent implements | |||
* @return the data object | |||
*/ | |||
protected T getData(String key) { | |||
DataProvider<T> dataProvider = getParent().getDataProvider(); | |||
DataCommunicator<T> dataProvider = getParent().getDataCommunicator(); | |||
if (dataProvider != null) { | |||
return dataProvider.getKeyMapper().get(key); | |||
} | |||
@@ -103,7 +103,7 @@ public abstract class AbstractListing<T> extends AbstractComponent implements | |||
* data object to refresh | |||
*/ | |||
protected void refresh(T data) { | |||
DataProvider<T> dataProvider = getParent().getDataProvider(); | |||
DataCommunicator<T> dataProvider = getParent().getDataCommunicator(); | |||
if (dataProvider != null) { | |||
dataProvider.refresh(data); | |||
} | |||
@@ -111,14 +111,14 @@ public abstract class AbstractListing<T> extends AbstractComponent implements | |||
} | |||
/* DataProvider for this Listing component */ | |||
private DataProvider<T> dataProvider; | |||
private DataCommunicator<T> dataCommunicator; | |||
/* TypedDataGenerators used by this Listing */ | |||
private Set<TypedDataGenerator<T>> generators = new LinkedHashSet<>(); | |||
/* SelectionModel for this Listing */ | |||
private SelectionModel<T> selectionModel; | |||
/** | |||
* Adds a {@link TypedDataGenerator} for the {@link DataProvider} of this | |||
* Adds a {@link TypedDataGenerator} for the {@link DataCommunicator} of this | |||
* Listing component. | |||
* | |||
* @param generator | |||
@@ -127,13 +127,13 @@ public abstract class AbstractListing<T> extends AbstractComponent implements | |||
protected void addDataGenerator(TypedDataGenerator<T> generator) { | |||
generators.add(generator); | |||
if (dataProvider != null) { | |||
dataProvider.addDataGenerator(generator); | |||
if (dataCommunicator != null) { | |||
dataCommunicator.addDataGenerator(generator); | |||
} | |||
} | |||
/** | |||
* Removed a {@link TypedDataGenerator} from the {@link DataProvider} of | |||
* Removed a {@link TypedDataGenerator} from the {@link DataCommunicator} of | |||
* this Listing component. | |||
* | |||
* @param generator | |||
@@ -142,8 +142,8 @@ public abstract class AbstractListing<T> extends AbstractComponent implements | |||
protected void removeDataGenerator(TypedDataGenerator<T> generator) { | |||
generators.remove(generator); | |||
if (dataProvider != null) { | |||
dataProvider.removeDataGenerator(generator); | |||
if (dataCommunicator != null) { | |||
dataCommunicator.removeDataGenerator(generator); | |||
} | |||
} | |||
@@ -154,16 +154,16 @@ public abstract class AbstractListing<T> extends AbstractComponent implements | |||
* @param dataProvider | |||
* new data provider | |||
*/ | |||
protected void setDataProvider(DataProvider<T> dataProvider) { | |||
if (this.dataProvider == dataProvider) { | |||
protected void setDataCommunicator(DataCommunicator<T> dataProvider) { | |||
if (this.dataCommunicator == dataProvider) { | |||
return; | |||
} | |||
if (this.dataProvider != null) { | |||
this.dataProvider.remove(); | |||
if (this.dataCommunicator != null) { | |||
this.dataCommunicator.remove(); | |||
} | |||
this.dataProvider = dataProvider; | |||
this.dataCommunicator = dataProvider; | |||
if (dataProvider != null) { | |||
addExtension(dataProvider); | |||
@@ -177,12 +177,12 @@ public abstract class AbstractListing<T> extends AbstractComponent implements | |||
} | |||
/** | |||
* Get the {@link DataProvider} of this Listing component. | |||
* Get the {@link DataCommunicator} of this Listing component. | |||
* | |||
* @return data provider | |||
*/ | |||
protected DataProvider<T> getDataProvider() { | |||
return dataProvider; | |||
protected DataCommunicator<T> getDataCommunicator() { | |||
return dataCommunicator; | |||
} | |||
@SuppressWarnings("unchecked") |
@@ -19,7 +19,7 @@ import java.util.LinkedHashMap; | |||
import java.util.Map; | |||
import java.util.function.Function; | |||
import com.vaadin.tokka.server.communication.data.DataProvider; | |||
import com.vaadin.tokka.server.communication.data.DataCommunicator; | |||
import com.vaadin.tokka.server.communication.data.DataSource; | |||
import com.vaadin.tokka.server.communication.data.SingleSelection; | |||
import com.vaadin.tokka.ui.components.AbstractListing; | |||
@@ -36,7 +36,7 @@ public class Grid<T> extends AbstractListing<T> { | |||
@Override | |||
public void setDataSource(DataSource<T> data) { | |||
this.dataSource = data; | |||
setDataProvider(new DataProvider<>(data)); | |||
setDataCommunicator(new DataCommunicator<>(data)); | |||
} | |||
@Override |
@@ -18,7 +18,7 @@ package com.vaadin.tokka.ui.components.nativeselect; | |||
import java.util.function.Function; | |||
import com.vaadin.shared.data.typed.DataProviderConstants; | |||
import com.vaadin.tokka.server.communication.data.DataProvider; | |||
import com.vaadin.tokka.server.communication.data.DataCommunicator; | |||
import com.vaadin.tokka.server.communication.data.DataSource; | |||
import com.vaadin.tokka.server.communication.data.SingleSelection; | |||
import com.vaadin.tokka.server.communication.data.TypedDataGenerator; | |||
@@ -56,9 +56,9 @@ public class NativeSelect<T> extends AbstractListing<T> { | |||
public void setDataSource(DataSource<T> data) { | |||
dataSource = data; | |||
if (dataSource != null) { | |||
setDataProvider(new DataProvider<>(dataSource)); | |||
setDataCommunicator(new DataCommunicator<>(dataSource)); | |||
} else { | |||
setDataProvider(null); | |||
setDataCommunicator(null); | |||
} | |||
} | |||
@@ -8,7 +8,7 @@ import org.junit.Before; | |||
import org.junit.Test; | |||
import com.vaadin.tokka.server.communication.data.AbstractDataSource; | |||
import com.vaadin.tokka.server.communication.data.DataProvider; | |||
import com.vaadin.tokka.server.communication.data.DataCommunicator; | |||
import com.vaadin.tokka.server.communication.data.DataSource; | |||
import com.vaadin.tokka.ui.components.AbstractListing; | |||
import com.vaadin.tokka.ui.components.AbstractListing.AbstractListingExtension; | |||
@@ -38,7 +38,7 @@ public class AbstractListingTest { | |||
@Override | |||
public void setDataSource(DataSource<String> data) { | |||
this.data = data; | |||
setDataProvider(new DataProvider<>(data)); | |||
setDataCommunicator(new DataCommunicator<>(data)); | |||
} | |||
@Override | |||
@@ -76,7 +76,7 @@ public class AbstractListingTest { | |||
CountGenerator countGenerator = new CountGenerator(); | |||
countGenerator.extend(testComponent); | |||
testComponent.getDataProvider().beforeClientResponse(true); | |||
testComponent.getDataCommunicator().beforeClientResponse(true); | |||
assertEquals("Generator was not called.", 1, countGenerator.callCount); | |||
} | |||
@@ -87,7 +87,7 @@ public class AbstractListingTest { | |||
countGenerator.extend(testComponent); | |||
countGenerator.remove(); | |||
testComponent.getDataProvider().beforeClientResponse(true); | |||
testComponent.getDataCommunicator().beforeClientResponse(true); | |||
assertEquals("Generator was called.", 0, countGenerator.callCount); | |||
} |
@@ -24,7 +24,7 @@ import elemental.json.JsonObject; | |||
* | |||
* @since | |||
*/ | |||
public interface DataProviderClientRpc extends ClientRpc { | |||
public interface DataCommunicatorClientRpc extends ClientRpc { | |||
/** | |||
* Informs the client-side DataSource that all data has been invalidated. |