summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorHenrik Paul <henrik@vaadin.com>2015-03-18 10:16:47 +0200
committerHenrik Paul <henrik@vaadin.com>2015-03-18 10:16:47 +0200
commit5c2da23e72e17d04e3cafc67ff1166dc313b9712 (patch)
treed2f538133a5ab3e0f54c0793ecc3a9d5355c6cb3 /client
parent251ed2cbb633778d467e0a646ad6f87e3e8ca4bb (diff)
downloadvaadin-framework-5c2da23e72e17d04e3cafc67ff1166dc313b9712.tar.gz
vaadin-framework-5c2da23e72e17d04e3cafc67ff1166dc313b9712.zip
Fixes a bug when scrolling a Grid with details open (#16644)
If the a row with an open details row was pushed out of the active row range, the component would be removed from the connector hierarchy on the server side but not on the client side. Vaadin gave a warning for this. This patch makes sure that the widget is properly deregistered when it gets outside of the active range pre-emptively. Change-Id: I2145e82a990ded31e4426e85e59edad9d4d4194f
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/connectors/GridConnector.java40
-rw-r--r--client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java15
-rw-r--r--client/src/com/vaadin/client/data/AbstractRemoteDataSource.java14
3 files changed, 53 insertions, 16 deletions
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java
index 70ad2504d8..1787dc5c97 100644
--- a/client/src/com/vaadin/client/connectors/GridConnector.java
+++ b/client/src/com/vaadin/client/connectors/GridConnector.java
@@ -29,7 +29,6 @@ import java.util.Set;
import java.util.logging.Logger;
import com.google.gwt.core.client.Scheduler;
-import com.google.gwt.core.client.Scheduler.RepeatingCommand;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.user.client.Timer;
@@ -40,6 +39,7 @@ import com.vaadin.client.DeferredWorker;
import com.vaadin.client.MouseEventDetailsBuilder;
import com.vaadin.client.annotations.OnStateChange;
import com.vaadin.client.communication.StateChangeEvent;
+import com.vaadin.client.connectors.RpcDataSourceConnector.DetailsListener;
import com.vaadin.client.connectors.RpcDataSourceConnector.RpcDataSource;
import com.vaadin.client.data.DataSource.RowHandle;
import com.vaadin.client.renderers.Renderer;
@@ -107,8 +107,7 @@ import elemental.json.JsonValue;
*/
@Connect(com.vaadin.ui.Grid.class)
public class GridConnector extends AbstractHasComponentsConnector implements
- SimpleManagedLayout, RpcDataSourceConnector.DetailsListener,
- DeferredWorker {
+ SimpleManagedLayout, DeferredWorker {
private static final class CustomCellStyleGenerator implements
CellStyleGenerator<JsonObject> {
@@ -534,6 +533,25 @@ public class GridConnector extends AbstractHasComponentsConnector implements
private final DetailsConnectorFetcher detailsConnectorFetcher = new DetailsConnectorFetcher();
+ private final DetailsListener detailsListener = new DetailsListener() {
+ @Override
+ public void reapplyDetailsVisibility(int rowIndex, JsonObject row) {
+ if (row.hasKey(GridState.JSONKEY_DETAILS_VISIBLE)
+ && row.getBoolean(GridState.JSONKEY_DETAILS_VISIBLE)) {
+ getWidget().setDetailsVisible(rowIndex, true);
+ } else {
+ getWidget().setDetailsVisible(rowIndex, false);
+ }
+
+ detailsConnectorFetcher.schedule();
+ }
+
+ @Override
+ public void closeDetails(int rowIndex) {
+ getWidget().setDetailsVisible(rowIndex, false);
+ }
+ };
+
@Override
@SuppressWarnings("unchecked")
public Grid<JsonObject> getWidget() {
@@ -1145,19 +1163,11 @@ public class GridConnector extends AbstractHasComponentsConnector implements
}
@Override
- public void reapplyDetailsVisibility(int rowIndex, JsonObject row) {
- if (row.hasKey(GridState.JSONKEY_DETAILS_VISIBLE)
- && row.getBoolean(GridState.JSONKEY_DETAILS_VISIBLE)) {
- getWidget().setDetailsVisible(rowIndex, true);
- } else {
- getWidget().setDetailsVisible(rowIndex, false);
- }
-
- detailsConnectorFetcher.schedule();
- }
-
- @Override
public boolean isWorkPending() {
return detailsConnectorFetcher.isWorkPending();
}
+
+ public DetailsListener getDetailsListener() {
+ return detailsListener;
+ }
}
diff --git a/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java b/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
index ae4249de78..e8c7ee5286 100644
--- a/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
+++ b/client/src/com/vaadin/client/connectors/RpcDataSourceConnector.java
@@ -64,6 +64,14 @@ public class RpcDataSourceConnector extends AbstractExtensionConnector {
* @see GridState#JSONKEY_DETAILS_VISIBLE
*/
void reapplyDetailsVisibility(int rowIndex, JsonObject row);
+
+ /**
+ * Closes details for a row.
+ *
+ * @param rowIndex
+ * the index of the row for which to close details
+ */
+ void closeDetails(int rowIndex);
}
public class RpcDataSource extends AbstractRemoteDataSource<JsonObject> {
@@ -213,6 +221,11 @@ public class RpcDataSourceConnector extends AbstractExtensionConnector {
rowData.get(i));
}
}
+
+ @Override
+ protected void onDropFromCache(int rowIndex) {
+ detailsListener.closeDetails(rowIndex);
+ }
}
private final RpcDataSource dataSource = new RpcDataSource();
@@ -220,7 +233,7 @@ public class RpcDataSourceConnector extends AbstractExtensionConnector {
@Override
protected void extend(ServerConnector target) {
GridConnector gridConnector = (GridConnector) target;
- dataSource.setDetailsListener(gridConnector);
+ dataSource.setDetailsListener(gridConnector.getDetailsListener());
gridConnector.setDataSource(dataSource);
}
}
diff --git a/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java b/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java
index 0ac4c33c83..152b66f2ca 100644
--- a/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java
+++ b/client/src/com/vaadin/client/data/AbstractRemoteDataSource.java
@@ -332,9 +332,23 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> {
for (int i = range.getStart(); i < range.getEnd(); i++) {
T removed = indexToRowMap.remove(Integer.valueOf(i));
keyToIndexMap.remove(getRowKey(removed));
+
+ onDropFromCache(i);
}
}
+ /**
+ * A hook that can be overridden to do something whenever a row is dropped
+ * from the cache.
+ *
+ * @since
+ * @param rowIndex
+ * the index of the dropped row
+ */
+ protected void onDropFromCache(int rowIndex) {
+ // noop
+ }
+
private void handleMissingRows(Range range) {
if (range.isEmpty()) {
return;