1 23 package org.objectweb.clif.scenario.util.isac.plugin.gui; 24 25 import java.util.Hashtable ; 26 import java.util.StringTokenizer ; 27 import java.util.Vector ; 28 29 import org.apache.log4j.Category; 30 import org.eclipse.jface.window.ApplicationWindow; 31 import org.eclipse.swt.SWT; 32 import org.eclipse.swt.custom.ScrolledComposite; 33 import org.eclipse.swt.events.ModifyEvent; 34 import org.eclipse.swt.events.ModifyListener; 35 import org.eclipse.swt.events.SelectionEvent; 36 import org.eclipse.swt.events.SelectionListener; 37 import org.eclipse.swt.layout.FillLayout; 38 import org.eclipse.swt.layout.GridData; 39 import org.eclipse.swt.layout.GridLayout; 40 import org.eclipse.swt.widgets.Combo; 41 import org.eclipse.swt.widgets.Composite; 42 import org.eclipse.swt.widgets.Label; 43 import org.objectweb.clif.scenario.util.isac.gui.ScenarioGUIEditor; 44 import org.objectweb.clif.scenario.util.isac.plugin.PluginDescription; 45 import org.objectweb.clif.scenario.util.isac.plugin.PluginManager; 46 import org.objectweb.clif.scenario.util.isac.util.tree.Node; 47 import org.objectweb.clif.scenario.util.isac.util.tree.NodeDescription; 48 import org.objectweb.clif.scenario.util.isac.util.tree.ScenarioNode; 49 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager; 50 import org.objectweb.clif.scenario.util.isac.util.tree.nodes.NonePluginNode; 51 58 public class PluginGUIManager implements SelectionListener, ModifyListener { 59 static Category cat = Category.getInstance(PluginGUIManager.class.getName()) ; 60 61 64 protected static PluginGUIManager instance = null; 65 68 private Hashtable panels; 69 private Composite parent; 70 private ScrolledComposite top; 71 private ScrolledComposite contents; 72 private Composite contentsComposite; 73 private Composite topComposite; 74 private Composite mainComposite; 75 private Composite main; 76 private Label topLabel; 77 private GridData gridDataTop; 78 private ParameterPanel parametersPanel; 79 private ScenarioNode currentNode; 80 private Combo comboTop; 81 private ScenarioGUIEditor window; 82 private Hashtable nonePluginPanels ; 83 84 87 protected PluginGUIManager(ApplicationWindow window) { 88 cat.debug("-> constructor") ; 89 this.panels = new Hashtable (); 90 this.window = (ScenarioGUIEditor) window; 91 } 92 93 98 public static PluginGUIManager getPluginGUIManager(ApplicationWindow window) { 99 cat.debug("-> getPluginGUIManager") ; 100 if (instance == null) { 101 if (window == null) 102 return null; 103 instance = new PluginGUIManager(window); 104 } 105 return instance; 106 } 107 108 115 public void setParentComposite(Composite parent) { 116 cat.debug("-> setParentComposite") ; 117 this.parent = new Composite(parent, SWT.FLAT); 119 GridLayout gridLayout = new GridLayout(); 121 gridLayout.verticalSpacing = 4; 122 gridLayout.numColumns = 1; 123 gridLayout.marginHeight = 0; 124 gridLayout.marginWidth = 0; 125 this.parent.setLayout(gridLayout); 126 this.top = new ScrolledComposite(this.parent, SWT.BORDER | SWT.H_SCROLL 128 | SWT.V_SCROLL); 129 this.top.setExpandHorizontal(true); 130 this.top.setExpandVertical(true); 131 this.top.setAlwaysShowScrollBars(false); 132 this.gridDataTop = new GridData(); 134 gridDataTop.grabExcessHorizontalSpace = true; 135 gridDataTop.horizontalAlignment = GridData.FILL; 136 this.top.setLayoutData(this.gridDataTop); 137 this.main = new Composite(this.parent, SWT.FLAT); 139 this.main.setLayout(new FillLayout()); 140 this.main.setBackground(this.parent.getDisplay().getSystemColor( 141 SWT.COLOR_WHITE)); 142 GridData gridDataMain = new GridData(); 143 gridDataMain.grabExcessHorizontalSpace = true; 144 gridDataMain.grabExcessVerticalSpace = true; 145 gridDataMain.horizontalAlignment = GridData.FILL; 146 gridDataMain.verticalAlignment = GridData.FILL; 147 this.main.setLayoutData(gridDataMain); 148 this.mainComposite = new Composite(this.main, SWT.BORDER); 150 this.mainComposite.setBackground(this.parent.getDisplay() 151 .getSystemColor(SWT.COLOR_WHITE)); 152 153 this.createLabelTopComposite("Panel for parameters nodes edition"); 155 } 156 157 160 private void updateTopPanel() { 161 cat.debug("-> updateTopPanel") ; 162 this.top.setContent(this.topComposite); 163 this.top.setMinSize(this.topComposite.computeSize(SWT.DEFAULT, 164 SWT.DEFAULT)); 165 this.top.layout(); 166 this.topComposite.layout(); 167 this.gridDataTop.heightHint = this.topComposite.computeSize( 169 SWT.DEFAULT, SWT.DEFAULT).y; 170 this.parent.layout(); 171 } 172 173 180 private void createLabelTopComposite(String text) { 181 cat.debug("-> createLabelTopComposite") ; 182 this.topComposite = new Composite(this.top, SWT.FLAT); 184 this.topComposite.setBackground(this.top.getDisplay().getSystemColor( 185 SWT.COLOR_WHITE)); 186 GridLayout gridLayout = new GridLayout(); 188 gridLayout.numColumns = 1; 189 this.topComposite.setLayout(gridLayout); 190 this.topLabel = new Label(this.topComposite, SWT.CENTER | SWT.BORDER); 191 GridData gridData = new GridData(); 193 gridData.horizontalAlignment = GridData.FILL; 194 gridData.grabExcessHorizontalSpace = true; 195 this.topLabel.setLayoutData(gridData); 196 this.topLabel.setText(text); 197 this.updateTopPanel(); 198 } 199 200 207 private void createTestSwitcherTopComposite(String type) { 208 cat.debug("-> createTestSwitcherTopComposite") ; 209 this.topComposite = new Composite(this.top, SWT.FLAT); 210 this.topComposite.setBackground(this.top.getDisplay().getSystemColor( 211 SWT.COLOR_WHITE)); 212 GridLayout gridLayout = new GridLayout(); 214 gridLayout.numColumns = 1; 215 this.topComposite.setLayout(gridLayout); 216 this.topLabel = new Label(this.topComposite, SWT.CENTER | SWT.BORDER); 217 GridData gridData = new GridData(); 219 gridData.horizontalAlignment = GridData.FILL; 220 gridData.grabExcessHorizontalSpace = true; 221 this.topLabel.setLayoutData(gridData); 222 this.topLabel.setText("Select a test condition of the " + type 223 + " controler node :"); 224 this.comboTop = new Combo(this.topComposite, SWT.FLAT | SWT.READ_ONLY); 226 this.comboTop.setBackground(this.top.getDisplay().getSystemColor( 227 SWT.COLOR_WHITE)); 228 GridData gridDataCombo = new GridData(); 229 gridDataCombo.horizontalAlignment = GridData.FILL; 230 gridDataCombo.grabExcessHorizontalSpace = true; 231 comboTop.setLayoutData(gridDataCombo); 232 comboTop.addSelectionListener(this); 234 Vector usedPlugins = (TreeManager.getTreeManager(null)).getUsedPluginsName() ; 237 Vector nodesDescs = (PluginManager.getPluginManager()) 238 .createNodesDescriptionsByPlugins(usedPlugins, Node.TEST); 239 for (int i = 0; i < nodesDescs.size(); i++) { 241 NodeDescription nodeDesc = (NodeDescription) nodesDescs 242 .elementAt(i); 243 comboTop.add(nodeDesc.getPlugin() + "." + nodeDesc.getActionName()); 244 } 245 this.comboTop.setText(""); 247 this.updateTopPanel(); 248 } 249 250 256 public void switchPanel(ScenarioNode node) { 257 cat.debug("-> switchPanel") ; 258 this.currentNode = node; 260 if (this.topComposite != null) 263 this.topComposite.dispose(); 264 if (this.mainComposite != null) 265 this.mainComposite.dispose(); 266 TreeManager treeManager = TreeManager.getTreeManager(null); 268 String type = treeManager.getNodeType(node); 270 if (type == null) { 271 this.createLabelTopComposite("Panel for parameters nodes edition"); 272 showParametersEditionPanel(null, null); 273 return; 274 } 275 if (Node.isPluginNode(type)) { 277 NodeDescription nodeDesc = treeManager.getNodeDescription(node); 278 this.createLabelTopComposite(type + " : " + nodeDesc.getPlugin() 279 + "." + nodeDesc.getActionName()); 280 String guiKey = (PluginManager.getPluginManager()) 281 .getPluginActionGUIKey(nodeDesc.getPlugin(), nodeDesc 282 .getType(), nodeDesc.getActionName()); 283 showParametersEditionPanel(guiKey, nodeDesc.getParams()); 284 return; 285 } 286 if (Node.isControllerNode(type)) { 288 NodeDescription desc = TreeManager.getTreeManager(null).getNodeDescription(this.currentNode) ; 289 this.createTestSwitcherTopComposite(type); 290 if ((desc.getPlugin() != null)&&(desc.getActionName() != null)) { 292 switchTestParametersPanel(desc.getPlugin(),desc.getActionName()) ; 293 this.comboTop.setText(desc.getPlugin() + "." + desc.getActionName()) ; 294 } 295 else 296 showParametersEditionPanel(null, null); 297 return; 298 } 299 if (!Node.isPluginNode(type)) { 301 NodeDescription desc = TreeManager.getTreeManager(null).getNodeDescription(this.currentNode) ; 302 this.createLabelTopComposite("The node is a " + type); 303 this.showParametersNonePluginPanel(desc) ; 304 return ; 305 } 306 } 307 308 312 private void showParametersNonePluginPanel(NodeDescription desc) { 313 cat.debug("-> showParametersNonePluginPanel") ; 314 if (!panels.containsKey(desc.getType())) { 315 ParametersWidgetsNode pwn = NonePluginNode.createParametersWidgetsNode(desc.getType()) ; 316 if (pwn == null) 317 pwn = new ParametersWidgetsNode(null) ; 318 this.panels.put(desc.getType(), pwn) ; 319 } 320 showParametersEditionPanel(desc.getType(), desc.getParams()) ; 321 } 322 323 331 private void showParametersEditionPanel(String guiKey, Hashtable params) { 332 cat.debug("-> showParametersEditionPanel") ; 333 if (this.mainComposite != null) { 335 this.mainComposite.dispose(); 336 } 337 if (guiKey == null) { 339 this.mainComposite = new Composite(this.main, SWT.BORDER); 340 this.mainComposite.setBackground(this.parent.getDisplay() 341 .getSystemColor(SWT.COLOR_WHITE)); 342 this.main.layout(); 343 return; 344 } 345 this.mainComposite = new Composite(this.main, SWT.FLAT); 347 GridLayout gridLayout = new GridLayout(); 348 gridLayout.marginHeight = 0; 349 gridLayout.marginWidth = 0; 350 gridLayout.numColumns = 1; 351 this.mainComposite.setLayout(gridLayout); 352 this.contents = new ScrolledComposite(this.mainComposite, SWT.BORDER 354 | SWT.H_SCROLL | SWT.V_SCROLL); 355 this.contents.setExpandHorizontal(true); 356 this.contents.setExpandVertical(true); 357 this.contents.setAlwaysShowScrollBars(false); 358 GridData gridData = new GridData(); 360 gridData.grabExcessVerticalSpace = true; 361 gridData.grabExcessHorizontalSpace = true; 362 gridData.verticalAlignment = GridData.FILL; 363 gridData.horizontalAlignment = GridData.FILL; 364 this.contents.setLayoutData(gridData); 365 this.contentsComposite = new Composite(this.contents, SWT.FLAT); 367 this.contents.setContent(this.contentsComposite); 368 this.contentsComposite.setLayout(new FillLayout()); 369 ParametersWidgetsNode node = (ParametersWidgetsNode) this.panels 371 .get(guiKey); 372 this.parametersPanel = ParameterPanel.createParameterPanel(node, 373 this.contentsComposite, this); 374 TreeManager treeManager = TreeManager.getTreeManager(null) ; 376 String type = treeManager.getNodeType(this.currentNode) ; 377 378 if (!type.equals(Node.USE)) { 379 if (Node.isPluginNode(type) || Node.isControllerNode(type)) { 380 Vector values = treeManager.getPluginObjectByName(treeManager.getNodeDescription(this.currentNode).getPlugin()) ; 381 this.parametersPanel.setComboValues(values) ; 382 } 383 } 384 this.parametersPanel.setParametersValues(params); 385 386 this.contents.setMinSize(this.contentsComposite.computeSize( 388 SWT.DEFAULT, SWT.DEFAULT)); 389 this.main.layout(); 391 } 392 393 401 private void switchTestParametersPanel(String pluginName, String testName) { 402 cat.debug("-> switchTestParametersPanel") ; 403 String guiKey = (PluginManager.getPluginManager()) 404 .getPluginActionGUIKey(pluginName, Node.TEST, testName); 405 Hashtable values = (TreeManager.getTreeManager(null)).getNodeDescription( 406 this.currentNode).getParams(); 407 showParametersEditionPanel(guiKey, values); 408 } 409 410 411 422 public void createPanels(PluginDescription plugin, String guiFile) { 423 cat.debug("-> createPanels") ; 424 if (parent != null) 425 ParameterPanel.createNewPanelsFromXML(plugin, guiFile, this.panels); 426 else 427 System.out 428 .println("Unable to generate Panels, because they don't have any parent composite to be defined"); 429 } 430 431 434 private void updateParametersValues() { 435 cat.debug("-> updateParametersValues") ; 436 if (this.parametersPanel == null) 437 return; 438 Hashtable values = this.parametersPanel.getParametersValues(); 440 boolean flag = (TreeManager.getTreeManager(null)).setParametersValues(this.currentNode, 441 values); 442 if (!flag) { 443 NodeDescription desc = TreeManager.getTreeManager(null).getNodeDescription(this.currentNode) ; 445 Hashtable oldValues = desc.getParams() ; 446 this.parametersPanel.setParametersValues(oldValues) ; 447 } 448 } 449 450 453 public void widgetDefaultSelected(SelectionEvent event) { 454 cat.debug("-> widgetDefaultSelected") ; 455 cat.debug("default selected" + event.getSource()); 456 457 } 458 461 public void widgetSelected(SelectionEvent event) { 462 cat.debug("-> widgetSelected") ; 463 if (event.getSource() == this.comboTop) { 464 StringTokenizer st = new StringTokenizer (this.comboTop.getText(), 465 "."); 466 if (st.countTokens() < 2) 467 return; 468 String plugin = ""; 469 while (st.countTokens() > 2) { 471 String token = st.nextToken(); 472 plugin = plugin.concat(token + "."); 473 } 474 plugin = plugin.concat(st.nextToken()); 475 String test = st.nextToken(); 476 Vector help = (PluginManager.getPluginManager()).getPluginActionHelp(plugin, 478 Node.TEST, test); 479 this.window.updateHelp(help) ; 480 TreeManager.getTreeManager(null).setNodeCondition(this.currentNode, plugin, test) ; 482 this.switchTestParametersPanel(plugin, test); 483 return ; 484 } 485 if (this.parametersPanel.addButtonSelected(event.getSource())) { 486 this.contents.setMinSize(this.contentsComposite.computeSize( 489 SWT.DEFAULT, SWT.DEFAULT)); 490 this.main.layout(); 492 return ; 493 } 494 if (this.parametersPanel.removeButtonSelected(event.getSource())) { 495 this.updateParametersValues() ; 496 this.contents.setMinSize(this.contentsComposite.computeSize( 499 SWT.DEFAULT, SWT.DEFAULT)); 500 this.main.layout(); 502 return ; 503 } 504 this.updateParametersValues() ; 506 } 507 508 511 public void modifyText(ModifyEvent event) { 512 cat.debug("-> modifyText") ; 513 this.parametersPanel.modifySomething(event.getSource()) ; 514 this.updateParametersValues() ; 515 } 516 } | Popular Tags |