1 package org.apache.turbine.util; 2 3 56 57 import org.apache.ecs.Element; 58 import org.apache.ecs.GenericElement; 59 import org.apache.ecs.html.Option; 60 import org.apache.ecs.html.Select; 61 62 105 public class SelectorBox 106 { 107 108 private Select sel = null; 109 110 111 private int size = 1; 112 113 114 private String name = null; 115 116 117 private Object [] names = null; 118 119 120 private Object [] values = null; 121 122 123 private boolean[] selected = null; 124 125 126 134 public SelectorBox ( String name, 135 Object [] names, 136 Object [] values ) 137 { 138 this(name, names,values, 1, null); 139 } 140 141 149 public SelectorBox ( String name, 150 Object [] names, 151 Object [] values, 152 int size ) 153 { 154 this(name, names,values, size, null); 155 } 156 157 165 public SelectorBox ( String name, 166 Object [] names, 167 Object [] values, 168 boolean[] selected ) 169 { 170 this(name, names,values, 1, selected); 171 } 172 173 182 public SelectorBox ( String name, 183 Object [] names, 184 Object [] values, 185 int size, 186 boolean[] selected ) 187 { 188 this.name = name; 189 this.names = names; 190 this.values = values; 191 this.size = size; 192 this.selected = selected; 193 194 sel = new Select(name, size); 195 sel.setName(name); 196 sel.setSize(size); 197 } 198 199 211 public void buildBooleans(Object [] selectedSet, 212 Object [] entireSet) 213 { 214 selected = new boolean[entireSet.length]; 215 for ( int j=0; j<entireSet.length; j++ ) 216 { 217 Object r2 = entireSet[j]; 218 for ( int i=0; i<selectedSet.length; i++ ) 219 { 220 Object r1 = selectedSet[i]; 221 if ( r1 != null && r2 != null && 222 r1.toString().equalsIgnoreCase(r2.toString()) ) 223 { 224 selected[j] = true; 225 } 226 } 227 } 228 } 229 230 238 public String toString(int size) 239 { 240 sel.setSize(size); 241 sel.setName(name); 242 for (int f=0;f<values.length;f++) 243 { 244 Option opt = new Option((String )values[f]); 245 opt.addElement((String )names[f]); 246 if ( selected != null && selected[f] == true ) 247 { 248 opt.setSelected(true); 249 } 250 sel.addElement(opt); 251 } 252 String output = sel.toString(); 253 reset(); 254 return output; 255 } 256 257 260 public void reset() 261 { 262 sel = new Select(name, size); 263 } 264 265 273 public String toString() 274 { 275 return this.toString(size); 276 } 277 278 288 public SelectorBox setMultiple ( boolean val ) 289 { 290 sel.setMultiple(val); 291 return this; 292 } 293 294 301 public SelectorBox setName ( String name ) 302 { 303 this.name = name; 304 sel.setName(name); 305 return this; 306 } 307 308 314 public SelectorBox setSize(int size) 315 { 316 this.size = size; 317 sel.setSize(size); 318 return this; 319 } 320 321 327 public SelectorBox setOnChange(String script) 328 { 329 sel.setOnChange(script); 330 return this; 331 } 332 333 339 public SelectorBox setSelected(boolean[] bools) 340 { 341 this.selected = bools; 342 return this; 343 } 344 345 352 public SelectorBox setSelected(Object name) 353 { 354 if (name != null) 355 { 356 selected = new boolean[names.length]; 357 for ( int i=0; i<names.length; i++ ) 358 { 359 Object o = names[i]; 360 if ( o != null && 361 o.toString().equalsIgnoreCase(name.toString()) ) 362 { 363 selected[i] = true; 364 } 365 } 366 } 367 return this; 368 } 369 } 370 | Popular Tags |