Преглед изворни кода

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
tags/7.5.0.alpha1
Henrik Paul пре 9 година
родитељ
комит
5c2da23e72

+ 25
- 15
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() {
@@ -1144,20 +1162,12 @@ public class GridConnector extends AbstractHasComponentsConnector implements
getWidget().onResize();
}

@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;
}
}

+ 14
- 1
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);
}
}

+ 14
- 0
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;

Loading…
Откажи
Сачувај