2009-06-25 Thiago H. de Paula Figueiredo:
> 2009/6/25 Przemysław Wojnowski <przemyslaw.wojnow...@nask.pl>:
> > My point is that the current implementation of Grid#setupDataSource()
> > uses getAvailableRows() to calculate exact values for start and end
> > indices. Shouldn't this be responsibility of GridDataSource?
> 
> Nice points in the whole message. :)
> One solution would be to create another interface, because Grid needs
> to know the number of available rows (regardless if before or after
> prepare()) and changing GridDataSource now would break backward
> compatibility quite badly.
> > IMHO there is no need for special value. It's just matter of the current
> > implementation of Grid#setupDataSource().
> 
> You're suggesting the reversal of invokating order of prepare() and
> getAvailableRows()? I don't see any way of Grid working without
> getAvailableRows(), as it's needed to handle paging.
> 
I think i was misunderstood. I don't want to change any interface,
especially GridDataSource. I'm just writing about current (Tapestry
5.2.0-snapshot) implementation of one method: Grid#setupDataSource().
The source code for this method is as follows:
--- code ---
void setupDataSource()
    {
        // TAP5-34: (...)
        cachingSource = new CachingDataSource(source);
        int availableRows = cachingSource.getAvailableRows();
        if (availableRows == 0) return;
        int maxPage = ((availableRows - 1) / rowsPerPage) + 1;

        // This captures when the number of rows has decreased,
typically due to deletions.
        int effectiveCurrentPage = getCurrentPage();
        if (effectiveCurrentPage > maxPage)
            effectiveCurrentPage = maxPage;

        int startIndex = (effectiveCurrentPage - 1) * rowsPerPage;
        int endIndex = Math.min(startIndex + rowsPerPage - 1,
availableRows - 1);

        dataModel = null;
        cachingSource.prepare(startIndex, endIndex,
sortModel.getSortConstraints());
    }
--- code ---

Here getAvailableRows() is used only to calculate start and end indices.
But their exact values (taking into account decreased number of rows)
can (maybe should?) be calculated in implementation of GridDataSource
and then implementation of Grid#setupDataSource() could look like this:
--- code ---
void setupDataSource()
{
    cachingSource = new CachingDataSource(source);
    int startIndex = (getCurrentPage()-1) * rowsPerPage;
    cachingSource.prepare(startIndex, startIndex+rowsPerPage,
sortModel.getSortConstraints());
}
--- code ---

Grid still uses getAvailableRows() but not in setupDataSource() method,
and not before prepare().

Maybe I misunderstood something or not seeing something. In that case I
would like to know what. :-)

Best regards and thanks for response!
Przemysław Wojnowski


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to