1 5 6 package com.raptus.owxv3.api; 7 8 import java.util.*; 9 10 import javax.servlet.http.HttpServletRequest ; 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 selcatid=null; 23 24 25 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 if( count > ((float) ((int) count)) ) 39 count ++; 40 } 41 42 return (int) count; 43 } 44 45 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 64 public Vector getList() 65 { 66 return elements; 67 } 68 69 72 public void setCategorySelector(CategorySelector selector) 73 { 74 this.catsel = selector; 75 } 76 77 public CategorySelector getCategorySelector() 78 { 79 return catsel; 80 } 81 82 85 public Vector getCategories() 86 { 87 return catsel.getGResCategories(); 88 } 89 90 93 public Vector getCategoryNames() 94 { 95 return catsel.getCategoryNames(); 101 } 102 103 106 public void togleFolder(String id) 107 { 108 catsel.togleFolder(id); 109 } 110 111 114 public boolean isOpen(String 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 id,Locale l) 125 { 126 return catsel.getTree(id,l); 127 } 128 129 130 131 public String getSelCatID() 132 { 133 return selcatid; 134 } 135 136 public void setSelCatID(String s) 137 { 138 selcatid = s; 139 } 140 141 144 public void setValues(Hashtable values) 145 { 146 this.values = values; 147 148 String cat = (String )values.get("catid"); 149 if(cat != null) 150 { 151 try 152 { 153 154 togleFolder(cat); 155 } 156 catch(Exception ex) 157 { 158 } 159 } 160 String catid = (String )values.get("selcatid"); 161 if(catid!=null) 162 { 163 String first=(String )values.get("first"); 164 if(first!=null) 165 { 166 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 Vector v = filter.getIDs(); 186 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 )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 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 } 222 } 223 224 public Hashtable getValues() 225 { 226 return values; 227 } 228 229 230 public String getURL() 231 { 232 return super.getURI(); 233 } 234 235 236 public String getURI() 237 { 238 String 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 vmid) 247 { 248 String oldvm=vmodule; 249 if(oldvm!=null) 250 { 251 if(! vmid.equals(oldvm)) 252 { 253 setSelCatID(null); 255 } 256 } 257 super.setList(list,lcle,vmid); 258 259 } 260 261 264 public void reset(ActionMapping mapping, HttpServletRequest request) 265 { 266 272 super.reset(mapping, request); 273 } 274 275 } 276 277 | Popular Tags |