View | Details | Raw Unified | Return to bug 34796
Collapse All | Expand All

(-)ViewResultsFullVisualizer.java (-186 / +79 lines)
Lines 44-49 Link Here
44
import javax.swing.JTextArea;
44
import javax.swing.JTextArea;
45
import javax.swing.JTextPane;
45
import javax.swing.JTextPane;
46
import javax.swing.JTree;
46
import javax.swing.JTree;
47
import javax.swing.ToolTipManager;
47
import javax.swing.event.TreeSelectionEvent;
48
import javax.swing.event.TreeSelectionEvent;
48
import javax.swing.event.TreeSelectionListener;
49
import javax.swing.event.TreeSelectionListener;
49
import javax.swing.text.BadLocationException;
50
import javax.swing.text.BadLocationException;
Lines 796-981 Link Here
796
    	}
797
    	}
797
    }
798
    }
798
    
799
    
799
    /**
800
    *A extended class of DefaultMutableTreeNode except that it also attached
801
    *XML node and convert XML document into DefaultMutableTreeNode
802
    * author <a href="mailto:d.maung@mdl.com">Dave Maung</a>
803
    * 
804
    */
805
    public class XMLDefaultMutableTreeNode extends DefaultMutableTreeNode 
806
    {
807
808
    	boolean isRoot;
809
    	private Node xmlNode;
810
    	public XMLDefaultMutableTreeNode(Node root) throws SAXException 
811
    	{
812
    	    super(root.getNodeName());
813
    		initRoot(root);
814
    		
815
    	}
816
    	
817
    	public XMLDefaultMutableTreeNode(String name,Node xmlNode) 
818
    	{
819
    		super(name);
820
    		this.xmlNode = xmlNode;
821
    		
822
    	}
823
    	/**
824
    	 * init root
825
    	 * @param root
826
    	 * @throws SAXException
827
    	 */
828
    	private void initRoot(Node xmlRoot) throws SAXException {
829
    		
830
    	
831
    		NodeList childNodes = xmlRoot.getChildNodes();
832
    		if(childNodes == null) 
833
    			initAttributeNode(xmlRoot, this);
834
    		
835
    		for (int i = 0; i < childNodes.getLength(); i++) {
836
    			Node childNode = childNodes.item(i);
837
    			initNode(childNode, this);
838
    		}
839
840
    	}
841
    	/**
842
    	 * init node
843
    	 * @param node
844
    	 * @param mTreeNode
845
    	 * @throws SAXException
846
    	 */
847
    	private void initNode(Node node, XMLDefaultMutableTreeNode mTreeNode)
848
    			throws SAXException 
849
    			{
850
851
    		switch (node.getNodeType())
852
    		{
853
    		case Node.ELEMENT_NODE:
854
    			initElementNode(node, mTreeNode);
855
    			break;
856
    			
857
    		case Node.TEXT_NODE:
858
    			 initTextNode((Text)node, mTreeNode);
859
    			break;
860
    			
861
862
    		case Node.CDATA_SECTION_NODE:
863
    			initCDATASectionNode((CDATASection)node, mTreeNode);
864
    			break;
865
    		case Node.COMMENT_NODE:
866
    			initCommentNode((Comment)node,mTreeNode);
867
    			break;
868
    		
869
    		default:
870
    		    //if other node type, we will just skip it
871
    			break;
872
873
    		}
874
875
    	}
876
    	/**
877
    	 * init element node
878
    	 * @param node
879
    	 * @param mTreeNode
880
    	 * @throws SAXException
881
    	 */
882
    	private void initElementNode(Node node, DefaultMutableTreeNode mTreeNode)
883
    			throws SAXException {
884
    		String nodeName = node.getNodeName();
885
    		
886
    		NodeList childNodes = node.getChildNodes();
887
    		XMLDefaultMutableTreeNode childTreeNode = new XMLDefaultMutableTreeNode(nodeName
888
    				,node);
889
890
    		mTreeNode.add(childTreeNode);
891
    		initAttributeNode(node, childTreeNode);
892
    		for (int i = 0; i < childNodes.getLength(); i++) 
893
    		{
894
    			Node childNode = childNodes.item(i);
895
    			initNode(childNode, childTreeNode);
896
    		}
897
898
    	}
899
    	/**
900
    	 * init attribute node
901
    	 * @param node
902
    	 * @param mTreeNode
903
    	 * @throws SAXException
904
    	 */
905
    	private void initAttributeNode(Node node, DefaultMutableTreeNode mTreeNode)
906
    			throws SAXException {
907
    		NamedNodeMap nm = node.getAttributes();
908
    		for (int i = 0; i < nm.getLength(); i++) 
909
    		{
910
    			Attr nmNode = (Attr)nm.item(i);
911
    			String value = nmNode.getName() + " = \"" + nmNode.getValue() + "\"";
912
    			XMLDefaultMutableTreeNode attributeNode = new XMLDefaultMutableTreeNode(
913
    					value,nmNode);
914
    			mTreeNode.add(attributeNode);
915
916
    		}
917
    	}
918
    	/**
919
    	 * init comment Node
920
    	 * @param node
921
    	 * @param mTreeNode
922
    	 * @throws SAXException
923
    	 */
924
    	private void initCommentNode(Comment node, DefaultMutableTreeNode mTreeNode) throws SAXException{
925
    		String data = node.getData();
926
    		if(data != null || data.length() > 0)
927
    		{
928
    			String value = "<!--" + node.getData() + "-->";
929
    			XMLDefaultMutableTreeNode commentNode = new XMLDefaultMutableTreeNode(value,node);
930
    			mTreeNode.add(commentNode);
931
    		}
932
    	}
933
    	/**
934
    	 * init CDATASection Node
935
    	 * @param node
936
    	 * @param mTreeNode
937
    	 * @throws SAXException
938
    	 */
939
    	private void initCDATASectionNode(CDATASection node, DefaultMutableTreeNode mTreeNode) throws SAXException 
940
    	{
941
    		String data = node.getData();
942
    		if(data != null || data.length() > 0) 
943
    		{
944
    			String value = "<!-[CDATA" + node.getData() + "]]>";
945
    			XMLDefaultMutableTreeNode commentNode = new XMLDefaultMutableTreeNode(value,node);
946
    			mTreeNode.add(commentNode);
947
    		}
948
    	}
949
    	/**
950
    	 * init the TextNode
951
    	 * @param node
952
    	 * @param mTreeNode
953
    	 * @throws SAXException
954
    	 */
955
    	private void initTextNode(Text node, DefaultMutableTreeNode mTreeNode) throws SAXException 
956
    	{
957
    		String text = node.getNodeValue().trim();
958
    		if(text != null && text.length() > 0) 
959
    		{
960
    			XMLDefaultMutableTreeNode textNode = new XMLDefaultMutableTreeNode(node
961
    				.getNodeValue(),node);
962
    			mTreeNode.add(textNode);
963
    		}
964
    	}
965
    	
966
    	
967
    	
968
    	/**
969
    	 * get the xml node
970
    	 * @return
971
    	 */
972
    	public Node getXMLNode() 
973
    	{
974
    		return xmlNode;
975
    	}
976
    	
977
978
    }
979
    
800
    
980
    
801
    
981
     /**
802
     /**
Lines 992-998 Link Here
992
    	public DOMTreePanel(org.w3c.dom.Document document) {
813
    	public DOMTreePanel(org.w3c.dom.Document document) {
993
    		super(new GridLayout(1, 0));
814
    		super(new GridLayout(1, 0));
994
    		try {
815
    		try {
995
    		    
996
    		    Node firstElement = getFirstElement(document);
816
    		    Node firstElement = getFirstElement(document);
997
    			DefaultMutableTreeNode top = new XMLDefaultMutableTreeNode(
817
    			DefaultMutableTreeNode top = new XMLDefaultMutableTreeNode(
998
    					firstElement);
818
    					firstElement);
Lines 1004-1010 Link Here
1004
    		    JScrollPane domJScrollPane = new JScrollPane(domJTree);
824
    		    JScrollPane domJScrollPane = new JScrollPane(domJTree);
1005
    			domJTree.setAutoscrolls(true);
825
    			domJTree.setAutoscrolls(true);
1006
    			this.add(domJScrollPane);
826
    			this.add(domJScrollPane);
1007
    			this.setSize(800, 600);
827
    			ToolTipManager.sharedInstance().registerComponent(domJTree);
828
    	        domJTree.setCellRenderer(new DomTreeRenderer());
1008
    			this.setPreferredSize(new Dimension(800, 600));
829
    			this.setPreferredSize(new Dimension(800, 600));
1009
    		} catch (SAXException e) {
830
    		} catch (SAXException e) {
1010
    			log.warn("",e);
831
    			log.warn("",e);
Lines 1029-1039 Link Here
1029
    		}
850
    		}
1030
    		return toReturn;
851
    		return toReturn;
1031
    	}
852
    	}
1032
853
    	/**
1033
    
854
    	 * This class is to view as tooltext. This is very useful, when
1034
    	
855
    	 * the contents has long string and does not fit in the view.
1035
    	
856
    	 * it will also automatically wrap line for each
857
    	 * 100 characters since tool tip support html.
858
    	 * author <a href="mailto:d.maung@mdl.com">Dave Maung</a>
859
    	 *
860
    	 * TODO To change the template for this generated type comment go to
861
    	 * Window - Preferences - Java - Code Style - Code Templates
862
    	 */
863
    	private class DomTreeRenderer extends DefaultTreeCellRenderer {
864
    	    public Component getTreeCellRendererComponent(
865
    	                    JTree tree,
866
    	                    Object value,
867
    	                    boolean sel,
868
    	                    boolean expanded,
869
    	                    boolean leaf,
870
    	                    int row,
871
    	                    boolean hasFocus) 
872
    	    {
873
    	           super.getTreeCellRendererComponent(
874
    	                            tree, value, sel,
875
    	                            expanded, leaf, row,
876
    	                            hasFocus);
877
    	           
878
    	            DefaultMutableTreeNode valueTreeNode = (DefaultMutableTreeNode)value;
879
    	            setToolTipText(getHTML(valueTreeNode.toString(),"<br/>",100));
880
    	            return this;
881
    	      }
882
    	        
883
    	        /**
884
    	         * get the html
885
    	         * @param str
886
    	         * @param separator
887
    	         * @param maxChar
888
    	         * @return
889
    	         */
890
    	        private String getHTML(String str,String separator, int maxChar) 
891
    	        {
892
    	        	StringBuffer strBuf = new StringBuffer("<html><body bgcolor=\"yellow\"><b>");
893
    	        	char[] chars = str.toCharArray();
894
    	        	for(int i=0; i< chars.length; i++) {
895
    	        		
896
    	        		if(i % maxChar == 0 && i != 0) 
897
    	        			strBuf.append(separator);
898
    	        		strBuf.append(encode(chars[i]));	
899
    	        		
900
    	        	}
901
    	        	strBuf.append("</b></body></html>");
902
    	        	return strBuf.toString();
903
    	        	
904
    	        }
905
    	        private String encode(char c) 
906
    	        {
907
    	            String toReturn = String.valueOf(c);
908
    	            switch(c) {
909
    	            	case '<':
910
    	            	    toReturn = "&lt;";
911
    	            	    break;
912
    	            	case '>':
913
    	            	    toReturn = "&gt;";
914
    	            	    break;
915
    	            	case '\'':
916
    	            	    toReturn = "&apos;";
917
    	            	    break;
918
    	            	case '\"':
919
    	            	    toReturn = "&quot;";
920
    	            	    break;
921
    	            	    
922
    	            }
923
    	            return toReturn;
924
    	        }
925
    	}
1036
    }
926
    }
927
    
928
    
1037
929
1038
    private static void showErrorMessageDialog(String message,int messageType) {
930
    private static void showErrorMessageDialog(String message,int messageType) {
1039
        JOptionPane.showMessageDialog(null, message, "Error", messageType); 
931
        JOptionPane.showMessageDialog(null, message, "Error", messageType); 
Lines 1121-1124 Link Here
1121
        }
1013
        }
1122
    }
1014
    }
1123
    
1015
    
1016
	
1124
}
1017
}
(-)XMLDefaultMutableTreeNode.java (+191 lines)
Added Link Here
1
/*
2
 * Created on May 7, 2005
3
 *
4
 * TODO To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Style - Code Templates
6
 */
7
package org.apache.jmeter.visualizers;
8
9
import javax.swing.tree.DefaultMutableTreeNode;
10
import org.w3c.dom.Attr;
11
import org.w3c.dom.CDATASection;
12
import org.w3c.dom.Comment;
13
import org.w3c.dom.NamedNodeMap;
14
import org.w3c.dom.Node;
15
import org.w3c.dom.NodeList;
16
import org.w3c.dom.Text;
17
import org.xml.sax.SAXException;
18
19
/**
20
 *A extended class of DefaultMutableTreeNode except that it also attached
21
 *XML node and convert XML document into DefaultMutableTreeNode
22
 * author <a href="mailto:d.maung@mdl.com">Dave Maung</a>
23
 * 
24
 */
25
 public class XMLDefaultMutableTreeNode extends DefaultMutableTreeNode 
26
 {
27
    private static final int LIMIT_STR_SIZE = 100;
28
 	boolean isRoot;
29
 	private Node xmlNode;
30
 	public XMLDefaultMutableTreeNode(Node root) throws SAXException 
31
 	{
32
 	    super(root.getNodeName());
33
 	    initAttributeNode(root, this);
34
 		initRoot(root);
35
 		
36
 	}
37
 	
38
 	public XMLDefaultMutableTreeNode(String name,Node xmlNode) 
39
 	{
40
 		super(name);
41
 		this.xmlNode = xmlNode;
42
 		
43
 	}
44
 	/**
45
 	 * init root
46
 	 * @param root
47
 	 * @throws SAXException
48
 	 */
49
 	private void initRoot(Node xmlRoot) throws SAXException {
50
 		
51
 	
52
 		NodeList childNodes = xmlRoot.getChildNodes();
53
 		for (int i = 0; i < childNodes.getLength(); i++) {
54
 			Node childNode = childNodes.item(i);
55
 			initNode(childNode, this);
56
 		}
57
58
 	}
59
 	/**
60
 	 * init node
61
 	 * @param node
62
 	 * @param mTreeNode
63
 	 * @throws SAXException
64
 	 */
65
 	private void initNode(Node node, XMLDefaultMutableTreeNode mTreeNode)
66
 			throws SAXException 
67
 			{
68
69
 		switch (node.getNodeType())
70
 		{
71
 		case Node.ELEMENT_NODE:
72
 			initElementNode(node, mTreeNode);
73
 			break;
74
 			
75
 		case Node.TEXT_NODE:
76
 			 initTextNode((Text)node, mTreeNode);
77
 			break;
78
 			
79
80
 		case Node.CDATA_SECTION_NODE:
81
 			initCDATASectionNode((CDATASection)node, mTreeNode);
82
 			break;
83
 		case Node.COMMENT_NODE:
84
 			initCommentNode((Comment)node,mTreeNode);
85
 			break;
86
 		
87
 		default:
88
 		    //if other node type, we will just skip it
89
 			break;
90
91
 		}
92
93
 	}
94
 	/**
95
 	 * init element node
96
 	 * @param node
97
 	 * @param mTreeNode
98
 	 * @throws SAXException
99
 	 */
100
 	private void initElementNode(Node node, DefaultMutableTreeNode mTreeNode)
101
 			throws SAXException {
102
 		String nodeName = node.getNodeName();
103
 		
104
 		NodeList childNodes = node.getChildNodes();
105
 		XMLDefaultMutableTreeNode childTreeNode = new XMLDefaultMutableTreeNode(nodeName
106
 				,node);
107
108
 		mTreeNode.add(childTreeNode);
109
 		initAttributeNode(node, childTreeNode);
110
 		for (int i = 0; i < childNodes.getLength(); i++) 
111
 		{
112
 			Node childNode = childNodes.item(i);
113
 			initNode(childNode, childTreeNode);
114
 		}
115
116
 	}
117
 	/**
118
 	 * init attribute node
119
 	 * @param node
120
 	 * @param mTreeNode
121
 	 * @throws SAXException
122
 	 */
123
 	private void initAttributeNode(Node node, DefaultMutableTreeNode mTreeNode)
124
 			throws SAXException {
125
 		NamedNodeMap nm = node.getAttributes();
126
 		for (int i = 0; i < nm.getLength(); i++) 
127
 		{
128
 			Attr nmNode = (Attr)nm.item(i);
129
 			String value = nmNode.getName() + " = \"" + nmNode.getValue() + "\"";
130
 			XMLDefaultMutableTreeNode attributeNode = new XMLDefaultMutableTreeNode(
131
 			       value,nmNode);
132
 			mTreeNode.add(attributeNode);
133
134
 		}
135
 	}
136
 	/**
137
 	 * init comment Node
138
 	 * @param node
139
 	 * @param mTreeNode
140
 	 * @throws SAXException
141
 	 */
142
 	private void initCommentNode(Comment node, DefaultMutableTreeNode mTreeNode) throws SAXException{
143
 		String data = node.getData();
144
 		if(data != null || data.length() > 0)
145
 		{
146
 			String value = "<!--" + node.getData() + "-->";
147
 			XMLDefaultMutableTreeNode commentNode = new XMLDefaultMutableTreeNode(value,node);
148
 			mTreeNode.add(commentNode);
149
 		}
150
 	}
151
 	/**
152
 	 * init CDATASection Node
153
 	 * @param node
154
 	 * @param mTreeNode
155
 	 * @throws SAXException
156
 	 */
157
 	private void initCDATASectionNode(CDATASection node, DefaultMutableTreeNode mTreeNode) throws SAXException 
158
 	{
159
 		String data = node.getData();
160
 		if(data != null || data.length() > 0) 
161
 		{
162
 			String value = "<!-[CDATA" + node.getData() + "]]>";
163
 			XMLDefaultMutableTreeNode commentNode = new XMLDefaultMutableTreeNode(value,node);
164
 			mTreeNode.add(commentNode);
165
 		}
166
 	}
167
 	/**
168
 	 * init the TextNode
169
 	 * @param node
170
 	 * @param mTreeNode
171
 	 * @throws SAXException
172
 	 */
173
 	private void initTextNode(Text node, DefaultMutableTreeNode mTreeNode) throws SAXException 
174
 	{
175
 		String text = node.getNodeValue().trim();
176
 		if(text != null && text.length() > 0) 
177
 		{
178
 			XMLDefaultMutableTreeNode textNode = new XMLDefaultMutableTreeNode(text,node);
179
 			mTreeNode.add(textNode);
180
 		}
181
 	}
182
 	
183
 	/**
184
 	 * get the xml node
185
 	 * @return
186
 	 */
187
 	public Node getXMLNode() 
188
 	{
189
 		return xmlNode;
190
 	}
191
}

Return to bug 34796