Repository: tapestry-5
Updated Branches:
  refs/heads/master 61bc522ee -> 68303b1d6


TAP5-2589: extend interface with methods that ease incremental paging


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/4958b713
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/4958b713
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/4958b713

Branch: refs/heads/master
Commit: 4958b713fff229c6b0f028a7226a719549cf4d5b
Parents: 61bc522
Author: Jochen Kemnade <jochen.kemn...@eddyson.de>
Authored: Fri Oct 13 09:51:52 2017 +0200
Committer: Jochen Kemnade <jochen.kemn...@eddyson.de>
Committed: Fri Oct 13 09:51:52 2017 +0200

----------------------------------------------------------------------
 .../apache/tapestry5/grid/GridDataSource.java   | 29 ++++++++++++++++++++
 .../internal/grid/CollectionGridDataSource.java |  6 ++++
 2 files changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4958b713/tapestry-core/src/main/java/org/apache/tapestry5/grid/GridDataSource.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/main/java/org/apache/tapestry5/grid/GridDataSource.java 
b/tapestry-core/src/main/java/org/apache/tapestry5/grid/GridDataSource.java
index 9ebe488..8fca800 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/grid/GridDataSource.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/grid/GridDataSource.java
@@ -23,6 +23,35 @@ import java.util.List;
  */
 public interface GridDataSource
 {
+
+    /**
+     * Return whether the data source is empty, i.e. does not have any rows 
available.
+     */
+    default public boolean isEmpty()
+    {
+        return getAvailableRows(1) == 0;
+    }
+
+    /**
+     * Return the number of rows available in the data source with an upper 
limit.
+     * If determining the total number of rows is expensive, this method 
should be overridden to provide a more
+     * efficient implementation.
+     * Please note that the default Grid pager will still determine the total 
number of rows, so for this to have
+     * an effect, a custom pager should be used.
+     *
+     * @param limit the upper limit
+     * @return the number of rows or {@code limit}, whichever is lower
+     */
+    default public int getAvailableRows(final int limit)
+    {
+        int availableRows = getAvailableRows();
+        if (availableRows >= limit)
+        {
+            return limit;
+        }
+        return availableRows;
+    }
+
     /**
      * Returns the number of rows available in the data source.
      */

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4958b713/tapestry-core/src/main/java/org/apache/tapestry5/internal/grid/CollectionGridDataSource.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/grid/CollectionGridDataSource.java
 
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/grid/CollectionGridDataSource.java
index 414d146..63591b1 100644
--- 
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/grid/CollectionGridDataSource.java
+++ 
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/grid/CollectionGridDataSource.java
@@ -36,6 +36,12 @@ public class CollectionGridDataSource implements 
GridDataSource
         list = CollectionFactory.newList(collection);
     }
 
+    @Override
+    public boolean isEmpty()
+    {
+        return list.isEmpty();
+    }
+
     public int getAvailableRows()
     {
         return list.size();

Reply via email to