summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/widgetset
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2014-12-11 19:18:44 +0200
committerVaadin Code Review <review@vaadin.com>2014-12-12 06:43:41 +0000
commite1e960f62269d09b813908bcab87be3028b15397 (patch)
treec76429d49a797e25095700faf9033a56452656cc /uitest/src/com/vaadin/tests/widgetset
parent71f3551fe0e26f5d4297f98835520dbd24309ffb (diff)
downloadvaadin-framework-e1e960f62269d09b813908bcab87be3028b15397.tar.gz
vaadin-framework-e1e960f62269d09b813908bcab87be3028b15397.zip
Make AbstractRemoteDataSource easier to use (#13334)
- Adds a callback to requestRows so implementors know what to do when receiving data - Guestimate the initial amount of available rows so an initial request can be made before the actual size is known Change-Id: Iba44eab1695e3ff9947a4e7ed16eee55af98fec4
Diffstat (limited to 'uitest/src/com/vaadin/tests/widgetset')
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientDataSourcesWidget.java52
1 files changed, 26 insertions, 26 deletions
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientDataSourcesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientDataSourcesWidget.java
index 76a146bfd2..aca11cfab3 100644
--- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientDataSourcesWidget.java
+++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientDataSourcesWidget.java
@@ -18,6 +18,7 @@ package com.vaadin.tests.widgetset.client.grid;
import java.util.ArrayList;
import java.util.List;
+import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.vaadin.client.data.AbstractRemoteDataSource;
import com.vaadin.client.ui.grid.Grid;
@@ -28,6 +29,10 @@ import com.vaadin.client.ui.grid.renderers.TextRenderer;
public class GridClientDataSourcesWidget extends
PureGWTTestApplication<Grid<String[]>> {
+ private interface RestCallback {
+ void onResponse(RestishDataSource.Backend.Result result);
+ }
+
/**
* This is an emulated datasource that has a back-end that changes size
* constantly. The back-end is unable to actively push data to Grid.
@@ -66,8 +71,6 @@ public class GridClientDataSourcesWidget extends
* </ol>
*/
private class RestishDataSource extends AbstractRemoteDataSource<String[]> {
- private int currentSize = 0;
-
/**
* Pretend like this class doesn't exist. It just simulates a backend
* somewhere.
@@ -83,14 +86,22 @@ public class GridClientDataSourcesWidget extends
private int size = 200;
private int modCount = 0;
- public Result query(int firstRowIndex, int numberOfRows) {
- Result result = new Result();
+ public void query(int firstRowIndex, int numberOfRows,
+ final RestCallback callback) {
+ final Result result = new Result();
result.size = size;
- result.rows = getRows(firstRowIndex, numberOfRows);
- return result;
+ result.rows = fetchRows(firstRowIndex, numberOfRows);
+
+ Scheduler.get().scheduleDeferred(new ScheduledCommand() {
+ @Override
+ public void execute() {
+ callback.onResponse(result);
+ }
+ });
+
}
- private List<String[]> getRows(int firstRowIndex, int numberOfRows) {
+ private List<String[]> fetchRows(int firstRowIndex, int numberOfRows) {
List<String[]> rows = new ArrayList<String[]>();
for (int i = 0; i < numberOfRows; i++) {
String id = String.valueOf(firstRowIndex + i);
@@ -121,29 +132,18 @@ public class GridClientDataSourcesWidget extends
public RestishDataSource() {
backend = new Backend();
- currentSize = backend.size;
- }
-
- @Override
- public int size() {
- return currentSize;
}
@Override
- protected void requestRows(int firstRowIndex, int numberOfRows) {
- Backend.Result result = backend.query(firstRowIndex, numberOfRows);
- final List<String[]> newRows = result.rows;
-
- // order matters: first set row data, only then modify size.
+ protected void requestRows(int firstRowIndex, int numberOfRows,
+ final RequestRowsCallback<String[]> callback) {
- /* Here's the requested data. Process it, please. */
- setRowData(firstRowIndex, newRows);
-
- /* Let's check whether the backend size changed. */
- if (currentSize != result.size) {
- currentSize = result.size;
- resetDataAndSize(currentSize);
- }
+ backend.query(firstRowIndex, numberOfRows, new RestCallback() {
+ @Override
+ public void onResponse(Backend.Result result) {
+ callback.onResponse(result.rows, result.size);
+ }
+ });
}
@Override