KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class CategoryPagedBean extends PagedListBean
17 {
18     CategorySelector catsel;
19     CategoryFilter filter;
20     Vector elements;
21     Hashtable values;
22     String JavaDoc selcatid=null;
23     
24     
25     /**
26      * this will return the updated page count, using the created category filter
27      */

28     public int getPageCount()
29     {
30         float count = 0;
31         if(elements != null)
32         {
33             if(maxRows > 0)
34                 count = ((float) (elements.size())) / ((float) maxRows);
35             else
36                 count = 1;
37             //LoggingManager.log("getPageCount| count: "+count+" count (int): "+((int)count)+" listsize: "+list.size());
38
if( count > ((float) ((int) count)) )
39                 count ++;
40         }
41
42         return (int) count;
43     }
44
45     /**
46      * return the number of pages, after aplying the filter
47      * actually returns the number of pages using the filter vector? :)
48      */

49     public void updatePage()
50     {
51        if(elements!= null && maxRows > 0)
52         {
53             offset = ((currentPage * maxRows) - maxRows);
54             if(offset >= elements.size())
55                 offset = 0;
56         }
57         else
58             offset = 0;
59     }
60
61     /**
62      * return list of selected items
63      */

64     public Vector getList()
65     {
66         return elements;
67     }
68
69     /**
70      * set the category selector
71      */

72     public void setCategorySelector(CategorySelector selector)
73     {
74         this.catsel = selector;
75     }
76
77     public CategorySelector getCategorySelector()
78     {
79         return catsel;
80     }
81
82     /*
83      * return the categories
84      */

85     public Vector getCategories()
86     {
87         return catsel.getGResCategories();
88     }
89
90     /*
91      * return the category names
92      */

93     public Vector getCategoryNames()
94     {
95         //Vector v = catsel.getCategoryNames();
96
//for(int i=0;i<v.size();i++)
97
//{
98
// LoggingManager.log("cat "+(String)v.elementAt(i));
99
//}
100
return catsel.getCategoryNames();
101     }
102
103     /*
104      * change folder status
105      */

106     public void togleFolder(String JavaDoc id)
107     {
108        catsel.togleFolder(id);
109     }
110
111     /*
112      * return true if folder is open, false if not
113      */

114     public boolean isOpen(String JavaDoc id)
115     {
116         return catsel.isOpen(id);
117     }
118
119     public Vector getFolderStatus()
120     {
121         return catsel.getFolderStatus();
122     }
123
124     public Vector getTree(String JavaDoc id,Locale l)
125     {
126         return catsel.getTree(id,l);
127     }
128
129     
130
131     public String JavaDoc getSelCatID()
132     {
133         return selcatid;
134     }
135
136     public void setSelCatID(String JavaDoc s)
137     {
138         selcatid = s;
139     }
140
141     /**
142      * get the data from request values
143      */

144     public void setValues(Hashtable values)
145     {
146         this.values = values;
147         
148         String JavaDoc cat = (String JavaDoc)values.get("catid");
149         if(cat != null)
150         {
151             try
152             {
153
154                 togleFolder(cat);
155             }
156             catch(Exception JavaDoc ex)
157             {
158             }
159         }
160         String JavaDoc catid = (String JavaDoc)values.get("selcatid");
161         if(catid!=null)
162         {
163             String JavaDoc first=(String JavaDoc)values.get("first");
164             if(first!=null)
165             {
166                 /*
167                   we were called the firdt time
168                  only if selCatID==null initialize
169                  */

170                 if( getSelCatID()==null ) this.setSelCatID(catid);
171             }
172             else
173             {
174                 this.setSelCatID(catid);
175             }
176         }
177         catid=getSelCatID();
178         if(catid!=null)
179         {
180            
181             filter = new CategoryFilter(catid);
182            
183             // got the filter. Now set up the elements wich are both in filter and
184
// in list of items
185
Vector v = filter.getIDs();
186             //LoggingManager.log("Vector size="+v.size());
187
elements = null;
188             elements = new Vector();
189             int indexes[]=new int[list.size()];
190             for (int i=0;i<indexes.length;i++) indexes[i]=0;
191
192             for(int i=0;i<v.size();i++)
193             {
194                 int id = ((Integer JavaDoc)v.elementAt(i)).intValue();
195                 for(int j=0;j<list.size();j++)
196                 {
197
198                     ComparableItemIFace ifa = (ComparableItemIFace)list.elementAt(j);
199                     if(ifa.equals(id))
200                     {
201                         //elements.add(ifa);
202
indexes[j]=1;
203                     }
204                 }
205             }
206
207             for(int j=0;j<list.size();j++)
208             {
209                 if(indexes[j]>0) elements.add(list.elementAt(j));
210
211             }
212
213         }
214         else
215         {
216
217             selcatid=null;
218             elements = null;
219             elements = list;
220             //LoggingManager.log("Setting all:"+elements.size());
221
}
222     }
223
224     public Hashtable getValues()
225     {
226         return values;
227     }
228
229
230     public String JavaDoc getURL()
231     {
232         return super.getURI();
233     }
234
235
236     public String JavaDoc getURI()
237     {
238         String JavaDoc s = super.getURI();
239         if(s.indexOf("selcatid=")==-1)
240         {
241             return s+"?selcatid="+selcatid;
242         }
243         return s;
244     }
245     
246     public void setList(Vector list, Locale lcle,String JavaDoc vmid)
247     {
248         String JavaDoc oldvm=vmodule;
249         if(oldvm!=null)
250         {
251             if(! vmid.equals(oldvm))
252             {
253                 //We have swicthed to another vmodule
254
setSelCatID(null);
255             }
256         }
257         super.setList(list,lcle,vmid);
258             
259     }
260     
261     /**
262      *
263      */

264     public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request)
265     {
266 // CategorySelector catsel = null;
267
// CategoryFilter filter = null;
268
// Vector elements = null;
269
// Hashtable values = null;
270
// String selcatid = null;
271

272         super.reset(mapping, request);
273     }
274     
275 }
276
277
Popular Tags