KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Note: It's just helper test for investigate issue 37875 (failing RootContextTest)
43  * Will be removed when issue 37875 is closed.
44  *
45  * @author Jiri Rechtacek
46  */

47 public class SelectNodeInListViewTest extends NbTestCase {
48     
49     public SelectNodeInListViewTest (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 (SelectNodeInListViewTest.class);
59         return suite;
60     }
61     
62     /** Run all tests in AWT thread */
63     protected boolean runInEQ () {
64         return true;
65     }
66     
67     public void testSelectedNodeInListView () throws Exception JavaDoc {
68     
69         // helper variables
70
Node[] arr1, arr2;
71         Node root1, root2;
72     
73         arr1 = new Node [3];
74         arr1[0] = new AbstractNode (Children.LEAF);
75         arr1[0].setName ("One");
76         
77         arr1[1] = new AbstractNode (Children.LEAF);
78         arr1[1].setName ("Two");
79         
80         arr1[2] = new AbstractNode (Children.LEAF);
81         arr1[2].setName ("Three");
82         
83         Array ch1 = new Array ();
84         ch1.add (arr1);
85         
86         arr2 = new Node [3];
87         arr2[0] = new AbstractNode (Children.LEAF);
88         arr2[0].setName ("Aaa");
89         
90         arr2[1] = new AbstractNode (Children.LEAF);
91         arr2[1].setName ("Bbb");
92         
93         arr2[2] = new AbstractNode (Children.LEAF);
94         arr2[2].setName ("Ccc");
95
96         Array ch2 = new Array ();
97         ch2.add (arr2);
98         
99         root1 = new AbstractNode (ch1);
100         root1.setName ("Root1");
101         root2 = new AbstractNode (ch2);
102         root2.setName ("Root2");
103         
104         ListView view = new ListView ();
105         view.setSelectionMode (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
106         
107         ExplorerPanel panel = new ExplorerPanel ();
108         ExplorerManager mgr = panel.getExplorerManager ();
109         
110         panel.add (view);
111         panel.open ();
112         
113         Node[] selNodes = mgr.getSelectedNodes ();
114         log ("Default root is " + mgr.getRootContext ());
115         //assertNull ( "Root context is null", mgr.getRootContext ());
116
assertEquals ("Count of the selected node is ", 0, selNodes.length);
117
118         mgr.setRootContext (root1);
119         log ("New root is " + mgr.getRootContext ());
120         mgr.setSelectedNodes (new Node[] {arr1[0], arr1[2]});
121
122         selNodes = mgr.getSelectedNodes ();
123         assertEquals ("Root context is ", "Root1", mgr.getRootContext ().getName ());
124         assertEquals ("Count of the selected node is ", 2, selNodes.length);
125         
126     }
127
128 }
129
Popular Tags