1 19 20 package org.netbeans.core; 21 22 import java.io.*; 23 import java.util.*; 24 import org.openide.filesystems.*; 25 import org.openide.actions.*; 26 import org.openide.loaders.DataLoader; 27 import org.openide.nodes.Index; 28 import org.openide.nodes.Node; 29 import org.openide.util.actions.SystemAction; 30 31 32 36 public class LoaderPoolNodeReorderTest extends org.netbeans.junit.NbTestCase { 37 private OldStyleLoader oldL; 38 private NewStyleLoader newL; 39 40 public LoaderPoolNodeReorderTest (String testName) { 41 super (testName); 42 } 43 44 protected void setUp () throws java.lang.Exception { 45 LoaderPoolNode.installationFinished(); 46 47 oldL = (OldStyleLoader)OldStyleLoader.getLoader (OldStyleLoader.class); 48 newL = (NewStyleLoader)NewStyleLoader.getLoader (NewStyleLoader.class); 49 LoaderPoolNode.doAdd (oldL, null); 50 LoaderPoolNode.doAdd (newL, null); 51 LoaderPoolNode.waitFinished(); 52 } 53 54 protected void tearDown () throws java.lang.Exception { 55 for (Enumeration en = LoaderPoolNode.getNbLoaderPool().loaders(); en.hasMoreElements(); ) { 56 DataLoader l = (DataLoader)en.nextElement(); 57 58 LoaderPoolNode.remove(l); 59 } 60 LoaderPoolNode.waitFinished(); 61 } 62 63 public void testReorderABit () throws Exception { 64 { 65 Node[] arr = extractFixed(LoaderPoolNode.getLoaderPoolNode().getChildren().getNodes()); 66 assertEquals(2, arr.length); 67 assertEquals(arr[0].getDisplayName(), oldL.getDisplayName()); 68 assertEquals(arr[1].getDisplayName(), newL.getDisplayName()); 69 } 70 71 Index idx = LoaderPoolNode.getLoaderPoolNode().getLookup().lookup(Index.class); 72 assertNotNull("There is index in the node", idx); 73 74 idx.reorder(new int[] { 1, 0 }); 75 LoaderPoolNode.waitFinished(); 76 77 78 { 79 Node[] arr = extractFixed(LoaderPoolNode.getLoaderPoolNode().getChildren().getNodes()); 80 assertEquals(2, arr.length); 81 assertEquals("reord1", arr[1].getDisplayName(), oldL.getDisplayName()); 82 assertEquals("reord0", arr[0].getDisplayName(), newL.getDisplayName()); 83 } 84 85 idx.reorder(new int[] { 1, 0 }); 86 LoaderPoolNode.waitFinished(); 87 88 { 89 Node[] arr = extractFixed(LoaderPoolNode.getLoaderPoolNode().getChildren().getNodes()); 90 assertEquals(2, arr.length); 91 assertEquals("noreord0", arr[0].getDisplayName(), oldL.getDisplayName()); 92 assertEquals("noreord1", arr[1].getDisplayName(), newL.getDisplayName()); 93 } 94 } 95 96 97 private static Node[] extractFixed(Node[] arr) { 98 ArrayList all = new ArrayList(); 99 for (int i = 0; i < arr.length; i++) { 100 if (!arr[i].getDisplayName().contains("fixed")) { 101 all.add(arr[i]); 102 } 103 } 104 return (Node[])all.toArray(new Node[0]); 105 } 106 107 public static class OldStyleLoader extends org.openide.loaders.UniFileLoader { 108 boolean defaultActionsCalled; 109 110 public OldStyleLoader () { 111 super (org.openide.loaders.MultiDataObject.class); 112 113 setDisplayName(getClass().getName()); 114 } 115 116 protected org.openide.loaders.MultiDataObject createMultiObject (FileObject fo) throws IOException { 117 throw new IOException ("Not implemented"); 118 } 119 120 protected SystemAction[] defaultActions () { 121 defaultActionsCalled = true; 122 SystemAction[] retValue; 123 124 retValue = super.defaultActions(); 125 return retValue; 126 } 127 128 129 } 130 131 public static final class NewStyleLoader extends OldStyleLoader { 132 protected String actionsContext () { 133 return "Loaders/IamTheNewBeggining"; 134 } 135 } 136 public static final class L1 extends OldStyleLoader { 137 } 138 public static final class L2 extends OldStyleLoader { 139 } 140 public static final class L3 extends OldStyleLoader { 141 } 142 public static final class L4 extends OldStyleLoader { 143 } 144 public static final class L5 extends OldStyleLoader { 145 } 146 } 147 | Popular Tags |