1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.action; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Component ; 24 import java.awt.EventQueue ; 25 import java.lang.ref.WeakReference ; 26 import java.lang.reflect.InvocationTargetException ; 27 import javax.swing.JFrame ; 28 import javax.swing.JLabel ; 29 import javax.swing.JPanel ; 30 import javax.swing.JTextField ; 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 40 public class GUIRegistrationPanelTest extends LayerTestBase { 41 42 private JFrame frame; 43 private JPanel outerPane; 44 private GUIRegistrationPanel regPane; 45 private WeakReference regPaneWR; 46 private boolean valid; 47 48 public GUIRegistrationPanelTest(String testName) { 49 super(testName); 50 } 51 52 public void testMemoryLeak_70032() throws Exception { 53 TestBase.initializeBuildProperties(getWorkDir(), getDataDir()); 54 final WizardDescriptor wd = new WizardDescriptor(new WizardDescriptor.ArrayIterator() { 55 public WizardDescriptor.Panel current() { return new BasicWizardPanel(null) { 57 public Component getComponent() { 58 return new JPanel (); 59 } 60 }; 61 } 62 }); 63 wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT, 64 TestBase.generateStandaloneModule(getWorkDir(), "module")); 65 EventQueue.invokeAndWait(new Runnable () { 66 public void run() { 67 regPane = new GUIRegistrationPanel(wd, new DataModel(wd)); 68 regPane.editorContext.setSelected(true); 70 regPane.fileTypeContext.setSelected(true); 71 regPane.globalMenuItem.setSelected(true); 72 regPane.globalToolbarButton.setSelected(true); 73 74 outerPane = new JPanel (); 76 outerPane.add(regPane); 77 78 regPaneWR = new WeakReference (regPane); 79 80 frame = new JFrame ("testMemoryLeak_70032"); 81 frame.getContentPane().setLayout(new BorderLayout ()); 82 frame.getContentPane().add(new JLabel ("<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 frame.setVisible(true); 88 } 89 }); 90 while (!isRegPaneValid()) { 91 Thread.sleep(200); 92 } 93 EventQueue.invokeAndWait(new Runnable () { 94 public void run() { 95 frame.getContentPane().remove(outerPane); 96 97 JTextField dummyFocusEater = new JTextField (); 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 , InvocationTargetException { 114 EventQueue.invokeAndWait(new Runnable () { 115 public void run() { 116 valid = regPane.checkValidity(); 117 } 118 }); 119 return valid; 120 } 121 122 } 123 | Popular Tags |