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 RootContextTest extends NbTestCase { 48 49 public RootContextTest (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 (RootContextTest.class); 59 return suite; 60 } 61 62 Node[] arr1, arr2; 64 Node root1, root2; 65 boolean initialized = false; 66 67 68 public void initTest () { 70 71 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 112 protected boolean runInEQ() { 113 return true; 114 } 115 116 public void doViewTest (final ExplorerManager mgr) throws Exception { 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 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 141 public void testBeanTreeView() throws Exception { 142 143 initTest (); 144 145 TreeView view = new BeanTreeView (); 146 view.setSelectionMode (TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); 147 148 ExplorerPanel panel = new ExplorerPanel (); 149 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 { 161 162 initTest (); 163 164 TreeView view = new ContextTreeView (); 165 view.setSelectionMode (TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); 166 167 ExplorerPanel panel = new ExplorerPanel (); 168 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 { 180 181 initTest (); 182 183 TreeTableView view = new TreeTableView (); 184 view.setSelectionMode (TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); 185 186 ExplorerPanel panel = new ExplorerPanel (); 187 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 { 199 200 initTest (); 201 202 ListView view = new ListView (); 203 view.setSelectionMode (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 204 205 ExplorerPanel panel = new ExplorerPanel (); 206 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 { 218 219 initTest (); 220 221 ListTableView view = new ListTableView (); 222 view.setSelectionMode (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 223 224 ExplorerPanel panel = new ExplorerPanel (); 225 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 |