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.tapestry.grid;
016
017 import java.util.List;
018
019 /**
020 * Defines how a {@link org.apache.tapestry.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.
043 */
044 Object getRowValue(int index);
045
046 /**
047 * Returns the type of value in the rows, or null if not known. This value is used to create a default {@link
048 * org.apache.tapestry.beaneditor.BeanModel} when no such model is explicitly provided.
049 *
050 * @return the row type, or null
051 */
052 Class getRowType();
053 }