001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.navigator;
043:
044: import java.lang.ref.WeakReference;
045: import java.util.ArrayList;
046: import java.util.Arrays;
047: import java.util.Collection;
048: import java.util.Iterator;
049: import java.util.List;
050: import javax.swing.Action;
051: import javax.swing.ActionMap;
052: import javax.swing.JComboBox;
053: import javax.swing.JComponent;
054: import javax.swing.JLabel;
055: import javax.swing.text.DefaultEditorKit;
056: import org.netbeans.junit.NbTest;
057: import org.netbeans.junit.NbTestCase;
058: import org.netbeans.junit.NbTestSuite;
059: import org.netbeans.spi.navigator.NavigatorHandler;
060: import org.netbeans.spi.navigator.NavigatorLookupHint;
061: import org.netbeans.spi.navigator.NavigatorPanel;
062: import org.netbeans.spi.navigator.NavigatorPanelWithUndo;
063: import org.openide.awt.UndoRedo;
064: import org.openide.nodes.AbstractNode;
065: import org.openide.nodes.Children;
066: import org.openide.nodes.Node;
067: import org.openide.util.ContextGlobalProvider;
068: import org.openide.util.Lookup;
069: import org.openide.util.lookup.AbstractLookup;
070: import org.openide.util.lookup.InstanceContent;
071: import org.openide.util.lookup.Lookups;
072:
073: /**
074: *
075: * @author Dafe Simonek
076: */
077: public class NavigatorTCTest extends NbTestCase {
078:
079: /** Creates a new instance of ProviderRegistryTest */
080: public NavigatorTCTest() {
081: super ("");
082: }
083:
084: public NavigatorTCTest(String testName) {
085: super (testName);
086: }
087:
088: public static void main(java.lang.String[] args) {
089: junit.textui.TestRunner.run(suite());
090: }
091:
092: public static NbTest suite() {
093: NbTestSuite suite = new NbTestSuite(NavigatorTCTest.class);
094: return suite;
095: }
096:
097: public void testCorrectCallsOfNavigatorPanelMethods()
098: throws Exception {
099: System.out
100: .println("Testing correct calls of NavigatorPanel methods...");
101: InstanceContent ic = getInstanceContent();
102:
103: TestLookupHint ostravskiHint = new TestLookupHint(
104: "ostravski/gyzd");
105: //nodesLkp.setNodes(new Node[]{ostravskiNode});
106: ic.add(ostravskiHint);
107:
108: NavigatorTC navTC = NavigatorTC.getInstance();
109: navTC.componentOpened();
110:
111: NavigatorPanel selPanel = navTC.getSelectedPanel();
112:
113: assertNotNull("Selected panel is null", selPanel);
114: assertTrue("Panel class not expected",
115: selPanel instanceof OstravskiGyzdProvider);
116: OstravskiGyzdProvider ostravak = (OstravskiGyzdProvider) selPanel;
117: assertEquals("panelActivated calls count invalid: "
118: + ostravak.getPanelActivatedCallsCount(), 1, ostravak
119: .getPanelActivatedCallsCount());
120: assertEquals(0, ostravak.getPanelDeactivatedCallsCount());
121:
122: TestLookupHint prazskyHint = new TestLookupHint("prazsky/pepik");
123: ic.add(prazskyHint);
124: ic.remove(ostravskiHint);
125:
126: // wait for selected node change to be applied, because changes are
127: // reflected with little delay
128: waitForChange();
129:
130: selPanel = navTC.getSelectedPanel();
131: assertNotNull(selPanel);
132: assertTrue(selPanel instanceof PrazskyPepikProvider);
133: PrazskyPepikProvider prazak = (PrazskyPepikProvider) selPanel;
134:
135: assertEquals(1, ostravak.getPanelDeactivatedCallsCount());
136: assertTrue(ostravak.wasGetCompBetween());
137: assertFalse(ostravak.wasActCalledOnActive());
138: assertFalse(ostravak.wasDeactCalledOnInactive());
139:
140: assertEquals(1, prazak.getPanelActivatedCallsCount());
141: assertEquals(0, prazak.getPanelDeactivatedCallsCount());
142:
143: ic.remove(prazskyHint);
144: ic.add(ostravskiHint);
145: // wait for selected node change to be applied, because changes are
146: // reflected with little delay
147: waitForChange();
148:
149: selPanel = navTC.getSelectedPanel();
150: assertNotNull("Selected panel is null", selPanel);
151:
152: assertEquals(1, prazak.getPanelDeactivatedCallsCount());
153: assertTrue(prazak.wasGetCompBetween());
154: assertFalse(prazak.wasActCalledOnActive());
155: assertFalse(prazak.wasDeactCalledOnInactive());
156:
157: navTC.componentClosed();
158:
159: selPanel = navTC.getSelectedPanel();
160: assertNull("Selected panel should be null", selPanel);
161: assertNull("Set of panels should be null", navTC.getPanels());
162:
163: // clean
164: ic.remove(ostravskiHint);
165: }
166:
167: public void testBugfix104145_DeactivatedNotCalled()
168: throws Exception {
169: System.out.println("Testing bugfix 104145...");
170: InstanceContent ic = getInstanceContent();
171:
172: TestLookupHint ostravskiHint = new TestLookupHint(
173: "ostravski/gyzd");
174: ic.add(ostravskiHint);
175:
176: try {
177: NavigatorTC navTC = NavigatorTC.getInstance();
178: navTC.componentOpened();
179:
180: NavigatorPanel selPanel = navTC.getSelectedPanel();
181: OstravskiGyzdProvider ostravak = (OstravskiGyzdProvider) selPanel;
182: ostravak.resetDeactCalls();
183:
184: navTC.componentClosed();
185:
186: int deact = ostravak.getPanelDeactivatedCallsCount();
187: assertEquals(
188: "panelDeactivated expected to be called once but called "
189: + deact + " times.", 1, deact);
190:
191: } finally {
192: // clean in finally block so that test doesn't affect others
193: ic.remove(ostravskiHint);
194: }
195:
196: }
197:
198: public void testBugfix80155_NotEmptyOnProperties() throws Exception {
199: System.out
200: .println("Testing bugfix 80155, keeping content on Properties window and similar...");
201: InstanceContent ic = getInstanceContent();
202:
203: TestLookupHint ostravskiHint = new TestLookupHint(
204: "ostravski/gyzd");
205: ic.add(ostravskiHint);
206:
207: NavigatorTC navTC = NavigatorTC.getInstance();
208: navTC.componentOpened();
209:
210: NavigatorPanel selPanel = navTC.getSelectedPanel();
211:
212: assertNotNull("Selected panel is null", selPanel);
213:
214: ic.remove(ostravskiHint);
215:
216: // wait for selected node change to be applied, because changes are
217: // reflected with little delay
218: waitForChange();
219:
220: // after 80155 fix, previous navigator should keep its content even when
221: // new component was activated, but didn't contain any activated nodes or navigator lookup hint
222: selPanel = navTC.getSelectedPanel();
223: assertNotNull("Selected panel is null", selPanel);
224: assertTrue("Panel class not expected",
225: selPanel instanceof OstravskiGyzdProvider);
226:
227: // cleanup
228: navTC.componentClosed();
229: }
230:
231: public void testBugfix93123_RefreshCombo() throws Exception {
232: System.out
233: .println("Testing bugfix 93123, correct refreshing of combo box with providers list...");
234:
235: InstanceContent ic = getInstanceContent();
236:
237: TestLookupHint ostravskiHint = new TestLookupHint(
238: "ostravski/gyzd");
239: ic.add(ostravskiHint);
240: TestLookupHint prazskyHint = new TestLookupHint("prazsky/pepik");
241: ic.add(prazskyHint);
242:
243: NavigatorTC navTC = NavigatorTC.getInstance();
244: navTC.componentOpened();
245:
246: List<NavigatorPanel> panels = navTC.getPanels();
247:
248: assertNotNull("Selected panel should not be null", navTC
249: .getSelectedPanel());
250: assertTrue("Expected 2 provider panels, but got "
251: + panels.size(), panels.size() == 2);
252:
253: NavigatorHandler.activatePanel(panels.get(1));
254:
255: NavigatorPanel selPanel = navTC.getSelectedPanel();
256: int selIdx = panels.indexOf(selPanel);
257:
258: assertTrue("Expected selected provider #2, but got #1",
259: selIdx == 1);
260:
261: TestLookupHint prazskyHint2 = new TestLookupHint(
262: "moravsky/honza");
263: ic.add(prazskyHint2);
264:
265: // wait for selected node change to be applied, because changes are
266: // reflected with little delay
267: waitForChange();
268:
269: panels = navTC.getPanels();
270: assertTrue("Expected 3 provider panels, but got "
271: + panels.size(), panels.size() == 3);
272:
273: JComboBox combo = navTC.getPanelSelector();
274: assertTrue("Expected 3 combo items, but got "
275: + combo.getItemCount(), combo.getItemCount() == 3);
276:
277: assertTrue("Expected the same selection", selPanel.equals(navTC
278: .getSelectedPanel()));
279:
280: selIdx = panels.indexOf(selPanel);
281: assertTrue(
282: "Expected the same selection in combo, sel panel index: "
283: + selIdx + ", sel in combo index: "
284: + combo.getSelectedIndex(), selIdx == combo
285: .getSelectedIndex());
286:
287: // cleanup
288: ic.remove(ostravskiHint);
289: ic.remove(prazskyHint);
290: ic.remove(prazskyHint2);
291: navTC.componentClosed();
292: }
293:
294: /** Test for IZ feature #93711. It tests ability of NavigatorPanel implementors
295: * to provide activated nodes for whole navigator panel TopComponent.
296: *
297: * See inner class ActNodeLookupProvider, especially getLookup method to get
298: * inspiration how to write providers that provide also activated nodes.
299: */
300: public void testFeature93711_ActivatedNodes() throws Exception {
301: System.out
302: .println("Testing feature #93711, providing activated nodes...");
303:
304: InstanceContent ic = getInstanceContent();
305:
306: TestLookupHint actNodesHint = new TestLookupHint(
307: "actNodes/tester");
308: ic.add(actNodesHint);
309:
310: NavigatorTC navTC = NavigatorTC.getInstance();
311: navTC.componentOpened();
312:
313: List<NavigatorPanel> panels = navTC.getPanels();
314: assertNotNull("Selected panel should not be null", navTC
315: .getSelectedPanel());
316: assertTrue("Expected 1 provider panel, but got "
317: + panels.size(), panels != null && panels.size() == 1);
318: assertTrue("Panel class not expected",
319: panels.get(0) instanceof ActNodeLookupProvider);
320: ActNodeLookupProvider provider = (ActNodeLookupProvider) panels
321: .get(0);
322:
323: // wait for selected node change to be applied, because changes are
324: // reflected with little delay
325: waitForChange();
326:
327: // test if lookup content from provider propagated correctly to the
328: // activated nodes of navigator TopComponent
329: Node[] actNodes = navTC.getActivatedNodes();
330: Node realContent = provider.getCurLookupContent();
331: String tcDisplayName = navTC.getDisplayName();
332: String providerDisplayName = provider.getDisplayName();
333:
334: assertNotNull("Activated nodes musn't be null", actNodes);
335: assertTrue("Expected 1 activated node, but got "
336: + actNodes.length, actNodes.length == 1);
337: assertTrue("Incorrect instance of activated node "
338: + actNodes[0].getName(), actNodes[0] == realContent);
339: assertTrue("Expected display name starting with '"
340: + providerDisplayName + "', but got '" + tcDisplayName
341: + "'", (tcDisplayName != null)
342: && tcDisplayName.startsWith(providerDisplayName));
343:
344: // change provider's lookup content and check again, to test infrastructure
345: // ability to listen to client's lookup content change
346: provider.changeLookup();
347: actNodes = navTC.getActivatedNodes();
348: realContent = provider.getCurLookupContent();
349: tcDisplayName = navTC.getDisplayName();
350: providerDisplayName = provider.getDisplayName();
351:
352: assertNotNull("Activated nodes musn't be null", actNodes);
353: assertTrue("Expected 1 activated node, but got "
354: + actNodes.length, actNodes.length == 1);
355: assertTrue("Incorrect instance of activated node "
356: + actNodes[0].getName(), actNodes[0] == realContent);
357: assertTrue("Expected display name starting with '"
358: + providerDisplayName + "', but got '" + tcDisplayName
359: + "'", (tcDisplayName != null)
360: && tcDisplayName.startsWith(providerDisplayName));
361:
362: // cleanup
363: ic.remove(actNodesHint);
364: navTC.componentClosed();
365: }
366:
367: /** Test for IZ feature #98125. It tests ability of NavigatorPanelWithUndo
368: * implementors to provide UndoRedo support for their view through
369: * navigator TopComponent.
370: */
371: public void testFeature98125_UndoRedo() throws Exception {
372: System.out
373: .println("Testing feature #98125, providing UndoRedo...");
374:
375: InstanceContent ic = getInstanceContent();
376:
377: TestLookupHint undoHint = new TestLookupHint("undoRedo/tester");
378: ic.add(undoHint);
379:
380: NavigatorTC navTC = NavigatorTC.getInstance();
381: navTC.componentOpened();
382:
383: NavigatorPanel selPanel = navTC.getSelectedPanel();
384: assertNotNull("Selected panel should not be null", navTC
385: .getSelectedPanel());
386: assertTrue("Panel class not expected",
387: selPanel instanceof UndoRedoProvider);
388: UndoRedoProvider provider = (UndoRedoProvider) selPanel;
389:
390: UndoRedo panelUndo = provider.getUndoRedo();
391: UndoRedo tcUndo = navTC.getUndoRedo();
392:
393: assertTrue("Expected undo manager " + panelUndo + ", but got "
394: + tcUndo, panelUndo == tcUndo);
395:
396: // cleanup
397: ic.remove(undoHint);
398: navTC.componentClosed();
399:
400: }
401:
402: /** Test for IZ issue #113764. Checks that after closing navigator window, clientsLookup
403: * in NavigatorController is updated properly and does not hold Node instance through
404: * SimpleProxyLookup.delegate member variable.
405: */
406: public void testBugfix113764_clientsLookupLeak() throws Exception {
407: System.out
408: .println("Testing bugfix #113764, clientsLookup leak...");
409:
410: InstanceContent ic = getInstanceContent();
411:
412: TestLookupHint actNodesHint = new TestLookupHint(
413: "undoRedo/tester");
414: ic.add(actNodesHint);
415:
416: // add node to play activated node role
417: Node actNode = new AbstractNode(Children.LEAF);
418: actNode.setDisplayName("clientsLookupLeak test node");
419: ic.add(actNode);
420:
421: NavigatorTC navTC = NavigatorTC.getInstance();
422: navTC.componentOpened();
423:
424: // wait for selected node change to be applied, because changes are
425: // reflected with little delay
426: waitForChange();
427:
428: // get the lookup that leaked, take weak ref on it
429: NavigatorController.ClientsLookup cliLkp = navTC
430: .getController().getClientsLookup();
431: Lookup[] lkpArray = cliLkp.obtainLookups();
432: assertTrue("Lookups array mustn't be empty",
433: lkpArray.length > 0);
434:
435: ArrayList<WeakReference<Lookup>> wLkps = new ArrayList<WeakReference<Lookup>>(
436: lkpArray.length);
437: for (int i = 0; i < lkpArray.length; i++) {
438: WeakReference<Lookup> wLkp = new WeakReference<Lookup>(
439: lkpArray[i]);
440: wLkps.add(wLkp);
441: }
442:
443: // erase, close and check, lookup should be freed
444: lkpArray = null;
445: navTC.componentClosed();
446:
447: for (WeakReference<Lookup> wLkp : wLkps) {
448: assertGC(
449: "Lookup instance NavigatorController.getLookup() still not GCed",
450: wLkp);
451: }
452:
453: // cleanup
454: ic.remove(actNodesHint);
455: ic.remove(actNode);
456: }
457:
458: /**
459: */
460: public void test_118082_ExplorerView() throws Exception {
461: System.out
462: .println("Testing #118082, Explorer view integration...");
463:
464: InstanceContent ic = getInstanceContent();
465:
466: TestLookupHint explorerHint = new TestLookupHint(
467: "explorerview/tester");
468: ic.add(explorerHint);
469:
470: NavigatorTC navTC = NavigatorTC.getInstance();
471: navTC.componentOpened();
472:
473: List<NavigatorPanel> panels = navTC.getPanels();
474: assertNotNull("Selected panel should not be null", navTC
475: .getSelectedPanel());
476: assertTrue("Expected 1 provider panel, but got "
477: + panels.size(), panels != null && panels.size() == 1);
478: assertTrue("Panel class not expected",
479: panels.get(0) instanceof ListViewNavigatorPanel);
480: ListViewNavigatorPanel provider = (ListViewNavigatorPanel) panels
481: .get(0);
482:
483: // wait for selected node change to be applied, because changes are
484: // reflected with little delay
485: waitForChange();
486:
487: Node[] actNodes = navTC.getActivatedNodes();
488: Action copyAction = provider.getCopyAction();
489: assertTrue("Copy action should be enabled", copyAction
490: .isEnabled());
491: assertNotNull("Activated nodes musn't be null", actNodes);
492: Node[] selNodes = provider.getExplorerManager()
493: .getSelectedNodes();
494: assertNotNull("Explorer view selected nodes musn't be null",
495: selNodes);
496: assertTrue("Expected 1 activated node, but got "
497: + actNodes.length, actNodes.length == 1);
498: assertTrue(
499: "Nodes from explorer view not propagated correctly, should be the same as activated nodes, but got: \n"
500: + "activated nodes: "
501: + Arrays.toString(actNodes)
502: + "\n"
503: + "explorer view selected nodes: "
504: + Arrays.toString(selNodes), Arrays.equals(
505: actNodes, selNodes));
506:
507: // test if action map can be found in NavigatorTC lookup
508: Collection<? extends ActionMap> result = navTC.getLookup()
509: .lookupResult(ActionMap.class).allInstances();
510: boolean found = false;
511: for (Iterator<? extends ActionMap> it = result.iterator(); it
512: .hasNext();) {
513: ActionMap map = it.next();
514: Action a = map.get(DefaultEditorKit.copyAction);
515: if (a != null) {
516: found = true;
517: assertSame("Different action instance the expected", a,
518: copyAction);
519: }
520: }
521: assertTrue("Action " + DefaultEditorKit.copyAction
522: + " not found in action map", found);
523:
524: // cleanup
525: ic.remove(explorerHint);
526: navTC.componentClosed();
527: }
528:
529: /** Singleton global lookup. Lookup change notification won't come
530: * if setting global lookup (UnitTestUtils.prepareTest) is called
531: * multiple times.
532: */
533: private static InstanceContent getInstanceContent()
534: throws Exception {
535: if (instanceContent == null) {
536: instanceContent = new InstanceContent();
537: GlobalLookup4TestImpl nodesLkp = new GlobalLookup4TestImpl(
538: instanceContent);
539: UnitTestUtils
540: .prepareTest(
541: new String[] { "/org/netbeans/modules/navigator/resources/testCorrectCallsOfNavigatorPanelMethodsLayer.xml" },
542: Lookups.singleton(nodesLkp));
543: }
544: return instanceContent;
545: }
546:
547: private void waitForChange() {
548: synchronized (this ) {
549: try {
550: wait(NavigatorController.COALESCE_TIME + 500);
551: } catch (InterruptedException exc) {
552: System.out.println("waiting interrupted...");
553: }
554: }
555: }
556:
557: /** Test provider base, to test that infrastucture calls correct
558: * methods in correct order.
559: */
560: private static abstract class CorrectCallsProvider implements
561: NavigatorPanel {
562:
563: private int panelActCalls = 0;
564: private int panelDeactCalls = 0;
565:
566: private boolean wasGetCompBetween = true;
567:
568: private boolean wasActCalledOnActive = false;
569: private boolean wasDeactCalledOnInactive = false;
570:
571: private boolean activated = false;
572:
573: public JComponent getComponent() {
574: if (!activated) {
575: wasGetCompBetween = false;
576: }
577: return null;
578: }
579:
580: public void panelActivated(Lookup context) {
581: if (activated) {
582: wasActCalledOnActive = true;
583: }
584: panelActCalls++;
585: activated = true;
586: }
587:
588: public void panelDeactivated() {
589: if (!activated) {
590: wasDeactCalledOnInactive = true;
591: }
592: panelDeactCalls++;
593: activated = false;
594: }
595:
596: public Lookup getLookup() {
597: return null;
598: }
599:
600: public int getPanelActivatedCallsCount() {
601: return panelActCalls;
602: }
603:
604: public int getPanelDeactivatedCallsCount() {
605: return panelDeactCalls;
606: }
607:
608: public boolean wasGetCompBetween() {
609: return wasGetCompBetween;
610: }
611:
612: public boolean wasActCalledOnActive() {
613: return wasActCalledOnActive;
614: }
615:
616: public boolean wasDeactCalledOnInactive() {
617: return wasDeactCalledOnInactive;
618: }
619:
620: public void resetDeactCalls() {
621: panelDeactCalls = 0;
622: }
623:
624: }
625:
626: public static final class OstravskiGyzdProvider extends
627: CorrectCallsProvider {
628:
629: public String getDisplayName() {
630: return "Ostravski Gyzd";
631: }
632:
633: public String getDisplayHint() {
634: return null;
635: }
636:
637: public JComponent getComponent() {
638: // ensure call is counted by superclass
639: super .getComponent();
640: return new JLabel(getDisplayName());
641: }
642:
643: }
644:
645: public static final class PrazskyPepikProvider extends
646: CorrectCallsProvider {
647:
648: public String getDisplayName() {
649: return "Prazsky Pepik";
650: }
651:
652: public String getDisplayHint() {
653: return null;
654: }
655:
656: public JComponent getComponent() {
657: // ensure call is counted by superclass
658: super .getComponent();
659: return new JLabel(getDisplayName());
660: }
661:
662: }
663:
664: public static final class MoravskyHonzaProvider extends
665: CorrectCallsProvider {
666:
667: public String getDisplayName() {
668: return "Moravsky Honza";
669: }
670:
671: public String getDisplayHint() {
672: return null;
673: }
674:
675: public JComponent getComponent() {
676: // ensure call is counted by superclass
677: super .getComponent();
678: return new JLabel(getDisplayName());
679: }
680:
681: }
682:
683: /** NavigatorPanel implementation that affects activated nodes of whole
684: * navigator area TopComponent. See javadoc of NavigatorPanel.getLookup()
685: * for details.
686: *
687: * This test class defines method changeLookup to test infrastructure
688: * ability to listen to lookup changes.
689: */
690: public static final class ActNodeLookupProvider implements
691: NavigatorPanel {
692:
693: private Lookup lookup;
694: private Node node1, node2;
695: private boolean flag = false;
696: private InstanceContent ic;
697:
698: private static final String FIRST_NAME = "first";
699: private static final String SECOND_NAME = "second";
700:
701: public ActNodeLookupProvider() {
702: this .node1 = new AbstractNode(Children.LEAF);
703: this .node1.setDisplayName(FIRST_NAME);
704: this .node2 = new AbstractNode(Children.LEAF);
705: this .node2.setDisplayName(SECOND_NAME);
706:
707: ic = new InstanceContent();
708: ic.add(node1);
709: lookup = new AbstractLookup(ic);
710: }
711:
712: public Lookup getLookup() {
713: return lookup;
714: }
715:
716: public Node getCurLookupContent() {
717: return flag ? node2 : node1;
718: }
719:
720: public void changeLookup() {
721: flag = !flag;
722: if (flag) {
723: ic.remove(node1);
724: ic.add(node2);
725: } else {
726: ic.remove(node2);
727: ic.add(node1);
728: }
729: }
730:
731: public String getDisplayName() {
732: return flag ? SECOND_NAME : FIRST_NAME;
733: }
734:
735: public String getDisplayHint() {
736: return null;
737: }
738:
739: public JComponent getComponent() {
740: return new JLabel(getDisplayName());
741: }
742:
743: public void panelActivated(Lookup context) {
744: // no operation
745: }
746:
747: public void panelDeactivated() {
748: // no operation
749: }
750: }
751:
752: /**
753: * Test implementation of NavigatorPanelWithUndo which enables undo/redo support.
754: */
755: public static final class UndoRedoProvider implements
756: NavigatorPanelWithUndo {
757:
758: private UndoRedo undo;
759:
760: public UndoRedo getUndoRedo() {
761: if (undo == null) {
762: undo = new UndoRedo.Manager();
763: }
764: return undo;
765: }
766:
767: public String getDisplayName() {
768: return "UndoRedo provider";
769: }
770:
771: public String getDisplayHint() {
772: return null;
773: }
774:
775: public JComponent getComponent() {
776: return new JLabel("test");
777: }
778:
779: public void panelActivated(Lookup context) {
780: // no operation
781: }
782:
783: public void panelDeactivated() {
784: // no operation
785: }
786:
787: public Lookup getLookup() {
788: return null;
789: }
790:
791: }
792:
793: /** Envelope for textual (mime-type like) content type to be used in
794: * global lookup
795: */
796: public static class TestLookupHint implements NavigatorLookupHint {
797:
798: private final String contentType;
799:
800: public TestLookupHint(String contentType) {
801: this .contentType = contentType;
802: }
803:
804: public String getContentType() {
805: return contentType;
806: }
807:
808: }
809:
810: public static final class GlobalLookup4TestImpl extends
811: AbstractLookup implements ContextGlobalProvider {
812:
813: public GlobalLookup4TestImpl(AbstractLookup.Content content) {
814: super (content);
815: }
816:
817: public Lookup createGlobalContext() {
818: return this ;
819: }
820:
821: /*public GlobalLookup4Test() {
822: super(new Lookup[0]);
823: }
824:
825: public void setNodes(Node[] nodes) {
826: setLookups(new Lookup[] {Lookups.fixed(nodes)});
827: }*/
828: }
829:
830: private static InstanceContent instanceContent;
831:
832: }
|