From 6a31f286e21befc8ab367d9ab3da1f08f47614d8 Mon Sep 17 00:00:00 2001 From: Jonatan Kronqvist Date: Tue, 21 Jun 2011 07:32:57 +0000 Subject: [PATCH] Fixed a bug where lazyloading stopped working if a node containing lots of children was expanded (#6722) svn changeset:19464/svn branch:6.7 --- .../terminal/gwt/client/ui/VScrollTable.java | 32 ++++++++-- .../terminal/gwt/client/ui/VTreeTable.java | 11 ++++ src/com/vaadin/ui/Table.java | 9 +++ .../TreeTablePartialUpdates-LongScroll.html | 52 +++++++++++++++ .../treetable/TreeTablePartialUpdates.java | 63 +++++++++++++++++++ 5 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates-LongScroll.html create mode 100644 tests/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates.java diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index 9148b463fd..d215de9e11 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -1105,7 +1105,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, } } - private void updateTotalRows(UIDL uidl) { + protected void updateTotalRows(UIDL uidl) { int newTotalRows = uidl.getIntAttribute("totalrows"); if (newTotalRows != getTotalRows()) { if (scrollBody != null) { @@ -1376,10 +1376,17 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, scrollBody.unlinkRows( partialRowAdditions.getIntAttribute("firstprowix"), partialRowAdditions.getIntAttribute("numprows")); + scrollBody.ensureCacheFilled(); } else { - scrollBody.insertRows(partialRowAdditions, - partialRowAdditions.getIntAttribute("firstprowix"), - partialRowAdditions.getIntAttribute("numprows")); + if (partialRowAdditions.hasAttribute("delbelow")) { + scrollBody.insertRowsDeleteBelow(partialRowAdditions, + partialRowAdditions.getIntAttribute("firstprowix"), + partialRowAdditions.getIntAttribute("numprows")); + } else { + scrollBody.insertRows(partialRowAdditions, + partialRowAdditions.getIntAttribute("firstprowix"), + partialRowAdditions.getIntAttribute("numprows")); + } } updateCache(); @@ -3704,6 +3711,10 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, // this may be a new set of rows due content change, // ensure we have proper cache rows + ensureCacheFilled(); + } + + protected void ensureCacheFilled() { int reactFirstRow = (int) (firstRowInViewPort - pageLength * cache_react_rate); int reactLastRow = (int) (firstRowInViewPort + pageLength + pageLength @@ -3768,6 +3779,12 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, } } + protected void insertRowsDeleteBelow(UIDL rowData, int firstIndex, + int rows) { + unlinkAllRowsStartingAt(firstIndex); + insertRows(rowData, firstIndex, rows); + } + /** * This method is used to instantiate new rows for this table. It * automatically sets correct widths to rows cells and assigns correct @@ -3890,11 +3907,11 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, fixSpacers(); } - protected void unlinkAllRowsAfter(int index) { + protected void unlinkAllRowsStartingAt(int index) { if (firstRendered > index) { index = firstRendered; } - for (int ix = renderedRows.size() - 1; ix > index; ix--) { + for (int ix = renderedRows.size() - 1; ix >= index; ix--) { unlinkRowAtIndex(ix); lastRendered--; } @@ -5430,6 +5447,9 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, final int lastRendered = scrollBody.getLastRendered(); final int firstRendered = scrollBody.getFirstRendered(); + VConsole.log("firstRendered=" + firstRendered + " preLimit=" + preLimit + + " lastRendered=" + lastRendered + " postLimit=" + postLimit); + if (postLimit <= lastRendered && preLimit >= firstRendered) { // remember which firstvisible we requested, in case the server has // a differing opinion diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTreeTable.java b/src/com/vaadin/terminal/gwt/client/ui/VTreeTable.java index 974e96e8ae..40cdf580b9 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTreeTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTreeTable.java @@ -342,4 +342,15 @@ public class VTreeTable extends VScrollTable { super.setStyleName(style + " v-treetable"); } + @Override + protected void updateTotalRows(UIDL uidl) { + // Make sure that initializedAndAttached & al are not reset when the + // totalrows are updated on expand/collapse requests. + int newTotalRows = uidl.getIntAttribute("totalrows"); + if (collapseRequest) { + setTotalRows(newTotalRows); + } else { + super.setTotalRows(newTotalRows); + } + } } diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 27d17169f1..aa327a4833 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -2399,6 +2399,15 @@ public class Table extends AbstractSelect implements Action.Container, int count = getAddedRowCount(); target.startTag("prows"); + + int maxRows = (int) (getPageLength() * getCacheRate()); + if (!shouldHideAddedRows() && count > maxRows) { + count = maxRows + 1; + // delete the rows below, since they will fall beyond the cache + // page. + target.addAttribute("delbelow", true); + } + target.addAttribute("firstprowix", firstIx); target.addAttribute("numprows", count); diff --git a/tests/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates-LongScroll.html b/tests/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates-LongScroll.html new file mode 100644 index 0000000000..24a2f88d9c --- /dev/null +++ b/tests/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates-LongScroll.html @@ -0,0 +1,52 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.treetable.TreeTablePartialUpdates?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]12,6
scrollvaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]1692
pause300
scrollvaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]3889
pause300
screenCapturetreetable-long-scroll
+ + diff --git a/tests/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates.java b/tests/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates.java new file mode 100644 index 0000000000..23eaa5dfea --- /dev/null +++ b/tests/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates.java @@ -0,0 +1,63 @@ +package com.vaadin.tests.components.treetable; + +import com.vaadin.data.Container.Hierarchical; +import com.vaadin.data.util.HierarchicalContainer; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.TreeTable; + +public class TreeTablePartialUpdates extends TestBase { + + @Override + protected void setup() { + TreeTable tt = new TreeTable(); + tt.setContainerDataSource(makeHierarchicalContainer()); + tt.setWidth("300px"); + addComponent(tt); + } + + private Hierarchical makeHierarchicalContainer() { + HierarchicalContainer hc = new HierarchicalContainer(); + hc.addContainerProperty("p1", String.class, ""); + hc.addContainerProperty("p2", String.class, ""); + + Object r1 = hc.addItem(); + hc.getItem(r1).getItemProperty("p1").setValue("root1"); + hc.getItem(r1).getItemProperty("p2").setValue("root1"); + + Object r2 = hc.addItem(); + hc.getItem(r2).getItemProperty("p1").setValue("root2"); + hc.getItem(r2).getItemProperty("p2").setValue("root2"); + + Object r3 = hc.addItem(); + hc.getItem(r3).getItemProperty("p1").setValue("root3"); + hc.getItem(r3).getItemProperty("p2").setValue("root3"); + + Object r4 = hc.addItem(); + hc.getItem(r4).getItemProperty("p1").setValue("END"); + hc.setChildrenAllowed(r4, false); + + addNodesToRoot(hc, r1, 200); + addNodesToRoot(hc, r2, 200); + addNodesToRoot(hc, r3, 200); + return hc; + } + + private void addNodesToRoot(HierarchicalContainer hc, Object root, int count) { + for (int ix = 0; ix < count; ix++) { + Object id = hc.addItem(); + hc.getItem(id).getItemProperty("p1").setValue(String.valueOf(ix)); + hc.setParent(id, root); + } + } + + @Override + protected String getDescription() { + return ""; + } + + @Override + protected Integer getTicketNumber() { + return 6722; + } + +} -- 2.39.5