KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > output > ResultPanelTree


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.junit.output;
21
22 import java.awt.EventQueue JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.beans.PropertyVetoException JavaDoc;
26 import java.util.List JavaDoc;
27 import javax.accessibility.AccessibleContext JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.event.ChangeEvent JavaDoc;
30 import javax.swing.event.ChangeListener JavaDoc;
31 import org.openide.ErrorManager;
32 import org.openide.explorer.ExplorerManager;
33 import org.openide.nodes.Node;
34 import org.openide.util.NbBundle;
35
36 /**
37  *
38  * @author Marian Petras
39  */

40 final class ResultPanelTree extends JPanel JavaDoc
41                             implements ExplorerManager.Provider,
42                                        PropertyChangeListener JavaDoc {
43
44     /** manages the tree of nodes representing found objects */
45     private final ExplorerManager explorerManager;
46     /** root node of the tree */
47     private final RootNode rootNode;
48     /** */
49     private final ResultTreeView treeView;
50     /** should the results be filtered (only failures and errors displayed)? */
51     private boolean filtered = false;
52     /** */
53     private ChangeListener JavaDoc changeListener;
54     /** */
55     private ChangeEvent JavaDoc changeEvent;
56     /**
57      * holds an instance of RegexpUtils so that implementations of nodes
58      * displayed in the tree always get the same instance when they ask for one
59      * using RegexpUtils.getInstance().
60      */

61     private final RegexpUtils regexpUtils = RegexpUtils.getInstance();
62     /** */
63     private final ResultDisplayHandler displayHandler;
64
65     ResultPanelTree(ResultDisplayHandler displayHandler) {
66         super(new java.awt.BorderLayout JavaDoc());
67         
68         add(treeView = new ResultTreeView(), java.awt.BorderLayout.CENTER);
69         
70         explorerManager = new ExplorerManager();
71         explorerManager.setRootContext(rootNode = new RootNode(filtered));
72         explorerManager.addPropertyChangeListener(this);
73
74         initAccessibility();
75         
76         this.displayHandler = displayHandler;
77     }
78     
79     /**
80      */

81     private void initAccessibility() {
82         AccessibleContext JavaDoc accessCtx;
83
84         accessCtx = getAccessibleContext();
85         accessCtx.setAccessibleName(
86                NbBundle.getMessage(getClass(), "ACSN_ResultPanelTree"));//NOI18N
87
accessCtx.setAccessibleDescription(
88                NbBundle.getMessage(getClass(), "ACSD_ResultPanelTree"));//NOI18N
89

90         accessCtx = treeView.getHorizontalScrollBar().getAccessibleContext();
91         accessCtx.setAccessibleName(
92                NbBundle.getMessage(getClass(),
93                                    "ACSN_HorizontalScrollbar")); //NOI18N
94

95         accessCtx = treeView.getVerticalScrollBar().getAccessibleContext();
96         accessCtx.setAccessibleName(
97                NbBundle.getMessage(getClass(),
98                                    "ACSN_HorizontalScrollbar")); //NOI18N
99

100     }
101     
102     /**
103      */

104     void displayMsg(String JavaDoc msg) {
105         assert EventQueue.isDispatchThread();
106         
107         /* Called from the EventDispatch thread */
108         
109         rootNode.displayMessage(msg);
110     }
111     
112     /**
113      */

114     public void addNotify() {
115         super.addNotify();
116         
117         final Object JavaDoc[] pendingOutput;
118         
119         displayHandler.setTreePanel(this);
120     }
121     
122     /**
123      * Displays a message about a running suite.
124      *
125      * @param suiteName name of the running suite,
126      * or {@code ANONYMOUS_SUITE} for anonymous suites
127      * @see ResultDisplayHandler#ANONYMOUS_SUITE
128      */

129     void displaySuiteRunning(final String JavaDoc suiteName) {
130         assert EventQueue.isDispatchThread();
131         
132         /* Called from the EventDispatch thread */
133         
134         rootNode.displaySuiteRunning(suiteName);
135     }
136     
137     /**
138      */

139     void displayReport(final Report report) {
140         assert EventQueue.isDispatchThread();
141         
142         /* Called from the EventDispatch thread */
143         
144         TestsuiteNode node = rootNode.displayReport(report);
145         if ((node != null) && report.containsFailed()) {
146             treeView.expandReportNode(node);
147         }
148     }
149     
150     /**
151      * @param reports non-empty list of reports to be displayed
152      */

153     void displayReports(final List JavaDoc<Report> reports) {
154         assert EventQueue.isDispatchThread();
155         
156         /* Called from the EventDispatch thread */
157         
158         if (reports.size() == 1) {
159             displayReport(reports.get(0));
160         } else {
161             rootNode.displayReports(reports);
162         }
163     }
164     
165     /**
166      */

167     int getSuccessDisplayedLevel() {
168         return rootNode.getSuccessDisplayedLevel();
169     }
170     
171     /**
172      */

173     void viewOpened() {
174         assert EventQueue.isDispatchThread();
175
176         //PENDING:
177
//selectAndActivateNode(rootNode);
178
}
179
180     /**
181      */

182     void setFiltered(final boolean filtered) {
183         if (filtered == this.filtered) {
184             return;
185         }
186         
187         this.filtered = filtered;
188         
189         rootNode.setFiltered(filtered);
190     }
191
192     /**
193      */

194     public void propertyChange(PropertyChangeEvent JavaDoc e) {
195         if (ExplorerManager.PROP_SELECTED_NODES.equals(
196                         e.getPropertyName())) {
197             nodeSelectionChanged();
198         }
199     }
200
201     /**
202      */

203     private void nodeSelectionChanged() {
204         assert EventQueue.isDispatchThread();
205
206         fireChange();
207     }
208
209     /**
210      */

211     void setChangeListener(ChangeListener JavaDoc l) {
212         assert EventQueue.isDispatchThread();
213
214         this.changeListener = l;
215         if (changeListener == null) {
216             changeEvent = null;
217         } else if (changeEvent == null) {
218             changeEvent = new ChangeEvent JavaDoc(this);
219         }
220     }
221     
222     /**
223      */

224     private void fireNodeSelectionChange() {
225         fireChange();
226     }
227
228     /**
229      */

230     private void fireChange() {
231         assert EventQueue.isDispatchThread();
232
233         if (changeListener != null) {
234             changeListener.stateChanged(changeEvent);
235         }
236     }
237
238     /**
239      */

240     Node[] getSelectedNodes() {
241         return explorerManager.getSelectedNodes();
242     }
243
244     /**
245      * Selects and activates a given node.
246      * Selects a given node in the tree.
247      * If the nodes cannot be selected and/or activated,
248      * clears the selection (and notifies that no node is currently
249      * activated).
250      *
251      * @param node node to be selected and activated
252      */

253     private void selectAndActivateNode(final Node node) {
254         Node[] nodeArray = new Node[] {node};
255         try {
256             explorerManager.setSelectedNodes(nodeArray);
257             fireNodeSelectionChange();
258         } catch (PropertyVetoException JavaDoc ex) {
259             ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
260             nodeArray = new Node[0];
261             try {
262                 explorerManager.setSelectedNodes(nodeArray);
263                 fireNodeSelectionChange();
264             } catch (PropertyVetoException JavaDoc ex2) {
265                 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex2);
266             }
267         }
268     }
269
270     /**
271      */

272     public ExplorerManager getExplorerManager() {
273         return explorerManager;
274     }
275     
276     /**
277      */

278     public boolean requestFocusInWindow() {
279         return treeView.requestFocusInWindow();
280     }
281
282 }
283
Popular Tags