01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
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: /**
34: * Handles the following actions:
35: * - Clear (Data)
36: * - Clear All (Data)
37: * - Reset (Clear GUI)
38: */
39: public class Clear implements Command {
40: private static final Logger log = LoggingManager
41: .getLoggerForClass();
42:
43: private static Set commands = new HashSet();
44: static {
45: commands.add(ActionNames.CLEAR);
46: commands.add(ActionNames.CLEAR_ALL);
47: commands.add(ActionNames.RESET_GUI);
48: }
49:
50: public Clear() {
51: }
52:
53: public Set getActionNames() {
54: return commands;
55: }
56:
57: public void doAction(ActionEvent e) {
58: GuiPackage guiPackage = GuiPackage.getInstance();
59: final String actionCommand = e.getActionCommand();
60: if (actionCommand.equals(ActionNames.CLEAR)) {
61: JMeterGUIComponent guiComp = guiPackage.getCurrentGui();
62: if (guiComp instanceof Clearable) {
63: ((Clearable) guiComp).clearData();
64: }
65: } else if (actionCommand.equals(ActionNames.RESET_GUI)) {
66: JMeterGUIComponent guiComp = guiPackage.getCurrentGui();
67: guiComp.clearGui();
68: } else {
69: Iterator iter = guiPackage.getTreeModel().getNodesOfType(
70: Clearable.class).iterator();
71: while (iter.hasNext()) {
72: JMeterTreeNode node = null;
73: JMeterGUIComponent guiComp = null;
74: try {
75: Object next = iter.next();
76: node = (JMeterTreeNode) next;
77: guiComp = guiPackage.getGui(node.getTestElement());
78: Clearable item = (Clearable) guiComp;
79: item.clearData();
80: } catch (Exception ex) {
81: log.error("Can't clear: " + node + " " + guiComp,
82: ex);
83: }
84: }
85: }
86: }
87: }
|