KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/Remove.java,v 1.10.2.2 2004/09/20 12:11:33 sebb 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.Set JavaDoc;
24
25 import javax.swing.JOptionPane 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
32 /**
33  * @author Michael Stover
34  * @version $Revision: 1.10.2.2 $
35  */

36 public class Remove implements Command
37 {
38     private static Set JavaDoc commands = new HashSet JavaDoc();
39     static {
40         commands.add("remove");
41     }
42
43     /**
44      * Constructor for the Remove object
45      */

46     public Remove()
47     {
48     }
49
50     /**
51      * Gets the ActionNames attribute of the Remove object.
52      *
53      * @return the ActionNames value
54      */

55     public Set JavaDoc getActionNames()
56     {
57         return commands;
58     }
59
60     public void doAction(ActionEvent JavaDoc e)
61     {
62         ActionRouter.getInstance().actionPerformed(
63             new ActionEvent JavaDoc(e.getSource(), e.getID(), CheckDirty.REMOVE));
64         GuiPackage guiPackage = GuiPackage.getInstance();
65         JMeterTreeNode[] nodes =
66             guiPackage.getTreeListener().getSelectedNodes();
67         TreePath JavaDoc newTreePath = //Save parent node for later
68
guiPackage.getTreeListener().removedSelectedNode();
69         for (int i = nodes.length - 1; i >= 0; i--)
70         {
71             removeNode(nodes[i]);
72         }
73         guiPackage.getTreeListener().getJTree().setSelectionPath(newTreePath);
74         guiPackage.updateCurrentGui();
75     }
76
77     public static void removeNode(JMeterTreeNode node)
78     {
79         TestElement testElement = node.getTestElement();
80         if (testElement.canRemove())
81         {
82             GuiPackage.getInstance().getTreeModel().removeNodeFromParent(node);
83             GuiPackage.getInstance().removeNode(testElement);
84         }
85         else
86         {
87             String JavaDoc message=testElement.getClass().getName()+ " is busy";
88             JOptionPane.showMessageDialog(null, message, "Cannot remove item",
89                     JOptionPane.ERROR_MESSAGE);
90         }
91     }
92 }
93
Popular Tags