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 58866
Collapse All | Expand All

(-)ant/project/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java (+4 lines)
Lines 471-476 Link Here
471
        return dir;
471
        return dir;
472
    }
472
    }
473
    
473
    
474
    public void notifyDeleted() {
475
        state.notifyDeleted();
476
    }
477
    
474
    /**
478
    /**
475
     * Mark this project as being modified without actually changing anything in it.
479
     * Mark this project as being modified without actually changing anything in it.
476
     * Should only be called from {@link ProjectGenerator#createProject}.
480
     * Should only be called from {@link ProjectGenerator#createProject}.
(-)projects/projectapi/apichanges.xml (+22 lines)
Lines 76-81 Link Here
76
76
77
    <changes>
77
    <changes>
78
78
79
        <change id="notify-deleted">
80
            <api name="general"/>
81
            <summary>notifyDeleted method added to the ProjectState</summary>
82
            <version major="1" minor="4"/>
83
            <date day="12" month="05" year="2005"/>
84
            <author login="jlahoda"/>
85
            <compatibility>
86
                <p>
87
                    As only the ProjectManager is allowed to implement ProjectState interface,
88
                    this change should not directly affect any clients.
89
                </p>
90
            </compatibility>
91
            <description>
92
                <p>
93
                    The <code>notifyDeleted</code> action is added to the <code>ProjectState</code>,
94
                    allowing the project implmentation to let the <code>ProjectManager</code>
95
                    know that the project has been deleted.
96
                </p>
97
            </description>
98
            <issue number="51468"/>
99
        </change>
100
        
79
        <change id="rel-vers-1">
101
        <change id="rel-vers-1">
80
            <api name="general"/>
102
            <api name="general"/>
81
            <summary>Switched to major release version 1</summary>
103
            <summary>Switched to major release version 1</summary>
(-)projects/projectapi/src/org/netbeans/api/project/ProjectManager.java (-1 / +33 lines)
Lines 15-20 Link Here
15
15
16
import java.io.IOException;
16
import java.io.IOException;
17
import java.lang.ref.Reference;
17
import java.lang.ref.Reference;
18
import java.net.URI;
18
import java.util.Arrays;
19
import java.util.Arrays;
19
import java.util.HashSet;
20
import java.util.HashSet;
20
import java.util.Iterator;
21
import java.util.Iterator;
Lines 455-461 Link Here
455
                }
456
                }
456
            });
457
            });
457
        }
458
        }
458
        
459
460
        public void notifyDeleted() throws IllegalStateException {
461
            assert p != null;
462
            mutex().writeAccess(new Mutex.Action() {
463
                public Object run() {
464
                    if (proj2Factory.get(p) == null) {
465
                        throw new IllegalStateException("An attempt to call notifyDeleted more than once. Project: " + p.getProjectDirectory());
466
                    }
467
                    
468
                    dir2Proj.remove(p.getProjectDirectory());
469
                    proj2Factory.remove(p);
470
                    modifiedProjects.remove(p);
471
                    return null;
472
                }
473
            });
474
        }
475
459
    }
476
    }
460
    
477
    
461
    /**
478
    /**
Lines 548-553 Link Here
548
        } catch (MutexException e) {
565
        } catch (MutexException e) {
549
            throw (IOException)e.getException();
566
            throw (IOException)e.getException();
550
        }
567
        }
568
    }
569
    
570
    /**
571
     * Check whether a given project is still valid (ie. not deleted).
572
     * <p>Acquires read access.</p>
573
     * @param p a project loaded by this manager
574
     */
575
    public boolean isValid(final Project p) {
576
        return ((Boolean)mutex().readAccess(new Mutex.Action() {
577
            public Object run() {
578
                synchronized (dir2Proj) {
579
                    return Boolean.valueOf(proj2Factory.containsKey(p));
580
                }
581
            }
582
        })).booleanValue();
551
    }
583
    }
552
    
584
    
553
    /**
585
    /**
(-)projects/projectapi/src/org/netbeans/spi/project/ActionProvider.java (-1 / +5 lines)
Lines 86-92 Link Here
86
     */
86
     */
87
    String COMMAND_DEBUG_STEP_INTO = "debug.stepinto"; // NOI18N
87
    String COMMAND_DEBUG_STEP_INTO = "debug.stepinto"; // NOI18N
88
    
88
    
89
        
89
    /**
90
     * Standard command for deleting the project.
91
     */
92
    String COMMAND_DELETE = "delete"; // NOI18N
93
    
90
    /**
94
    /**
91
     * Get a list of all commands which this project supports.
95
     * Get a list of all commands which this project supports.
92
     * @return a list of command names suitable for {@link #invokeAction}
96
     * @return a list of command names suitable for {@link #invokeAction}
(-)projects/projectapi/src/org/netbeans/spi/project/ProjectState.java (-2 / +19 lines)
Lines 19-26 Link Here
19
/**
19
/**
20
 * Callback permitting {@link Project}s to inform the {@link ProjectManager}
20
 * Callback permitting {@link Project}s to inform the {@link ProjectManager}
21
 * of important lifecycle events.
21
 * of important lifecycle events.
22
 * Currently the only available event is modification of the project metadata.
22
 * Currently the only available events are modification of the project metadata
23
 * However in the future other events may be added, such as moving or deleting
23
 * and project deletion notification.
24
 * However in the future other events may be added, such as moving
24
 * the project, which the project manager would need to be informed of.
25
 * the project, which the project manager would need to be informed of.
25
 * <p>
26
 * <p>
26
 * This interface may only be implemented by the project manager. A
27
 * This interface may only be implemented by the project manager. A
Lines 38-42 Link Here
38
     * <p>Acquires write access.
39
     * <p>Acquires write access.
39
     */
40
     */
40
    void markModified();
41
    void markModified();
42
    
43
    /**
44
     * <p>Inform the manager that the project has been deleted. The project will
45
     * be removed from any {@link ProjectManager}'s  mappings.
46
     * If {@link ProjectManager#findProject} is called on the project directory,
47
     * the {@link ProjectFactory ProjectFactories} are asked again to recognize
48
     * the project.</p>
49
     *
50
     * <p>The project is no longer recognized as created by the {@link ProjectManager}.</p>
51
     *
52
     * <p>Acquires write access.</p>
53
     *
54
     * @throws IllegalStateException if notifyDeleted is called more than once for a project.
55
     * @since 1.4
56
     */
57
    void notifyDeleted() throws IllegalStateException ;
41
    
58
    
42
}
59
}
(-)projects/projectapi/test/unit/src/org/netbeans/api/project/ProjectManagerTest.java (+71 lines)
Lines 373-376 Link Here
373
        }
373
        }
374
    }
374
    }
375
    
375
    
376
    public void testNotifyDeleted() throws Exception {
377
        FileObject p1 = scratch.createFolder("p1");
378
        FileObject p1TestProject = p1.createFolder("testproject");
379
        
380
        Project project1 = pm.findProject(p1);
381
        
382
        assertNotNull("project1 is recognized", project1);
383
        p1TestProject.delete();
384
        TestUtil.notifyDeleted(project1);
385
        
386
        assertFalse("project1 is not valid", pm.isValid(project1));
387
        assertNull("project1 is deleted", pm.findProject(p1));
388
389
        FileObject p2 = scratch.createFolder("p2");
390
        FileObject p2TestProject = p2.createFolder("testproject");
391
        
392
        Project project2 = pm.findProject(p2);
393
        
394
        assertNotNull("project2 is recognized", project2);
395
        TestUtil.notifyDeleted(project2);
396
        
397
        assertFalse("project2 is not valid", pm.isValid(project2));
398
        
399
        Project project2b = pm.findProject(p2);
400
        
401
        assertTrue("project2 is newly recognized", project2b != project2);
402
        assertNotNull("project2 is newly recognized", project2b);
403
404
        FileObject p3 = scratch.createFolder("p3");
405
        FileObject p3TestProject = p3.createFolder("testproject");
406
        
407
        Project project3 = pm.findProject(p3);
408
        
409
        assertNotNull("project3 is recognized", project3);
410
        TestUtil.modify(project3);
411
        assertTrue("project3 is modified", pm.isModified(project3));
412
        TestUtil.notifyDeleted(project3);
413
        
414
        assertFalse("project3 is not valid", pm.isValid(project3));
415
        
416
        boolean wasException = false;
417
        try {
418
            pm.isModified(project3);
419
        } catch (IllegalArgumentException e) {
420
            //the project is no longer recognized by the ProjectManager.
421
            wasException = true;
422
        }
423
        
424
        assertTrue("the project is no longer recognized by the ProjectManager", wasException);
425
        
426
        FileObject p4 = scratch.createFolder("p4");
427
        FileObject p4TestProject = p4.createFolder("testproject");
428
        
429
        Project project4 = pm.findProject(p4);
430
        
431
        assertNotNull("project4 is recognized", project4);
432
        TestUtil.notifyDeleted(project4);
433
        
434
        assertFalse("project4 is not valid", pm.isValid(project3));
435
        
436
        wasException = false;
437
        try {
438
            TestUtil.notifyDeleted(project4);
439
        } catch (IllegalStateException e) {
440
            //the project is no longer recognized by the ProjectManager.
441
            wasException = true;
442
        }
443
        
444
        assertTrue("An IllegalStateException was thrown when calling notifyDeleted twice.", wasException);
445
    }
446
    
376
}
447
}
(-)projects/projectapi/test/unit/src/org/netbeans/api/project/TestUtil.java (+8 lines)
Lines 192-197 Link Here
192
    }
192
    }
193
    
193
    
194
    /**
194
    /**
195
     * Mark a test project as modified.
196
     * @param p a test project
197
     */
198
    public static void notifyDeleted(Project p) {
199
        ((TestProject)p).state.notifyDeleted();
200
    }
201
    
202
    /**
195
     * If set to something non-null, loading a broken project will wait for
203
     * If set to something non-null, loading a broken project will wait for
196
     * notification on this monitor before throwing an exception.
204
     * notification on this monitor before throwing an exception.
197
     * @see ProjectManagerTest#testLoadExceptionWithConcurrentLoad
205
     * @see ProjectManagerTest#testLoadExceptionWithConcurrentLoad
(-)projects/projectui/src/org/netbeans/modules/project/ui/OpenProjectList.java (-1 / +5 lines)
Lines 726-732 Link Here
726
                if ( projectReference != null ) { // Reference to project exists
726
                if ( projectReference != null ) { // Reference to project exists
727
                    p = (Project)projectReference.get();
727
                    p = (Project)projectReference.get();
728
                    if ( p != null ) {
728
                    if ( p != null ) {
729
                        return p; // And refers to some project
729
                        // And refers to some project, check for validity:
730
                        if ( ProjectManager.getDefault().isValid( p ) )
731
                            return p; 
732
                        else
733
                            return null;
730
                    }
734
                    }
731
                }
735
                }
732
                
736
                
(-)projects/projectui/src/org/netbeans/modules/project/ui/actions/Actions.java (-2 / +18 lines)
Lines 48-53 Link Here
48
    private static Action OPEN_SUBPROJECTS;
48
    private static Action OPEN_SUBPROJECTS;
49
    private static Action CLOSE_PROJECT;
49
    private static Action CLOSE_PROJECT;
50
    private static Action NEW_FILE;
50
    private static Action NEW_FILE;
51
    private static Action DELETE_PROJECT;
51
            
52
            
52
    public synchronized Action setAsMainProjectAction() {
53
    public synchronized Action setAsMainProjectAction() {
53
        if ( SET_AS_MAIN_PROJECT == null ) {
54
        if ( SET_AS_MAIN_PROJECT == null ) {
Lines 84-94 Link Here
84
        return NEW_FILE;
85
        return NEW_FILE;
85
    }    
86
    }    
86
    
87
    
88
    public Action deleteProjectAction() {
89
        return deleteProject();
90
    }
91
87
    public synchronized Action newProjectAction() {
92
    public synchronized Action newProjectAction() {
88
        return new NewProject();
93
        return new NewProject();
89
    }
94
    }
90
    
95
    
91
    
92
    public Action projectCommandAction(String command, String namePattern, Icon icon ) {
96
    public Action projectCommandAction(String command, String namePattern, Icon icon ) {
93
        return new ProjectAction( command, namePattern, icon, null );
97
        return new ProjectAction( command, namePattern, icon, null );
94
    }
98
    }
Lines 162-167 Link Here
162
        return a;
166
        return a;
163
    }
167
    }
164
    
168
    
169
    public static synchronized Action deleteProject() {
170
        if (DELETE_PROJECT == null) {
171
            DELETE_PROJECT = new ProjectAction (
172
                ActionProvider.COMMAND_DELETE,
173
                NbBundle.getMessage(Actions.class, "LBL_DeleteProjectAction_Name" ), // NOI18N
174
                null,
175
                null );
176
        }
177
        
178
        return DELETE_PROJECT;
179
    }
180
    
165
    // 1-off actions -----------------------------------------------------------
181
    // 1-off actions -----------------------------------------------------------
166
    
182
    
167
    public static Action compileSingle() {
183
    public static Action compileSingle() {
Lines 257-261 Link Here
257
        a.putValue("iconBase","org/netbeans/modules/project/ui/resources/debugProject.gif"); //NOI18N
273
        a.putValue("iconBase","org/netbeans/modules/project/ui/resources/debugProject.gif"); //NOI18N
258
        return a;
274
        return a;
259
    }
275
    }
260
            
276
261
}
277
}
(-)projects/projectui/src/org/netbeans/modules/project/ui/actions/Bundle.properties (+1 lines)
Lines 42-47 Link Here
42
LBL_TestProjectAction_Name=Test {0,choice,0#Project|1#"{1}"|1<{0} Projects}
42
LBL_TestProjectAction_Name=Test {0,choice,0#Project|1#"{1}"|1<{0} Projects}
43
LBL_CompileSingleAction_Name=Co&mpile {0,choice,0#File|1#"{1}"|1<Files}
43
LBL_CompileSingleAction_Name=Co&mpile {0,choice,0#File|1#"{1}"|1<Files}
44
LBL_StopBuildingAction_Name=&Stop Building
44
LBL_StopBuildingAction_Name=&Stop Building
45
LBL_DeleteProjectAction_Name=Delete {0,choice,0#Project|1#"{1}"|1<{0} Projects}
45
46
46
LBL_RunProjectAction_Name=Run {0,choice,0#Project|1#"{1}" Project|1<{0} Projects}
47
LBL_RunProjectAction_Name=Run {0,choice,0#Project|1#"{1}" Project|1<{0} Projects}
47
LBL_DebugProjectAction_Name=Run {0,choice,0#Project|1#"{1}" Project|1<{0} Projects} in Debugger
48
LBL_DebugProjectAction_Name=Run {0,choice,0#Project|1#"{1}" Project|1<{0} Projects} in Debugger
(-)projects/projectui/src/org/netbeans/modules/project/ui/resources/layer.xml (-1 / +17 lines)
Lines 84-89 Link Here
84
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.project.ui.actions.Actions.runProject"/>
84
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.project.ui.actions.Actions.runProject"/>
85
            </file>
85
            </file>
86
                        
86
                        
87
            <file name="org-netbeans-modules-project-ui-DeleteProject.instance">
88
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.project.ui.actions.Actions.deleteProject"/>
89
            </file>
90
87
            <!-- 1 off actions -->            
91
            <!-- 1 off actions -->            
88
            <file name="org-netbeans-modules-project-ui-CompileSingle.instance">
92
            <file name="org-netbeans-modules-project-ui-CompileSingle.instance">
89
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.project.ui.actions.Actions.compileSingle"/>
93
                <attr name="instanceCreate" methodvalue="org.netbeans.modules.project.ui.actions.Actions.compileSingle"/>
Lines 266-274 Link Here
266
                <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>                 
270
                <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>                 
267
            </file>
271
            </file>
268
            
272
            
273
            <attr name="SeparatorOpen.instance/org-netbeans-modules-project-ui-DeleteProject.shadow" boolvalue="true" />
274
            
275
            <file name="org-netbeans-modules-project-ui-DeleteProject.shadow">
276
                <attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-DeleteProject.instance"/>
277
            </file>
278
            
279
            <attr name="org-netbeans-modules-project-ui-DeleteProject.shadow/SeparatorOpen2.instance" boolvalue="true" />
280
            
281
            <file name="SeparatorOpen2.instance">
282
                <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/>                 
283
            </file>
284
            
269
            <!-- SetMain and customize -->
285
            <!-- SetMain and customize -->
270
            
286
            
271
            <attr name="SeparatorOpen.instance/org-netbeans-modules-project-ui-SetMainProject.shadow" boolvalue="true" />
287
            <attr name="SeparatorOpen2.instance/org-netbeans-modules-project-ui-SetMainProject.shadow" boolvalue="true" />
272
            
288
            
273
            <file name="org-netbeans-modules-project-ui-SetMainProject.shadow">
289
            <file name="org-netbeans-modules-project-ui-SetMainProject.shadow">
274
                <attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-SetMainProject.instance"/>
290
                <attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-SetMainProject.instance"/>
(-)projects/projectui/test/unit/src/org/netbeans/modules/project/ui/OpenProjectListTest.java (+36 lines)
Lines 177-182 Link Here
177
        assertEquals("both close hooks were called", 2, TestProjectOpenedHookImpl.closed);
177
        assertEquals("both close hooks were called", 2, TestProjectOpenedHookImpl.closed);
178
    }
178
    }
179
    
179
    
180
    public void testNotifyDeleted() throws Exception {
181
        FileObject workDir = FileUtil.toFileObject (getWorkDir ());
182
        
183
        FileObject p1 = workDir.createFolder("p1");
184
        FileObject p1TestProject = p1.createFolder("testproject");
185
        
186
        Project project1 = ProjectManager.getDefault().findProject(p1);
187
        
188
        assertNotNull("project1 is recognized", project1);
189
        
190
        OpenProjectList.getDefault().open(project1);
191
        
192
        OpenProjectList.getDefault().close(new Project[] {project1});
193
        
194
        p1TestProject.delete();
195
        TestSupport.notifyDeleted(project1);
196
        
197
        assertNull("project1 is deleted", ProjectManager.getDefault().findProject(p1));
198
        
199
        assertFalse("project1 is not in recent projects list", OpenProjectList.getDefault().getRecentProjects().contains(project1));
200
        
201
        FileObject p2 = workDir.createFolder("p2");
202
        FileObject p2TestProject = p2.createFolder("testproject");
203
        
204
        Project project2 = ProjectManager.getDefault().findProject(p2);
205
        
206
        assertNotNull("project2 is recognized", project2);
207
        OpenProjectList.getDefault().open(project1);
208
        
209
        OpenProjectList.getDefault().close(new Project[] {project1});
210
        
211
        TestSupport.notifyDeleted(project2);
212
        
213
        assertFalse("project2 is not in recent projects list", OpenProjectList.getDefault().getRecentProjects().contains(project2));
214
    }
215
    
180
    // helper code
216
    // helper code
181
217
182
    private static class MySubprojectProvider implements SubprojectProvider {
218
    private static class MySubprojectProvider implements SubprojectProvider {
(-)projects/projectui/test/unit/src/org/netbeans/modules/project/ui/actions/TestSupport.java (+3 lines)
Lines 50-55 Link Here
50
        return new TestProjectFactory();
50
        return new TestProjectFactory();
51
    }
51
    }
52
    
52
    
53
    public static void notifyDeleted(Project p) {
54
        ((TestProject) p).state.notifyDeleted();
55
    }
53
        
56
        
54
    private static final class TestProjectFactory implements ProjectFactory {
57
    private static final class TestProjectFactory implements ProjectFactory {
55
        
58
        
(-)projects/projectuiapi/src/org/netbeans/modules/project/uiapi/ActionsFactory.java (+2 lines)
Lines 35-40 Link Here
35
    
35
    
36
    public Action newFileAction();
36
    public Action newFileAction();
37
    
37
    
38
    public Action deleteProjectAction();
39
    
38
    public Action newProjectAction();
40
    public Action newProjectAction();
39
            
41
            
40
    // Actions sensitive to project selection
42
    // Actions sensitive to project selection
(-)projects/projectuiapi/src/org/netbeans/spi/project/ui/support/CommonProjectActions.java (+13 lines)
Lines 99-104 Link Here
99
    }
99
    }
100
    
100
    
101
    /**
101
    /**
102
     * Create an action "Delete Project".
103
     * It should be invoked with an action context containing
104
     * one or more {@link org.netbeans.api.project.Project}s.
105
     * <p class="nonnormative">
106
     * You might include this in the context menu of a logical view.
107
     * </p>
108
     * @return an action
109
     */
110
    public static Action deleteProjectAction() {
111
        return Utilities.getActionsFactory().deleteProjectAction();
112
    }
113
114
    /**
102
     * Creates action that invokes <b>New Project</b> wizard.
115
     * Creates action that invokes <b>New Project</b> wizard.
103
     * 
116
     * 
104
     * <p>{@link #EXISTING_SOURCES_DIRECTORY} keyed action
117
     * <p>{@link #EXISTING_SOURCES_DIRECTORY} keyed action

Return to bug 58866