KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > ExplorerUtilCreateLookupTest


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.openide.explorer;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.DefaultKeyboardFocusManager JavaDoc;
25 import java.awt.KeyboardFocusManager JavaDoc;
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.beans.FeatureDescriptor JavaDoc;
28 import java.util.*;
29 import javax.swing.AbstractAction JavaDoc;
30 import javax.swing.ActionMap JavaDoc;
31 import javax.swing.JTextField JavaDoc;
32
33 import junit.framework.*;
34
35 import org.netbeans.junit.*;
36 import org.openide.cookies.*;
37 import org.openide.nodes.*;
38 import org.openide.util.*;
39 import org.openide.util.lookup.AbstractLookup;
40 import org.openide.util.lookup.InstanceContent;
41
42 /**
43  * Check the behaviour of ExplorerManager's lookup by doing the same
44  * operations as in case of TopComponent's lookup. Done by providing a fake
45  * component that converts setActivatedNodes to ExplorerManager calls.
46  *
47  * @author Jaroslav Tulach
48  */

49 public class ExplorerUtilCreateLookupTest extends org.openide.windows.TopComponentGetLookupTest {
50     public ExplorerUtilCreateLookupTest(String JavaDoc testName) {
51         super(testName);
52     }
53     
54     public static void main(String JavaDoc[] args) {
55         junit.textui.TestRunner.run(suite());
56     }
57     
58     public static Test suite() {
59         return new NbTestSuite(ExplorerUtilCreateLookupTest.class);
60     }
61     
62     
63     protected boolean runInEQ () {
64         return true;
65     }
66     
67     /** Setup component with lookup.
68      */

69     protected void setUp () {
70         class ExTC extends org.openide.windows.TopComponent
71         implements java.beans.PropertyChangeListener JavaDoc {
72             ExplorerManager em = new ExplorerManager ();
73             {
74                 addPropertyChangeListener (this);
75                 em.setRootContext (new AbstractNode (new Children.Array ()));
76             }
77             
78             public void propertyChange (java.beans.PropertyChangeEvent JavaDoc ev) {
79                 if ("activatedNodes".equals (ev.getPropertyName())) {
80                     try {
81                         Node[] arr = getActivatedNodes ();
82                         Children.Array ch = (Children.Array)em.getRootContext ().getChildren ();
83                         for (int i = 0; i < arr.length; i++) {
84                             if (arr[i].getParentNode() != em.getRootContext()) {
85                                 assertTrue ("If this fails we are in troubles", ch.add (new Node[] { arr[i] }));
86                             }
87                         }
88                         em.setSelectedNodes (getActivatedNodes ());
89                     } catch (java.beans.PropertyVetoException JavaDoc ex) {
90                         ex.printStackTrace();
91                         fail (ex.getMessage());
92                     }
93                 }
94             }
95         }
96         ExTC e = new ExTC ();
97         
98         top = e;
99         lookup = ExplorerUtils.createLookup (e.em, e.getActionMap ());
100     }
101     
102 }
103
Popular Tags