KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > api > PagedListBean


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.api;
7
8 import java.util.*;
9
10 import javax.servlet.http.HttpServletRequest JavaDoc;
11
12 import org.apache.struts.action.ActionMapping;
13
14 import com.raptus.owxv3.LoggingManager;
15
16 /**
17  *
18  *
19  * <hr>
20  * <table width="100%" border="0">
21  * <tr>
22  * <td width="24%"><b>Filename</b></td><td width="76%">PagedListBean.java</td>
23  * </tr>
24  * <tr>
25  * <td width="24%"><b>Author</b></td><td width="76%">Guy Zürcher (gzuercher@raptus.com)</td>
26  * </tr>
27  * <tr>
28  * <td width="24%"><b>Date</b></td><td width="76%">29th of April 2001</td>
29  * </tr>
30  * </table>
31  * <hr>
32  * <table width="100%" border="0">
33  * <tr>
34  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
35  * </tr>
36  * </table>
37  * <hr>
38  */

39 public class PagedListBean extends OmniaWebBean
40 {
41     /**
42      * the whole list
43      */

44     protected Vector list = null;
45
46     /**
47      *
48      */

49     protected int offset = 0;
50
51     /**
52      * a value of 0 means all
53      */

54     protected int maxRows = 0;
55
56     /**
57      * starts with 1 (not with 0!)
58      */

59     protected int currentPage = 1;
60
61     /**
62      *
63      */

64     protected String JavaDoc uri = null;
65
66     /**
67      *
68      */

69     protected String JavaDoc vmodule=null;
70
71     /**
72      *
73      */

74     public void updatePage()
75     {
76         if(list != null && maxRows > 0)
77         {
78             offset = ((currentPage * maxRows) - maxRows);
79             if(offset >= list.size())
80                 offset = 0;
81         }
82         else
83             offset = 0;
84
85         //LoggingManager.log("updatePage| offset: "+offset+" maxRows: "+maxRows+" currentPage: "+currentPage+" pageCount: "+getPageCount()+" locale: "+currLocale.toString());
86
}
87
88     /**
89      *
90      */

91     public int getPageCount()
92     {
93         float count = 0;
94         if(list != null)
95         {
96             if(maxRows > 0)
97                 count = ((float) (list.size())) / ((float) maxRows);
98             else
99                 count = 1;
100             //LoggingManager.log("getPageCount| count: "+count+" count (int): "+((int)count)+" listsize: "+list.size());
101
if( count > ((float) ((int) count)) )
102                 count ++;
103         }
104
105         return (int) count;
106     }
107
108     /**
109      *
110      */

111     public void setCurrentPage(int pageNo)
112     {
113         if( (pageNo > 0) && (pageNo <= getPageCount()) )
114             currentPage = pageNo;
115         else
116             currentPage = 1;
117
118         updatePage();
119     }
120
121     /**
122      *
123      */

124     public boolean isListLoaded(Locale l,String JavaDoc vmid)
125     {
126         return (list != null && (currLocale != null && currLocale.equals(l)) && (vmodule!=null && vmodule.equals(vmid)) );
127     }
128
129     /**
130      *
131      */

132     public void setList(Vector list, Locale lcle,String JavaDoc vmid)
133     {
134         this.list = list;
135         this.currLocale = lcle;
136         this.vmodule=vmid;
137         updatePage();
138     }
139
140     /**
141      *
142      */

143     public Vector getList() { return list; }
144
145     /**
146      *
147      */

148     public int getMaxRows() { return maxRows; }
149     public void setMaxRows(int rows) { this.maxRows = rows; }
150
151     /**
152      *
153      */

154     public int getOffset() { return offset; }
155
156     /**
157      *
158      */

159     public int getCurrentPage() { return currentPage; }
160
161     /**
162      *
163      */

164     public String JavaDoc getURI() { return uri; }
165
166     /**
167      *
168      */

169     public void setURI(String JavaDoc uri) { this.uri = uri; }
170
171     /**
172      *
173      */

174     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request)
175     {
176 // setList(null, currLocale, vmodule);
177

178         super.reset(mapping, request);
179     }
180
181 }
182
183 // eof
184
Popular Tags