1 19 20 package org.netbeans.modules.project.ui.groups; 21 22 import java.io.IOException ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.util.Enumeration ; 26 import java.util.Set ; 27 import java.util.logging.Level ; 28 import java.util.logging.Logger ; 29 import java.util.prefs.Preferences ; 30 import org.netbeans.api.progress.ProgressHandle; 31 import org.netbeans.api.project.Project; 32 import org.netbeans.api.project.ProjectManager; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileStateInvalidException; 35 import org.openide.filesystems.URLMapper; 36 import org.openide.util.Exceptions; 37 38 42 public class DirectoryGroup extends Group { 43 44 private static final Logger LOG = Logger.getLogger(DirectoryGroup.class.getName()); 45 46 static final String KIND = "directory"; 48 51 public static DirectoryGroup create(String name, FileObject dir) throws FileStateInvalidException { 52 String path = dir.getURL().toExternalForm(); 53 String id = sanitizeNameAndUniquifyForId(name); 54 LOG.log(Level.FINE, "Creating: {0}", id); 55 Preferences p = NODE.node(id); 56 p.put(KEY_NAME, name); 57 p.put(KEY_KIND, KIND); 58 p.put(KEY_PATH, path); 59 return new DirectoryGroup(id); 60 } 61 62 DirectoryGroup(String id) { 63 super(id); 64 } 65 66 protected void findProjects(Set <Project> projects, ProgressHandle h, int start, int end) { 67 String dir = prefs().get(KEY_PATH, null); 68 FileObject fo = null; 69 try { 70 fo = URLMapper.findFileObject(new URL (dir)); 71 } catch (MalformedURLException x) { 72 LOG.log(Level.WARNING, null, x); 73 } 74 if (fo != null && fo.isFolder()) { 75 try { 76 Project p = ProjectManager.getDefault().findProject(fo); 77 if (p != null) { 78 projects.add(p); 79 if (h != null) { 80 h.progress(progressMessage(p), Math.min(++start, end)); 81 } 82 } 83 } catch (IOException x) { 84 Exceptions.printStackTrace(x); 85 } 86 Enumeration <? extends FileObject> e = fo.getFolders(true); 87 while (e.hasMoreElements()) { 88 try { 89 Project p = ProjectManager.getDefault().findProject(e.nextElement()); 90 if (p != null) { 91 projects.add(p); 92 if (h != null) { 93 h.progress(progressMessage(p), Math.min(++start, end)); 94 } 95 } 96 } catch (IOException x) { 97 Exceptions.printStackTrace(x); 98 } 99 } 100 } 101 } 102 103 public FileObject getDirectory() { 104 String p = prefs().get(KEY_PATH, null); 105 if (p != null && p.length() > 0) { 106 try { 107 return URLMapper.findFileObject(new URL (p)); 108 } catch (MalformedURLException x) { 109 LOG.log(Level.WARNING, null, x); 110 } 111 } 112 return null; 113 } 114 115 public GroupEditPanel createPropertiesPanel() { 116 return new DirectoryGroupEditPanel(this); 117 } 118 119 } 120 | Popular Tags |