This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 26338
Collapse All | Expand All

(-)src/org/netbeans/core/projects/SystemFileSystem.java (-7 / +36 lines)
Lines 37-43 Link Here
37
*
37
*
38
* @author Jan Jancura, Ian Formanek, Petr Hamernik
38
* @author Jan Jancura, Ian Formanek, Petr Hamernik
39
*/
39
*/
40
public final class SystemFileSystem extends MultiFileSystem implements FileSystem.Status {
40
public final class SystemFileSystem extends MultiFileSystem 
41
implements FileSystem.Status, org.openide.util.LookupListener {
41
    // Must be public for BeanInfo to work: #11186.
42
    // Must be public for BeanInfo to work: #11186.
42
43
43
    /** generated Serialized Version UID */
44
    /** generated Serialized Version UID */
Lines 59-64 Link Here
59
    private static final String ATTR_ICON_32 = "SystemFileSystem.icon32"; // NOI18N
60
    private static final String ATTR_ICON_32 = "SystemFileSystem.icon32"; // NOI18N
60
    /** name of the layer where changed file will be stored, default is session */
61
    /** name of the layer where changed file will be stored, default is session */
61
    static final String ATTR_LAYER = "SystemFileSystem.layer"; // NOI18N
62
    static final String ATTR_LAYER = "SystemFileSystem.layer"; // NOI18N
63
    /** lookup result we listen on */
64
    private static Lookup.Result result = Lookup.getDefault ().lookup (new Lookup.Template (FileSystem.class));
65
    /** the set of layers provided by the system */
66
    private static FileSystem[] layers;
67
62
68
63
    /** user fs */
69
    /** user fs */
64
    private ModuleLayeredFileSystem user;
70
    private ModuleLayeredFileSystem user;
Lines 72-84 Link Here
72
78
73
    /** @param fss list of file systems to delegate to
79
    /** @param fss list of file systems to delegate to
74
    */
80
    */
75
    private SystemFileSystem (FileSystem[] fss) throws PropertyVetoException {
81
    private SystemFileSystem () throws PropertyVetoException {
76
        super (fss);
82
        super (computeLayers ());
77
        user = (ModuleLayeredFileSystem) fss[0];
83
        user = (ModuleLayeredFileSystem) layers[0];
78
        home = fss.length > 2 ? (ModuleLayeredFileSystem) fss[1] : null;
84
        home = layers.length > 2 ? (ModuleLayeredFileSystem) layers[1] : null;
79
85
80
        setSystemName (SYSTEM_NAME);
86
        setSystemName (SYSTEM_NAME);
81
        setHidden (true);
87
        setHidden (true);
88
        
89
        result.addLookupListener (this);
82
    }
90
    }
83
91
84
92
Lines 112-119 Link Here
112
            else
120
            else
113
                s.add (arr[i]);
121
                s.add (arr[i]);
114
122
123
        layers = (FileSystem []) arr.clone ();
115
        // create own internal copy of passed filesystems
124
        // create own internal copy of passed filesystems
116
        setDelegates ((FileSystem []) arr.clone ());
125
        setDelegates (computeLayers ());
117
        firePropertyChange ("layers", null, null); // NOI18N
126
        firePropertyChange ("layers", null, null); // NOI18N
118
    }
127
    }
119
    
128
    
Lines 126-131 Link Here
126
        // don't return reference to internal buffer
135
        // don't return reference to internal buffer
127
        return (FileSystem []) getDelegates ().clone ();
136
        return (FileSystem []) getDelegates ().clone ();
128
    }
137
    }
138
    
139
    private synchronized static FileSystem[] computeLayers () {
140
        FileSystem[] fromLookup = (FileSystem[])result.allInstances ().toArray (new FileSystem[0]);
141
        
142
        if (fromLookup.length > 0) {
143
            ArrayList arr = new ArrayList (layers.length + fromLookup.length);
144
            arr.addAll (Arrays.asList (layers));
145
            arr.addAll (Arrays.asList (fromLookup));
146
            return (FileSystem[])arr.toArray (new FileSystem[0]);
147
        }
148
        
149
        return layers;
150
    }
129
151
130
    private final static ThreadLocal newFiles = new ThreadLocal();
152
    private final static ThreadLocal newFiles = new ThreadLocal();
131
    /** workaround enabling create new file on other layer than target folder
153
    /** workaround enabling create new file on other layer than target folder
Lines 398-404 Link Here
398
            ("org.netbeans.core.projects.FixedFileSystem", "Automatic Manifest Installation"); // NOI18N
420
            ("org.netbeans.core.projects.FixedFileSystem", "Automatic Manifest Installation"); // NOI18N
399
        arr[home == null ? 1 : 2] = FixedFileSystem.deflt;
421
        arr[home == null ? 1 : 2] = FixedFileSystem.deflt;
400
422
401
        return new SystemFileSystem (arr);
423
        layers = arr;
424
        return new SystemFileSystem ();
402
    }
425
    }
403
426
404
    /** Getter for message.
427
    /** Getter for message.
Lines 437-442 Link Here
437
        new NotSerializableException ("WARNING - SystemFileSystem is not designed to be serialized").printStackTrace (); // NOI18N
460
        new NotSerializableException ("WARNING - SystemFileSystem is not designed to be serialized").printStackTrace (); // NOI18N
438
        return new SingletonSerializer ();
461
        return new SingletonSerializer ();
439
    }
462
    }
463
    
464
    /** Refresh layers */
465
    public synchronized void resultChanged (org.openide.util.LookupEvent ev) {
466
        setDelegates (computeLayers ());
467
    }
468
    
440
    private static final class SingletonSerializer extends Object implements Serializable {
469
    private static final class SingletonSerializer extends Object implements Serializable {
441
        private static final long serialVersionUID = 6436781994611L;
470
        private static final long serialVersionUID = 6436781994611L;
442
        SingletonSerializer() {}
471
        SingletonSerializer() {}
(-)test/unit/src/org/netbeans/core/projects/SystemFileSystemTest.java (+15 lines)
Lines 94-99 Link Here
94
        assertEquals("correct localized data object name", "Localized Name", n.getDisplayName());
94
        assertEquals("correct localized data object name", "Localized Name", n.getDisplayName());
95
    }
95
    }
96
    
96
    
97
    public void testContentOfFileSystemIsInfluencedByLookup () throws Exception {
98
        MemoryFileSystem mem = new MemoryFileSystem ();
99
        String dir = "/yarda/own/file";
100
        org.openide.filesystems.FileUtil.createFolder (mem.getRoot (), dir);
101
        
102
        assertNull ("File is not there yet", Repository.getDefault ().getDefaultFileSystem ().findResource (dir));
103
        NbTopManager.get().register (mem);
104
        try {
105
            assertNotNull ("The file is there now", Repository.getDefault ().getDefaultFileSystem ().findResource (dir));
106
        } finally {
107
            NbTopManager.get().unregister (mem);
108
        }
109
        assertNull ("File is no longer there", Repository.getDefault ().getDefaultFileSystem ().findResource (dir));
110
    }
111
    
97
    public void testIconFromURL() throws Exception {
112
    public void testIconFromURL() throws Exception {
98
        FileObject bar = Repository.getDefault().getDefaultFileSystem().findResource("foo/bar.txt");
113
        FileObject bar = Repository.getDefault().getDefaultFileSystem().findResource("foo/bar.txt");
99
        Node n = DataObject.find(bar).getNodeDelegate();
114
        Node n = DataObject.find(bar).getNodeDelegate();

Return to bug 26338