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.HashMap;
24: import java.util.Map;
25: import java.util.Set;
26:
27: import javax.swing.JComponent;
28: import javax.swing.tree.TreePath;
29:
30: import org.apache.jmeter.gui.ReportGuiPackage;
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: import org.apache.jorphan.logging.LoggingManager;
35: import org.apache.log.Logger;
36:
37: /**
38: * @author Peter Lin
39: * @version $Revision: 493793 $ Last updated: $Date: 2007-01-07 18:19:27 +0000 (Sun, 07 Jan 2007) $
40: */
41: public class ReportAddToTree implements Command {
42: transient private static Logger log = LoggingManager
43: .getLoggerForClass();
44:
45: private Map allJMeterComponentCommands;
46:
47: public ReportAddToTree() {
48: allJMeterComponentCommands = new HashMap();
49: allJMeterComponentCommands.put("Add", "Add");
50: }
51:
52: /**
53: * Gets the Set of actions this Command class responds to.
54: *
55: * @return the ActionNames value
56: */
57: public Set getActionNames() {
58: return allJMeterComponentCommands.keySet();
59: }
60:
61: /**
62: * Adds the specified class to the current node of the tree.
63: */
64: public void doAction(ActionEvent e) {
65: try {
66: TestElement node = ReportGuiPackage.getInstance()
67: .createTestElement(
68: ((JComponent) e.getSource()).getName());
69: addObjectToTree(node);
70: } catch (Exception err) {
71: log.error("", err);
72: }
73: }
74:
75: protected void addObjectToTree(TestElement el) {
76: ReportGuiPackage guiPackage = ReportGuiPackage.getInstance();
77: ReportTreeNode node = new ReportTreeNode(el, guiPackage
78: .getTreeModel());
79: guiPackage.getTreeModel().insertNodeInto(
80: node,
81: guiPackage.getTreeListener().getCurrentNode(),
82: guiPackage.getTreeListener().getCurrentNode()
83: .getChildCount());
84: TestElement curNode = (TestElement) guiPackage
85: .getTreeListener().getCurrentNode().getUserObject();
86: if (curNode != null) {
87: curNode.addTestElement(el);
88: guiPackage.getMainFrame().getTree().setSelectionPath(
89: new TreePath(node.getPath()));
90: }
91: }
92: }
|