01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/common/tool-lib/src/java/org/theospi/portfolio/shared/tool/PagingList.java $
03: * $Id: PagingList.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.shared.tool;
21:
22: import java.util.List;
23:
24: /**
25: * Created by IntelliJ IDEA.
26: * User: John Ellis
27: * Date: Nov 18, 2005
28: * Time: 3:14:15 PM
29: * To change this template use File | Settings | File Templates.
30: */
31: public class PagingList {
32:
33: private int firstItem = 0;
34: private int pageSize = 10;
35:
36: private List wholeList;
37:
38: public PagingList(List wholeList) {
39: this .wholeList = wholeList;
40: }
41:
42: public int getTotalItems() {
43: return wholeList.size();
44: }
45:
46: public boolean isRendered() {
47: return getTotalItems() > 0;
48: }
49:
50: public int getFirstItem() {
51: return firstItem;
52: }
53:
54: public void setFirstItem(int firstItem) {
55: this .firstItem = firstItem;
56: }
57:
58: public int getPageSize() {
59: return pageSize;
60: }
61:
62: public void setPageSize(int pageSize) {
63: this .pageSize = pageSize;
64: }
65:
66: public List getWholeList() {
67: return wholeList;
68: }
69:
70: public void setWholeList(List wholeList) {
71: this .wholeList = wholeList;
72: }
73:
74: public List getSubList() {
75: if (pageSize == 0) {
76: return wholeList;
77: } else {
78: return wholeList.subList(getFirstItem(), getLastItem());
79: }
80: }
81:
82: public int getLastItem() {
83: int lastItem = getFirstItem() + getPageSize();
84: if (lastItem >= wholeList.size()) {
85: lastItem = wholeList.size();
86: }
87: return lastItem;
88: }
89: }
|