| 1 19 20 package org.netbeans.spi.navigator; 21 22 import java.io.File ; 23 import java.net.URL ; 24 import java.util.List ; 25 import javax.swing.JComponent ; 26 import javax.swing.JPanel ; 27 import junit.framework.*; 28 import org.netbeans.modules.navigator.NavigatorTC; 29 import org.netbeans.modules.navigator.UnitTestUtils; 30 import org.netbeans.spi.navigator.NavigatorHandler; 31 import org.netbeans.spi.navigator.NavigatorLookupHint; 32 import org.netbeans.spi.navigator.NavigatorPanel; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileUtil; 35 import org.openide.filesystems.URLMapper; 36 import org.openide.loaders.DataFolder; 37 import org.openide.loaders.DataObject; 38 import org.openide.loaders.DataShadow; 39 import org.openide.util.ContextGlobalProvider; 40 import org.openide.util.Lookup; 41 import org.openide.util.lookup.AbstractLookup; 42 import org.openide.util.lookup.InstanceContent; 43 import org.openide.util.lookup.Lookups; 44 45 46 50 public class NavigatorHandlerTest extends TestCase { 51 52 public NavigatorHandlerTest(String testName) { 53 super(testName); 54 } 55 56 public static void main(java.lang.String [] args) { 57 junit.textui.TestRunner.run(suite()); 58 } 59 60 protected void setUp() throws Exception { 61 } 62 63 protected void tearDown() throws Exception { 64 } 65 66 public static Test suite() { 67 TestSuite suite = new TestSuite(NavigatorHandlerTest.class); 68 return suite; 69 } 70 71 public void testActivatePanel () throws Exception { 72 System.out.println("Testing NavigatorHandlerTest.activatePanel"); 73 InstanceContent ic = new InstanceContent(); 74 GlobalLookup4TestImpl nodesLkp = new GlobalLookup4TestImpl(ic); 75 UnitTestUtils.prepareTest(new String [] { 76 "/org/netbeans/modules/navigator/resources/NavigatorHandlerTestProvider.xml" }, 77 Lookups.singleton(nodesLkp) 78 ); 79 80 TestLookupHint hint = new TestLookupHint("NavigatorHandlerTest/TestMimeType"); 81 ic.add(hint); 82 83 NavigatorTC navTC = NavigatorTC.getInstance(); 84 navTC.componentOpened(); 85 86 NavigatorPanel selPanel = navTC.getSelectedPanel(); 87 assertNotNull("Selected panel is null", selPanel); 88 89 List <NavigatorPanel> panels = navTC.getPanels(); 90 assertEquals(2, panels.size()); 91 92 int selIndex = panels.indexOf(selPanel); 93 assertTrue(selIndex >= 0); 94 95 System.out.println("selected panel before: " + navTC.getSelectedPanel().getDisplayName()); 96 97 if (selIndex == 0) { 98 NavigatorHandler.activatePanel(panels.get(1)); 99 } else { 100 NavigatorHandler.activatePanel(panels.get(0)); 101 } 102 103 assertTrue(selPanel != navTC.getSelectedPanel()); 104 105 System.out.println("selected panel after: " + navTC.getSelectedPanel().getDisplayName()); 106 107 } 108 109 111 public static final class PanelImpl1 implements NavigatorPanel { 112 113 public String getDisplayName () { 114 return "Panel Impl 1"; 115 } 116 117 public String getDisplayHint () { 118 return null; 119 } 120 121 public JComponent getComponent () { 122 return new JPanel (); 123 } 124 125 public void panelActivated (Lookup context) { 126 } 127 128 public void panelDeactivated () { 129 } 130 131 public Lookup getLookup () { 132 return null; 133 } 134 } 135 136 138 public static final class PanelImpl2 implements NavigatorPanel { 139 140 public String getDisplayName () { 141 return "Panel Impl 2"; 142 } 143 144 public String getDisplayHint () { 145 return null; 146 } 147 148 public JComponent getComponent () { 149 return new JPanel (); 150 } 151 152 public void panelActivated (Lookup context) { 153 } 154 155 public void panelDeactivated () { 156 } 157 158 public Lookup getLookup () { 159 return null; 160 } 161 } 162 163 164 167 private static final class TestLookupHint implements NavigatorLookupHint { 168 169 private final String contentType; 170 171 public TestLookupHint (String contentType) { 172 this.contentType = contentType; 173 } 174 175 public String getContentType () { 176 return contentType; 177 } 178 179 } 180 181 182 private static final class GlobalLookup4TestImpl extends AbstractLookup implements ContextGlobalProvider { 183 184 public GlobalLookup4TestImpl (AbstractLookup.Content content) { 185 super(content); 186 } 187 188 public Lookup createGlobalContext() { 189 return this; 190 } 191 } 192 193 194 } 195 | Popular Tags |