From 61b7d6475115a4e163069ff902cf6cc18b66bd05 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 4 Nov 2011 12:23:49 +0000 Subject: [PATCH] #7839 Corrected cases where pagelength=0 or where number of children > pagebuffer size svn changeset:21910/svn branch:6.7 --- src/com/vaadin/ui/Table.java | 50 +++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 640fd927af..5efb2545e0 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -1582,13 +1582,14 @@ public class Table extends AbstractSelect implements Action.Container, * @param firstIndex * The position where new rows should be inserted * @param rows - * The number of rows that should be inserted + * The maximum number of rows that should be inserted at position + * firstIndex. Less rows will be inserted if the page buffer is + * too small. * @return */ private Object[][] getVisibleCellsInsertIntoCache(int firstIndex, int rows) { - Object[][] cells = getVisibleCellsNoCache(firstIndex, rows, false); logger.finest("Insert " + rows + " rows at index " + firstIndex - + " to existing page buffer with " + cells.length + " items"); + + " to existing page buffer requested"); // Page buffer must not become larger than pageLength*cacheRate before // or after the current page @@ -1602,6 +1603,10 @@ public class Table extends AbstractSelect implements Action.Container, + (int) (getPageLength() * (1 + getCacheRate())); int maxBufferSize = maxPageBufferIndex - minPageBufferIndex; + if (getPageLength() == 0) { + // If pageLength == 0 then all rows should be rendered + maxBufferSize = pageBuffer[0].length + rows; + } /* * Number of rows that were previously cached. This is not necessarily * the same as pageLength if we do not have enough rows in the @@ -1618,6 +1623,11 @@ public class Table extends AbstractSelect implements Action.Container, */ int firstIndexInPageBuffer = firstIndex - pageBufferFirstIndex; + /* If rows > size available in page buffer */ + if (firstIndexInPageBuffer + rows > maxBufferSize) { + rows = maxBufferSize - firstIndexInPageBuffer; + } + /* * "rows" rows will be inserted at firstIndex. Find out how many old * rows fall outside the new buffer so we can unregister components in @@ -1657,6 +1667,9 @@ public class Table extends AbstractSelect implements Action.Container, } } + /* Paint the new rows into a separate buffer */ + Object[][] cells = getVisibleCellsNoCache(firstIndex, rows, false); + /* * Create the new cache buffer and fill it with the data from the old * buffer as well as the inserted rows. @@ -2745,27 +2758,19 @@ public class Table extends AbstractSelect implements Action.Container, target.startTag("prows"); - /* - * Caching says we should cache the current page and - * cacheRate*pageLength rows below it (and the same above). We only add - * rows below in this case. - */ - int maxRows = (int) (getPageLength() * (1 + 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); - if (!shouldHideAddedRows()) { logger.finest("Paint rows for add. Index: " + firstIx + ", count: " - + count + ". Max rows: " + maxRows); + + count + "."); + // Partial row additions bypass the normal caching mechanism. Object[][] cells = getVisibleCellsInsertIntoCache(firstIx, count); + if (cells[0].length < count) { + // delete the rows below, since they will fall beyond the cache + // page. + target.addAttribute("delbelow", true); + count = cells[0].length; + } + for (int indexInRowbuffer = 0; indexInRowbuffer < count; indexInRowbuffer++) { final Object itemId = cells[CELL_ITEMID][indexInRowbuffer]; if (shouldHideNullSelectionItem()) { @@ -2779,10 +2784,13 @@ public class Table extends AbstractSelect implements Action.Container, } } else { logger.finest("Paint rows for remove. Index: " + firstIx - + ", count: " + count + ". Max rows: " + maxRows); + + ", count: " + count + "."); removeRowsFromCacheAndFillBottom(firstIx, count); target.addAttribute("hide", true); } + + target.addAttribute("firstprowix", firstIx); + target.addAttribute("numprows", count); target.endTag("prows"); } -- 2.39.5