KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > action > GUIRegistrationPanelTest


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.modules.apisupport.project.ui.wizard.action;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.EventQueue JavaDoc;
25 import java.lang.ref.WeakReference JavaDoc;
26 import java.lang.reflect.InvocationTargetException JavaDoc;
27 import javax.swing.JFrame JavaDoc;
28 import javax.swing.JLabel JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.JTextField JavaDoc;
31 import org.netbeans.modules.apisupport.project.TestBase;
32 import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
33 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardPanel;
34 import org.netbeans.modules.project.uiapi.ProjectChooserFactory;
35 import org.openide.WizardDescriptor;
36
37 /**
38  * @author Martin Krauskopf
39  */

40 public class GUIRegistrationPanelTest extends LayerTestBase {
41     
42     private JFrame JavaDoc frame;
43     private JPanel JavaDoc outerPane;
44     private GUIRegistrationPanel regPane;
45     private WeakReference JavaDoc regPaneWR;
46     private boolean valid;
47     
48     public GUIRegistrationPanelTest(String JavaDoc testName) {
49         super(testName);
50     }
51     
52     public void testMemoryLeak_70032() throws Exception JavaDoc {
53         TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
54         final WizardDescriptor wd = new WizardDescriptor(new WizardDescriptor.ArrayIterator() {
55             public WizardDescriptor.Panel current() { // satisfying WizardDescriptor 1.32 (#76318)
56
return new BasicWizardPanel(null) {
57                     public Component JavaDoc getComponent() {
58                         return new JPanel JavaDoc();
59                     }
60                 };
61             }
62         });
63         wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT,
64                 TestBase.generateStandaloneModule(getWorkDir(), "module"));
65         EventQueue.invokeAndWait(new Runnable JavaDoc() {
66             public void run() {
67                 regPane = new GUIRegistrationPanel(wd, new DataModel(wd));
68                 // let's force checkValidity failed until all data are loaded
69
regPane.editorContext.setSelected(true);
70                 regPane.fileTypeContext.setSelected(true);
71                 regPane.globalMenuItem.setSelected(true);
72                 regPane.globalToolbarButton.setSelected(true);
73                 
74                 // workaround for inability to GC JFrame/JDialog itself
75
outerPane = new JPanel JavaDoc();
76                 outerPane.add(regPane);
77                 
78                 regPaneWR = new WeakReference JavaDoc(regPane);
79                 
80                 frame = new JFrame JavaDoc("testMemoryLeak_70032");
81                 frame.getContentPane().setLayout(new BorderLayout JavaDoc());
82                 frame.getContentPane().add(new JLabel JavaDoc("<html><font color='blue'>I will close myself" +
83                         " as soon as I load all data from the SystemFileSystem</font></html>"), BorderLayout.NORTH);
84                 frame.getContentPane().add(outerPane, BorderLayout.CENTER);
85                 frame.pack();
86                 // NOTE: we have to show the frame to take combobox renderers into the game
87
frame.setVisible(true);
88             }
89         });
90         while (!isRegPaneValid()) {
91             Thread.sleep(200);
92         }
93         EventQueue.invokeAndWait(new Runnable JavaDoc() {
94             public void run() {
95                 frame.getContentPane().remove(outerPane);
96                 
97                 // prevents KeyboardFocusManager.permanentFocusOwner and
98
// JTextComponent.focusedComponent to hold us
99
JTextField JavaDoc dummyFocusEater = new JTextField JavaDoc();
100                 frame.getContentPane().add(dummyFocusEater);
101                 dummyFocusEater.requestFocus();
102                 frame.setVisible(false);
103                 frame.dispose();
104             }
105         });
106         
107         outerPane = null;
108         regPane = null;
109         
110         assertGC("GCing comp", regPaneWR);
111     }
112     
113     private boolean isRegPaneValid() throws InterruptedException JavaDoc, InvocationTargetException JavaDoc {
114         EventQueue.invokeAndWait(new Runnable JavaDoc() {
115             public void run() {
116                 valid = regPane.checkValidity();
117             }
118         });
119         return valid;
120     }
121     
122 }
123
Popular Tags