Index: core/startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java =================================================================== RCS file: /cvs/core/startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java,v retrieving revision 1.1 diff -u -r1.1 SystemFileSystem.java --- core/startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java 4 Jun 2005 05:11:59 -0000 1.1 +++ core/startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java 20 Oct 2005 07:31:29 -0000 @@ -34,7 +34,8 @@ * * @author Jan Jancura, Ian Formanek, Petr Hamernik */ -public final class SystemFileSystem extends MultiFileSystem implements FileSystem.Status { +public final class SystemFileSystem extends MultiFileSystem +implements FileSystem.Status, org.openide.util.LookupListener { // Must be public for BeanInfo to work: #11186. /** generated Serialized Version UID */ @@ -55,6 +56,11 @@ /** name of file attribute with URL to 32x32 color icon */ private static final String ATTR_ICON_32 = "SystemFileSystem.icon32"; // NOI18N + /** lookup result we listen on */ + private static Lookup.Result result = Lookup.getDefault ().lookup (new Lookup.Template (FileSystem.class)); + /** the set of layers provided by the system */ + private static FileSystem[] layers; + /** user fs */ private ModuleLayeredFileSystem user; /** home fs */ @@ -67,13 +73,15 @@ /** @param fss list of file systems to delegate to */ - private SystemFileSystem (FileSystem[] fss) throws PropertyVetoException { - super (fss); - user = (ModuleLayeredFileSystem) fss[0]; - home = fss.length > 2 ? (ModuleLayeredFileSystem) fss[1] : null; + private SystemFileSystem () throws PropertyVetoException { + super (computeLayers ()); + user = (ModuleLayeredFileSystem) layers[0]; + home = layers.length > 2 ? (ModuleLayeredFileSystem) layers[1] : null; setSystemName (SYSTEM_NAME); setHidden (true); + + result.addLookupListener (this); } @@ -107,8 +115,9 @@ else s.add (arr[i]); + layers = (FileSystem []) arr.clone (); // create own internal copy of passed filesystems - setDelegates ((FileSystem []) arr.clone ()); + setDelegates (computeLayers ()); firePropertyChange ("layers", null, null); // NOI18N } @@ -121,6 +130,19 @@ // don't return reference to internal buffer return (FileSystem []) getDelegates ().clone (); } + + private synchronized static FileSystem[] computeLayers () { + FileSystem[] fromLookup = (FileSystem[])result.allInstances ().toArray (new FileSystem[0]); + + if (fromLookup.length > 0) { + ArrayList arr = new ArrayList (layers.length + fromLookup.length); + arr.addAll (Arrays.asList (layers)); + arr.addAll (Arrays.asList (fromLookup)); + return (FileSystem[])arr.toArray (new FileSystem[0]); + } + + return layers; + } protected FileSystem createWritableOnForRename (String oldName, String newName) throws IOException { return createWritableOn (oldName); @@ -318,7 +340,8 @@ ("org.netbeans.core.projects.FixedFileSystem", "Automatic Manifest Installation"); // NOI18N arr[home == null ? 1 : 2] = FixedFileSystem.deflt; - return new SystemFileSystem (arr); + layers = arr; + return new SystemFileSystem (); } /** Getter for message. @@ -357,6 +380,12 @@ new NotSerializableException ("WARNING - SystemFileSystem is not designed to be serialized").printStackTrace (); // NOI18N return new SingletonSerializer (); } + + /** Refresh layers */ + public synchronized void resultChanged (org.openide.util.LookupEvent ev) { + setDelegates (computeLayers ()); + } + private static final class SingletonSerializer extends Object implements Serializable { private static final long serialVersionUID = 6436781994611L; SingletonSerializer() {} Index: core/test/unit/src/org/netbeans/core/projects/SystemFileSystemTest.java =================================================================== RCS file: /cvs/core/test/unit/src/org/netbeans/core/projects/SystemFileSystemTest.java,v retrieving revision 1.4 diff -u -r1.4 SystemFileSystemTest.java --- core/test/unit/src/org/netbeans/core/projects/SystemFileSystemTest.java 4 Jun 2005 05:15:56 -0000 1.4 +++ core/test/unit/src/org/netbeans/core/projects/SystemFileSystemTest.java 20 Oct 2005 07:31:29 -0000 @@ -89,6 +89,21 @@ assertEquals("correct localized data object name", "Localized Name", n.getDisplayName()); } + public void testContentOfFileSystemIsInfluencedByLookup () throws Exception { + MemoryFileSystem mem = new MemoryFileSystem (); + String dir = "/yarda/own/file"; + org.openide.filesystems.FileUtil.createFolder (mem.getRoot (), dir); + + assertNull ("File is not there yet", Repository.getDefault ().getDefaultFileSystem ().findResource (dir)); + NbTopManager.get().register (mem); + try { + assertNotNull ("The file is there now", Repository.getDefault ().getDefaultFileSystem ().findResource (dir)); + } finally { + NbTopManager.get().unregister (mem); + } + assertNull ("File is no longer there", Repository.getDefault ().getDefaultFileSystem ().findResource (dir)); + } + public void testIconFromURL() throws Exception { FileObject bar = Repository.getDefault().getDefaultFileSystem().findResource("foo/bar.txt"); Node n = DataObject.find(bar).getNodeDelegate();