1 19 20 package org.netbeans.modules.refactoring.spi.impl; 21 22 import java.io.File ; 23 import java.util.LinkedHashSet ; 24 import java.util.Set ; 25 import org.openide.filesystems.FileChangeListener; 26 import org.openide.filesystems.FileObject; 27 import org.openide.filesystems.FileStateInvalidException; 28 import org.openide.filesystems.FileSystem; 29 import org.openide.filesystems.FileUtil; 30 31 35 36 public class Util { 37 38 45 private static FileSystem[] fileSystems; 46 47 private static FileSystem[] getFileSystems() { 48 if (fileSystems != null) { 49 return fileSystems; 50 } 51 File [] roots = File.listRoots(); 52 Set allRoots = new LinkedHashSet (); 53 assert roots != null && roots.length > 0 : "Could not list file roots"; 55 for (int i = 0; i < roots.length; i++) { 56 File root = roots[i]; 57 FileObject random = FileUtil.toFileObject(root); 58 if (random == null) continue; 59 60 FileSystem fs; 61 try { 62 fs = random.getFileSystem(); 63 allRoots.add(fs); 64 65 69 70 if (fs != null) { 71 break; 72 } 73 } catch (FileStateInvalidException e) { 74 throw new AssertionError (e); 75 } 76 } 77 FileSystem[] retVal = new FileSystem [allRoots.size()]; 78 allRoots.toArray(retVal); 79 assert retVal.length > 0 : "Could not get any filesystem"; 81 return fileSystems = retVal; 82 } 83 84 88 public static void addFileSystemsListener(FileChangeListener l) { 89 FileSystem[] fileSystems = getFileSystems(); 90 for (int i=0; i<fileSystems.length; i++) { 91 fileSystems[i].addFileChangeListener(l); 92 } 93 } 94 95 99 public static void removeFileSystemsListener(FileChangeListener l) { 100 FileSystem[] fileSystems = getFileSystems(); 101 for (int i=0; i<fileSystems.length; i++) { 102 fileSystems[i].removeFileChangeListener(l); 103 } 104 } 105 } | Popular Tags |