# HG changeset patch # User Milos Kleint # Date 1227695075 -3600 # Node ID c682e4092760080f789e78204883a47fe1bb2ffa # Parent 256bfef65ab45c8dfa42ecf698142cd3865f39a9 #153923 extend ProjectFactory to provide a project icon and rewrite the project open dialog to utilize it diff -r 256bfef65ab4 -r c682e4092760 maven/src/org/netbeans/modules/maven/NbMavenProjectFactory.java --- a/maven/src/org/netbeans/modules/maven/NbMavenProjectFactory.java Tue Nov 25 17:17:42 2008 -0800 +++ b/maven/src/org/netbeans/modules/maven/NbMavenProjectFactory.java Wed Nov 26 11:24:35 2008 +0100 @@ -43,7 +43,8 @@ import java.io.File; import java.io.IOException; import org.netbeans.api.project.Project; -import org.netbeans.spi.project.ProjectFactory; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.spi.project.ProjectFactory2; import org.netbeans.spi.project.ProjectState; import org.openide.ErrorManager; import org.openide.filesystems.FileObject; @@ -55,7 +56,7 @@ * @author Milos Kleint */ @org.openide.util.lookup.ServiceProvider(service=org.netbeans.spi.project.ProjectFactory.class, position=666) -public class NbMavenProjectFactory implements ProjectFactory { +public class NbMavenProjectFactory implements ProjectFactory2 { /** Creates a new instance of NbMavenProjectFactory */ public NbMavenProjectFactory() { @@ -77,6 +78,14 @@ } return project.isFile() && !"nbproject".equalsIgnoreCase(projectDir.getName()); //NOI18N } + + public ProjectManager.Result isProject2(FileObject projectDirectory) { + if (isProject(projectDirectory)) { + return new ProjectManager.Result("org/netbeans/modules/maven/Maven2Icon.gif"); //NOI18N + } + return null; + } + public Project loadProject(FileObject fileObject, ProjectState projectState) throws IOException { @@ -112,7 +121,5 @@ public void saveProject(Project project) throws IOException { // what to do here?? - } - - + } } diff -r 256bfef65ab4 -r c682e4092760 projectapi/src/org/netbeans/api/project/ProjectManager.java --- a/projectapi/src/org/netbeans/api/project/ProjectManager.java Tue Nov 25 17:17:42 2008 -0800 +++ b/projectapi/src/org/netbeans/api/project/ProjectManager.java Wed Nov 26 11:24:35 2008 +0100 @@ -54,10 +54,12 @@ import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; +import javax.swing.Icon; import org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation; import org.netbeans.modules.projectapi.TimedWeakReference; import org.netbeans.spi.project.FileOwnerQueryImplementation; import org.netbeans.spi.project.ProjectFactory; +import org.netbeans.spi.project.ProjectFactory2; import org.netbeans.spi.project.ProjectState; import org.openide.filesystems.FileChangeAdapter; import org.openide.filesystems.FileChangeListener; @@ -65,6 +67,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; +import org.openide.util.ImageUtilities; import org.openide.util.Lookup; import org.openide.util.LookupEvent; import org.openide.util.LookupListener; @@ -388,6 +391,10 @@ * @throws IllegalArgumentException if the supplied file object is null or not a folder */ public boolean isProject(final FileObject projectDirectory) throws IllegalArgumentException { + return isProject2(projectDirectory) != null; + } + + public Result isProject2(final FileObject projectDirectory) throws IllegalArgumentException { if (projectDirectory == null) { throw new IllegalArgumentException("Attempted to pass a null directory to isProject"); // NOI18N } @@ -397,11 +404,11 @@ if (projectDirectory.isValid()) { throw new IllegalArgumentException("Attempted to pass a non-directory to isProject: " + projectDirectory); // NOI18N } else { - return false; + return null; } } - return mutex().readAccess(new Mutex.Action() { - public Boolean run() { + return mutex().readAccess(new Mutex.Action() { + public Result run() { synchronized (dir2Proj) { Union2,LoadStatus> o; do { @@ -416,26 +423,27 @@ } while (LoadStatus.LOADING_PROJECT.is(o)); assert !LoadStatus.LOADING_PROJECT.is(o); if (LoadStatus.NO_SUCH_PROJECT.is(o)) { - return false; + return null; } else if (o != null) { // Reference or SOME_SUCH_PROJECT - return true; + // rather check for result than load project and lookup projectInformation for icon. + return checkForProject(projectDirectory); } // Not in cache. dir2Proj.put(projectDirectory, LoadStatus.LOADING_PROJECT.wrap()); } boolean resetLP = false; try { - boolean p = checkForProject(projectDirectory); + Result p = checkForProject(projectDirectory); synchronized (dir2Proj) { resetLP = true; dir2Proj.notifyAll(); - if (p) { + if (p != null) { dir2Proj.put(projectDirectory, LoadStatus.SOME_SUCH_PROJECT.wrap()); - return true; + return p; } else { dir2Proj.put(projectDirectory, LoadStatus.NO_SUCH_PROJECT.wrap()); - return false; + return null; } } } finally { @@ -449,18 +457,25 @@ }); } - private boolean checkForProject(FileObject dir) { + private Result checkForProject(FileObject dir) { assert dir != null; assert dir.isFolder() : dir; assert mutex().isReadAccess(); - Iterator it = factories.allInstances().iterator(); + Iterator it = factories.allInstances().iterator(); while (it.hasNext()) { - ProjectFactory factory = (ProjectFactory)it.next(); - if (factory.isProject(dir)) { - return true; + ProjectFactory factory = it.next(); + if (factory instanceof ProjectFactory2) { + Result res = ((ProjectFactory2)factory).isProject2(dir); + if (res != null) { + return res; + } + } else { + if (factory.isProject(dir)) { + return new Result((String)null); + } } } - return false; + return null; } /** @@ -671,5 +686,28 @@ } } + + public static final class Result { + private Icon icon; + private String path; + + public Result(String iconpath) { + path = iconpath; + } + + public Result(Icon icon) { + this.icon = icon; + } + + public Icon getIcon() { + if (icon == null) { + if (path != null) { + icon = ImageUtilities.image2Icon(ImageUtilities.loadImage(path)); + } + } + return icon; + } + } + } diff -r 256bfef65ab4 -r c682e4092760 projectui/src/org/netbeans/modules/project/ui/ProjectChooserAccessory.java --- a/projectui/src/org/netbeans/modules/project/ui/ProjectChooserAccessory.java Tue Nov 25 17:17:42 2008 -0800 +++ b/projectui/src/org/netbeans/modules/project/ui/ProjectChooserAccessory.java Wed Nov 26 11:24:35 2008 +0100 @@ -387,6 +387,16 @@ return OpenProjectList.fileToProject( dir ); } + private static ProjectManager.Result getProjectResult(File dir) { + FileObject fo = FileUtil.toFileObject(dir); + if (fo != null && /* #60518 */ fo.isFolder()) { + return ProjectManager.getDefault().isProject2(fo); + } else { + return null; + } + + } + private void setAccessoryEnablement( boolean enable, int numberOfProjects ) { jLabelProjectName.setEnabled( enable ); jTextFieldProjectName.setEnabled( enable ); @@ -605,10 +615,19 @@ } public void run() { - Project p = OpenProjectList.fileToProject(lookingForIcon); + ProjectManager.Result r = getProjectResult(lookingForIcon); Icon icon; - if (p != null) { - icon = ProjectUtils.getInformation(p).getIcon(); + if (r != null) { + icon = r.getIcon(); + if (icon == null) { + Project p = getProject(lookingForIcon); + if (p != null) { + icon = ProjectUtils.getInformation(p).getIcon(); + } else { + // Could also badge with an error icon: + icon = chooser.getFileSystemView().getSystemIcon(lookingForIcon); + } + } } else { // Could also badge with an error icon: icon = chooser.getFileSystemView().getSystemIcon(lookingForIcon); diff -r 256bfef65ab4 -r c682e4092760 projectui/src/org/netbeans/modules/project/ui/actions/OpenProject.java --- a/projectui/src/org/netbeans/modules/project/ui/actions/OpenProject.java Tue Nov 25 17:17:42 2008 -0800 +++ b/projectui/src/org/netbeans/modules/project/ui/actions/OpenProject.java Wed Nov 26 11:24:35 2008 +0100 @@ -49,7 +49,6 @@ import javax.swing.SwingUtilities; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; -import org.netbeans.api.project.ui.OpenProjects; import org.netbeans.modules.project.ui.OpenProjectList; import org.netbeans.modules.project.ui.OpenProjectListSettings; import org.netbeans.modules.project.ui.ProjectChooserAccessory;