aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-01-29 14:20:01 +0200
committerTeemu Suo-Anttila <teemusa@vaadin.com>2016-01-29 14:20:01 +0200
commit4274350c31bb7bf4c3a8b5672bdac877f75cc069 (patch)
tree1b271f0ca8f5407412e23bc95da102b18859e83a
parent3ecb2cab7c35118fb21699953518eaaa04e92d9e (diff)
downloadvaadin-framework-4274350c31bb7bf4c3a8b5672bdac877f75cc069.tar.gz
vaadin-framework-4274350c31bb7bf4c3a8b5672bdac877f75cc069.zip
Add a dummy DataProvider for Collections
Change-Id: I190e807094d8e235797e618ea80cb4b7136d1111
-rw-r--r--client/src/com/vaadin/client/connectors/GridConnector.java4
-rw-r--r--client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java2
-rw-r--r--client/src/com/vaadin/client/connectors/data/typed/DataSourceConnector.java48
-rw-r--r--client/src/com/vaadin/client/data/HasDataSource.java6
-rw-r--r--server/src/com/vaadin/server/communication/data/typed/DataProvider.java62
-rw-r--r--uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java54
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DummyDataConnector.java52
7 files changed, 223 insertions, 5 deletions
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java
index 1a50b905de..15901656ff 100644
--- a/client/src/com/vaadin/client/connectors/GridConnector.java
+++ b/client/src/com/vaadin/client/connectors/GridConnector.java
@@ -48,9 +48,9 @@ import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
import com.vaadin.client.connectors.RpcDataSourceConnector.DetailsListener;
import com.vaadin.client.connectors.RpcDataSourceConnector.RpcDataSource;
-import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.client.data.DataSource;
import com.vaadin.client.data.HasDataSource;
+import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.client.ui.AbstractHasComponentsConnector;
import com.vaadin.client.ui.ConnectorFocusAndBlurHandler;
import com.vaadin.client.ui.SimpleManagedLayout;
@@ -112,7 +112,7 @@ import elemental.json.JsonValue;
*/
@Connect(com.vaadin.ui.Grid.class)
public class GridConnector extends AbstractHasComponentsConnector implements
- SimpleManagedLayout, DeferredWorker, HasDataSource<JsonObject> {
+ SimpleManagedLayout, DeferredWorker, HasDataSource {
private static final class CustomStyleGenerator implements
CellStyleGenerator<JsonObject>, RowStyleGenerator<JsonObject> {
diff --git a/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java b/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
index f9f10158ed..6dc6ed4ea8 100644
--- a/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
+++ b/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
@@ -248,7 +248,7 @@ public class RpcDataSourceConnector extends AbstractExtensionConnector {
@Override
protected void extend(ServerConnector target) {
if (target instanceof HasDataSource) {
- ((HasDataSource<JsonObject>) target).setDataSource(dataSource);
+ ((HasDataSource) target).setDataSource(dataSource);
} else {
throw new IllegalArgumentException(
"Parent connector does not implement HasDataSource");
diff --git a/client/src/com/vaadin/client/connectors/data/typed/DataSourceConnector.java b/client/src/com/vaadin/client/connectors/data/typed/DataSourceConnector.java
new file mode 100644
index 0000000000..e122787851
--- /dev/null
+++ b/client/src/com/vaadin/client/connectors/data/typed/DataSourceConnector.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2000-2014 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.client.connectors.data.typed;
+
+import com.vaadin.client.ServerConnector;
+import com.vaadin.client.data.DataSource;
+import com.vaadin.client.data.HasDataSource;
+import com.vaadin.client.extensions.AbstractExtensionConnector;
+import com.vaadin.client.widget.grid.datasources.ListDataSource;
+import com.vaadin.server.communication.data.typed.DataProvider;
+import com.vaadin.shared.ui.Connect;
+
+import elemental.json.JsonObject;
+
+/**
+ * A simple connector for DataProvider class.
+ *
+ * @since
+ */
+@Connect(DataProvider.class)
+public class DataSourceConnector extends AbstractExtensionConnector {
+
+ DataSource<JsonObject> ds = new ListDataSource<JsonObject>();
+
+ @Override
+ protected void extend(ServerConnector target) {
+ ServerConnector parent = getParent();
+ if (parent instanceof HasDataSource) {
+ ((HasDataSource) parent).setDataSource(ds);
+ } else {
+ assert false : "Parent not implementing HasDataSource";
+ }
+ }
+
+}
diff --git a/client/src/com/vaadin/client/data/HasDataSource.java b/client/src/com/vaadin/client/data/HasDataSource.java
index 97e52b2d94..d7572ff291 100644
--- a/client/src/com/vaadin/client/data/HasDataSource.java
+++ b/client/src/com/vaadin/client/data/HasDataSource.java
@@ -15,12 +15,14 @@
*/
package com.vaadin.client.data;
+import elemental.json.JsonObject;
+
/**
* Interface describing a class that supports setting a {@link DataSource}.
*
* @since
*/
-public interface HasDataSource<T> {
+public interface HasDataSource {
- public void setDataSource(DataSource<T> ds);
+ public void setDataSource(DataSource<JsonObject> ds);
}
diff --git a/server/src/com/vaadin/server/communication/data/typed/DataProvider.java b/server/src/com/vaadin/server/communication/data/typed/DataProvider.java
new file mode 100644
index 0000000000..13755a5ce8
--- /dev/null
+++ b/server/src/com/vaadin/server/communication/data/typed/DataProvider.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2000-2014 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.communication.data.typed;
+
+import java.util.Collection;
+
+import com.vaadin.server.AbstractExtension;
+import com.vaadin.shared.data.DataRequestRpc;
+import com.vaadin.ui.AbstractComponent;
+
+import elemental.json.JsonArray;
+
+/**
+ * DataProvider for Collection "container".
+ *
+ * @since
+ */
+public class DataProvider<T> extends AbstractExtension {
+
+ private Collection<T> data;
+
+ /**
+ * Creates a new DataProvider, connecting it to given Collection and
+ * Component
+ *
+ * @param data
+ * collection of data to use
+ * @param component
+ * component to extend
+ */
+ public DataProvider(Collection<T> data, AbstractComponent component) {
+ this.data = data;
+ extend(component);
+
+ registerRpc(new DataRequestRpc() {
+ @Override
+ public void requestRows(int firstRowIndex, int numberOfRows,
+ int firstCachedRowIndex, int cacheSize) {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ @Override
+ public void dropRows(JsonArray rowKeys) {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+ });
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java b/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java
new file mode 100644
index 0000000000..943c2b3b96
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2000-2014 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.tests.dataprovider;
+
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.Random;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.communication.data.typed.DataProvider;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.fieldgroup.ComplexPerson;
+import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.ui.AbstractComponent;
+
+@Widgetset(TestingWidgetSet.NAME)
+public class DummyDataProviderUI extends AbstractTestUI {
+
+ public static class DummyDataComponent<T> extends AbstractComponent {
+
+ public DummyDataComponent(Collection<T> data) {
+ new DataProvider<T>(data, this);
+ }
+
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ addComponent(new DummyDataComponent<ComplexPerson>(getPersons(20)));
+ }
+
+ private Collection<ComplexPerson> getPersons(int count) {
+ Random r = new Random(1337);
+ Collection<ComplexPerson> c = new LinkedHashSet<ComplexPerson>();
+ for (int i = 0; i < count; ++i) {
+ c.add(ComplexPerson.create(r));
+ }
+ return c;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DummyDataConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DummyDataConnector.java
new file mode 100644
index 0000000000..fab7dbe75e
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DummyDataConnector.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2000-2014 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.tests.widgetset.client.dataprovider;
+
+import java.util.logging.Logger;
+
+import com.vaadin.client.data.DataSource;
+import com.vaadin.client.data.HasDataSource;
+import com.vaadin.client.ui.AbstractComponentConnector;
+import com.vaadin.client.ui.VLabel;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.tests.dataprovider.DummyDataProviderUI.DummyDataComponent;
+
+import elemental.json.JsonObject;
+
+@Connect(DummyDataComponent.class)
+public class DummyDataConnector extends AbstractComponentConnector implements
+ HasDataSource {
+
+ @Override
+ public VLabel getWidget() {
+ return (VLabel) super.getWidget();
+ }
+
+ @Override
+ protected void init() {
+ super.init();
+
+ getWidget().setText("foo");
+ }
+
+ @Override
+ public void setDataSource(DataSource<JsonObject> ds) {
+ Logger.getLogger("foo").warning(
+ "I'm not using the data source for anything!");
+ // TODO: implement access to data source
+ }
+
+}