1 18 19 package org.apache.jmeter.gui.action; 20 import java.awt.Component ; 21 import java.awt.event.ActionEvent ; 22 import java.util.HashSet ; 23 import java.util.Set ; 24 25 import org.apache.jmeter.gui.GuiPackage; 26 import org.apache.jmeter.gui.tree.JMeterTreeNode; 27 import org.apache.jmeter.testelement.TestElement; 28 import org.apache.jorphan.logging.LoggingManager; 29 import org.apache.log.Logger; 30 31 35 public class AddParent implements Command 36 { 37 transient private static Logger log = LoggingManager.getLoggerForClass(); 38 private static Set commands = new HashSet (); 39 static 40 { 41 commands.add("Add Parent"); 42 } 43 44 public AddParent() 45 { 46 } 47 48 public void doAction(ActionEvent e) 49 { 50 String name = ((Component ) e.getSource()).getName(); 51 try 52 { 53 TestElement controller = 54 (TestElement) GuiPackage.getInstance().createTestElement(name); 55 addParentToTree(controller); 56 } 57 catch (Exception err) 58 { 59 log.error("", err); 60 } 61 62 } 63 64 public Set getActionNames() 65 { 66 return commands; 67 } 68 69 protected void addParentToTree(TestElement newParent) 70 { 71 GuiPackage guiPackage = GuiPackage.getInstance(); 72 JMeterTreeNode newNode = 73 new JMeterTreeNode(newParent, guiPackage.getTreeModel()); 74 JMeterTreeNode currentNode = 75 guiPackage.getTreeListener().getCurrentNode(); 76 JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent(); 77 int index = parentNode.getIndex(currentNode); 78 guiPackage.getTreeModel().removeNodeFromParent(currentNode); 79 guiPackage.getTreeModel().insertNodeInto( 80 newNode, 81 (JMeterTreeNode) parentNode, 82 index); 83 guiPackage.getTreeModel().insertNodeInto( 84 currentNode, 85 newNode, 86 newNode.getChildCount()); 87 } 88 } 89 | Popular Tags |