summaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java/com
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2019-08-29 16:06:25 +0300
committerGitHub <noreply@github.com>2019-08-29 16:06:25 +0300
commit6c190de82c22232cf9d59b807530b07822b0dfae (patch)
treecbb9f7c0ba75e3f80c5a3ea8c5dd4533aeb089cc /uitest/src/main/java/com
parentbcb5aada51b1f70fbf26355b039b4d4a6b3c2987 (diff)
downloadvaadin-framework-6c190de82c22232cf9d59b807530b07822b0dfae.tar.gz
vaadin-framework-6c190de82c22232cf9d59b807530b07822b0dfae.zip
Updated row and spacer handling for Escalator (#11438)
Updated row and spacer handling for Escalator. Main changes: - Spacers are only maintained and checked for rows that have DOM representation, and not at all if there is no details generator. This gives notable performance improvements to some particularly large Grids - Escalator no longer tries to trim away any rows that don't fit within the viewport just because a details row gets opened in Grid. This leads to some increase in simultaneous DOM elements, but simplifies the logic considerably. For example opening or closing details rows doesn't require checking the overall content validity beyond the details row itself anymore, but some repositioning at most. There are also no longer any orphaned spacers without corresponding DOM rows. - Spacers are better integrated into the overall position calculations. - Some public methods that are no longer used by Escalator or have changed functionality or order of operations. Any extending classes that tap into row, spacer, or scroll position handling are likely to need reworking after this update. - Auto-detecting row height is delayed until Escalator is both attached and displayed.
Diffstat (limited to 'uitest/src/main/java/com')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBigDetailsManager.java37
-rw-r--r--uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java68
-rw-r--r--uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java5
3 files changed, 102 insertions, 8 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBigDetailsManager.java b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBigDetailsManager.java
index 5699ee4372..8fb9a358e4 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBigDetailsManager.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridBigDetailsManager.java
@@ -48,7 +48,7 @@ public class TreeGridBigDetailsManager extends AbstractTestUI {
treeGrid.setSizeFull();
treeGrid.addColumn(String::toString).setCaption("String")
.setId("string");
- treeGrid.addColumn((i) -> "--").setCaption("Nothing");
+ treeGrid.addColumn((i) -> items.indexOf(i)).setCaption("Index");
treeGrid.setHierarchyColumn("string");
treeGrid.setDetailsGenerator(
row -> new Label("details for " + row.toString()));
@@ -77,21 +77,54 @@ public class TreeGridBigDetailsManager extends AbstractTestUI {
treeGrid.collapse(items);
});
collapseAll.setId("collapseAll");
+ @SuppressWarnings("deprecation")
Button scrollTo55 = new Button("Scroll to 55",
event -> treeGrid.scrollTo(55));
scrollTo55.setId("scrollTo55");
scrollTo55.setVisible(false);
+ Button scrollTo3055 = new Button("Scroll to 3055",
+ event -> treeGrid.scrollTo(3055));
+ scrollTo3055.setId("scrollTo3055");
+ scrollTo3055.setVisible(false);
+ Button scrollToEnd = new Button("Scroll to end",
+ event -> treeGrid.scrollToEnd());
+ scrollToEnd.setId("scrollToEnd");
+ scrollToEnd.setVisible(false);
+ Button scrollToStart = new Button("Scroll to start",
+ event -> treeGrid.scrollToStart());
+ scrollToStart.setId("scrollToStart");
+ scrollToStart.setVisible(false);
+
+ Button toggle15 = new Button("Toggle 15",
+ event -> treeGrid.setDetailsVisible(items.get(15),
+ !treeGrid.isDetailsVisible(items.get(15))));
+ toggle15.setId("toggle15");
+ toggle15.setVisible(false);
+
+ Button toggle3000 = new Button("Toggle 3000",
+ event -> treeGrid.setDetailsVisible(items.get(3000),
+ !treeGrid.isDetailsVisible(items.get(3000))));
+ toggle3000.setId("toggle3000");
+ toggle3000.setVisible(false);
+
Button addGrid = new Button("Add grid", event -> {
addComponent(treeGrid);
getLayout().setExpandRatio(treeGrid, 2);
scrollTo55.setVisible(true);
+ scrollTo3055.setVisible(true);
+ scrollToEnd.setVisible(true);
+ scrollToStart.setVisible(true);
+ toggle15.setVisible(true);
+ toggle3000.setVisible(true);
});
addGrid.setId("addGrid");
addComponents(
new HorizontalLayout(showDetails, hideDetails, expandAll,
collapseAll),
- new HorizontalLayout(addGrid, scrollTo55));
+ new HorizontalLayout(scrollTo55, scrollTo3055, scrollToEnd,
+ scrollToStart),
+ new HorizontalLayout(addGrid, toggle15, toggle3000));
getLayout().getParent().setHeight("100%");
getLayout().setHeight("100%");
diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java
index 2d7dd5cc37..941f1ce928 100644
--- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java
+++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java
@@ -1,9 +1,12 @@
package com.vaadin.tests.widgetset.client.grid;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import com.google.gwt.core.client.Duration;
+import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.TableCellElement;
import com.google.gwt.user.client.DOM;
@@ -16,6 +19,8 @@ import com.vaadin.client.widget.escalator.RowContainer;
import com.vaadin.client.widget.escalator.RowContainer.BodyRowContainer;
import com.vaadin.client.widget.escalator.Spacer;
import com.vaadin.client.widget.escalator.SpacerUpdater;
+import com.vaadin.client.widget.escalator.events.SpacerIndexChangedEvent;
+import com.vaadin.client.widget.escalator.events.SpacerIndexChangedHandler;
import com.vaadin.client.widgets.Escalator;
import com.vaadin.shared.ui.grid.ScrollDestination;
import com.vaadin.tests.widgetset.client.v7.grid.PureGWTTestApplication;
@@ -156,6 +161,7 @@ public class EscalatorBasicClientFeaturesWidget
private int rowCounter = 0;
private final List<Integer> columns = new ArrayList<>();
private final List<Integer> rows = new ArrayList<>();
+ private final Map<Integer, Integer> spacers = new HashMap<>();
@SuppressWarnings("boxing")
public void insertRows(final int offset, final int amount) {
@@ -247,6 +253,11 @@ public class EscalatorBasicClientFeaturesWidget
cell.setColSpan(2);
}
}
+ if (spacers.containsKey(cell.getRow()) && !escalator
+ .getBody().spacerExists(cell.getRow())) {
+ escalator.getBody().setSpacer(cell.getRow(),
+ spacers.get(cell.getRow()));
+ }
}
@Override
@@ -262,7 +273,12 @@ public class EscalatorBasicClientFeaturesWidget
public void removeRows(final int offset, final int amount) {
for (int i = 0; i < amount; i++) {
rows.remove(offset);
+ if (spacers.containsKey(offset + i)) {
+ spacers.remove(offset + i);
+ }
}
+ // the following spacers get their indexes updated through
+ // SpacerIndexChangedHandler
}
public void removeColumns(final int offset, final int amount) {
@@ -313,6 +329,21 @@ public class EscalatorBasicClientFeaturesWidget
createFrozenMenu();
createColspanMenu();
createSpacerMenu();
+
+ escalator.addHandler(new SpacerIndexChangedHandler() {
+ @Override
+ public void onSpacerIndexChanged(SpacerIndexChangedEvent event) {
+ // remove spacer from old index and move to new index
+ Integer height = data.spacers.remove(event.getOldIndex());
+ if (height != null) {
+ data.spacers.put(event.getNewIndex(), height);
+ } else {
+ // no height, make sure the new index doesn't
+ // point to anything else either
+ data.spacers.remove(event.getNewIndex());
+ }
+ }
+ }, SpacerIndexChangedEvent.TYPE);
}
private void createFrozenMenu() {
@@ -558,11 +589,24 @@ public class EscalatorBasicClientFeaturesWidget
@Override
public void init(Spacer spacer) {
spacer.getElement().appendChild(DOM.createInputText());
+ updateRowPositions(spacer);
}
@Override
public void destroy(Spacer spacer) {
spacer.getElement().removeAllChildren();
+ updateRowPositions(spacer);
+ }
+
+ private void updateRowPositions(Spacer spacer) {
+ if (spacer.getRow() < escalator.getBody()
+ .getRowCount()) {
+ Scheduler.get().scheduleFinally(() -> {
+ escalator.getBody().updateRowPositions(
+ spacer.getRow(),
+ escalator.getBody().getRowCount());
+ });
+ }
}
}), menupath);
@@ -575,12 +619,18 @@ public class EscalatorBasicClientFeaturesWidget
private void createSpacersMenuForRow(final int rowIndex,
String[] menupath) {
menupath = new String[] { menupath[0], menupath[1], "Row " + rowIndex };
- addMenuCommand("Set 100px",
- () -> escalator.getBody().setSpacer(rowIndex, 100), menupath);
- addMenuCommand("Set 50px",
- () -> escalator.getBody().setSpacer(rowIndex, 50), menupath);
- addMenuCommand("Remove",
- () -> escalator.getBody().setSpacer(rowIndex, -1), menupath);
+ addMenuCommand("Set 100px", () -> {
+ escalator.getBody().setSpacer(rowIndex, 100);
+ data.spacers.put(rowIndex, 100);
+ }, menupath);
+ addMenuCommand("Set 50px", () -> {
+ escalator.getBody().setSpacer(rowIndex, 50);
+ data.spacers.put(rowIndex, 50);
+ }, menupath);
+ addMenuCommand("Remove", () -> {
+ escalator.getBody().setSpacer(rowIndex, -1);
+ data.spacers.remove(rowIndex);
+ }, menupath);
addMenuCommand("Scroll here (ANY, 0)", () -> escalator
.scrollToSpacer(rowIndex, ScrollDestination.ANY, 0), menupath);
addMenuCommand("Scroll here row+spacer below (ANY, 0)", () -> escalator
@@ -596,6 +646,9 @@ public class EscalatorBasicClientFeaturesWidget
} else {
container.insertRows(offset, number);
}
+ if (container.getRowCount() > offset + number) {
+ container.refreshRows(offset + number, container.getRowCount());
+ }
}
private void removeRows(final RowContainer container, int offset,
@@ -606,6 +659,9 @@ public class EscalatorBasicClientFeaturesWidget
} else {
container.removeRows(offset, number);
}
+ if (container.getRowCount() > offset) {
+ container.refreshRows(offset, container.getRowCount());
+ }
}
private void insertColumns(final int offset, final int number) {
diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java
index fe6f7ab94b..5d5148109b 100644
--- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java
+++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java
@@ -125,6 +125,11 @@ public class EscalatorProxy extends Escalator {
throw new UnsupportedOperationException(
"setNewRowCallback is not supported");
}
+
+ @Override
+ public void updateRowPositions(int index, int numberOfRows) {
+ rowContainer.updateRowPositions(index, numberOfRows);
+ }
}
private class RowContainerProxy implements RowContainer {