KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > view > RootContextTest


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
21 package org.openide.explorer.view;
22
23 import java.beans.PropertyVetoException JavaDoc;
24 import javax.swing.ListSelectionModel JavaDoc;
25 import javax.swing.tree.TreeSelectionModel JavaDoc;
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28
29 import org.netbeans.junit.NbTestCase;
30 import org.netbeans.junit.NbTestSuite;
31
32 import org.openide.explorer.ExplorerManager;
33 import org.openide.explorer.ExplorerPanel;
34 import org.openide.explorer.view.*;
35
36 import org.openide.nodes.AbstractNode;
37 import org.openide.nodes.Children;
38 import org.openide.nodes.Node;
39 import org.openide.nodes.Children.Array;
40
41 /*
42  * RootContextTest.java tests a change the root context and set selected node
43  * in each root context.
44  *
45  * @author Jiri Rechtacek
46  */

47 public class RootContextTest extends NbTestCase {
48     
49     public RootContextTest (java.lang.String JavaDoc testName) {
50         super (testName);
51     }
52     
53     public static void main (java.lang.String JavaDoc[] args) {
54         junit.textui.TestRunner.run (suite ());
55     }
56     
57     public static Test suite () {
58         TestSuite suite = new NbTestSuite (RootContextTest.class);
59         return suite;
60     }
61     
62     // helper variables
63
Node[] arr1, arr2;
64     Node root1, root2;
65     boolean initialized = false;
66
67     
68     // initialize the test variables
69
public void initTest () {
70         
71         // do init only once
72
if (initialized) {
73             return ;
74         } else {
75             initialized = true;
76         }
77
78         arr1 = new Node [3];
79         arr1[0] = new AbstractNode (Children.LEAF);
80         arr1[0].setName ("One");
81         
82         arr1[1] = new AbstractNode (Children.LEAF);
83         arr1[1].setName ("Two");
84         
85         arr1[2] = new AbstractNode (Children.LEAF);
86         arr1[2].setName ("Three");
87         
88         Array ch1 = new Array ();
89         ch1.add (arr1);
90         
91         arr2 = new Node [3];
92         arr2[0] = new AbstractNode (Children.LEAF);
93         arr2[0].setName ("Aaa");
94         
95         arr2[1] = new AbstractNode (Children.LEAF);
96         arr2[1].setName ("Bbb");
97         
98         arr2[2] = new AbstractNode (Children.LEAF);
99         arr2[2].setName ("Ccc");
100
101         Array ch2 = new Array ();
102         ch2.add (arr2);
103         
104         root1 = new AbstractNode (ch1);
105         root1.setName ("Root1");
106         root2 = new AbstractNode (ch2);
107         root2.setName ("Root2");
108         
109     }
110     
111     /** Run all tests in AWT thread */
112     protected boolean runInEQ() {
113         return true;
114     }
115     
116     // assure the node selections with given manager
117
public void doViewTest (final ExplorerManager mgr) throws Exception JavaDoc {
118         mgr.setRootContext (root1);
119         mgr.setSelectedNodes (new Node[] {arr1[0], arr1[2]});
120
121         Node[] selNodes = mgr.getSelectedNodes ();
122         assertEquals ("Root context is ", "Root1", mgr.getRootContext ().getName ());
123         assertEquals ("Count of the selected node is ", 2, selNodes.length);
124         // pending: an order migth be different
125
//Arrays.sort (selNodes);
126
assertEquals ("Selected node is ", "One", selNodes[0].getName ());
127         assertEquals ("Selected node is ", "Three", selNodes[1].getName ());
128
129         mgr.setRootContext (root2);
130         mgr.setSelectedNodes(new Node[] { arr2[1] });
131
132         selNodes = mgr.getSelectedNodes ();
133         assertEquals ("Root context is ", "Root2", mgr.getRootContext ().getName ());
134         assertEquals ("Count of the selected node is ", 1, selNodes.length);
135         assertEquals ("Selected node is ", "Bbb", selNodes[0].getName ());
136
137     }
138     
139     // test for each type of view
140

141     public void testBeanTreeView() throws Exception JavaDoc {
142         
143         initTest ();
144         
145         TreeView view = new BeanTreeView ();
146         view.setSelectionMode (TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
147         
148         ExplorerPanel panel = new ExplorerPanel ();
149         //#47021
150
panel.setName("preferredID");
151         ExplorerManager mgr = panel.getExplorerManager ();
152         
153         panel.add (view);
154         panel.open ();
155         
156         doViewTest(mgr);
157         
158     }
159     
160     public void testContextTreeView() throws Exception JavaDoc {
161         
162         initTest ();
163         
164         TreeView view = new ContextTreeView ();
165         view.setSelectionMode (TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
166         
167         ExplorerPanel panel = new ExplorerPanel ();
168         //#47021
169
panel.setName("preferredID");
170         ExplorerManager mgr = panel.getExplorerManager ();
171         
172         panel.add (view);
173         panel.open ();
174         
175         doViewTest(mgr);
176         
177     }
178     
179     public void testTreeTableView() throws Exception JavaDoc {
180         
181         initTest ();
182         
183         TreeTableView view = new TreeTableView ();
184         view.setSelectionMode (TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
185         
186         ExplorerPanel panel = new ExplorerPanel ();
187         //#47021
188
panel.setName("preferredID");
189         ExplorerManager mgr = panel.getExplorerManager ();
190         
191         panel.add (view);
192         panel.open ();
193         
194         doViewTest(mgr);
195         
196     }
197     
198     public void testListView() throws Exception JavaDoc {
199         
200         initTest ();
201         
202         ListView view = new ListView ();
203         view.setSelectionMode (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
204         
205         ExplorerPanel panel = new ExplorerPanel ();
206         //#47021
207
panel.setName("preferredID");
208         ExplorerManager mgr = panel.getExplorerManager ();
209         
210         panel.add (view);
211         panel.open ();
212         
213         doViewTest(mgr);
214
215     }
216     
217     public void testListTableView() throws Exception JavaDoc {
218         
219         initTest ();
220         
221         ListTableView view = new ListTableView ();
222         view.setSelectionMode (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
223         
224         ExplorerPanel panel = new ExplorerPanel ();
225         //#47021
226
panel.setName("preferredID");
227         ExplorerManager mgr = panel.getExplorerManager ();
228         
229         panel.add (view);
230         panel.open ();
231         
232         doViewTest(mgr);
233         
234     }
235     
236 }
237
Popular Tags