1 package org.apache.turbine.util.template; 2 3 18 19 import org.apache.ecs.html.Option; 20 import org.apache.ecs.html.Select; 21 22 65 public class SelectorBox 66 { 67 68 private Select sel = null; 69 70 71 private int size = 1; 72 73 74 private String name = null; 75 76 77 private Object [] names = null; 78 79 80 private Object [] values = null; 81 82 83 private boolean[] selected = null; 84 85 93 public SelectorBox(String name, Object [] names, Object [] values) 94 { 95 this(name, names, values, 1, null); 96 } 97 98 106 public SelectorBox(String name, Object [] names, Object [] values, int size) 107 { 108 this(name, names, values, size, null); 109 } 110 111 119 public SelectorBox(String name, Object [] names, Object [] values, 120 boolean[] selected) 121 { 122 this(name, names, values, 1, selected); 123 } 124 125 134 public SelectorBox(String name, Object [] names, Object [] values, int size, 135 boolean[] selected) 136 { 137 this.name = name; 138 this.names = names; 139 this.values = values; 140 this.size = size; 141 this.selected = selected; 142 143 sel = new Select(name, size); 144 sel.setName(name); 145 sel.setSize(size); 146 } 147 148 160 public void buildBooleans(Object [] selectedSet, Object [] entireSet) 161 { 162 selected = new boolean[entireSet.length]; 163 for (int j = 0; j < entireSet.length; j++) 164 { 165 Object r2 = entireSet[j]; 166 for (int i = 0; i < selectedSet.length; i++) 167 { 168 Object r1 = selectedSet[i]; 169 if (r1 != null && r2 != null && 170 r1.toString().equalsIgnoreCase(r2.toString())) 171 { 172 selected[j] = true; 173 } 174 } 175 } 176 } 177 178 186 public String toString(int size) 187 { 188 sel.setSize(size); 189 sel.setName(name); 190 for (int f = 0; f < values.length; f++) 191 { 192 Option opt = new Option((String ) values[f]); 193 opt.addElement((String ) names[f]); 194 if (selected != null && selected[f] == true) 195 { 196 opt.setSelected(true); 197 } 198 sel.addElement(opt); 199 } 200 String output = sel.toString(); 201 reset(); 202 return output; 203 } 204 205 208 public void reset() 209 { 210 sel = new Select(name, size); 211 } 212 213 221 public String toString() 222 { 223 return this.toString(size); 224 } 225 226 236 public SelectorBox setMultiple(boolean val) 237 { 238 sel.setMultiple(val); 239 return this; 240 } 241 242 249 public SelectorBox setName(String name) 250 { 251 this.name = name; 252 sel.setName(name); 253 return this; 254 } 255 256 262 public SelectorBox setSize(int size) 263 { 264 this.size = size; 265 sel.setSize(size); 266 return this; 267 } 268 269 275 public SelectorBox setOnChange(String script) 276 { 277 sel.setOnChange(script); 278 return this; 279 } 280 281 287 public SelectorBox setSelected(boolean[] bools) 288 { 289 this.selected = bools; 290 return this; 291 } 292 293 300 public SelectorBox setSelected(Object name) 301 { 302 if (name != null) 303 { 304 selected = new boolean[names.length]; 305 for (int i = 0; i < names.length; i++) 306 { 307 Object o = names[i]; 308 if (o != null && o.toString().equalsIgnoreCase(name.toString())) 309 { 310 selected[i] = true; 311 } 312 } 313 } 314 return this; 315 } 316 } 317 | Popular Tags |