Return-Path: Delivered-To: apmail-click-commits-archive@www.apache.org Received: (qmail 50340 invoked from network); 28 Mar 2010 04:17:59 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 28 Mar 2010 04:17:59 -0000 Received: (qmail 19836 invoked by uid 500); 28 Mar 2010 04:17:59 -0000 Delivered-To: apmail-click-commits-archive@click.apache.org Received: (qmail 19819 invoked by uid 500); 28 Mar 2010 04:17:58 -0000 Mailing-List: contact commits-help@click.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: click-dev@click.apache.org Delivered-To: mailing list commits@click.apache.org Received: (qmail 19811 invoked by uid 99); 28 Mar 2010 04:17:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Mar 2010 04:17:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Mar 2010 04:17:55 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E8E8323889B3; Sun, 28 Mar 2010 04:17:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r928333 - /click/trunk/click/framework/src/org/apache/click/control/Table.java Date: Sun, 28 Mar 2010 04:17:33 -0000 To: commits@click.apache.org From: sabob@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100328041733.E8E8323889B3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sabob Date: Sun Mar 28 04:17:33 2010 New Revision: 928333 URL: http://svn.apache.org/viewvc?rev=928333&view=rev Log: added paging data provider support to table Modified: click/trunk/click/framework/src/org/apache/click/control/Table.java Modified: click/trunk/click/framework/src/org/apache/click/control/Table.java URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Table.java?rev=928333&r1=928332&r2=928333&view=diff ============================================================================== --- click/trunk/click/framework/src/org/apache/click/control/Table.java (original) +++ click/trunk/click/framework/src/org/apache/click/control/Table.java Sun Mar 28 04:17:33 2010 @@ -32,6 +32,7 @@ import org.apache.click.element.Element; import org.apache.click.util.ClickUtils; import org.apache.click.util.DataProvider; import org.apache.click.util.HtmlStringBuffer; +import org.apache.click.util.PagingDataProvider; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; @@ -1030,35 +1031,7 @@ public class Table extends AbstractContr @SuppressWarnings("unchecked") public List getRowList() { if (rowList == null) { - - if (getDataProvider() != null) { - Iterable iterableData = getDataProvider().getData(); - - if (iterableData == null) { - String msg = "DataProvider '" - + getDataProvider().getClass().getSimpleName() - + "' returned null data"; - throw new IllegalStateException(msg); - } - - if (iterableData instanceof List) { - rowList = (List) iterableData; - - } else { - // Create and populate the rowList from the Iterable data - rowList = new ArrayList(); - - for (Object row : iterableData) { - rowList.add(row); - } - } - - this.rowCount = rowList.size(); - - } else { - rowList = new ArrayList(); - this.rowCount = 0; - } + rowList = createRowList(); } return rowList; @@ -1076,10 +1049,10 @@ public class Table extends AbstractContr @SuppressWarnings("unchecked") public void setRowList(List rowList) { this.rowList = rowList; - if (rowList == null) { + if (this.rowList == null) { this.rowCount = 0; } else { - this.rowCount = rowList.size(); + this.rowCount = this.rowList.size(); } } @@ -1439,6 +1412,72 @@ public class Table extends AbstractContr // ------------------------------------------------------ Protected Methods /** + * Create a new table row list. If a {@link #getDataProvider() dataProvider} + * is specified the new row list will be populated from the data provider. + * + * @return a new table row list + */ + protected List createRowList() { + DataProvider dp = getDataProvider(); + + List rowList = null; + + if (dp != null) { + + boolean isPaginating = false; + + if (dp instanceof PagingDataProvider) { + isPaginating = true; + } + + if (isPaginating) { + // rowCount is provided by the paging data provider. Its + // important to set the rowCount *before* invoking dp.getData + // since the getData implementation could have a dependency + // on the methods getFirstRow, getLastRow etc all of which + // depends on the rowCount value + this.rowCount = ((PagingDataProvider) dp).size(); + + // paginated datasets cannot be sorted by the table since it + // has access to only a limited number of rows. The dataset has + // to be sorted by a database or other means. Set the sorted + // property to true indicating that the data is already in a + // sorted state + setSorted(true); + } + + Iterable iterableData = dataProvider.getData(); + + // If dataProvider returns a list, use that as the rowList + if (iterableData instanceof List) { + rowList = (List) iterableData; + + } else { + + // Create and populate the rowList from the Iterable data + rowList = new ArrayList(); + if (iterableData != null) { + for (Object row : iterableData) { + rowList.add(row); + } + } + } + + if (!isPaginating) { + // for non paginating data provider the row count equals + // the number of rows in the rowList + this.rowCount = rowList.size(); + } + } else { + // Create empty list + rowList = new ArrayList(); + this.rowCount = 0; + } + + return rowList; + } + + /** * Render the table header row of column names. * * @param buffer the StringBuffer to render the header row in @@ -1482,8 +1521,15 @@ public class Table extends AbstractContr } } - int firstRow = getFirstRow(); - int lastRow = getLastRow(); + int firstRow = 0; + int lastRow = 0; + + if (getDataProvider() instanceof PagingDataProvider) { + lastRow = getRowList().size(); + } else { + firstRow = getFirstRow(); + lastRow = getLastRow(); + } if (lastRow == 0) { renderBodyNoRows(buffer);