1 23 package org.objectweb.clif.scenario.util.isac.plugin.gui; 24 25 import java.util.Enumeration ; 26 import java.util.EventListener ; 27 import java.util.Hashtable ; 28 import java.util.Vector ; 29 30 import org.apache.log4j.Category; 31 import org.eclipse.swt.SWT; 32 import org.eclipse.swt.events.ModifyListener; 33 import org.eclipse.swt.layout.GridLayout; 34 import org.eclipse.swt.widgets.Composite; 35 import org.objectweb.clif.scenario.util.isac.plugin.ObjectDescription; 36 import org.objectweb.clif.scenario.util.isac.plugin.PluginDescription; 37 import org.objectweb.clif.scenario.util.isac.plugin.SampleDescription; 38 import org.objectweb.clif.scenario.util.isac.plugin.TestDescription; 39 import org.objectweb.clif.scenario.util.isac.plugin.TimerDescription; 40 import org.objectweb.clif.scenario.util.isac.util.tree.Node; 41 42 48 public class ParameterPanel extends Composite { 49 private Hashtable params; 50 51 private Composite parent; 52 53 static Category cat = Category.getInstance(ParameterPanel.class.getName()); 54 55 61 public ParameterPanel(Composite parent) { 62 super(parent, SWT.FLAT); 63 cat.debug("-> constructor"); 64 this.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); 65 GridLayout grid = new GridLayout(); 66 grid.numColumns = 1; 67 this.setLayout(grid); 68 this.params = new Hashtable (); 69 } 70 71 85 public Composite addWidget(Hashtable params, int style, String name, 86 String label, Composite c, EventListener listener) { 87 cat.debug("-> addWidget"); 88 ParameterWidget pw = new ParameterWidget(style, name, label, params, c, 89 listener); 90 this.params.put(name, pw); 91 this.layout(); 92 return pw.getComposite(); 93 } 94 95 100 public Hashtable getParametersValues() { 101 cat.debug("-> getParametersValues"); 102 Hashtable values = new Hashtable (); 103 Enumeration e = this.params.elements(); 104 while (e.hasMoreElements()) { 105 ParameterWidget temp = (ParameterWidget) e.nextElement(); 106 if (temp.getStyle() != WidgetDescription.GROUP) { 107 if (temp.getValue() != null) 108 values.put(temp.getName(), temp.getValue()); 109 else 110 values.put(temp.getName(), ""); 111 } 112 } 113 return values; 114 } 115 116 127 public static void createNewPanelsFromXML(PluginDescription plugin, 128 String fileName, Hashtable panels) { 129 130 cat.debug("-> createNewPanelsFromXML"); 131 if ((fileName == null) || (fileName.equals("null"))) { 133 createNewDefaultsPanels(plugin, panels); 134 return; 135 } 136 137 Vector errors = GUIDescriptionParser.loadGUIDescriptionFile(fileName, 139 plugin, panels); 140 } 141 142 150 private static void createNewDefaultsPanels(PluginDescription plugin, 151 Hashtable panels) { 152 cat.debug("-> createNewDefaultsPanels"); 153 ObjectDescription obj = plugin.getObject(); 155 if (obj != null) { 157 Vector params = obj.getParams(); 158 cat.warn("THE NB PARAMS = " + params.size()); 159 ParametersWidgetsNode tree = ParametersWidgetsNode 160 .createParametersWidgetsNode(params.elements(), Node.USE, 161 plugin.getName()); 162 int intKey = tree.hashCode(); 163 while (panels.containsKey(new String ((new Integer (intKey)) 164 .toString()))) 165 intKey++; 166 panels.put(new String ((new Integer (intKey)).toString()), tree); 167 obj.setGUIKey(new String ((Integer.toString(intKey)))); 168 } 169 Hashtable samples = plugin.getSamples(); 171 if (samples != null) { 172 Enumeration samplesKeys = samples.keys(); 174 while (samplesKeys.hasMoreElements()) { 175 String sampleKey = (String ) samplesKeys.nextElement(); 176 SampleDescription sample = (SampleDescription) samples 177 .get(sampleKey); 178 Vector params = sample.getParams(); 179 if (params != null) { 180 ParametersWidgetsNode tree = ParametersWidgetsNode 181 .createParametersWidgetsNode(params.elements(), 182 Node.SAMPLE, plugin.getName()); 183 int intKey = tree.hashCode(); 184 while (panels.containsKey(new String ((new Integer (intKey)) 185 .toString()))) 186 intKey++; 187 panels.put(new String ((new Integer (intKey)).toString()), 188 tree); 189 sample.setGUIKey(new String ((new Integer (intKey)) 190 .toString())); 191 } else { 192 ParametersWidgetsNode tree = ParametersWidgetsNode 193 .createParametersWidgetsNode(null, Node.SAMPLE, 194 plugin.getName()); 195 int intKey = tree.hashCode(); 196 while (panels.containsKey(new String ((new Integer (intKey)) 197 .toString()))) 198 intKey++; 199 panels.put(new String ((new Integer (intKey)).toString()), 200 tree); 201 sample.setGUIKey(new String ((new Integer (intKey)) 202 .toString())); 203 } 204 } 205 } 206 Hashtable timers = plugin.getTimers(); 208 if (timers != null) { 209 Enumeration timersKeys = timers.keys(); 211 while (timersKeys.hasMoreElements()) { 212 String timerKey = (String ) timersKeys.nextElement(); 213 TimerDescription timer = (TimerDescription) timers 214 .get(timerKey); 215 Vector params = timer.getParams(); 216 if (params != null) { 217 ParametersWidgetsNode tree = ParametersWidgetsNode 218 .createParametersWidgetsNode(params.elements(), 219 Node.TIMER, plugin.getName()); 220 int intKey = tree.hashCode(); 221 while (panels.containsKey(new String ((new Integer (intKey)) 222 .toString()))) 223 intKey++; 224 panels.put(new String ((new Integer (intKey)).toString()), 225 tree); 226 timer 227 .setGUIKey(new String ((new Integer (intKey)) 228 .toString())); 229 } else { 230 ParametersWidgetsNode tree = ParametersWidgetsNode 231 .createParametersWidgetsNode(null, Node.TIMER, 232 plugin.getName()); 233 int intKey = tree.hashCode(); 234 while (panels.containsKey(new String ((new Integer (intKey)) 235 .toString()))) 236 intKey++; 237 panels.put(new String ((new Integer (intKey)).toString()), 238 tree); 239 timer 240 .setGUIKey(new String ((new Integer (intKey)) 241 .toString())); 242 } 243 } 244 } 245 Hashtable tests = plugin.getTests(); 247 if (tests != null) { 248 Enumeration testsKeys = tests.keys(); 250 while (testsKeys.hasMoreElements()) { 251 String testKey = (String ) testsKeys.nextElement(); 252 TestDescription test = (TestDescription) tests.get(testKey); 253 Vector params = test.getParams(); 254 if (params != null) { 255 ParametersWidgetsNode tree = ParametersWidgetsNode 256 .createParametersWidgetsNode(params.elements(), 257 Node.TEST, plugin.getName()); 258 int intKey = tree.hashCode(); 259 while (panels.containsKey(new String ((new Integer (intKey)) 260 .toString()))) 261 intKey++; 262 panels.put(new String ((new Integer (intKey)).toString()), 263 tree); 264 test 265 .setGUIKey(new String ((new Integer (intKey)) 266 .toString())); 267 } else { 268 ParametersWidgetsNode tree = ParametersWidgetsNode 269 .createParametersWidgetsNode(null, Node.TEST, 270 plugin.getName()); 271 int intKey = tree.hashCode(); 272 while (panels.containsKey(new String ((new Integer (intKey)) 273 .toString()))) 274 intKey++; 275 panels.put(new String ((new Integer (intKey)).toString()), 276 tree); 277 test 278 .setGUIKey(new String ((new Integer (intKey)) 279 .toString())); 280 } 281 } 282 } 283 } 284 285 297 public static ParameterPanel createParameterPanel( 298 ParametersWidgetsNode node, Composite parent, 299 ModifyListener listener) { 300 cat.debug("-> createParameterPanel"); 301 ParameterPanel panel = new ParameterPanel(parent); 302 analyseParametersWidgetsNode(panel, node, panel, listener); 303 304 return panel; 305 } 306 307 319 private static void analyseParametersWidgetsNode(ParameterPanel panel, 320 ParametersWidgetsNode node, Composite parent, 321 ModifyListener listener) { 322 cat.debug("-> analyseParametersWidgetsNode"); 323 WidgetDescription desc = node.getWidget(); 324 Composite composite = null; 325 if (desc != null) { 326 composite = panel.addWidget(desc.getParams(), desc.getType(), desc 327 .getText(), desc.getLabel(), parent, listener); 328 if (composite == null) 329 return; 330 } else 331 composite = parent; 332 Vector children = node.getChildren(); 334 for (int i = 0; i < children.size(); i++) { 335 ParametersWidgetsNode child = (ParametersWidgetsNode) children 336 .elementAt(i); 337 analyseParametersWidgetsNode(panel, child, composite, listener); 338 } 339 } 340 341 347 public void setComboValues(Vector values) { 348 cat.debug("-> setComboValues"); 349 if (this.params.containsKey("id")) { 350 ParameterWidget pw = (ParameterWidget) this.params.get("id"); 351 pw.setComboValues(values); 352 } 353 } 354 355 361 public void setParametersValues(Hashtable values) { 362 cat.debug("-> set ParametersValues"); 363 if (values == null) 364 return; 365 Enumeration keys = values.keys(); 367 while (keys.hasMoreElements()) { 368 String name = (String ) keys.nextElement(); 369 if (this.params.containsKey(name)) { 370 ((ParameterWidget) this.params.get(name)) 371 .setValue((String ) values.get(name)); 372 } else { 373 cat.warn(name + " can't be found"); 374 } 375 } 376 } 377 378 public boolean addButtonSelected(Object source) { 379 Enumeration elements = params.elements(); 380 while (elements.hasMoreElements()) { 381 ParameterWidget pw = (ParameterWidget) elements.nextElement(); 382 if (pw.getStyle() == WidgetDescription.NFIELD) { 383 if (pw.addEmtyFieldForNField(source)) 384 return true; 385 } else if (pw.getStyle() == WidgetDescription.TABLE) { 386 if (pw.addEmtyEntryForTable(source)) 387 return true; 388 } 389 } 390 return false; 391 } 392 393 public boolean removeButtonSelected(Object source) { 394 Enumeration elements = params.elements(); 395 while (elements.hasMoreElements()) { 396 ParameterWidget pw = (ParameterWidget) elements.nextElement(); 397 if (pw.getStyle() == WidgetDescription.NFIELD) { 398 if (pw.removeLastFieldForNField(source)) 399 return true; 400 } else if (pw.getStyle() == WidgetDescription.TABLE) { 401 if (pw.removeLastEntryForTable(source)) 402 return true; 403 } 404 } 405 return false; 406 } 407 408 public boolean modifySomething(Object source) { 409 Enumeration elements = params.elements(); 410 while (elements.hasMoreElements()) { 411 ParameterWidget pw = (ParameterWidget) elements.nextElement(); 412 if (pw.getStyle() == WidgetDescription.TABLE) { 413 if (pw.modifyText(source)) 414 return true; 415 } 416 } 417 return false; 418 } 419 420 423 public void dispose() { 424 cat.debug("-> dispose"); 425 if (params != null) { 426 Enumeration elements = params.elements(); 427 while (elements.hasMoreElements()) { 428 ParameterWidget pw = (ParameterWidget) elements.nextElement(); 429 pw.dispose(); 430 } 431 } 432 this.dispose(); 433 } 434 } | Popular Tags |