| 1 18 19 package org.apache.jmeter.ejb.jndi.config.gui; 20 import java.awt.Component ; 21 import java.awt.Dimension ; 22 import java.awt.Font ; 23 import java.awt.Frame ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 import java.awt.event.MouseAdapter ; 27 import java.awt.event.MouseEvent ; 28 import java.awt.event.MouseListener ; 29 import java.lang.reflect.Field ; 30 import java.util.ArrayList ; 31 import java.util.Collection ; 32 import java.util.Iterator ; 33 import javax.swing.BorderFactory ; 34 import javax.swing.JButton ; 35 import javax.swing.JComboBox ; 36 import javax.swing.JLabel ; 37 import javax.swing.JPanel ; 38 import javax.swing.JTree ; 39 import javax.swing.border.Border ; 40 import javax.swing.border.EmptyBorder ; 41 import javax.swing.event.TreeSelectionEvent ; 42 import javax.swing.event.TreeSelectionListener ; 43 import javax.swing.tree.DefaultMutableTreeNode ; 44 import javax.swing.tree.DefaultTreeModel ; 45 import javax.swing.tree.TreePath ; 46 import javax.swing.tree.TreeSelectionModel ; 47 import org.apache.jmeter.gui.GuiPackage; 48 import org.apache.jmeter.gui.NamePanel; 49 import org.apache.jmeter.gui.util.VerticalLayout; 50 import org.apache.jmeter.testelement.TestPlan; 51 import org.apache.jmeter.threads.ThreadGroup; 52 import org.apache.jmeter.util.JMeterUtils; 53 import org.apache.jorphan.logging.LoggingManager; 54 import org.apache.log.Logger; 55 61 public class MethodConfigGui 62 extends JPanel  63 implements ModelSupported, ActionListener , TreeSelectionListener  64 { 65 transient private static Logger log = LoggingManager.getLoggerForClass(); 66 protected static final String REFLECT = "MethodConfigGui.reflect"; 67 protected static final String INVOKE = "MethodConfigGui.invoke"; 68 protected static final String STRING_CLASS = "java.lang.String"; 69 protected JComboBox methodHomeNameBox; 70 protected JComboBox methodRemoteNameBox; 71 protected JComboBox remoteInterfaceBox; 72 protected DefaultMutableTreeNode rootHome; 73 protected DefaultMutableTreeNode rootRemote; 74 protected DefaultTreeModel treeModelHome; 75 protected DefaultTreeModel treeModelRemote; 76 protected NamePanel namePanel; 77 protected JPanel methodHomeNamePanel; 78 protected JPanel methodHomeParmsPanel; 79 protected JPanel remoteInterfaceListPanel; 80 protected JPanel methodRemoteNamePanel; 81 protected JPanel methodRemoteParmsPanel; 82 protected JPanel controlPanel; 83 protected JButton actionButton; 84 protected JTree jTreeHome; 85 protected JTree jTreeRemote; 86 protected boolean displayName; 87 protected MethodConfig model; 88 protected Frame frame; 89 public MethodConfigGui() 94 { 95 displayName = true; 96 } 97 public MethodConfigGui(boolean displayName) 98 { 99 this.displayName = displayName; 100 } 101 public void setModel(Object model) 103 { 104 this.model = (MethodConfig) model; 105 init(); 106 } 107 public void updateGui() 108 { 109 log.debug("Start : updateGui1"); 110 log.info("updateGui1"); 111 String methodName = model.getMethodHomeName(); 114 log.debug("updateGui1 : home method name - " + methodName); 115 String [] strings = model.getMethodHomeList(); 116 setupPullDown(methodHomeNameBox, methodName, strings); 117 if (methodName == null && strings != null) 122 { 123 model.setMethodHomeName(strings[0]); 124 } 125 int childCount = treeModelHome.getChildCount(rootHome); 129 if (log.isDebugEnabled()) 130 { 131 log.debug("updateGui1 : state - " + model.getState()); 132 log.debug("updateGui1 : METHOD_GET_HOME_NAMES"); 133 log.debug("updateGui1 : rootHome child count - " + childCount); 134 } 135 if (model.getState() > MethodConfig.METHOD_GET_HOME_PARMS 138 && childCount == 0) 139 { 140 log.debug("updateGui1 : METHOD_GET_HOME_PARMS"); 141 rootHome.setUserObject(model.getMethodHomeName()); 142 Class [] parmTypes = model.getMethodHomeParms(); 145 for (int i = 0; i < parmTypes.length; i++) 147 { 148 log.debug("updateGui1 : parmType #" + i + " - " + parmTypes[i]); 149 recurseParm(parmTypes[i], rootHome, i, treeModelHome); 150 } 151 if (parmTypes.length == 0) 155 { 156 jTreeHome.treeDidChange(); 157 } 158 } 159 if (model.getState() > MethodConfig.METHOD_SELECT_REMOTE_INTERFACE) 163 { 164 log.debug("METHOD_SELECT_REMOTE_INTERFACE"); 165 Object remoteInterfaceType = model.getRemoteInterfaceType(); 169 String interfaceName = null; 170 if (remoteInterfaceType != null) 171 { 172 interfaceName = remoteInterfaceType.toString(); 173 } 174 ArrayList remoteInterfaces = (ArrayList ) model.getRemoteInterfaceList(); 175 if (log.isDebugEnabled()) 176 { 177 log.debug("updateGui1 : remote interfaces - " + remoteInterfaces); 178 log.debug( 179 "updateGui1 : remoteInterfacesType - " + remoteInterfaces.getClass()); 180 } 181 Object [] remoteInterfacesArray = remoteInterfaces.toArray(); 184 strings = new String [remoteInterfacesArray.length]; 185 for (int i = 0; i < remoteInterfacesArray.length; i++) 186 { 187 strings[i] = remoteInterfacesArray[i].toString(); 188 } 189 setupPullDown(remoteInterfaceBox, interfaceName, strings); 190 if (interfaceName == null && remoteInterfacesArray != null) 195 { 196 model.setRemoteInterfaceType(remoteInterfacesArray[0]); 197 } 198 } 199 if (model.getState() > MethodConfig.METHOD_GET_REMOTE_NAMES) 202 { 203 log.debug("METHOD_GET_REMOTE_NAMES"); 204 methodName = model.getMethodRemoteName(); 205 log.debug("updateGui1 : remote method name - " + methodName); 206 strings = model.getMethodRemoteList(); 207 setupPullDown(methodRemoteNameBox, methodName, strings); 208 childCount = treeModelRemote.getChildCount(rootRemote); 209 if (log.isDebugEnabled()) 210 { 211 log.debug("updateGui1 : rootRemote child count - " + childCount); 212 } 213 } 214 if (model.getState() > MethodConfig.METHOD_GET_REMOTE_PARMS 217 && childCount == 0) 218 { 219 log.debug("METHOD_GET_REMOTE_PARMS"); 220 rootRemote.setUserObject(model.getMethodRemoteName()); 221 Class [] parmTypes = model.getMethodRemoteParms(); 224 for (int i = 0; i < parmTypes.length; i++) 226 { 227 log.debug("updateGui1 : parmType #" + i + " - " + parmTypes[i]); 228 recurseParm(parmTypes[i], rootHome, i, treeModelHome); 229 } 230 if (parmTypes.length == 0) 234 { 235 jTreeRemote.treeDidChange(); 236 } 237 } 238 if (displayName) 241 { 242 namePanel.updateGui(); 243 } 244 log.debug("End : updateGui1"); 245 } 246 protected void init() 248 { 249 log.info("Start : init1"); 250 GuiPackage guiPkg = GuiPackage.getInstance(); 255 frame = guiPkg.getMainFrame(); 256 model.setState(MethodConfig.METHOD_GET_HOME_NAMES); 257 model.setGui(this); 258 methodHomeNameBox = new JComboBox (); 259 methodHomeNameBox.setEditable(false); 260 methodHomeNameBox.setAlignmentX(Component.LEFT_ALIGNMENT); 261 methodHomeNameBox.addActionListener(new ActionListener () 262 { 263 public void actionPerformed(ActionEvent e) 264 { 265 log.debug("actionPerformed1 : Home name method JComboBox changed"); 266 JComboBox comboBox = (JComboBox ) e.getSource(); 268 String method = (String ) methodHomeNameBox.getSelectedItem(); 269 model.setMethodHomeName(method); 270 model.setState(MethodConfig.METHOD_GET_HOME_PARMS); 271 resetHomeMethodParms(); 272 resetRemoteInterfaceList(); 273 resetRemoteMethodName(); 274 resetRemoteMethodParms(); 275 actionButton.setText( 277 JMeterUtils.getResString("jndi_method_button_reflect")); 278 updateGui(); 279 } 280 }); 281 remoteInterfaceBox = new JComboBox (); 282 remoteInterfaceBox.setEditable(false); 283 remoteInterfaceBox.setAlignmentX(Component.LEFT_ALIGNMENT); 284 remoteInterfaceBox.addActionListener(new ActionListener () 285 { 286 public void actionPerformed(ActionEvent e) 287 { 288 log.debug("actionPerformed1 : Remote Interface JComboBox changed"); 289 JComboBox comboBox = (JComboBox ) e.getSource(); 290 String interfaceName = (String ) remoteInterfaceBox.getSelectedItem(); 291 ArrayList remoteInterfaceList = 294 (ArrayList ) model.getRemoteInterfaceList(); 295 if (remoteInterfaceList != null) 296 { 297 Object [] remoteInterfaceListArray = remoteInterfaceList.toArray(); 298 int i = 0; 299 boolean found = false; 300 String remoteInterfaceListName = null; 301 Object selectedInterface = null; 302 while (i < remoteInterfaceListArray.length && !found) 303 { 304 remoteInterfaceListName = remoteInterfaceListArray[i].toString(); 305 if (remoteInterfaceListName.equals(interfaceName)) 306 { 307 found = true; 308 selectedInterface = remoteInterfaceListArray[i]; 309 } 310 i++; 311 } 312 model.setRemoteInterfaceType(selectedInterface); 313 model.setState(MethodConfig.METHOD_GET_REMOTE_NAMES); 314 } 315 resetRemoteMethodName(); 316 resetRemoteMethodParms(); 317 actionButton.setText( 319 JMeterUtils.getResString("jndi_method_button_reflect")); 320 updateGui(); 321 } 322 }); 323 methodRemoteNameBox = new JComboBox (); 324 methodRemoteNameBox.setEditable(false); 325 methodRemoteNameBox.setAlignmentX(Component.LEFT_ALIGNMENT); 326 methodRemoteNameBox.addActionListener(new ActionListener () 327 { 328 public void actionPerformed(ActionEvent e) 329 { 330 log.debug("actionPerformed1 : Remote method name JComboBox changed"); 331 JComboBox comboBox = (JComboBox ) e.getSource(); 333 String method = (String ) methodRemoteNameBox.getSelectedItem(); 334 model.setMethodRemoteName(method); 335 model.setState(MethodConfig.METHOD_GET_REMOTE_PARMS); 336 resetRemoteMethodParms(); 337 actionButton.setText( 339 JMeterUtils.getResString("jndi_method_button_reflect")); 340 updateGui(); 341 } 342 }); 343 this.setLayout( 346 new VerticalLayout(5, VerticalLayout.LEFT, VerticalLayout.TOP)); 347 JPanel mainPanel = new JPanel (); 348 Border margin = new EmptyBorder (10, 10, 5, 10); 349 mainPanel.setBorder(margin); 350 mainPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); 351 JLabel panelTitleLabel = 353 new JLabel (JMeterUtils.getResString("jndi_method_title")); 354 Font curFont = panelTitleLabel.getFont(); 355 int curFontSize = curFont.getSize(); 356 curFontSize += 4; 357 panelTitleLabel.setFont( 358 new Font (curFont.getFontName(), curFont.getStyle(), curFontSize)); 359 mainPanel.add(panelTitleLabel); 360 namePanel = new NamePanel(model); 362 mainPanel.add(namePanel); 363 JPanel jndiPanel = new JPanel (); 365 jndiPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT)); 366 jndiPanel.setBorder( 367 BorderFactory.createTitledBorder( 368 JMeterUtils.getResString("jndi_method_name"))); 369 methodHomeNamePanel = getMethodHomeNamePanel(); 370 methodHomeParmsPanel = getMethodHomeParmsPanel(); 371 remoteInterfaceListPanel = getRemoteInterfaceListPanel(); 372 methodRemoteNamePanel = getMethodRemoteNamePanel(); 373 methodRemoteParmsPanel = getMethodRemoteParmsPanel(); 374 jndiPanel.add(methodHomeNamePanel); 375 jndiPanel.add(methodHomeParmsPanel); 376 jndiPanel.add(remoteInterfaceListPanel); 377 jndiPanel.add(methodRemoteNamePanel); 378 jndiPanel.add(methodRemoteParmsPanel); 379 controlPanel = new JPanel (); 380 actionButton = 381 new JButton (JMeterUtils.getResString("jndi_method_button_reflect")); 382 actionButton.addActionListener(this); 383 actionButton.setActionCommand(REFLECT); 384 controlPanel.add(actionButton); 385 jndiPanel.add(controlPanel); 386 mainPanel.add(jndiPanel); 387 this.add(mainPanel); 388 log.info("End : init1"); 390 } 391 406 protected void recurseParm( 407 Class parmType, 408 DefaultMutableTreeNode parentNode, 409 int childIndex, 410 DefaultTreeModel treeModel) 411 { 412 log.debug("Start - recurseParm1"); 413 DefaultMutableTreeNode node = new DefaultMutableTreeNode (parmType); 414 treeModel.insertNodeInto(node, parentNode, childIndex); 415 log.info("recurseParm1 - parent : " + parentNode); 416 log.info("recurseParm1 - parent : " + treeModel.getChildCount(parentNode)); 417 log.info("recurseParm1 - child : " + treeModel.getChildCount(node)); 418 if (parmType.isPrimitive()) 419 { 420 } 422 else if (parmType.getName().equals(STRING_CLASS)) 423 { 424 } 426 else if (parmType.isArray()) 427 { 428 } 430 else 431 { 432 Field [] fields = parmType.getFields(); 436 for (int i = 0; i < fields.length; i++) 437 { 438 Class fieldClass = fields[i].getType(); 439 log.debug("recurseParm1 : field #" + i + " - " + fieldClass); 440 recurseParm(fieldClass, node, i, treeModel); 441 } 442 } 443 log.debug("End - recurseParm1"); 444 } 445 protected JPanel getMethodHomeNamePanel() 446 { 447 log.info("Start : getMethodHomeNamePanel1"); 448 JPanel panel = new JPanel (); 449 panel.add(new JLabel (JMeterUtils.getResString("jndi_method_home_name"))); 450 String methodName = model.getMethodHomeName(); 451 if (methodName != null) 452 { 453 methodHomeNameBox.setSelectedItem(methodName); 454 } 455 panel.add(methodHomeNameBox); 456 log.info("End : getMethodHomeNamePanel1"); 457 return panel; 458 } 459 protected JPanel getRemoteInterfaceListPanel() 460 { 461 log.info("Start : getRemoteInterfaceListPanel1"); 462 JPanel panel = new JPanel (); 463 panel.add( 464 new JLabel ( 465 JMeterUtils.getResString("jndi_method_remote_interface_list"))); 466 Object remoteInterfaceType = model.getRemoteInterfaceType(); 467 if (remoteInterfaceType != null) 468 { 469 remoteInterfaceBox.setSelectedItem(remoteInterfaceType.toString()); 470 } 471 panel.add(remoteInterfaceBox); 472 log.info("End : getRemoteInterfaceListPanel1"); 473 return panel; 474 } 475 protected JPanel getMethodRemoteNamePanel() 476 { 477 log.info("Start : getMethodRemoteNamePanel1"); 478 JPanel panel = new JPanel (); 479 panel.add(new JLabel (JMeterUtils.getResString("jndi_method_remote_name"))); 480 String methodName = model.getMethodRemoteName(); 481 if (methodName != null) 482 { 483 methodRemoteNameBox.setSelectedItem(methodName); 484 } 485 panel.add(methodRemoteNameBox); 486 log.info("End : getMethodRemoteNamePanel1"); 487 return panel; 488 } 489 protected JPanel getMethodHomeParmsPanel() 490 { 491 log.info("Start : getMethodHomeParmsPanel1"); 492 JPanel panel = new JPanel (); 493 panel.add(new JLabel (JMeterUtils.getResString("jndi_method_home_parms"))); 494 rootHome = new DefaultMutableTreeNode ("Root"); 495 treeModelHome = new DefaultTreeModel (rootHome); 496 jTreeHome = new JTree (treeModelHome); 497 jTreeHome.getSelectionModel().setSelectionMode( 498 TreeSelectionModel.SINGLE_TREE_SELECTION); 499 jTreeHome.addTreeSelectionListener(this); 500 jTreeHome.setPreferredSize(new Dimension (200, 50)); 501 JPanel jTreePanel = new JPanel (); 502 jTreePanel.add(jTreeHome); 503 panel.add(jTreePanel); 504 MouseListener ml = new MouseAdapter () 506 { 507 public void mousePressed(MouseEvent e) 508 { 509 TreePath selPath = jTreeHome.getPathForLocation(e.getX(), e.getY()); 510 if (e.getClickCount() == 2) 511 { 512 log.info("Double clicked on - " + selPath.getLastPathComponent()); 513 DefaultMutableTreeNode node = 514 (DefaultMutableTreeNode ) selPath.getLastPathComponent(); 515 int childCount = node.getChildCount(); 516 if (childCount == 0 && node.getParent() != null) 520 { 521 log.info("Pop!!!"); 522 Object userObject = node.getUserObject(); 523 Class type = null; 524 if (userObject instanceof Class ) 525 { 526 type = (Class ) userObject; 527 } 528 else if (userObject instanceof MethodConfigUserObject) 529 { 530 type = (Class ) ((MethodConfigUserObject) userObject).getType(); 531 } 532 MethodConfigDialog dialog = new MethodConfigDialog(frame, type); 533 dialog.pack(); 534 dialog.setVisible(true); 535 MethodConfigUserObject input = dialog.getValidatedInput(); 536 log.info("input - " + input); 537 if (input != null) 538 { 539 node.setUserObject(input); 540 } 541 } 542 } 543 } 544 }; 545 jTreeHome.addMouseListener(ml); 546 log.info("End : getMethodHomeParmsPanel1"); 547 return panel; 548 } 549 protected JPanel getMethodRemoteParmsPanel() 550 { 551 log.info("Start : getMethodRemoteParmsPanel1"); 552 JPanel panel = new JPanel (); 553 panel.add(new JLabel (JMeterUtils.getResString("jndi_method_remote_parms"))); 554 rootRemote = new DefaultMutableTreeNode ("Root"); 555 treeModelRemote = new DefaultTreeModel (rootRemote); 556 jTreeRemote = new JTree (treeModelRemote); 557 jTreeRemote.getSelectionModel().setSelectionMode( 558 TreeSelectionModel.SINGLE_TREE_SELECTION); 559 jTreeRemote.addTreeSelectionListener(this); 560 jTreeRemote.setPreferredSize(new Dimension (200, 50)); 561 JPanel jTreePanel = new JPanel (); 562 jTreePanel.add(jTreeRemote); 563 panel.add(jTreePanel); 564 MouseListener ml = new MouseAdapter () 566 { 567 public void mousePressed(MouseEvent e) 568 { 569 TreePath selPath = jTreeRemote.getPathForLocation(e.getX(), e.getY()); 570 if (e.getClickCount() == 2) 571 { 572 log.info("Double clicked on - " + selPath.getLastPathComponent()); 573 DefaultMutableTreeNode node = 574 (DefaultMutableTreeNode ) selPath.getLastPathComponent(); 575 int childCount = node.getChildCount(); 576 if (childCount == 0) 577 { 578 log.info("Pop!!!"); 579 Object userObject = node.getUserObject(); 580 Class type = null; 581 if (userObject instanceof Class ) 582 { 583 type = (Class ) userObject; 584 } 585 else if (userObject instanceof MethodConfigUserObject) 586 { 587 type = (Class ) ((MethodConfigUserObject) userObject).getType(); 588 } 589 MethodConfigDialog dialog = new MethodConfigDialog(frame, type); 590 dialog.pack(); 591 dialog.setVisible(true); 592 MethodConfigUserObject input = dialog.getValidatedInput(); 593 log.info("input - " + input); 594 if (input != null) 595 { 596 node.setUserObject(input); 597 } 598 } 599 } 600 } 601 }; 602 jTreeRemote.addMouseListener(ml); 603 log.info("End : getMethodHomeParmsPanel1"); 604 return panel; 605 } 606 public MethodConfig getModel() 607 { 608 return model; 609 } 610 616 public Object [] getMethodParmsValues(int state) 617 throws MethodConfigUserObjectException 618 { 619 Object [] objects = null; 620 if (state == MethodConfig.METHOD_INVOKE_HOME) 621 { 622 objects = getMethodParmsValues(rootHome); 623 } 624 else if (state == MethodConfig.METHOD_INVOKE_REMOTE) 625 { 626 objects = getMethodParmsValues(rootRemote); 627 } 628 return objects; 629 } 630 public Object [] getMethodParmsValues(DefaultMutableTreeNode root) 631 throws MethodConfigUserObjectException 632
|