KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > navigator > NavigatorHandlerTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.navigator;
21
22 import java.io.File JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import javax.swing.JPanel JavaDoc;
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 /**
47  *
48  * @author Dafe Simonek
49  */

50 public class NavigatorHandlerTest extends TestCase {
51     
52     public NavigatorHandlerTest(String JavaDoc testName) {
53         super(testName);
54     }
55     
56     public static void main(java.lang.String JavaDoc[] args) {
57         junit.textui.TestRunner.run(suite());
58     }
59
60     protected void setUp() throws Exception JavaDoc {
61     }
62
63     protected void tearDown() throws Exception JavaDoc {
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 JavaDoc {
72         System.out.println("Testing NavigatorHandlerTest.activatePanel");
73         InstanceContent ic = new InstanceContent();
74         GlobalLookup4TestImpl nodesLkp = new GlobalLookup4TestImpl(ic);
75         UnitTestUtils.prepareTest(new String JavaDoc [] {
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 JavaDoc<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     /** Panel implementation 1
110      */

111     public static final class PanelImpl1 implements NavigatorPanel {
112         
113         public String JavaDoc getDisplayName () {
114             return "Panel Impl 1";
115         }
116     
117         public String JavaDoc getDisplayHint () {
118             return null;
119         }
120
121         public JComponent JavaDoc getComponent () {
122             return new JPanel JavaDoc();
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     /** Panel implementation 2
137      */

138     public static final class PanelImpl2 implements NavigatorPanel {
139         
140         public String JavaDoc getDisplayName () {
141             return "Panel Impl 2";
142         }
143     
144         public String JavaDoc getDisplayHint () {
145             return null;
146         }
147
148         public JComponent JavaDoc getComponent () {
149             return new JPanel JavaDoc();
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     /** Envelope for textual (mime-type like) content type to be used in
165      * global lookup
166      */

167     private static final class TestLookupHint implements NavigatorLookupHint {
168         
169         private final String JavaDoc contentType;
170                 
171         public TestLookupHint (String JavaDoc contentType) {
172             this.contentType = contentType;
173         }
174         
175         public String JavaDoc 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