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.Set;
24:
25: import javax.swing.JOptionPane;
26: import javax.swing.tree.TreePath;
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: 493779 $
35: */
36: public class Remove implements Command {
37:
38: private static Set commands = new HashSet();
39: static {
40: commands.add(ActionNames.REMOVE);
41: }
42:
43: /**
44: * Constructor for the Remove object
45: */
46: public Remove() {
47: }
48:
49: /**
50: * Gets the ActionNames attribute of the Remove object.
51: *
52: * @return the ActionNames value
53: */
54: public Set getActionNames() {
55: return commands;
56: }
57:
58: public void doAction(ActionEvent e) {
59: ActionRouter.getInstance().actionPerformed(
60: new ActionEvent(e.getSource(), e.getID(),
61: ActionNames.CHECK_REMOVE));
62: GuiPackage guiPackage = GuiPackage.getInstance();
63: JMeterTreeNode[] nodes = guiPackage.getTreeListener()
64: .getSelectedNodes();
65: TreePath newTreePath = // Save parent node for later
66: guiPackage.getTreeListener().removedSelectedNode();
67: for (int i = nodes.length - 1; i >= 0; i--) {
68: removeNode(nodes[i]);
69: }
70: guiPackage.getTreeListener().getJTree().setSelectionPath(
71: newTreePath);
72: guiPackage.updateCurrentGui();
73: }
74:
75: public static void removeNode(JMeterTreeNode node) {
76: TestElement testElement = node.getTestElement();
77: if (testElement.canRemove()) {
78: GuiPackage.getInstance().getTreeModel()
79: .removeNodeFromParent(node);
80: GuiPackage.getInstance().removeNode(testElement);
81: } else {
82: String message = testElement.getClass().getName()
83: + " is busy";
84: JOptionPane.showMessageDialog(null, message,
85: "Cannot remove item", JOptionPane.ERROR_MESSAGE);
86: }
87: }
88: }
|