1 18 19 package org.apache.jmeter.gui.action; 20 import java.awt.event.ActionEvent ; 21 import java.util.HashMap ; 22 import java.util.Map ; 23 import java.util.Set ; 24 25 import javax.swing.JComponent ; 26 import javax.swing.tree.TreePath ; 27 28 import org.apache.jmeter.gui.GuiPackage; 29 import org.apache.jmeter.gui.tree.JMeterTreeNode; 30 import org.apache.jmeter.testelement.TestElement; 31 import org.apache.jorphan.logging.LoggingManager; 32 import org.apache.log.Logger; 33 34 38 public class AddToTree implements Command 39 { 40 transient private static Logger log = LoggingManager.getLoggerForClass(); 41 private Map allJMeterComponentCommands; 42 43 public AddToTree() 44 { 45 allJMeterComponentCommands = new HashMap (); 46 allJMeterComponentCommands.put("Add", "Add"); 47 } 48 49 54 public Set getActionNames() 55 { 56 return allJMeterComponentCommands.keySet(); 57 } 58 59 62 public void doAction(ActionEvent e) 63 { 64 try 65 { 66 TestElement node = 67 GuiPackage.getInstance().createTestElement( 68 ((JComponent ) e.getSource()).getName()); 69 addObjectToTree(node); 70 } 71 catch (Exception err) 72 { 73 log.error("", err); 74 } 75 } 76 77 protected void addObjectToTree(TestElement el) 78 { 79 GuiPackage guiPackage = GuiPackage.getInstance(); 80 JMeterTreeNode node = new JMeterTreeNode(el, guiPackage.getTreeModel()); 81 guiPackage.getTreeModel().insertNodeInto( 82 node, 83 guiPackage.getTreeListener().getCurrentNode(), 84 guiPackage.getTreeListener().getCurrentNode().getChildCount()); 85 guiPackage.getMainFrame().getTree().setSelectionPath( 86 new TreePath (node.getPath())); 87 } 88 } 89 | Popular Tags |