KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/AddToTree.java,v 1.12 2004/02/13 02:21:36 sebb Exp $
2
/*
3  * Copyright 2002-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 import java.awt.event.ActionEvent JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import javax.swing.JComponent JavaDoc;
26 import javax.swing.tree.TreePath JavaDoc;
27
28 import org.apache.jmeter.gui.GuiPackage;
29 import org.apache.jmeter.gui.tree.JMeterTreeNode;
30 import org.apache.jmeter.testelement.TestElement;
31 import org.apache.jorphan.logging.LoggingManager;
32 import org.apache.log.Logger;
33
34 /**
35  * @author unattributed
36  * @version $Revision: 1.12 $ Last updated: $Date: 2004/02/13 02:21:36 $
37  */

38 public class AddToTree implements Command
39 {
40     transient private static Logger log = LoggingManager.getLoggerForClass();
41     private Map JavaDoc allJMeterComponentCommands;
42
43     public AddToTree()
44     {
45         allJMeterComponentCommands = new HashMap JavaDoc();
46         allJMeterComponentCommands.put("Add", "Add");
47     }
48
49     /**
50      * Gets the Set of actions this Command class responds to.
51      *
52      * @return the ActionNames value
53      */

54     public Set JavaDoc getActionNames()
55     {
56         return allJMeterComponentCommands.keySet();
57     }
58
59     /**
60      * Adds the specified class to the current node of the tree.
61      */

62     public void doAction(ActionEvent JavaDoc e)
63     {
64         try
65         {
66             TestElement node =
67                 GuiPackage.getInstance().createTestElement(
68                     ((JComponent JavaDoc) e.getSource()).getName());
69             addObjectToTree(node);
70         }
71         catch (Exception JavaDoc err)
72         {
73             log.error("", err);
74         }
75     }
76
77     protected void addObjectToTree(TestElement el)
78     {
79         GuiPackage guiPackage = GuiPackage.getInstance();
80         JMeterTreeNode node = new JMeterTreeNode(el, guiPackage.getTreeModel());
81         guiPackage.getTreeModel().insertNodeInto(
82             node,
83             guiPackage.getTreeListener().getCurrentNode(),
84             guiPackage.getTreeListener().getCurrentNode().getChildCount());
85         guiPackage.getMainFrame().getTree().setSelectionPath(
86             new TreePath JavaDoc(node.getPath()));
87     }
88 }
89
Popular Tags