    001    // Copyright 2007, 2008 The Apache Software Foundation
    002    //
    003    // Licensed under the Apache License, Version 2.0 (the "License");
    004    // you may not use this file except in compliance with the License.
    005    // You may obtain a copy of the License at
    006    //
    007    //     http://www.apache.org/licenses/LICENSE-2.0
    008    //
    009    // Unless required by applicable law or agreed to in writing, software
    010    // distributed under the License is distributed on an "AS IS" BASIS,
    011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012    // See the License for the specific language governing permissions and
    013    // limitations under the License.
    014
    015    package org.apache.tapestry5.grid;
    016
    017    import java.util.List;
    018
    019    /**
    020     * Defines how a {@link org.apache.tapestry5.corelib.components.Grid} component (and its sub-components) gain access to
    021     * the row data that is displayed on the page. In many cases, this is just a wrapper around a simple List, but the
    022     * abstractions exist to support access to a large data set that is accessible in sections.
    023     */
    024    public interface GridDataSource
    025    {
    026        /**
    027         * Returns the number of rows available in the data source.
    028         */
    029        int getAvailableRows();
    030
    031        /**
    032         * Invoked to allow the source to prepare to present values. This gives the source a chance to pre-fetch data (when
    033         * appropriate) and informs the source of the desired sort order.  Sorting comes first, then extraction by range.
    034         *
    035         * @param startIndex      the starting index to be retrieved
    036         * @param endIndex        the ending index to be retrieved
    037         * @param sortConstraints identify how data is to be sorted
    038         */
    039        void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints);
    040
    041        /**
    042         * Returns the row value at the provided index. This method will be invoked in sequential order. In rare instances,
    043         * {@link #getAvailableRows()} may return a different number of rows than are actually available (i.e., the database
    044         * was changed between calls to {@link #getAvailableRows()} and the call to {@link #prepare(int, int,
    045         * java.util.List)}).  In that case, this method should return null for any out-of-range indexes.
    046         */
    047        Object getRowValue(int index);
    048
    049        /**
    050         * Returns the type of value in the rows, or null if not known. This value is used to create a default {@link
    051         * org.apache.tapestry5.beaneditor.BeanModel} when no such model is explicitly provided.
    052         *
    053         * @return the row type, or null
    054         */
    055        Class getRowType();
    056    }