KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/AddParent.java,v 1.8 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.Component JavaDoc;
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.util.HashSet JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import org.apache.jmeter.gui.GuiPackage;
26 import org.apache.jmeter.gui.tree.JMeterTreeNode;
27 import org.apache.jmeter.testelement.TestElement;
28 import org.apache.jorphan.logging.LoggingManager;
29 import org.apache.log.Logger;
30
31 /**
32  * @author Michael Stover
33  * @version $Revision: 1.8 $
34  */

35 public class AddParent implements Command
36 {
37     transient private static Logger log = LoggingManager.getLoggerForClass();
38     private static Set JavaDoc commands = new HashSet JavaDoc();
39     static
40     {
41         commands.add("Add Parent");
42     }
43
44     public AddParent()
45     {
46     }
47
48     public void doAction(ActionEvent JavaDoc e)
49     {
50         String JavaDoc name = ((Component JavaDoc) e.getSource()).getName();
51         try
52         {
53             TestElement controller =
54                 (TestElement) GuiPackage.getInstance().createTestElement(name);
55             addParentToTree(controller);
56         }
57         catch (Exception JavaDoc err)
58         {
59             log.error("", err);
60         }
61
62     }
63
64     public Set JavaDoc getActionNames()
65     {
66         return commands;
67     }
68
69     protected void addParentToTree(TestElement newParent)
70     {
71         GuiPackage guiPackage = GuiPackage.getInstance();
72         JMeterTreeNode newNode =
73             new JMeterTreeNode(newParent, guiPackage.getTreeModel());
74         JMeterTreeNode currentNode =
75             guiPackage.getTreeListener().getCurrentNode();
76         JMeterTreeNode parentNode = (JMeterTreeNode) currentNode.getParent();
77         int index = parentNode.getIndex(currentNode);
78         guiPackage.getTreeModel().removeNodeFromParent(currentNode);
79         guiPackage.getTreeModel().insertNodeInto(
80             newNode,
81             (JMeterTreeNode) parentNode,
82             index);
83         guiPackage.getTreeModel().insertNodeInto(
84             currentNode,
85             newNode,
86             newNode.getChildCount());
87     }
88 }
89
Popular Tags