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

(-)a/maven/src/org/netbeans/modules/maven/NbMavenProjectFactory.java (-5 / +12 lines)
Lines 43-49 Link Here
43
import java.io.File;
43
import java.io.File;
44
import java.io.IOException;
44
import java.io.IOException;
45
import org.netbeans.api.project.Project;
45
import org.netbeans.api.project.Project;
46
import org.netbeans.spi.project.ProjectFactory;
46
import org.netbeans.api.project.ProjectManager;
47
import org.netbeans.spi.project.ProjectFactory2;
47
import org.netbeans.spi.project.ProjectState;
48
import org.netbeans.spi.project.ProjectState;
48
import org.openide.ErrorManager;
49
import org.openide.ErrorManager;
49
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
Lines 55-61 Link Here
55
 * @author  Milos Kleint
56
 * @author  Milos Kleint
56
 */
57
 */
57
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.project.ProjectFactory.class, position=666)
58
@org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.project.ProjectFactory.class, position=666)
58
public class NbMavenProjectFactory implements ProjectFactory {
59
public class NbMavenProjectFactory implements ProjectFactory2 {
59
    
60
    
60
    /** Creates a new instance of NbMavenProjectFactory */
61
    /** Creates a new instance of NbMavenProjectFactory */
61
    public NbMavenProjectFactory() {
62
    public NbMavenProjectFactory() {
Lines 77-82 Link Here
77
        }
78
        }
78
        return project.isFile() &&  !"nbproject".equalsIgnoreCase(projectDir.getName()); //NOI18N
79
        return project.isFile() &&  !"nbproject".equalsIgnoreCase(projectDir.getName()); //NOI18N
79
    }
80
    }
81
82
    public ProjectManager.Result isProject2(FileObject projectDirectory) {
83
        if (isProject(projectDirectory)) {
84
            return new ProjectManager.Result("org/netbeans/modules/maven/Maven2Icon.gif"); //NOI18N
85
        }
86
        return null;
87
    }
88
80
    
89
    
81
    public Project loadProject(FileObject fileObject, ProjectState projectState) throws IOException
90
    public Project loadProject(FileObject fileObject, ProjectState projectState) throws IOException
82
    {
91
    {
Lines 112-118 Link Here
112
    
121
    
113
    public void saveProject(Project project) throws IOException {
122
    public void saveProject(Project project) throws IOException {
114
        // what to do here??
123
        // what to do here??
115
    }
124
    }    
116
    
117
    
118
}
125
}
(-)a/projectapi/src/org/netbeans/api/project/ProjectManager.java (-15 / +53 lines)
Lines 54-63 Link Here
54
import java.util.logging.Level;
54
import java.util.logging.Level;
55
import java.util.logging.LogRecord;
55
import java.util.logging.LogRecord;
56
import java.util.logging.Logger;
56
import java.util.logging.Logger;
57
import javax.swing.Icon;
57
import org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation;
58
import org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation;
58
import org.netbeans.modules.projectapi.TimedWeakReference;
59
import org.netbeans.modules.projectapi.TimedWeakReference;
59
import org.netbeans.spi.project.FileOwnerQueryImplementation;
60
import org.netbeans.spi.project.FileOwnerQueryImplementation;
60
import org.netbeans.spi.project.ProjectFactory;
61
import org.netbeans.spi.project.ProjectFactory;
62
import org.netbeans.spi.project.ProjectFactory2;
61
import org.netbeans.spi.project.ProjectState;
63
import org.netbeans.spi.project.ProjectState;
62
import org.openide.filesystems.FileChangeAdapter;
64
import org.openide.filesystems.FileChangeAdapter;
63
import org.openide.filesystems.FileChangeListener;
65
import org.openide.filesystems.FileChangeListener;
Lines 65-70 Link Here
65
import org.openide.filesystems.FileObject;
67
import org.openide.filesystems.FileObject;
66
import org.openide.filesystems.FileSystem;
68
import org.openide.filesystems.FileSystem;
67
import org.openide.filesystems.FileUtil;
69
import org.openide.filesystems.FileUtil;
70
import org.openide.util.ImageUtilities;
68
import org.openide.util.Lookup;
71
import org.openide.util.Lookup;
69
import org.openide.util.LookupEvent;
72
import org.openide.util.LookupEvent;
70
import org.openide.util.LookupListener;
73
import org.openide.util.LookupListener;
Lines 388-393 Link Here
388
     * @throws IllegalArgumentException if the supplied file object is null or not a folder
391
     * @throws IllegalArgumentException if the supplied file object is null or not a folder
389
     */
392
     */
390
    public boolean isProject(final FileObject projectDirectory) throws IllegalArgumentException {
393
    public boolean isProject(final FileObject projectDirectory) throws IllegalArgumentException {
394
        return isProject2(projectDirectory) != null;
395
    }
396
397
    public Result isProject2(final FileObject projectDirectory) throws IllegalArgumentException {
391
        if (projectDirectory == null) {
398
        if (projectDirectory == null) {
392
            throw new IllegalArgumentException("Attempted to pass a null directory to isProject"); // NOI18N
399
            throw new IllegalArgumentException("Attempted to pass a null directory to isProject"); // NOI18N
393
        }
400
        }
Lines 397-407 Link Here
397
            if (projectDirectory.isValid()) {
404
            if (projectDirectory.isValid()) {
398
                throw new IllegalArgumentException("Attempted to pass a non-directory to isProject: " + projectDirectory); // NOI18N
405
                throw new IllegalArgumentException("Attempted to pass a non-directory to isProject: " + projectDirectory); // NOI18N
399
            } else {
406
            } else {
400
                return false;
407
                return null;
401
            }
408
            }
402
        }
409
        }
403
        return mutex().readAccess(new Mutex.Action<Boolean>() {
410
        return mutex().readAccess(new Mutex.Action<Result>() {
404
            public Boolean run() {
411
            public Result run() {
405
                synchronized (dir2Proj) {
412
                synchronized (dir2Proj) {
406
                    Union2<Reference<Project>,LoadStatus> o;
413
                    Union2<Reference<Project>,LoadStatus> o;
407
                    do {
414
                    do {
Lines 416-441 Link Here
416
                    } while (LoadStatus.LOADING_PROJECT.is(o));
423
                    } while (LoadStatus.LOADING_PROJECT.is(o));
417
                    assert !LoadStatus.LOADING_PROJECT.is(o);
424
                    assert !LoadStatus.LOADING_PROJECT.is(o);
418
                    if (LoadStatus.NO_SUCH_PROJECT.is(o)) {
425
                    if (LoadStatus.NO_SUCH_PROJECT.is(o)) {
419
                        return false;
426
                        return null;
420
                    } else if (o != null) {
427
                    } else if (o != null) {
421
                        // Reference<Project> or SOME_SUCH_PROJECT
428
                        // Reference<Project> or SOME_SUCH_PROJECT
422
                        return true;
429
                        // rather check for result than load project and lookup projectInformation for icon.
430
                        return checkForProject(projectDirectory);
423
                    }
431
                    }
424
                    // Not in cache.
432
                    // Not in cache.
425
                    dir2Proj.put(projectDirectory, LoadStatus.LOADING_PROJECT.wrap());
433
                    dir2Proj.put(projectDirectory, LoadStatus.LOADING_PROJECT.wrap());
426
                }
434
                }
427
                boolean resetLP = false;
435
                boolean resetLP = false;
428
                try {
436
                try {
429
                    boolean p = checkForProject(projectDirectory);
437
                    Result p = checkForProject(projectDirectory);
430
                    synchronized (dir2Proj) {
438
                    synchronized (dir2Proj) {
431
                        resetLP = true;
439
                        resetLP = true;
432
                        dir2Proj.notifyAll();
440
                        dir2Proj.notifyAll();
433
                        if (p) {
441
                        if (p != null) {
434
                            dir2Proj.put(projectDirectory, LoadStatus.SOME_SUCH_PROJECT.wrap());
442
                            dir2Proj.put(projectDirectory, LoadStatus.SOME_SUCH_PROJECT.wrap());
435
                            return true;
443
                            return p;
436
                        } else {
444
                        } else {
437
                            dir2Proj.put(projectDirectory, LoadStatus.NO_SUCH_PROJECT.wrap());
445
                            dir2Proj.put(projectDirectory, LoadStatus.NO_SUCH_PROJECT.wrap());
438
                            return false;
446
                            return null;
439
                        }
447
                        }
440
                    }
448
                    }
441
                } finally {
449
                } finally {
Lines 449-466 Link Here
449
        });
457
        });
450
    }
458
    }
451
    
459
    
452
    private boolean checkForProject(FileObject dir) {
460
    private Result checkForProject(FileObject dir) {
453
        assert dir != null;
461
        assert dir != null;
454
        assert dir.isFolder() : dir;
462
        assert dir.isFolder() : dir;
455
        assert mutex().isReadAccess();
463
        assert mutex().isReadAccess();
456
        Iterator it = factories.allInstances().iterator();
464
        Iterator<? extends ProjectFactory> it = factories.allInstances().iterator();
457
        while (it.hasNext()) {
465
        while (it.hasNext()) {
458
            ProjectFactory factory = (ProjectFactory)it.next();
466
            ProjectFactory factory = it.next();
459
            if (factory.isProject(dir)) {
467
            if (factory instanceof ProjectFactory2) {
460
                return true;
468
                Result res = ((ProjectFactory2)factory).isProject2(dir);
469
                if (res != null) {
470
                    return res;
471
                }
472
            } else {
473
                if (factory.isProject(dir)) {
474
                    return new Result((String)null);
475
                }
461
            }
476
            }
462
        }
477
        }
463
        return false;
478
        return null;
464
    }
479
    }
465
    
480
    
466
    /**
481
    /**
Lines 671-675 Link Here
671
        }
686
        }
672
        
687
        
673
    }
688
    }
689
690
    public static final class Result {
691
        private Icon icon;
692
        private String path;
693
694
        public Result(String iconpath) {
695
            path = iconpath;
696
        }
697
698
        public Result(Icon icon) {
699
            this.icon = icon;
700
        }
701
702
        public Icon getIcon() {
703
            if (icon == null) {
704
                if (path != null) {
705
                    icon = ImageUtilities.image2Icon(ImageUtilities.loadImage(path));
706
                }
707
            }
708
            return icon;
709
        }
710
    }
711
674
    
712
    
675
}
713
}
(-)a/projectui/src/org/netbeans/modules/project/ui/ProjectChooserAccessory.java (-3 / +22 lines)
Lines 387-392 Link Here
387
        return OpenProjectList.fileToProject( dir );
387
        return OpenProjectList.fileToProject( dir );
388
    }
388
    }
389
389
390
    private static ProjectManager.Result getProjectResult(File dir) {
391
        FileObject fo = FileUtil.toFileObject(dir);
392
        if (fo != null && /* #60518 */ fo.isFolder()) {
393
            return ProjectManager.getDefault().isProject2(fo);
394
        } else {
395
            return null;
396
        }
397
398
    }
399
390
    private void setAccessoryEnablement( boolean enable, int numberOfProjects ) {
400
    private void setAccessoryEnablement( boolean enable, int numberOfProjects ) {
391
        jLabelProjectName.setEnabled( enable );
401
        jLabelProjectName.setEnabled( enable );
392
        jTextFieldProjectName.setEnabled( enable );
402
        jTextFieldProjectName.setEnabled( enable );
Lines 605-614 Link Here
605
        }
615
        }
606
616
607
        public void run() {
617
        public void run() {
608
            Project p = OpenProjectList.fileToProject(lookingForIcon);
618
            ProjectManager.Result r = getProjectResult(lookingForIcon);
609
            Icon icon;
619
            Icon icon;
610
            if (p != null) {
620
            if (r != null) {
611
                icon = ProjectUtils.getInformation(p).getIcon();
621
                icon = r.getIcon();
622
                if (icon == null) {
623
                    Project p = getProject(lookingForIcon);
624
                    if (p != null) {
625
                        icon = ProjectUtils.getInformation(p).getIcon();
626
                    } else {
627
                        // Could also badge with an error icon:
628
                        icon = chooser.getFileSystemView().getSystemIcon(lookingForIcon);
629
                    }
630
                }
612
            } else {
631
            } else {
613
                // Could also badge with an error icon:
632
                // Could also badge with an error icon:
614
                icon = chooser.getFileSystemView().getSystemIcon(lookingForIcon);
633
                icon = chooser.getFileSystemView().getSystemIcon(lookingForIcon);
(-)a/projectui/src/org/netbeans/modules/project/ui/actions/OpenProject.java (-1 lines)
Lines 49-55 Link Here
49
import javax.swing.SwingUtilities;
49
import javax.swing.SwingUtilities;
50
import org.netbeans.api.project.FileOwnerQuery;
50
import org.netbeans.api.project.FileOwnerQuery;
51
import org.netbeans.api.project.Project;
51
import org.netbeans.api.project.Project;
52
import org.netbeans.api.project.ui.OpenProjects;
53
import org.netbeans.modules.project.ui.OpenProjectList;
52
import org.netbeans.modules.project.ui.OpenProjectList;
54
import org.netbeans.modules.project.ui.OpenProjectListSettings;
53
import org.netbeans.modules.project.ui.OpenProjectListSettings;
55
import org.netbeans.modules.project.ui.ProjectChooserAccessory;
54
import org.netbeans.modules.project.ui.ProjectChooserAccessory;

Return to bug 153923