001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.web.struts.form;
017:
018: import org.kuali.core.util.TableRenderUtil;
019:
020: /**
021: * This class holds the metadata necessary to render a table when displaytag is not being used.
022: */
023: public class KualiTableRenderFormMetadata {
024: private int viewedPageNumber;
025: private int totalNumberOfPages;
026: private int firstRowIndex;
027: private int lastRowIndex;
028: private int switchToPageNumber;
029:
030: /**
031: * The number of rows that match the query criteria
032: */
033: private int resultsActualSize;
034:
035: /**
036: * The number of rows that match the query criteria or
037: * the max results limit size (if applicable), whichever is less
038: */
039: private int resultsLimitedSize;
040:
041: /**
042: * when the looked results screen was rendered, the index of the column that the results were sorted on. -1 for unknown, index numbers
043: * starting at 0
044: */
045: private int previouslySortedColumnIndex;
046:
047: /**
048: * Comment for <code>columnToSortIndex</code>
049: */
050: private int columnToSortIndex;
051:
052: private boolean sortDescending;
053:
054: public KualiTableRenderFormMetadata() {
055: sortDescending = false;
056: }
057:
058: /**
059: * Gets the columnToSortIndex attribute.
060: * @return Returns the columnToSortIndex.
061: */
062: public int getColumnToSortIndex() {
063: return columnToSortIndex;
064: }
065:
066: /**
067: * Sets the columnToSortIndex attribute value.
068: * @param columnToSortIndex The columnToSortIndex to set.
069: */
070: public void setColumnToSortIndex(int columnToSortIndex) {
071: this .columnToSortIndex = columnToSortIndex;
072: }
073:
074: /**
075: * Gets the previouslySortedColumnIndex attribute.
076: * @return Returns the previouslySortedColumnIndex.
077: */
078: public int getPreviouslySortedColumnIndex() {
079: return previouslySortedColumnIndex;
080: }
081:
082: /**
083: * Sets the previouslySortedColumnIndex attribute value.
084: * @param previouslySortedColumnIndex The previouslySortedColumnIndex to set.
085: */
086: public void setPreviouslySortedColumnIndex(
087: int previouslySortedColumnIndex) {
088: this .previouslySortedColumnIndex = previouslySortedColumnIndex;
089: }
090:
091: /**
092: * Gets the resultsActualSize attribute.
093: * @return Returns the resultsActualSize.
094: */
095: public int getResultsActualSize() {
096: return resultsActualSize;
097: }
098:
099: /**
100: * Sets the resultsActualSize attribute value.
101: * @param resultsActualSize The resultsActualSize to set.
102: */
103: public void setResultsActualSize(int resultsActualSize) {
104: this .resultsActualSize = resultsActualSize;
105: }
106:
107: /**
108: * Gets the resultsLimitedSize attribute.
109: * @return Returns the resultsLimitedSize.
110: */
111: public int getResultsLimitedSize() {
112: return resultsLimitedSize;
113: }
114:
115: /**
116: * Sets the resultsLimitedSize attribute value.
117: * @param resultsLimitedSize The resultsLimitedSize to set.
118: */
119: public void setResultsLimitedSize(int resultsLimitedSize) {
120: this .resultsLimitedSize = resultsLimitedSize;
121: }
122:
123: /**
124: * Gets the switchToPageNumber attribute.
125: * @return Returns the switchToPageNumber.
126: */
127: public int getSwitchToPageNumber() {
128: return switchToPageNumber;
129: }
130:
131: /**
132: * Sets the switchToPageNumber attribute value.
133: * @param switchToPageNumber The switchToPageNumber to set.
134: */
135: public void setSwitchToPageNumber(int switchToPageNumber) {
136: this .switchToPageNumber = switchToPageNumber;
137: }
138:
139: /**
140: * Gets the viewedPageNumber attribute.
141: * @return Returns the viewedPageNumber.
142: */
143: public int getViewedPageNumber() {
144: return viewedPageNumber;
145: }
146:
147: /**
148: * Sets the viewedPageNumber attribute value.
149: * @param viewedPageNumber The viewedPageNumber to set.
150: */
151: public void setViewedPageNumber(int viewedPageNumber) {
152: this .viewedPageNumber = viewedPageNumber;
153: }
154:
155: /**
156: * Gets the totalNumberOfPages attribute.
157: * @return Returns the totalNumberOfPages.
158: */
159: public int getTotalNumberOfPages() {
160: return totalNumberOfPages;
161: }
162:
163: /**
164: * Sets the totalNumberOfPages attribute value.
165: * @param totalNumberOfPages The totalNumberOfPages to set.
166: */
167: public void setTotalNumberOfPages(int totalNumberOfPages) {
168: this .totalNumberOfPages = totalNumberOfPages;
169: }
170:
171: /**
172: * Gets the firstRowIndex attribute.
173: * @return Returns the firstRowIndex.
174: */
175: public int getFirstRowIndex() {
176: return firstRowIndex;
177: }
178:
179: /**
180: * Sets the firstRowIndex attribute value.
181: * @param firstRowIndex The firstRowIndex to set.
182: */
183: public void setFirstRowIndex(int firstRowIndex) {
184: this .firstRowIndex = firstRowIndex;
185: }
186:
187: /**
188: * Gets the lastRowIndex attribute.
189: * @return Returns the lastRowIndex.
190: */
191: public int getLastRowIndex() {
192: return lastRowIndex;
193: }
194:
195: /**
196: * Sets the lastRowIndex attribute value.
197: * @param lastRowIndex The lastRowIndex to set.
198: */
199: public void setLastRowIndex(int lastRowIndex) {
200: this .lastRowIndex = lastRowIndex;
201: }
202:
203: /**
204: * Gets the sortDescending attribute.
205: * @return Returns the sortDescending.
206: */
207: public boolean isSortDescending() {
208: return sortDescending;
209: }
210:
211: /**
212: * Sets the sortDescending attribute value.
213: * @param sortDescending The sortDescending to set.
214: */
215: public void setSortDescending(boolean sortDescending) {
216: this .sortDescending = sortDescending;
217: }
218:
219: /**
220: * Sets the paging form parameters to go to the first page of the list
221: *
222: * @param listSize size of table being rendered
223: * @param maxRowsPerPage
224: */
225: public void jumpToFirstPage(int listSize, int maxRowsPerPage) {
226: jumpToPage(0, listSize, maxRowsPerPage);
227: }
228:
229: /**
230: * Sets the paging form parameters to go to the last page of the list
231: *
232: * @param listSize size of table being rendered
233: * @param maxRowsPerPage
234: */
235: public void jumpToLastPage(int listSize, int maxRowsPerPage) {
236: jumpToPage(TableRenderUtil.computeTotalNumberOfPages(listSize,
237: maxRowsPerPage) - 1, listSize, maxRowsPerPage);
238: }
239:
240: /**
241: * Sets the paging form parameters to go to the specified page of the list
242: *
243: * @param pageNumber first page is 0, must be non-negative. If the list is not large enough to have the page specified, then
244: * this method will be equivalent to calling jumpToLastPage.
245: * @param listSize size of table being rendered
246: * @param maxRowsPerPage
247: *
248: * @see KualiTableRenderFormMetadata#jumpToLastPage(int, int)
249: */
250: public void jumpToPage(int pageNumber, int listSize,
251: int maxRowsPerPage) {
252: int totalPages = TableRenderUtil.computeTotalNumberOfPages(
253: listSize, maxRowsPerPage);
254: setTotalNumberOfPages(totalPages);
255: if (pageNumber >= totalPages) {
256: pageNumber = totalPages - 1;
257: }
258: setViewedPageNumber(pageNumber);
259: setFirstRowIndex(TableRenderUtil.computeStartIndexForPage(
260: pageNumber, listSize, maxRowsPerPage));
261: setLastRowIndex(TableRenderUtil.computeLastIndexForPage(
262: pageNumber, listSize, maxRowsPerPage));
263: }
264:
265: }
|