01: //$Header$
02: /*
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: *
18: */
19:
20: package org.apache.jmeter.report.gui.action;
21:
22: import java.awt.event.ActionEvent;
23: import java.util.HashSet;
24: import java.util.Set;
25:
26: import javax.swing.JOptionPane;
27: import javax.swing.tree.TreePath;
28:
29: import org.apache.jmeter.gui.ReportGuiPackage;
30: import org.apache.jmeter.report.gui.action.ReportCheckDirty;
31: import org.apache.jmeter.gui.action.Command;
32: import org.apache.jmeter.report.gui.tree.ReportTreeNode;
33: import org.apache.jmeter.testelement.TestElement;
34:
35: /**
36: * @author Peter Lin
37: * @version $Revision: 493793 $
38: */
39: public class ReportRemove implements Command {
40: private static Set commands = new HashSet();
41: static {
42: commands.add("remove");
43: }
44:
45: /**
46: * Constructor for the Remove object
47: */
48: public ReportRemove() {
49: }
50:
51: /**
52: * Gets the ActionNames attribute of the Remove object.
53: *
54: * @return the ActionNames value
55: */
56: public Set getActionNames() {
57: return commands;
58: }
59:
60: public void doAction(ActionEvent e) {
61: ReportActionRouter.getInstance().actionPerformed(
62: new ActionEvent(e.getSource(), e.getID(),
63: ReportCheckDirty.REMOVE));
64: ReportGuiPackage guiPackage = ReportGuiPackage.getInstance();
65: ReportTreeNode[] nodes = guiPackage.getTreeListener()
66: .getSelectedNodes();
67: TreePath newTreePath = // Save parent node for later
68: guiPackage.getTreeListener().removedSelectedNode();
69: for (int i = nodes.length - 1; i >= 0; i--) {
70: removeNode(nodes[i]);
71: }
72: guiPackage.getTreeListener().getJTree().setSelectionPath(
73: newTreePath);
74: guiPackage.updateCurrentGui();
75: }
76:
77: public static void removeNode(ReportTreeNode node) {
78: TestElement testElement = node.getTestElement();
79: if (testElement.canRemove()) {
80: ReportGuiPackage.getInstance().getTreeModel()
81: .removeNodeFromParent(node);
82: ReportGuiPackage.getInstance().removeNode(testElement);
83: } else {
84: String message = testElement.getClass().getName()
85: + " is busy";
86: JOptionPane.showMessageDialog(null, message,
87: "Cannot remove item", JOptionPane.ERROR_MESSAGE);
88: }
89: }
90: }
|