]> source.dussan.org Git - vaadin-framework.git/commitdiff
table couldn't handle row count change properly. fixes #1073
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 2 Nov 2007 12:54:55 +0000 (12:54 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 2 Nov 2007 12:54:55 +0000 (12:54 +0000)
svn changeset:2684/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java

index 6fc420fe852846f82a4c548f3138347604e6d563..d6962553eaac9878792c04f5ae6559c9695f0a1c 100644 (file)
@@ -137,7 +137,13 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
                this.client = client;
                this.paintableId = uidl.getStringAttribute("id");
                this.immediate = uidl.getBooleanAttribute("immediate");
-               this.totalRows = uidl.getIntAttribute("totalrows");
+               int newTotalRows = uidl.getIntAttribute("totalrows");
+               if(newTotalRows != totalRows) {
+                       this.totalRows = newTotalRows;
+                       if(initializedAndAttached)
+                               tBody.setContainerHeight();
+               }
+               
                this.pageLength = uidl.getIntAttribute("pagelength");
                if (pageLength == 0)
                        pageLength = totalRows;
@@ -199,9 +205,11 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
                        updateBody(rowData, uidl.getIntAttribute("firstrow"), uidl
                                        .getIntAttribute("rows"));
                } else {
-                       getTBody().renderInitialRows(rowData,
+                       tBody = new IScrollTableBody();
+
+                       tBody.renderInitialRows(rowData,
                                        uidl.getIntAttribute("firstrow"),
-                                       uidl.getIntAttribute("rows"), totalRows);
+                                       uidl.getIntAttribute("rows"));
                        bodyContainer.add(tBody);
                        initialContentReceived = true;
                        if (isAttached()) {
@@ -219,15 +227,6 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
                }
        }
 
-       private IScrollTableBody getTBody() {
-               if (tBody == null || totalRows != tBody.getTotalRows()) {
-                       if (tBody != null)
-                               tBody.removeFromParent();
-                       tBody = new IScrollTableBody();
-               }
-               return tBody;
-       }
-
        private void updateActionMap(UIDL c) {
                Iterator it = c.getChildIterator();
                while (it.hasNext()) {
@@ -1405,8 +1404,6 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
         * "simulates" very large table, keeping spacers which take room of
         * unrendered rows.
         * 
-        * @author mattitahvonen
-        * 
         */
        public class IScrollTableBody extends Panel {
 
@@ -1422,8 +1419,6 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
 
                private boolean initDone = false;
 
-               private int totalRows;
-
                Element preSpacer = DOM.createDiv();
                Element postSpacer = DOM.createDiv();
 
@@ -1461,9 +1456,7 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
                        return DOM.getElementPropertyInt(preSpacer, "offsetWidth");
                }
 
-               public void renderInitialRows(UIDL rowData, int firstIndex, int rows,
-                               int totalRows) {
-                       this.totalRows = totalRows;
+               public void renderInitialRows(UIDL rowData, int firstIndex, int rows) {
                        this.firstRendered = firstIndex;
                        this.lastRendered = firstIndex + rows - 1;
                        Iterator it = rowData.getChildIterator();
@@ -1602,8 +1595,14 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
 
                protected void onAttach() {
                        super.onAttach();
+                       setContainerHeight();
+               }
+               
+               /**
+                * Fix container blocks height according to totalRows to avoid "bouncing" when scrolling
+                */
+               private void setContainerHeight() {
                        fixSpacers();
-                       // fix container blocks height to avoid "bouncing" when scrolling
                        DOM.setStyleAttribute(container, "height", totalRows
                                        * getRowHeight() + "px");
                }
@@ -1615,10 +1614,6 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
                                        * (totalRows - 1 - lastRendered) + "px");
                }
 
-               public int getTotalRows() {
-                       return totalRows;
-               }
-
                public int getRowHeight() {
                        if (initDone)
                                return rowHeight;