]> source.dussan.org Git - vaadin-framework.git/commitdiff
extracted alignments and spacing to layouts subinterfaces
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 7 Feb 2008 16:42:54 +0000 (16:42 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 7 Feb 2008 16:42:54 +0000 (16:42 +0000)
svn changeset:3739/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java
src/com/itmill/toolkit/terminal/gwt/server/JsonPaintTarget.java
src/com/itmill/toolkit/ui/Table.java

index b144e6c8bef068ac2c18a80cb97aa001f44a940b..2462428e8d228517bd5c6c70534ac4da4a3ecba4 100644 (file)
@@ -687,8 +687,13 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
             rowRequestHandler
                     .setReqFirstRow((int) (firstRowInViewPort - pageLength
                             * CACHE_RATE));
-            rowRequestHandler
-                    .setReqRows((int) (2 * CACHE_RATE * pageLength + pageLength));
+            int last = firstRowInViewPort
+                    + (int) (CACHE_RATE * pageLength + pageLength);
+            if (last > totalRows) {
+                last = totalRows - 1;
+            }
+            rowRequestHandler.setReqRows(last
+                    - rowRequestHandler.getReqFirstRow());
             rowRequestHandler.deferRowFetch();
             return;
         }
@@ -791,6 +796,36 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
         public void run() {
             ApplicationConnection.getConsole().log(
                     "Getting " + reqRows + " rows from " + reqFirstRow);
+
+            int firstToBeRendered = tBody.firstRendered;
+            if (reqFirstRow < firstToBeRendered) {
+                firstToBeRendered = reqFirstRow;
+            } else if (firstRowInViewPort - (int) (CACHE_RATE * pageLength) > firstToBeRendered) {
+                firstToBeRendered = firstRowInViewPort
+                        - (int) (CACHE_RATE * pageLength);
+                if (firstToBeRendered < 0) {
+                    firstToBeRendered = 0;
+                }
+            }
+
+            int lastToBeRendered = tBody.lastRendered;
+
+            if (reqFirstRow + reqRows > lastToBeRendered) {
+                lastToBeRendered = reqFirstRow + reqRows;
+            } else if (firstRowInViewPort + pageLength + pageLength
+                    * CACHE_RATE < lastToBeRendered) {
+                lastToBeRendered = (firstRowInViewPort + pageLength + (int) (pageLength * CACHE_RATE));
+                if (lastToBeRendered >= totalRows) {
+                    lastToBeRendered = totalRows;
+                }
+            }
+
+            client.updateVariable(paintableId, "firstToBeRendered",
+                    firstToBeRendered, false);
+
+            client.updateVariable(paintableId, "lastToBeRendered",
+                    lastToBeRendered, false);
+
             client.updateVariable(paintableId, "firstvisible",
                     firstRowInViewPort, false);
             client.updateVariable(paintableId, "reqfirstrow", reqFirstRow,
index 531aa09ef049ecf38c9755f0776476afeedcbe45..ae014b7482dbf6112e04eda9de7c7ed2ec8db933 100644 (file)
@@ -48,7 +48,6 @@ import com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent;
 import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
 import com.itmill.toolkit.tests.util.Log;
 import com.itmill.toolkit.ui.Component;
-import com.itmill.toolkit.ui.ComponentContainer;
 import com.itmill.toolkit.ui.Upload;
 import com.itmill.toolkit.ui.Window;
 
@@ -324,7 +323,7 @@ public class CommunicationManager implements Paintable.RepaintRequestListener {
 
                         // TODO we may still get changes that have been
                         // rendered already (changes with only cached flag)
-                        if (!paintTarget.isAlreadyPainted(p)) {
+                        if (paintTarget.isNeedsToBePainted(p)) {
                             paintTarget.startTag("change");
                             paintTarget.addAttribute("format", "uidl");
                             final String pid = getPaintableId(p);
@@ -778,7 +777,7 @@ public class CommunicationManager implements Paintable.RepaintRequestListener {
      *                root window for which dirty components is to be fetched
      * @return
      */
-    public ArrayList getDirtyComponents(Window w) {
+    private ArrayList getDirtyComponents(Window w) {
         final ArrayList resultset = new ArrayList(dirtyPaintabletSet);
 
         // The following algorithm removes any components that would be painted
@@ -1004,15 +1003,12 @@ public class CommunicationManager implements Paintable.RepaintRequestListener {
      * @param child
      */
     private static boolean isChildOf(Component parent, Component child) {
-        if (parent instanceof ComponentContainer) {
-            Component p;
-            p = child.getParent();
-            while (p != null) {
-                if (parent == p) {
-                    return true;
-                }
-                p = p.getParent();
+        Component p = child.getParent();
+        while (p != null) {
+            if (parent == p) {
+                return true;
             }
+            p = p.getParent();
         }
         return false;
     }
index 4be9c1327fe02ec96171f5a932ef794f1160a332..3f19f7efa2695ce871ab9840eadcabeeabc81b1d 100644 (file)
@@ -21,6 +21,7 @@ import com.itmill.toolkit.terminal.Paintable;
 import com.itmill.toolkit.terminal.Resource;
 import com.itmill.toolkit.terminal.ThemeResource;
 import com.itmill.toolkit.terminal.VariableOwner;
+import com.itmill.toolkit.ui.Component;
 
 /**
  * User Interface Description Language Target.
@@ -1102,11 +1103,13 @@ public class JsonPaintTarget implements PaintTarget {
      * @param p
      * @return true if already painted
      */
-    public boolean isAlreadyPainted(Paintable p) {
+    public boolean isNeedsToBePainted(Paintable p) {
         if (paintedComponents.contains(p)) {
-            return true;
-        } else {
             return false;
+        } else if (((Component) p).getApplication() == null) {
+            return false;
+        } else {
+            return true;
         }
     }
 }
index 9539653b3c489fae6a55c366563bd11ae17b9f12..00ad905f17bc0551825c921c8de9b9be02a29cad 100644 (file)
@@ -280,6 +280,12 @@ public class Table extends AbstractSelect implements Action.Container,
      */
     private int reqFirstRowToPaint = -1;
 
+    private int firstToBeRenderedInClient = -1;
+
+    private int lastToBeRenderedInClient = -1;
+
+    private boolean rowFetch;
+
     /* Table constructors *************************************************** */
 
     /**
@@ -1292,6 +1298,16 @@ public class Table extends AbstractSelect implements Action.Container,
         // Sets requested firstrow and rows for the next paint
         if (variables.containsKey("reqfirstrow")
                 || variables.containsKey("reqrows")) {
+
+            try {
+                firstToBeRenderedInClient = ((Integer) variables
+                        .get("firstToBeRendered")).intValue();
+                lastToBeRenderedInClient = ((Integer) variables
+                        .get("lastToBeRendered")).intValue();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
             Integer value = (Integer) variables.get("reqfirstrow");
             if (value != null) {
                 reqFirstRowToPaint = value.intValue();
@@ -1299,9 +1315,13 @@ public class Table extends AbstractSelect implements Action.Container,
             value = (Integer) variables.get("reqrows");
             if (value != null) {
                 reqRowsToPaint = value.intValue();
+                // sanity check
+                if (reqFirstRowToPaint + reqRowsToPaint > size()) {
+                    reqRowsToPaint = size() - reqFirstRowToPaint;
+                }
             }
             pageBuffer = null;
-            requestRepaint();
+            requestRepaint(true);
         }
 
         // Actions
@@ -1380,6 +1400,26 @@ public class Table extends AbstractSelect implements Action.Container,
         }
     }
 
+    /**
+     * Reques repaint
+     * 
+     * @param rowFetch
+     *                true if this is just a row fetch
+     */
+    private void requestRepaint(boolean rowFetchOnly) {
+        if (rowFetchOnly) {
+            rowFetch = true;
+        } else {
+            rowFetch = false;
+        }
+        super.requestRepaint();
+        // TODO Auto-generated method stub
+    }
+
+    public void requestRepaint() {
+        requestRepaint(false);
+    }
+
     /**
      * Paints the content of this component.
      * 
@@ -1411,7 +1451,12 @@ public class Table extends AbstractSelect implements Action.Container,
         final boolean rowheads = getRowHeaderMode() != ROW_HEADER_MODE_HIDDEN;
         final Object[][] cells = getVisibleCells();
         final boolean iseditable = isEditable();
-        int rows = cells[0].length;
+        int rows;
+        if (reqRowsToPaint >= 0) {
+            rows = reqRowsToPaint;
+        } else {
+            rows = cells[0].length;
+        }
 
         if (!isNullSelectionAllowed() && getNullSelectionItemId() != null
                 && containsId(getNullSelectionItemId())) {
@@ -1475,7 +1520,22 @@ public class Table extends AbstractSelect implements Action.Container,
                     && Component.class.isAssignableFrom(colType);
         }
         target.startTag("rows");
-        for (int i = 0; i < cells[0].length; i++) {
+        // cells array contains all that are supposed to be visible on client,
+        // but we'll start from the one requested by client
+        int start = 0;
+        if (reqFirstRowToPaint != -1 && firstToBeRenderedInClient != -1) {
+            start = reqFirstRowToPaint - firstToBeRenderedInClient;
+        }
+        int end = cells[0].length;
+        if (reqRowsToPaint != -1) {
+            end = start + reqRowsToPaint;
+        }
+        // sanity check
+        if (lastToBeRenderedInClient != -1 && lastToBeRenderedInClient < end) {
+            end = lastToBeRenderedInClient + 1;
+        }
+
+        for (int i = start; i < end; i++) {
             final Object itemId = cells[CELL_ITEMID][i];
 
             if (!isNullSelectionAllowed() && getNullSelectionItemId() != null
@@ -1655,6 +1715,7 @@ public class Table extends AbstractSelect implements Action.Container,
             }
         }
         target.endTag("visiblecolumns");
+        rowFetch = false;
     }
 
     /**
@@ -1669,35 +1730,21 @@ public class Table extends AbstractSelect implements Action.Container,
     /**
      * Gets the cached visible table contents.
      * 
-     * @return the cahced visible table conetents.
+     * @return the cached visible table contents.
      */
     private Object[][] getVisibleCells() {
 
+        LinkedList oldListenedProperties = listenedProperties;
+        LinkedList oldVisibleComponents = visibleComponents;
+
         // Returns a buffered value if possible
         if (pageBuffer != null && isPageBufferingEnabled()) {
             return pageBuffer;
         }
 
-        // Stops listening the old properties and initialise the list
-        if (listenedProperties == null) {
-            listenedProperties = new LinkedList();
-        } else if (reqRowsToPaint < 0) {
-            // TODO the above if is not perfect - should be fixed properly
-            for (final Iterator i = listenedProperties.iterator(); i.hasNext();) {
-                ((Property.ValueChangeNotifier) i.next()).removeListener(this);
-            }
-        }
-
-        // Detach old visible component from the table
-        if (visibleComponents == null) {
-            visibleComponents = new LinkedList();
-        } else if (reqRowsToPaint < 0) {
-            // TODO the above if is not perfect - should be fixed properly
-            for (final Iterator i = visibleComponents.iterator(); i.hasNext();) {
-                ((Component) i.next()).setParent(null);
-            }
-            visibleComponents.clear();
-        }
+        // initialize the listener collections
+        listenedProperties = new LinkedList();
+        visibleComponents = new LinkedList();
 
         // Collects the basic facts about the table page
         final Object[] colids = getVisibleColumns();
@@ -1713,12 +1760,17 @@ public class Table extends AbstractSelect implements Action.Container,
         }
 
         // If "to be painted next" variables are set, use them
-        if (reqRowsToPaint >= 0) {
-            rows = reqRowsToPaint;
+        if (rowFetch
+                && lastToBeRenderedInClient - firstToBeRenderedInClient > 0) {
+            rows = lastToBeRenderedInClient - firstToBeRenderedInClient;
         }
         Object id;
-        if (reqFirstRowToPaint >= 0 && reqFirstRowToPaint < size()) {
-            firstIndex = reqFirstRowToPaint;
+        if (rowFetch && firstToBeRenderedInClient >= 0) {
+            if (firstToBeRenderedInClient < size()) {
+                firstIndex = firstToBeRenderedInClient;
+            } else {
+                firstIndex = size() - 1;
+            }
         }
         if (size() > 0) {
             if (rows + firstIndex > size()) {
@@ -1816,6 +1868,31 @@ public class Table extends AbstractSelect implements Action.Container,
             pageBuffer = cells;
         }
 
+        if (oldListenedProperties != null) {
+            int c = 0;
+            for (final Iterator i = oldListenedProperties.iterator(); i
+                    .hasNext();) {
+                Property.ValueChangeNotifier o = (ValueChangeNotifier) i.next();
+                if (!listenedProperties.contains(o)) {
+                    o.removeListener(this);
+                    c++;
+                }
+            }
+            System.out.println(c + " listeners removed");
+        }
+        if (oldVisibleComponents != null) {
+            int count = 0;
+            for (final Iterator i = oldVisibleComponents.iterator(); i
+                    .hasNext();) {
+                Component c = (Component) i.next();
+                if (!visibleComponents.contains(c)) {
+                    c.setParent(null);
+                    count++;
+                }
+            }
+            System.out.println(count + " components detached");
+        }
+
         return cells;
     }