KickJava   Java API By Example, From Geeks To Geeks.

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


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.openide.explorer.view;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.lang.reflect.InvocationTargetException JavaDoc;
24 import javax.swing.JFrame JavaDoc;
25 import javax.swing.JPanel JavaDoc;
26 import javax.swing.JTree JavaDoc;
27 import javax.swing.SwingUtilities JavaDoc;
28 import org.netbeans.junit.NbTestCase;
29 import org.openide.explorer.ExplorerManager;
30 import org.openide.nodes.AbstractNode;
31 import org.openide.nodes.Children;
32 import org.openide.nodes.Node;
33
34 /**
35  * Tests for class ContextTreeViewTest
36  */

37 public class ContextTreeViewTest extends NbTestCase {
38
39     private static final int NO_OF_NODES = 3;
40     
41     
42     public ContextTreeViewTest(String JavaDoc name) {
43         super(name);
44     }
45     
46     public void testLeafNodeReallyNotDisplayed() throws Throwable JavaDoc {
47         final AbstractNode root = new AbstractNode(new Children.Array());
48         root.setName("test root");
49         
50         
51         
52         root.getChildren().add(new Node[] {
53             createLeaf("kuk"),
54             createLeaf("huk"),
55         });
56         
57         Panel JavaDoc p = new Panel JavaDoc();
58         p.getExplorerManager().setRootContext(root);
59         
60         ContextTreeView ctv = new ContextTreeView();
61         p.add(BorderLayout.CENTER, ctv);
62         
63         JFrame JavaDoc f = new JFrame JavaDoc();
64         f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
65         f.getContentPane().add(BorderLayout.CENTER, p);
66         f.setVisible(true);
67         
68         final JTree JavaDoc tree = ctv.tree;
69         
70         class AWTTst implements Runnable JavaDoc {
71             public void run() {
72                 // wait a while till the frame is realized and ctv.addNotify called
73
Object JavaDoc r = tree.getModel().getRoot();
74                 assertEquals("There is root", Visualizer.findVisualizer(root), r);
75                 
76                 int cnt = tree.getModel().getChildCount(r);
77                 if (cnt != 0) {
78                     fail("Should be zero " + cnt + " but there was: " +
79                             tree.getModel().getChild(r, 0) + " and " +
80                             tree.getModel().getChild(r, 1)
81                             );
82                 }
83                 assertEquals("No children as they are leaves", 0, cnt);
84             }
85         }
86         AWTTst awt = new AWTTst();
87         try {
88             SwingUtilities.invokeAndWait(awt);
89         } catch (InvocationTargetException JavaDoc ex) {
90             throw ex.getTargetException();
91         }
92     }
93     
94     private static Node createLeaf(String JavaDoc name) {
95         AbstractNode n = new AbstractNode(Children.LEAF);
96         n.setName(name);
97         return n;
98     }
99     
100     private static class Panel extends JPanel JavaDoc
101             implements ExplorerManager.Provider {
102         private ExplorerManager em = new ExplorerManager();
103         
104         public ExplorerManager getExplorerManager() {
105             return em;
106         }
107     }
108 }
109
Popular Tags