aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeamcity <build@vaadin.com>2015-04-22 16:24:04 +0300
committerTeamcity <build@vaadin.com>2015-04-22 16:24:04 +0300
commitc9cfb4564eda3851d7f7b51a0d30138b95c4203b (patch)
tree408f4818acba6a8ae67b258b15934f6f53853a6e
parent6e5679cda4d9214646bc2b52e5971eb8e9e3dc63 (diff)
parentd001f62bd15ef08a46c04dc3d3e507abeb829397 (diff)
downloadvaadin-framework-c9cfb4564eda3851d7f7b51a0d30138b95c4203b.tar.gz
vaadin-framework-c9cfb4564eda3851d7f7b51a0d30138b95c4203b.zip
Merge branch 'refs/heads/master' into 'snapshot/7.5'
-rw-r--r--client/src/com/vaadin/client/data/AbstractRemoteDataSource.java33
-rw-r--r--client/src/com/vaadin/client/widget/grid/datasources/ListDataSource.java9
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridClientDataChangeHandler.java32
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridClientDataChangeHandlerTest.java38
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/grid/GridDataChangeHandlerWidget.java120
5 files changed, 212 insertions, 20 deletions
diff --git a/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java b/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java
index 88977d85ec..459127c9b4 100644
--- a/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java
+++ b/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java
@@ -166,7 +166,7 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> {
@Override
public void updateRow() {
int index = indexOf(row);
- if (index >= 0) {
+ if (index >= 0 && dataChangeHandler != null) {
dataChangeHandler.dataUpdated(index, 1);
}
}
@@ -301,7 +301,7 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> {
.partitionWith(cached);
handleMissingRows(missingCachePartition[0]);
handleMissingRows(missingCachePartition[2]);
- } else {
+ } else if (dataChangeHandler != null) {
dataChangeHandler.dataAvailable(cached.getStart(),
cached.length());
}
@@ -414,7 +414,6 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> {
* a list of rows, starting from <code>firstRowIndex</code>
*/
protected void setRowData(int firstRowIndex, List<T> rowData) {
-
assert firstRowIndex + rowData.size() <= size();
Profiler.enter("AbstractRemoteDataSource.setRowData");
@@ -464,7 +463,10 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> {
cached = newUsefulData;
}
}
- dataChangeHandler.dataAvailable(cached.getStart(), cached.length());
+ if (dataChangeHandler != null) {
+ dataChangeHandler.dataAvailable(cached.getStart(),
+ cached.length());
+ }
updatePinnedRows(rowData);
}
@@ -531,8 +533,9 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> {
cached = cached.offsetBy(-removedRange.length());
}
- assertDataChangeHandlerIsInjected();
- dataChangeHandler.dataRemoved(firstRowIndex, count);
+ if (dataChangeHandler != null) {
+ dataChangeHandler.dataRemoved(firstRowIndex, count);
+ }
ensureCoverageCheck();
Profiler.leave("AbstractRemoteDataSource.removeRowData");
@@ -577,8 +580,9 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> {
keyToIndexMap.remove(getRowKey(row));
}
}
- assertDataChangeHandlerIsInjected();
- dataChangeHandler.dataAdded(firstRowIndex, count);
+ if (dataChangeHandler != null) {
+ dataChangeHandler.dataAdded(firstRowIndex, count);
+ }
ensureCoverageCheck();
Profiler.leave("AbstractRemoteDataSource.insertRowData");
@@ -724,15 +728,8 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> {
size = newSize;
dropFromCache(getCachedRange());
cached = Range.withLength(0, 0);
- assertDataChangeHandlerIsInjected();
- dataChangeHandler.resetDataAndSize(newSize);
- }
-
- private void assertDataChangeHandlerIsInjected() {
- assert dataChangeHandler != null : "The dataChangeHandler was "
- + "called before it was injected. Maybe you tried "
- + "to manipulate the data in the DataSource's "
- + "constructor instead of in overriding onAttach() "
- + "and doing it there?";
+ if (dataChangeHandler != null) {
+ dataChangeHandler.resetDataAndSize(newSize);
+ }
}
}
diff --git a/client/src/com/vaadin/client/widget/grid/datasources/ListDataSource.java b/client/src/com/vaadin/client/widget/grid/datasources/ListDataSource.java
index 47e072490e..46e972b3e8 100644
--- a/client/src/com/vaadin/client/widget/grid/datasources/ListDataSource.java
+++ b/client/src/com/vaadin/client/widget/grid/datasources/ListDataSource.java
@@ -110,7 +110,9 @@ public class ListDataSource<T> implements DataSource<T> {
@Override
public void updateRow() {
- changeHandler.dataUpdated(ds.indexOf(getRow()), 1);
+ if (changeHandler != null) {
+ changeHandler.dataUpdated(ds.indexOf(getRow()), 1);
+ }
}
}
@@ -389,7 +391,10 @@ public class ListDataSource<T> implements DataSource<T> {
throw new IllegalStateException(
"Trying to fetch rows outside of array");
}
- changeHandler.dataAvailable(firstRowIndex, numberOfRows);
+
+ if (changeHandler != null) {
+ changeHandler.dataAvailable(firstRowIndex, numberOfRows);
+ }
}
@Override
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridClientDataChangeHandler.java b/uitest/src/com/vaadin/tests/components/grid/GridClientDataChangeHandler.java
new file mode 100644
index 0000000000..7bd1c838d7
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridClientDataChangeHandler.java
@@ -0,0 +1,32 @@
+/*
+ * 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.components.grid;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.tests.widgetset.client.grid.GridDataChangeHandlerWidget;
+import com.vaadin.tests.widgetset.server.TestWidgetComponent;
+
+@Widgetset(TestingWidgetSet.NAME)
+public class GridClientDataChangeHandler extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ addComponent(new TestWidgetComponent(GridDataChangeHandlerWidget.class));
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridClientDataChangeHandlerTest.java b/uitest/src/com/vaadin/tests/components/grid/GridClientDataChangeHandlerTest.java
new file mode 100644
index 0000000000..251039c644
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/GridClientDataChangeHandlerTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.components.grid;
+
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.NotificationElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class GridClientDataChangeHandlerTest extends SingleBrowserTest {
+
+ @Test
+ public void testNoErrorsOnGridInit() throws InterruptedException {
+ setDebug(true);
+ openTestURL();
+
+ // Wait for delayed functionality.
+ sleep(1000);
+
+ assertFalse("Unexpected exception is visible.",
+ $(NotificationElement.class).exists());
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridDataChangeHandlerWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridDataChangeHandlerWidget.java
new file mode 100644
index 0000000000..a865d90b43
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridDataChangeHandlerWidget.java
@@ -0,0 +1,120 @@
+/*
+ * 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.grid;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.RepeatingCommand;
+import com.google.gwt.user.client.Timer;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.SimplePanel;
+import com.vaadin.client.data.AbstractRemoteDataSource;
+import com.vaadin.client.widget.grid.datasources.ListDataSource;
+import com.vaadin.client.widgets.Grid;
+import com.vaadin.client.widgets.Grid.Column;
+
+public class GridDataChangeHandlerWidget extends Composite {
+
+ private final SimplePanel panel = new SimplePanel();
+ private final Grid<String> grid = new Grid<String>();
+
+ public static class DelayedDataSource extends ListDataSource<String> {
+
+ public DelayedDataSource(List<String> datasource) {
+ super(datasource);
+ }
+
+ @Override
+ public void ensureAvailability(final int firstRowIndex,
+ final int numberOfRows) {
+ new Timer() {
+
+ @Override
+ public void run() {
+ actualEnsureAvailability(firstRowIndex, numberOfRows);
+ }
+ }.schedule(500);
+ }
+
+ private void actualEnsureAvailability(int firstRowIndex,
+ int numberOfRows) {
+ super.ensureAvailability(firstRowIndex, numberOfRows);
+ }
+ }
+
+ public static class RemoteDelayedDataSource extends
+ AbstractRemoteDataSource<String> {
+
+ private List<String> rows;
+
+ public RemoteDelayedDataSource(List<String> datasource) {
+ super();
+ rows = datasource;
+ }
+
+ @Override
+ protected void requestRows(final int firstRowIndex,
+ final int numberOfRows,
+ final RequestRowsCallback<String> callback) {
+ new Timer() {
+
+ @Override
+ public void run() {
+ List<String> requested = rows.subList(firstRowIndex,
+ numberOfRows);
+ callback.onResponse(requested, requested.size());
+ }
+ }.schedule(500);
+ }
+
+ @Override
+ public Object getRowKey(String row) {
+ return row;
+ }
+
+ }
+
+ public GridDataChangeHandlerWidget() {
+ initWidget(panel);
+
+ panel.setWidget(grid);
+ grid.setDataSource(new RemoteDelayedDataSource(Arrays.asList("A", "B",
+ "C", "D", "E")));
+ grid.addColumn(new Column<String, String>("letter") {
+ @Override
+ public String getValue(String row) {
+ return row;
+ }
+ });
+ Scheduler.get().scheduleFinally(new RepeatingCommand() {
+
+ boolean run = false;
+
+ @Override
+ public boolean execute() {
+ grid.setDataSource(new DelayedDataSource(Arrays.asList("X",
+ "Y", "Z")));
+ if (run) {
+ return false;
+ }
+ run = true;
+ return true;
+ }
+ });
+ }
+}