KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > NbSheetTest


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import javax.swing.SwingUtilities JavaDoc;
24 import org.netbeans.core.actions.GlobalPropertiesAction;
25 import org.netbeans.junit.NbTestCase;
26 import org.openide.nodes.AbstractNode;
27 import org.openide.nodes.Children;
28 import org.openide.nodes.Node;
29 import org.openide.windows.TopComponent;
30
31 /**
32  *
33  * @author Jaroslav Tulach
34  */

35 public class NbSheetTest extends NbTestCase {
36     static {
37         System.setProperty("org.openide.windows.DummyWindowManager.VISIBLE", "false");
38     }
39     
40     NbSheet s;
41     GlobalPropertiesAction a;
42     TopComponent tc;
43     
44     public NbSheetTest(String JavaDoc testName) {
45         super(testName);
46     }
47     
48     protected void setUp() throws Exception JavaDoc {
49         super.setUp();
50         s = NbSheet.findDefault();
51         assertNotNull("Sheet found", s);
52         assertFalse("Not yet visible", s.isShowing());
53         a = GlobalPropertiesAction.get(GlobalPropertiesAction.class);
54         tc = new TopComponent();
55     }
56
57     protected void tearDown() throws Exception JavaDoc {
58         super.tearDown();
59     }
60
61     public void testIssue97069EgUseSetActivatedNodesNull() throws Exception JavaDoc {
62         class Empty implements Runnable JavaDoc {
63             public void run() { }
64         }
65         Empty empty = new Empty();
66         
67         class R implements Runnable JavaDoc {
68             N node = new N("node1");
69             public void run() {
70                 tc.setActivatedNodes(new Node[] { node });
71                 tc.open();
72                 tc.requestActive();
73
74                 assertTrue("action enabled", a.isEnabled());
75                 a.actionPerformed(new ActionEvent JavaDoc(a, 0, ""));
76             }
77         }
78         R activate = new R();
79         SwingUtilities.invokeAndWait(activate);
80         SwingUtilities.invokeAndWait(empty);
81         
82         for (int i = 0; i < 5; i++) {
83             if (s == TopComponent.getRegistry().getActivated()) {
84                 break;
85             }
86             Thread.sleep(500);
87         }
88         assertEquals("sheet activated", s, TopComponent.getRegistry().getActivated());
89         assertEquals("One node displayed", 1, s.getNodes().length);
90         assertEquals("it is node", activate.node, s.getNodes()[0]);
91         assertEquals("No activated nodes", null, s.getActivatedNodes());
92         
93         s.close();
94         
95         final N another = new N("another");
96         
97         tc.setActivatedNodes(new Node[] { another });
98         tc.requestActive();
99                 
100         
101         class R2 implements Runnable JavaDoc {
102             public void run() {
103                 assertTrue("action enabled", a.isEnabled());
104                 a.actionPerformed(new ActionEvent JavaDoc(a, 0, ""));
105             }
106         }
107         R2 anotherAct = new R2();
108         SwingUtilities.invokeAndWait(anotherAct);
109         SwingUtilities.invokeAndWait(empty);
110
111         for (int i = 0; i < 5; i++) {
112             if (s == TopComponent.getRegistry().getActivated()) {
113                 break;
114             }
115             Thread.sleep(500);
116         }
117         assertEquals("sheet activated another time", s, TopComponent.getRegistry().getActivated());
118         
119         assertEquals("One node displayed", 1, s.getNodes().length);
120         assertEquals("it is another", another, s.getNodes()[0]);
121         assertEquals("No activated nodes", null, s.getActivatedNodes());
122         
123     }
124
125     private static final class N extends AbstractNode {
126         public N(String JavaDoc n) {
127             super(Children.LEAF);
128             setName(n);
129         }
130     }
131 }
132
133
134
Popular Tags