KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > gui > action > Clear


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/Clear.java,v 1.8 2004/02/20 01:03:07 jsalvata Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Set JavaDoc;
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  * @author Michael Stover
35  * @version $Revision: 1.8 $
36  */

37 public class Clear implements Command
38 {
39     transient private static Logger log = LoggingManager.getLoggerForClass();
40     public final static String JavaDoc CLEAR = "action.clear";
41     public final static String JavaDoc CLEAR_ALL = "action.clear_all";
42
43     private static Set JavaDoc commands = new HashSet JavaDoc();
44     static
45     {
46         commands.add(CLEAR);
47         commands.add(CLEAR_ALL);
48     }
49
50     public Clear()
51     {
52     }
53
54     public Set JavaDoc getActionNames()
55     {
56         return commands;
57     }
58
59     public void doAction(ActionEvent JavaDoc 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 JavaDoc ex)
70             {
71                 log.error("", ex);
72             }
73         }
74         else
75         {
76             Iterator JavaDoc 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 JavaDoc ex)
91                 {
92                     log.error("", ex);
93                 }
94             }
95         }
96     }
97 }
98
Popular Tags