1 19 20 package org.openide.explorer.view; 21 22 import java.awt.BorderLayout ; 23 import java.lang.reflect.InvocationTargetException ; 24 import javax.swing.JFrame ; 25 import javax.swing.JPanel ; 26 import javax.swing.JTree ; 27 import javax.swing.SwingUtilities ; 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 37 public class ContextTreeViewTest extends NbTestCase { 38 39 private static final int NO_OF_NODES = 3; 40 41 42 public ContextTreeViewTest(String name) { 43 super(name); 44 } 45 46 public void testLeafNodeReallyNotDisplayed() throws Throwable { 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 p = new Panel (); 58 p.getExplorerManager().setRootContext(root); 59 60 ContextTreeView ctv = new ContextTreeView(); 61 p.add(BorderLayout.CENTER, ctv); 62 63 JFrame f = new JFrame (); 64 f.setDefaultCloseOperation(f.EXIT_ON_CLOSE); 65 f.getContentPane().add(BorderLayout.CENTER, p); 66 f.setVisible(true); 67 68 final JTree tree = ctv.tree; 69 70 class AWTTst implements Runnable { 71 public void run() { 72 Object 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 ex) { 90 throw ex.getTargetException(); 91 } 92 } 93 94 private static Node createLeaf(String name) { 95 AbstractNode n = new AbstractNode(Children.LEAF); 96 n.setName(name); 97 return n; 98 } 99 100 private static class Panel extends JPanel 101 implements ExplorerManager.Provider { 102 private ExplorerManager em = new ExplorerManager(); 103 104 public ExplorerManager getExplorerManager() { 105 return em; 106 } 107 } 108 } 109 | Popular Tags |