This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 70835
Collapse All | Expand All

(-)src/org/netbeans/modules/project/ui/actions/SetMainProject.java (+4 lines)
Lines 105-110 Link Here
105
            String label = NbBundle.getMessage( SetMainProject.class, "LBL_SetMainProjectAction_Name" ); // NOI18N
105
            String label = NbBundle.getMessage( SetMainProject.class, "LBL_SetMainProjectAction_Name" ); // NOI18N
106
            subMenu = new JMenu( label );
106
            subMenu = new JMenu( label );
107
            subMenu.setMnemonic (NbBundle.getMessage (SetMainProject.class, "MNE_SetMainProjectAction_Name").charAt (0)); // NOI18N
107
            subMenu.setMnemonic (NbBundle.getMessage (SetMainProject.class, "MNE_SetMainProjectAction_Name").charAt (0)); // NOI18N
108
            //#70835: the menu bar holds only subMenu not this action. As this action listens only weakly on OPL, noone holds this action.
109
            //The action is the garbage collected and the sub menu does not react on changes of opened projects.
110
            //The action instance has to exists as long as the subMenu:
111
            subMenu.putClientProperty(SetMainProject.class, this);
108
        }
112
        }
109
        
113
        
110
        subMenu.removeAll();
114
        subMenu.removeAll();
(-)test/unit/src/org/netbeans/modules/project/ui/actions/SetMainProjectTest.java (+92 lines)
Lines 13-20 Link Here
13
13
14
package org.netbeans.modules.project.ui.actions;
14
package org.netbeans.modules.project.ui.actions;
15
15
16
import java.io.IOException;
17
import java.lang.ref.WeakReference;
18
import javax.swing.JMenu;
19
import javax.swing.JMenuItem;
20
import org.netbeans.api.project.Project;
21
import org.netbeans.api.project.ProjectManager;
22
import org.netbeans.api.project.TestUtil;
16
import org.netbeans.junit.NbTestCase;
23
import org.netbeans.junit.NbTestCase;
24
import org.netbeans.modules.project.ui.OpenProjectList;
17
import org.netbeans.modules.project.ui.actions.ProjectActionTest.ActionCreator;
25
import org.netbeans.modules.project.ui.actions.ProjectActionTest.ActionCreator;
26
import org.openide.filesystems.FileObject;
27
import org.openide.filesystems.FileUtil;
18
import org.openide.util.Lookup;
28
import org.openide.util.Lookup;
19
29
20
public class SetMainProjectTest extends NbTestCase {
30
public class SetMainProjectTest extends NbTestCase {
Lines 23-28 Link Here
23
        super( name );
33
        super( name );
24
    }
34
    }
25
35
36
    public void setUp() throws Exception {
37
        super.setUp();
38
        
39
        TestUtil.setLookup(new Object[] {
40
            TestSupport.testProjectFactory(),
41
            TestSupport.createAuxiliaryConfiguration(),
42
        });
43
        clearWorkDir ();
44
    }
45
    
26
    public boolean runInEQ () {
46
    public boolean runInEQ () {
27
        return true;
47
        return true;
28
    }
48
    }
Lines 35-38 Link Here
35
        }, false);
55
        }, false);
36
    }
56
    }
37
    
57
    
58
    public void test70368() {
59
        SetMainProject a = new SetMainProject();
60
        WeakReference  ref = new WeakReference(a);
61
        
62
        a = null;
63
        
64
        assertGC("SetMainProject action's instance can be freed:", ref);
65
    }
66
    
67
    public void test70835() throws IOException {
68
        FileObject workDir = FileUtil.toFileObject (getWorkDir ());
69
        
70
        assertNotNull(workDir);
71
        
72
        FileObject f1 = TestSupport.createTestProject (workDir, "project1");
73
        FileObject f2 = TestSupport.createTestProject (workDir, "project2");
74
        
75
        assertNotNull(f1);
76
        assertNotNull(f2);
77
        
78
        Project p1 = ProjectManager.getDefault().findProject(f1);
79
        Project p2 = ProjectManager.getDefault().findProject(f2);
80
        
81
        assertNotNull(p1);
82
        assertNotNull(p2);
83
        
84
        OpenProjectList.getDefault().open(new Project[] {p1, p2}, false);
85
        
86
        SetMainProject a = new SetMainProject();
87
        
88
        JMenuItem item = a.getMenuPresenter();
89
        
90
        assertTrue(item instanceof JMenu);
91
        
92
        JMenu menu = (JMenu) item;
93
        
94
        item = null;
95
        
96
        assertEquals(2, menu.getItemCount());
97
        assertTrue(menu.isEnabled());
98
        
99
        WeakReference menuRef = new WeakReference(menu);
100
        WeakReference actionRef = new WeakReference(a);
101
        
102
        a = null;
103
        
104
        try {
105
            assertGC("", actionRef);
106
        } catch (Error e) {
107
            //ignore....
108
        }
109
        
110
        OpenProjectList.getDefault().close(new Project[] {p1});
111
        
112
        assertEquals(1, menu.getItemCount());
113
        assertTrue(menu.isEnabled());
114
115
        OpenProjectList.getDefault().close(new Project[] {p2});
116
        
117
        assertEquals(0, menu.getItemCount());
118
        assertFalse(menu.isEnabled());
119
120
        OpenProjectList.getDefault().open(new Project[] {p1}, false);
121
        
122
        assertEquals(1, menu.getItemCount());
123
        assertTrue(menu.isEnabled());
124
        
125
        menu = null;
126
        
127
        assertGC("", menuRef);
128
        assertGC("", actionRef);
129
    }
38
}
130
}

Return to bug 70835