]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed a bug where lazyloading stopped working if a node containing lots of children...
authorJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Tue, 21 Jun 2011 07:32:57 +0000 (07:32 +0000)
committerJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Tue, 21 Jun 2011 07:32:57 +0000 (07:32 +0000)
svn changeset:19464/svn branch:6.7

src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
src/com/vaadin/terminal/gwt/client/ui/VTreeTable.java
src/com/vaadin/ui/Table.java
tests/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates-LongScroll.html [new file with mode: 0644]
tests/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates.java [new file with mode: 0644]

index 9148b463fdd1a599913169eee4c3740805b282c6..d215de9e11097e8bf21001279ed4136a62432614 100644 (file)
@@ -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
index 974e96e8aee5c935d6666f3a67f581dc508aa17d..40cdf580b9f8767c8e9b47468dc7ea82f012b24e 100644 (file)
@@ -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);
+        }
+    }
 }
index 27d17169f1f5d39566d764c71508c7abaae06682..aa327a483312f5e5a8f6507e1ae0d4cd703d2d7f 100644 (file)
@@ -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 (file)
index 0000000..24a2f88
--- /dev/null
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+    <td>open</td>
+    <td>/run/com.vaadin.tests.components.treetable.TreeTablePartialUpdates?restartApplication</td>
+    <td></td>
+</tr>
+<tr>
+    <td>mouseClick</td>
+    <td>vaadin=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]</td>
+    <td>12,6</td>
+</tr>
+<tr>
+    <td>scroll</td>
+    <td>vaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]</td>
+    <td>1692</td>
+</tr>
+<tr>
+    <td>pause</td>
+    <td>300</td>
+    <td></td>
+</tr>
+<tr>
+    <td>scroll</td>
+    <td>vaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]</td>
+    <td>3889</td>
+</tr>
+<tr>
+    <td>pause</td>
+    <td>300</td>
+    <td></td>
+</tr>
+<tr>
+    <td>screenCapture</td>
+    <td></td>
+    <td>treetable-long-scroll</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
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 (file)
index 0000000..23eaa5d
--- /dev/null
@@ -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;
+    }
+
+}