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.Iterator ; 24 import java.util.Set ; 25 26 import org.apache.jmeter.gui.GuiPackage; 27 import org.apache.jmeter.gui.JMeterGUIComponent; 28 import org.apache.jmeter.gui.tree.JMeterTreeNode; 29 import org.apache.jmeter.samplers.Clearable; 30 import org.apache.jorphan.logging.LoggingManager; 31 import org.apache.log.Logger; 32 33 37 public class Clear implements Command 38 { 39 transient private static Logger log = LoggingManager.getLoggerForClass(); 40 public final static String CLEAR = "action.clear"; 41 public final static String CLEAR_ALL = "action.clear_all"; 42 43 private static Set commands = new HashSet (); 44 static 45 { 46 commands.add(CLEAR); 47 commands.add(CLEAR_ALL); 48 } 49 50 public Clear() 51 { 52 } 53 54 public Set getActionNames() 55 { 56 return commands; 57 } 58 59 public void doAction(ActionEvent e) 60 { 61 GuiPackage guiPackage = GuiPackage.getInstance(); 62 if (e.getActionCommand().equals(CLEAR)) 63 { 64 JMeterGUIComponent model = guiPackage.getCurrentGui(); 65 try 66 { 67 ((Clearable) model).clear(); 68 } 69 catch (Throwable ex) 70 { 71 log.error("", ex); 72 } 73 } 74 else 75 { 76 Iterator iter = 77 guiPackage 78 .getTreeModel() 79 .getNodesOfType(Clearable.class) 80 .iterator(); 81 while (iter.hasNext()) 82 { 83 try 84 { 85 Clearable item = 86 (Clearable) guiPackage.getGui( 87 ((JMeterTreeNode) iter.next()).getTestElement()); 88 item.clear(); 89 } 90 catch (Exception ex) 91 { 92 log.error("", ex); 93 } 94 } 95 } 96 } 97 } 98 | Popular Tags |