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;
}
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,
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;
// 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);
* 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
* @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;
}
*/
private int reqFirstRowToPaint = -1;
+ private int firstToBeRenderedInClient = -1;
+
+ private int lastToBeRenderedInClient = -1;
+
+ private boolean rowFetch;
+
/* Table constructors *************************************************** */
/**
// 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();
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
}
}
+ /**
+ * 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.
*
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())) {
&& 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
}
}
target.endTag("visiblecolumns");
+ rowFetch = false;
}
/**
/**
* 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();
}
// 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()) {
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;
}