1 18 19 package org.apache.jmeter.gui.action; 20 21 import java.awt.event.ActionEvent ; 22 import java.util.HashSet ; 23 import java.util.Set ; 24 25 import javax.swing.JOptionPane ; 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 32 36 public class Remove implements Command 37 { 38 private static Set commands = new HashSet (); 39 static { 40 commands.add("remove"); 41 } 42 43 46 public Remove() 47 { 48 } 49 50 55 public Set getActionNames() 56 { 57 return commands; 58 } 59 60 public void doAction(ActionEvent e) 61 { 62 ActionRouter.getInstance().actionPerformed( 63 new ActionEvent (e.getSource(), e.getID(), CheckDirty.REMOVE)); 64 GuiPackage guiPackage = GuiPackage.getInstance(); 65 JMeterTreeNode[] nodes = 66 guiPackage.getTreeListener().getSelectedNodes(); 67 TreePath newTreePath = guiPackage.getTreeListener().removedSelectedNode(); 69 for (int i = nodes.length - 1; i >= 0; i--) 70 { 71 removeNode(nodes[i]); 72 } 73 guiPackage.getTreeListener().getJTree().setSelectionPath(newTreePath); 74 guiPackage.updateCurrentGui(); 75 } 76 77 public static void removeNode(JMeterTreeNode node) 78 { 79 TestElement testElement = node.getTestElement(); 80 if (testElement.canRemove()) 81 { 82 GuiPackage.getInstance().getTreeModel().removeNodeFromParent(node); 83 GuiPackage.getInstance().removeNode(testElement); 84 } 85 else 86 { 87 String message=testElement.getClass().getName()+ " is busy"; 88 JOptionPane.showMessageDialog(null, message, "Cannot remove item", 89 JOptionPane.ERROR_MESSAGE); 90 } 91 } 92 } 93 | Popular Tags |