Example #1
0
 public void doAction(ActionEvent e) {
   String name = ((Component) e.getSource()).getName();
   GuiPackage guiPackage = GuiPackage.getInstance();
   JMeterTreeNode currentNode = guiPackage.getTreeListener().getCurrentNode();
   if (!(currentNode.getUserObject() instanceof Controller)) {
     Toolkit.getDefaultToolkit().beep();
     return;
   }
   try {
     guiPackage.updateCurrentNode();
     TestElement controller = guiPackage.createTestElement(name);
     changeParent(controller, guiPackage, currentNode);
   } catch (Exception err) {
     Toolkit.getDefaultToolkit().beep();
     log.error("Failed to change parent", err);
   }
 }
Example #2
0
 private void changeParent(
     TestElement newParent, GuiPackage guiPackage, JMeterTreeNode currentNode) {
   JMeterTreeModel treeModel = guiPackage.getTreeModel();
   JMeterTreeNode newNode = new JMeterTreeNode(newParent, treeModel);
   JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent();
   int index = parentNode.getIndex(currentNode);
   treeModel.insertNodeInto(newNode, parentNode, index);
   treeModel.removeNodeFromParent(currentNode);
   int childCount = currentNode.getChildCount();
   for (int i = 0; i < childCount; i++) {
     // Using index 0 is voluntary as child is removed in next step and added to new parent
     JMeterTreeNode node = (JMeterTreeNode) currentNode.getChildAt(0);
     treeModel.removeNodeFromParent(node);
     treeModel.insertNodeInto(node, newNode, newNode.getChildCount());
   }
 }