1 18 19 package org.apache.jmeter.gui.action; 20 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.ActionListener ; 23 import java.util.HashMap ; 24 import java.util.HashSet ; 25 import java.util.Map ; 26 import java.util.Set ; 27 28 import org.apache.jmeter.gui.GuiPackage; 29 import org.apache.jmeter.gui.tree.JMeterTreeNode; 30 import org.apache.jorphan.collections.HashTree; 31 import org.apache.jorphan.collections.HashTreeTraverser; 32 import org.apache.jorphan.collections.ListedHashTree; 33 import org.apache.jorphan.logging.LoggingManager; 34 import org.apache.log.Logger; 35 36 40 public class CheckDirty 41 extends AbstractAction 42 implements HashTreeTraverser, ActionListener 43 { 44 private static final Logger log = LoggingManager.getLoggerForClass(); 45 46 private static Map previousGuiItems; 47 public static final String CHECK_DIRTY = "check_dirty"; 48 public static final String SUB_TREE_SAVED = "sub_tree_saved"; 49 public static final String SUB_TREE_LOADED = "sub_tree_loaded"; 50 public static final String ADD_ALL = "add_all"; 51 public static final String REMOVE = "check_remove"; 55 56 boolean checkMode = false; 57 boolean removeMode = false; 58 boolean dirty = false; 59 60 private static Set commands = new HashSet (); 61 static 62 { 63 commands.add(CHECK_DIRTY); 64 commands.add(SUB_TREE_SAVED); 65 commands.add(SUB_TREE_LOADED); 66 commands.add(ADD_ALL); 67 commands.add(REMOVE); 68 } 69 70 public CheckDirty() 71 { 72 previousGuiItems = new HashMap (); 73 ActionRouter.getInstance().addPreActionListener( 74 ExitCommand.class, 75 this); 76 } 77 78 public void actionPerformed(ActionEvent e) 79 { 80 if (e.getActionCommand().equals(ExitCommand.EXIT)) 81 { 82 doAction(e); 83 } 84 } 85 86 89 public void doAction(ActionEvent e) 90 { 91 String action = e.getActionCommand(); 92 if (action.equals(SUB_TREE_SAVED)) 93 { 94 HashTree subTree = (HashTree) e.getSource(); 95 subTree.traverse(this); 96 } 97 else if (action.equals(SUB_TREE_LOADED)) 98 { 99 ListedHashTree addTree = (ListedHashTree) e.getSource(); 100 addTree.traverse(this); 101 } 102 else if (action.equals(ADD_ALL)) 103 { 104 previousGuiItems.clear(); 105 GuiPackage.getInstance().getTreeModel().getTestPlan().traverse( 106 this); 107 } 108 else if (action.equals(REMOVE)) 109 { 110 GuiPackage guiPackage = GuiPackage.getInstance(); 111 JMeterTreeNode[] nodes = 112 guiPackage.getTreeListener().getSelectedNodes(); 113 removeMode = true; 114 for (int i = nodes.length - 1; i >= 0; i--) 115 { 116 guiPackage.getTreeModel().getCurrentSubTree(nodes[i]).traverse( 117 this); 118 } 119 removeMode = false; 120 } 121 checkMode = true; 122 dirty = false; 123 HashTree wholeTree = 124 GuiPackage.getInstance().getTreeModel().getTestPlan(); 125 wholeTree.traverse(this); 126 GuiPackage.getInstance().setDirty(dirty); 127 checkMode = false; 128 } 129 130 134 public void addNode(Object node, HashTree subTree) 135 { 136 log.debug("Node is class:" + node.getClass()); 137 JMeterTreeNode treeNode = (JMeterTreeNode) node; 138 if (checkMode) 139 { 140 if (previousGuiItems.containsKey(treeNode)) 141 { 142 if (!previousGuiItems 143 .get(treeNode) 144 .equals(treeNode.getTestElement())) 145 { 146 dirty = true; 147 } 148 } 149 else 150 { 151 dirty = true; 152 } 153 } 154 else if (removeMode) 155 { 156 previousGuiItems.remove(treeNode); 157 } 158 else 159 { 160 previousGuiItems.put( 161 treeNode, 162 treeNode.getTestElement().clone()); 163 } 164 } 165 166 170 public void subtractNode() 171 { 172 } 173 174 180 public void processPath() 181 { 182 } 183 184 187 public Set getActionNames() 188 { 189 return commands; 190 } 191 } 192 | Popular Tags |