aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java14
-rw-r--r--server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java22
-rw-r--r--uitest/src/com/vaadin/tests/dataprovider/DataProviderTestUI.java187
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DataProviderTesterConnector.java157
4 files changed, 354 insertions, 26 deletions
diff --git a/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java b/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
index 6dc6ed4ea8..7a50a24b39 100644
--- a/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
+++ b/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
@@ -211,13 +211,13 @@ public class RpcDataSourceConnector extends AbstractExtensionConnector {
protected void setRowData(int firstRowIndex, List<JsonObject> rowData) {
super.setRowData(firstRowIndex, rowData);
- /*
- * Intercepting details information from the data source, rerouting
- * them back to the GridConnector (as a details listener)
- */
- for (int i = 0; i < rowData.size(); i++) {
- detailsListener.reapplyDetailsVisibility(firstRowIndex + i,
- rowData.get(i));
+ // TODO: Move this out of the RpcDataSource. Should be handled
+ // through some more generic interface, or specifically by Grid.
+ if (detailsListener != null) {
+ for (int i = 0; i < rowData.size(); i++) {
+ detailsListener.reapplyDetailsVisibility(firstRowIndex + i,
+ rowData.get(i));
+ }
}
}
diff --git a/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java b/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java
index 6aaeec42b0..f839437231 100644
--- a/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java
+++ b/server/src/com/vaadin/server/communication/data/RpcDataProviderExtension.java
@@ -37,6 +37,7 @@ import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.Property.ValueChangeNotifier;
+import com.vaadin.server.AbstractClientConnector;
import com.vaadin.server.AbstractExtension;
import com.vaadin.server.ClientConnector;
import com.vaadin.server.KeyMapper;
@@ -44,8 +45,6 @@ import com.vaadin.shared.data.DataProviderRpc;
import com.vaadin.shared.data.DataRequestRpc;
import com.vaadin.shared.ui.grid.GridState;
import com.vaadin.shared.ui.grid.Range;
-import com.vaadin.ui.Grid;
-import com.vaadin.ui.Grid.Column;
import elemental.json.Json;
import elemental.json.JsonArray;
@@ -194,10 +193,6 @@ public class RpcDataProviderExtension extends AbstractExtension {
}
}
- public void addColumns(Collection<Column> addedColumns) {
- updateRowData(itemId);
- }
-
private void internalAddProperties() {
for (final Object propertyId : item.getItemPropertyIds()) {
Property<?> property = item.getItemProperty(propertyId);
@@ -207,10 +202,6 @@ public class RpcDataProviderExtension extends AbstractExtension {
}
}
}
-
- public void removeColumns(Collection<Column> removedColumns) {
-
- }
}
private final Container container;
@@ -397,15 +388,8 @@ public class RpcDataProviderExtension extends AbstractExtension {
return rowObject;
}
- /**
- * Makes the data source available to the given {@link Grid} component.
- *
- * @param component
- * the remote data grid component to extend
- * @param columnKeys
- * the key mapper for columns
- */
- public void extend(Grid component) {
+ @Override
+ public void extend(AbstractClientConnector component) {
super.extend(component);
}
diff --git a/uitest/src/com/vaadin/tests/dataprovider/DataProviderTestUI.java b/uitest/src/com/vaadin/tests/dataprovider/DataProviderTestUI.java
new file mode 100644
index 0000000000..27425fb8c8
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/dataprovider/DataProviderTestUI.java
@@ -0,0 +1,187 @@
+/*
+ * 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.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.data.Container;
+import com.vaadin.data.Item;
+import com.vaadin.data.Property;
+import com.vaadin.data.util.AbstractContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.communication.data.DataGenerator;
+import com.vaadin.server.communication.data.RpcDataProviderExtension;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.ui.AbstractComponent;
+
+import elemental.json.JsonObject;
+
+@Widgetset(TestingWidgetSet.NAME)
+public class DataProviderTestUI extends AbstractTestUIWithLog {
+
+ public static class DataProviderTester extends AbstractComponent {
+
+ private RpcDataProviderExtension dataProvider;
+
+ public DataProviderTester(Container c) {
+ dataProvider = new RpcDataProviderExtension(c);
+ dataProvider.extend(this);
+
+ /* dataProvider.addDataGenerator(new DataGenerator() {
+
+ @Override
+ public void generateData(Object itemId, Item item,
+ JsonObject rowData) {
+ rowData.put("key", itemId.toString());
+ }
+
+ @Override
+ public void destroyData(Object itemId) {
+ }
+ }); */
+ }
+ }
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Container c = new AbstractContainer() {
+
+ Map<Object, Item> items = new LinkedHashMap<Object, Item>();
+
+ @Override
+ public Item getItem(Object itemId) {
+ return items.get(itemId);
+ }
+
+ @Override
+ public Collection<?> getContainerPropertyIds() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Collection<?> getItemIds() {
+ return items.keySet();
+ }
+
+ @Override
+ public Property getContainerProperty(Object itemId,
+ Object propertyId) {
+ throw new UnsupportedOperationException(
+ "No properties in this container.");
+ }
+
+ @Override
+ public Class<?> getType(Object propertyId) {
+ throw new UnsupportedOperationException(
+ "No properties in this container.");
+ }
+
+ @Override
+ public int size() {
+ return items.size();
+ }
+
+ @Override
+ public boolean containsId(Object itemId) {
+ return items.containsKey(itemId);
+ }
+
+ @Override
+ public Item addItem(Object itemId)
+ throws UnsupportedOperationException {
+ final Item value = new Item() {
+
+ @Override
+ public Property getItemProperty(Object id) {
+ throw new UnsupportedOperationException(
+ "No properties in this container.");
+ }
+
+ @Override
+ public Collection<?> getItemPropertyIds() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public boolean addItemProperty(Object id, Property property)
+ throws UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "No properties in this container.");
+ }
+
+ @Override
+ public boolean removeItemProperty(Object id)
+ throws UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "No properties in this container.");
+ }
+ };
+
+ items.put(itemId, value);
+ fireItemSetChange();
+ return value;
+ }
+
+ @Override
+ public Object addItem() throws UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "No id generation in this container.");
+ }
+
+ @Override
+ public boolean removeItem(Object itemId)
+ throws UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "No removing from this container.");
+ }
+
+ @Override
+ public boolean addContainerProperty(Object propertyId,
+ Class<?> type, Object defaultValue)
+ throws UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "No properties in this container.");
+ }
+
+ @Override
+ public boolean removeContainerProperty(Object propertyId)
+ throws UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "No properties in this container.");
+ }
+
+ @Override
+ public boolean removeAllItems()
+ throws UnsupportedOperationException {
+ throw new UnsupportedOperationException(
+ "No removing from this container.");
+ }
+ };
+
+ final DataProviderTester tester = new DataProviderTester(c);
+ tester.setSizeFull();
+ addComponent(tester);
+
+ for (Integer i = 0; i < 1000; ++i) {
+ c.addItem(i);
+ }
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DataProviderTesterConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DataProviderTesterConnector.java
new file mode 100644
index 0000000000..c96d816532
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/widgetset/client/dataprovider/DataProviderTesterConnector.java
@@ -0,0 +1,157 @@
+/*
+ * 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 com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.HTML;
+import com.vaadin.client.data.DataChangeHandler;
+import com.vaadin.client.data.DataSource;
+import com.vaadin.client.data.HasDataSource;
+import com.vaadin.client.ui.AbstractComponentConnector;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.grid.Range;
+import com.vaadin.tests.dataprovider.DataProviderTestUI.DataProviderTester;
+
+import elemental.json.JsonObject;
+
+@Connect(DataProviderTester.class)
+public class DataProviderTesterConnector extends AbstractComponentConnector
+ implements HasDataSource {
+
+ public static class DataProviderTesterWidget extends FlowPanel {
+
+ private DataSource<JsonObject> datasource;
+ private Range available;
+ private int pageLength = 20;
+ private int page = 0;
+
+ private boolean isScheduled = false;
+ private ScheduledCommand redrawCmd = new ScheduledCommand() {
+
+ @Override
+ public void execute() {
+ while (getWidgetCount() > 1) {
+ remove(1);
+ }
+
+ if (available != null) {
+ for (int i = available.getStart(); i < available.getEnd(); ++i) {
+ add(new HTML(i + ": " + datasource.getRow(i).toJson()));
+ }
+ }
+
+ isScheduled = false;
+ }
+ };
+
+ public DataProviderTesterWidget() {
+ final FlowPanel w = new FlowPanel();
+ add(w);
+ final Button previous = new Button("<");
+ previous.addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ if (page > 0) {
+ --page;
+ requestData();
+ }
+ }
+ });
+ final Button next = new Button(">");
+ next.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ if (page < (datasource.size() / pageLength) - 1) {
+ ++page;
+ requestData();
+ }
+ }
+
+ });
+
+ w.add(previous);
+ w.add(next);
+ }
+
+ public void setDataSource(DataSource<JsonObject> ds) {
+
+ datasource = ds;
+ ds.setDataChangeHandler(new DataChangeHandler() {
+
+ @Override
+ public void resetDataAndSize(int estimatedNewDataSize) {
+ redraw();
+ }
+
+ @Override
+ public void dataUpdated(int firstRowIndex, int numberOfRows) {
+ redraw();
+ }
+
+ @Override
+ public void dataRemoved(int firstRowIndex, int numberOfRows) {
+ redraw();
+ }
+
+ @Override
+ public void dataAvailable(int firstRowIndex, int numberOfRows) {
+ available = Range.withLength(firstRowIndex, numberOfRows);
+ }
+
+ @Override
+ public void dataAdded(int firstRowIndex, int numberOfRows) {
+ redraw();
+ }
+ });
+
+ datasource.ensureAvailability(0, pageLength);
+ }
+
+ protected void requestData() {
+ datasource
+ .ensureAvailability(page * pageLength, Math.min(
+ datasource.size() - page * pageLength, pageLength));
+ }
+
+ protected void redraw() {
+ if (!isScheduled) {
+ Scheduler.get().scheduleFinally(redrawCmd);
+ isScheduled = true;
+ }
+ }
+ }
+
+ @Override
+ public DataProviderTesterWidget getWidget() {
+ return (DataProviderTesterWidget) super.getWidget();
+ }
+
+ @Override
+ protected void init() {
+ super.init();
+ }
+
+ @Override
+ public void setDataSource(DataSource<JsonObject> ds) {
+ getWidget().setDataSource(ds);
+ }
+}