1 19 20 21 package org.openide.explorer.view; 22 23 import java.beans.PropertyVetoException ; 24 import javax.swing.ListSelectionModel ; 25 import javax.swing.tree.TreeSelectionModel ; 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 47 public class SelectNodeInListViewTest extends NbTestCase { 48 49 public SelectNodeInListViewTest (java.lang.String testName) { 50 super (testName); 51 } 52 53 public static void main (java.lang.String [] 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 63 protected boolean runInEQ () { 64 return true; 65 } 66 67 public void testSelectedNodeInListView () throws Exception { 68 69 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 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 |