Source Code Cross Referenced for ReportTreeModel.java in  » Testing » jakarta-jmeter » org » apache » jmeter » report » gui » tree » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta jmeter » org.apache.jmeter.report.gui.tree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jmeter.report.gui.tree;
020:
021:        import java.util.Enumeration;
022:        import java.util.Iterator;
023:        import java.util.LinkedList;
024:        import java.util.List;
025:
026:        import javax.swing.tree.DefaultTreeModel;
027:
028:        import org.apache.jmeter.config.gui.AbstractConfigGui;
029:        import org.apache.jmeter.control.gui.ReportGui;
030:        import org.apache.jmeter.exceptions.IllegalUserActionException;
031:        import org.apache.jmeter.gui.ReportGuiPackage;
032:        import org.apache.jmeter.gui.JMeterGUIComponent;
033:        import org.apache.jmeter.report.gui.tree.ReportTreeNode;
034:        import org.apache.jmeter.testelement.TestElement;
035:        import org.apache.jmeter.testelement.ReportPlan;
036:        import org.apache.jmeter.testelement.property.NullProperty;
037:        import org.apache.jmeter.util.NameUpdater;
038:        import org.apache.jorphan.collections.HashTree;
039:        import org.apache.jorphan.collections.ListedHashTree;
040:
041:        /**
042:         * 
043:         * author Peter Lin
044:         * 
045:         * @version $Revision: 493793 $
046:         */
047:        public class ReportTreeModel extends DefaultTreeModel {
048:
049:            public ReportTreeModel() {
050:                super (new ReportTreeNode(new ReportGui().createTestElement(),
051:                        null));
052:                initTree();
053:            }
054:
055:            /**
056:             * Returns a list of tree nodes that hold objects of the given class type.
057:             * If none are found, an empty list is returned.
058:             */
059:            public List getNodesOfType(Class type) {
060:                List nodeList = new LinkedList();
061:                traverseAndFind(type, (ReportTreeNode) this .getRoot(), nodeList);
062:                return nodeList;
063:            }
064:
065:            /**
066:             * Get the node for a given TestElement object.
067:             */
068:            public ReportTreeNode getNodeOf(TestElement userObject) {
069:                return traverseAndFind(userObject, (ReportTreeNode) getRoot());
070:            }
071:
072:            /**
073:             * Adds the sub tree at the given node. Returns a boolean indicating whether
074:             * the added sub tree was a full test plan.
075:             */
076:            public HashTree addSubTree(HashTree subTree, ReportTreeNode current)
077:                    throws IllegalUserActionException {
078:                Iterator iter = subTree.list().iterator();
079:                while (iter.hasNext()) {
080:                    TestElement item = (TestElement) iter.next();
081:                    if (item instanceof  ReportPlan) {
082:                        current = (ReportTreeNode) ((ReportTreeNode) getRoot())
083:                                .getChildAt(0);
084:                        ((TestElement) current.getUserObject())
085:                                .addTestElement(item);
086:                        ((ReportPlan) current.getUserObject()).setName(item
087:                                .getPropertyAsString(TestElement.NAME));
088:                        addSubTree(subTree.getTree(item), current);
089:                    } else {
090:                        if (subTree.getTree(item) != null) {
091:                            addSubTree(subTree.getTree(item), addComponent(
092:                                    item, current));
093:                        }
094:                    }
095:                }
096:                return getCurrentSubTree(current);
097:            }
098:
099:            public ReportTreeNode addComponent(TestElement component,
100:                    ReportTreeNode node) throws IllegalUserActionException {
101:                if (node.getUserObject() instanceof  AbstractConfigGui) {
102:                    throw new IllegalUserActionException(
103:                            "This node cannot hold sub-elements");
104:                }
105:                component.setProperty(TestElement.GUI_CLASS, NameUpdater
106:                        .getCurrentName(component
107:                                .getPropertyAsString(TestElement.GUI_CLASS)));
108:                ReportGuiPackage.getInstance().updateCurrentNode();
109:                JMeterGUIComponent guicomp = ReportGuiPackage.getInstance()
110:                        .getGui(component);
111:                guicomp.configure(component);
112:                guicomp.modifyTestElement(component);
113:                ReportGuiPackage.getInstance().getCurrentGui(); // put the gui object back
114:                // to the way it was.
115:                ReportTreeNode newNode = new ReportTreeNode(component, this );
116:
117:                // This check the state of the TestElement and if returns false it
118:                // disable the loaded node
119:                try {
120:                    if (component.getProperty(TestElement.ENABLED) instanceof  NullProperty
121:                            || component
122:                                    .getPropertyAsBoolean(TestElement.ENABLED)) {
123:                        newNode.setEnabled(true);
124:                    } else {
125:                        newNode.setEnabled(false);
126:                    }
127:                } catch (Exception e) {
128:                    newNode.setEnabled(true);
129:                }
130:
131:                this .insertNodeInto(newNode, node, node.getChildCount());
132:                return newNode;
133:            }
134:
135:            public void removeNodeFromParent(ReportTreeNode node) {
136:                if (!(node.getUserObject() instanceof  ReportPlan)) {
137:                    super .removeNodeFromParent(node);
138:                }
139:            }
140:
141:            private void traverseAndFind(Class type, ReportTreeNode node,
142:                    List nodeList) {
143:                if (type.isInstance(node.getUserObject())) {
144:                    nodeList.add(node);
145:                }
146:                Enumeration enumNode = node.children();
147:                while (enumNode.hasMoreElements()) {
148:                    ReportTreeNode child = (ReportTreeNode) enumNode
149:                            .nextElement();
150:                    traverseAndFind(type, child, nodeList);
151:                }
152:            }
153:
154:            private ReportTreeNode traverseAndFind(TestElement userObject,
155:                    ReportTreeNode node) {
156:                if (userObject == node.getUserObject()) {
157:                    return node;
158:                }
159:                Enumeration enumNode = node.children();
160:                while (enumNode.hasMoreElements()) {
161:                    ReportTreeNode child = (ReportTreeNode) enumNode
162:                            .nextElement();
163:                    ReportTreeNode result = traverseAndFind(userObject, child);
164:                    if (result != null)
165:                        return result;
166:                }
167:                return null;
168:            }
169:
170:            public HashTree getCurrentSubTree(ReportTreeNode node) {
171:                ListedHashTree hashTree = new ListedHashTree(node);
172:                Enumeration enumNode = node.children();
173:                while (enumNode.hasMoreElements()) {
174:                    ReportTreeNode child = (ReportTreeNode) enumNode
175:                            .nextElement();
176:                    hashTree.add(node, getCurrentSubTree(child));
177:                }
178:                return hashTree;
179:            }
180:
181:            public HashTree getReportPlan() {
182:                return getCurrentSubTree((ReportTreeNode) ((ReportTreeNode) this 
183:                        .getRoot()).getChildAt(0));
184:            }
185:
186:            public void clearTestPlan() {
187:                super .removeNodeFromParent((ReportTreeNode) getChild(getRoot(),
188:                        0));
189:                initTree();
190:            }
191:
192:            private void initTree() {
193:                TestElement rp = new ReportGui().createTestElement();
194:                this .insertNodeInto(new ReportTreeNode(rp, this ),
195:                        (ReportTreeNode) getRoot(), 0);
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.