1 19 20 package org.netbeans.modules.project.ui.groups; 21 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 import java.util.Set ; 25 import java.util.logging.Level ; 26 import java.util.logging.Logger ; 27 import java.util.prefs.Preferences ; 28 import org.netbeans.api.progress.ProgressHandle; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.api.project.ProjectUtils; 31 import org.netbeans.spi.project.SubprojectProvider; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileStateInvalidException; 34 import org.openide.filesystems.URLMapper; 35 36 40 public class SubprojectsGroup extends Group { 41 42 private static final Logger LOG = Logger.getLogger(SubprojectsGroup.class.getName()); 43 44 static final String KIND = "subprojects"; 46 52 public static SubprojectsGroup create(Project project) throws FileStateInvalidException { 53 String path = project.getProjectDirectory().getURL().toExternalForm(); 54 String id = sanitizeNameAndUniquifyForId(ProjectUtils.getInformation(project).getName()); 55 LOG.log(Level.FINE, "Creating: {0}", id); 56 Preferences p = NODE.node(id); 57 p.put(KEY_KIND, KIND); 58 p.put(KEY_PATH, path); 59 p.put(KEY_MAIN, path); 60 return new SubprojectsGroup(id); 61 } 62 63 SubprojectsGroup(String id) { 64 super(id); 65 } 66 67 @Override 68 protected String getNameOrNull() { 69 String n = super.getNameOrNull(); 70 if (n == null) { 71 Project p = projectForPath(prefs().get(KEY_PATH, null)); 72 if (p != null) { 73 return ProjectUtils.getInformation(p).getDisplayName(); 74 } 75 } 76 return n; 77 } 78 79 protected void findProjects(Set <Project> projects, ProgressHandle h, int start, int end) { 80 Project p = projectForPath(prefs().get(KEY_PATH, null)); 81 if (p != null) { 82 visitSubprojects(p, projects, h, new int[] {start, end}); 83 } 84 } 85 86 private static void visitSubprojects(Project p, Set <Project> projects, ProgressHandle h, int[] startEnd) { 87 if (projects.add(p)) { 88 if (h != null) { 89 h.progress(progressMessage(p), Math.min(++startEnd[0], startEnd[1])); 90 } 91 SubprojectProvider spp = p.getLookup().lookup(SubprojectProvider.class); 92 if (spp != null) { 93 for (Project p2 : spp.getSubprojects()) { 94 visitSubprojects(p2, projects, h, startEnd); 95 } 96 } 97 } 98 } 99 100 public FileObject getMasterProjectDirectory() { 101 String p = prefs().get(KEY_PATH, null); 102 if (p != null && p.length() > 0) { 103 try { 104 return URLMapper.findFileObject(new URL (p)); 105 } catch (MalformedURLException x) { 106 LOG.log(Level.WARNING, null, x); 107 } 108 } 109 return null; 110 } 111 112 public GroupEditPanel createPropertiesPanel() { 113 return new SubprojectsGroupEditPanel(this); 114 } 115 116 } 117 | Popular Tags |