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 171092
Collapse All | Expand All

(-)a/core.startup/src/org/netbeans/core/startup/layers/SystemFileSystem.java (-121 / +3 lines)
Lines 41-60 Link Here
41
41
42
package org.netbeans.core.startup.layers;
42
package org.netbeans.core.startup.layers;
43
43
44
import java.awt.Image;
45
import java.awt.Toolkit;
46
import java.beans.BeanInfo;
47
import java.beans.PropertyVetoException;
44
import java.beans.PropertyVetoException;
48
import java.io.File;
45
import java.io.File;
49
import java.io.IOException;
46
import java.io.IOException;
50
import java.io.NotSerializableException;
47
import java.io.NotSerializableException;
51
import java.io.ObjectStreamException;
48
import java.io.ObjectStreamException;
52
import java.io.Serializable;
49
import java.io.Serializable;
53
import java.net.URL;
54
import java.util.Arrays;
55
import java.util.HashSet;
50
import java.util.HashSet;
56
import java.util.MissingResourceException;
57
import java.util.ResourceBundle;
58
import java.util.Set;
51
import java.util.Set;
59
import java.util.logging.Level;
52
import java.util.logging.Level;
60
import java.util.logging.LogRecord;
53
import java.util.logging.LogRecord;
Lines 70-77 Link Here
70
import org.openide.filesystems.FileUtil;
63
import org.openide.filesystems.FileUtil;
71
import org.openide.filesystems.LocalFileSystem;
64
import org.openide.filesystems.LocalFileSystem;
72
import org.openide.filesystems.MultiFileSystem;
65
import org.openide.filesystems.MultiFileSystem;
66
import org.openide.filesystems.Repository;
73
import org.openide.util.Exceptions;
67
import org.openide.util.Exceptions;
74
import org.openide.util.ImageUtilities;
75
import org.openide.util.NbBundle;
68
import org.openide.util.NbBundle;
76
69
77
/** The system FileSystem - represents system files under $NETBEANS_HOME/system.
70
/** The system FileSystem - represents system files under $NETBEANS_HOME/system.
Lines 79-85 Link Here
79
* @author Jan Jancura, Ian Formanek, Petr Hamernik
72
* @author Jan Jancura, Ian Formanek, Petr Hamernik
80
*/
73
*/
81
public final class SystemFileSystem extends MultiFileSystem 
74
public final class SystemFileSystem extends MultiFileSystem 
82
implements FileSystem.Status, FileChangeListener {
75
implements FileChangeListener {
83
    // Must be public for BeanInfo to work: #11186.
76
    // Must be public for BeanInfo to work: #11186.
84
77
85
    /** generated Serialized Version UID */
78
    /** generated Serialized Version UID */
Lines 88-101 Link Here
88
    /** system name of this filesystem */
81
    /** system name of this filesystem */
89
    private static final String SYSTEM_NAME = "SystemFileSystem"; // NOI18N
82
    private static final String SYSTEM_NAME = "SystemFileSystem"; // NOI18N
90
83
91
    /** name of file attribute with localizing bundle */
92
    private static final String ATTR_BUNDLE = "SystemFileSystem.localizingBundle"; // NOI18N
93
94
    /** name of file attribute with URL to 16x16 color icon */
95
    private static final String ATTR_ICON_16 = "SystemFileSystem.icon"; // NOI18N
96
    /** name of file attribute with URL to 32x32 color icon */
97
    private static final String ATTR_ICON_32 = "SystemFileSystem.icon32"; // NOI18N
98
99
    private static final Logger LOG = Logger.getLogger(SystemFileSystem.class.getName());
84
    private static final Logger LOG = Logger.getLogger(SystemFileSystem.class.getName());
100
85
101
    /** user fs */
86
    /** user fs */
Lines 189-300 Link Here
189
    }
174
    }
190
175
191
    public @Override FileSystem.Status getStatus() {
176
    public @Override FileSystem.Status getStatus() {
192
        return this;
177
        return Repository.createDefaultFileSystemStatus();
193
    }
178
    }
194
    
179
    
195
    static final String annotateName(FileObject fo) {
196
197
        String bundleName = (String) fo.getAttribute(ATTR_BUNDLE); // NOI18N
198
        if (bundleName != null) {
199
            try {
200
                bundleName = org.openide.util.Utilities.translate(bundleName);
201
                ResourceBundle b = NbBundle.getBundle(bundleName);
202
                try {
203
                    return b.getString(fo.getPath());
204
                } catch (MissingResourceException ex) {
205
                    // ignore--normal
206
                    }
207
            } catch (MissingResourceException ex) {
208
                Exceptions.attachMessage(ex, warningMessage(bundleName, fo));
209
                ModuleLayeredFileSystem.err.log(Level.WARNING, null, ex);
210
                // ignore
211
            }
212
        }
213
        return (String)fo.getAttribute("displayName"); // NOI18N
214
    }
215
    private static String warningMessage(String name, FileObject fo) {
216
        Object by = fo.getAttribute("layers"); // NOI18N
217
        if (by instanceof Object[]) {
218
            by = Arrays.toString((Object[])by);
219
        }
220
        return "Cannot load " + name + " for " + fo + " defined by " + by; // NOI18N
221
    }
222
223
    /** Annotate name
224
    */
225
    public String annotateName(String s, Set<? extends FileObject> files) {
226
227
        // Look for a localized file name.
228
        // Note: all files in the set are checked. But please only place the attribute
229
        // on the primary file, and use this primary file name as the bundle key.
230
        for (FileObject fo : files) {
231
            // annotate a name
232
            String displayName = annotateName(fo);
233
            if (displayName != null) {
234
                return displayName;
235
            }
236
        }
237
238
        return s;
239
    }
240
    
241
    static Image annotateIcon(FileObject fo, int type) {
242
        String attr = null;
243
        if (type == BeanInfo.ICON_COLOR_16x16) {
244
            attr = ATTR_ICON_16;
245
        } else if (type == BeanInfo.ICON_COLOR_32x32) {
246
            attr = ATTR_ICON_32;
247
        }
248
249
        if (attr != null) {
250
            Object value = fo.getAttribute(attr);
251
            if (value != null) {
252
                if (value instanceof URL) {
253
                    return Toolkit.getDefaultToolkit().getImage((URL) value);
254
                } else if (value instanceof Image) {
255
                    // #18832
256
                    return (Image) value;
257
                } else {
258
                    ModuleLayeredFileSystem.err.warning("Attribute " + attr + " on " + fo + " expected to be a URL or Image; was: " + value);
259
                }
260
            }
261
        }
262
263
        String base = (String) fo.getAttribute("iconBase"); // NOI18N
264
        if (base != null) {
265
            if (type == BeanInfo.ICON_COLOR_16x16) {
266
                return ImageUtilities.loadImage(base, true);
267
            } else if (type == BeanInfo.ICON_COLOR_32x32) {
268
                return ImageUtilities.loadImage(insertBeforeSuffix(base, "_32"), true); // NOI18N
269
            }
270
        }
271
        return null;
272
    }
273
274
    private static String insertBeforeSuffix(String path, String toInsert) {
275
        String withoutSuffix = path;
276
        String suffix = ""; // NOI18N
277
278
        if (path.lastIndexOf('.') >= 0) {
279
            withoutSuffix = path.substring(0, path.lastIndexOf('.'));
280
            suffix = path.substring(path.lastIndexOf('.'), path.length());
281
        }
282
283
        return withoutSuffix + toInsert + suffix;
284
    }
285
286
    /** Annotate icon
287
    */
288
    public Image annotateIcon(Image im, int type, Set<? extends FileObject> files) {
289
        for (FileObject fo : files) {
290
            Image img = annotateIcon(fo, type);
291
            if (img != null) {
292
                return img;
293
            }
294
        }
295
        return im;
296
    }
297
298
    /** Initializes and creates new repository. This repository's system fs is
180
    /** Initializes and creates new repository. This repository's system fs is
299
    * based on the content of ${HOME_DIR}/system and ${USER_DIR}/system directories
181
    * based on the content of ${HOME_DIR}/system and ${USER_DIR}/system directories
300
    *
182
    *
(-)a/core.startup/test/unit/src/org/netbeans/core/startup/layers/CacheManagerTestBaseHid.java (-3 / +6 lines)
Lines 48-53 Link Here
48
import java.io.InputStream;
48
import java.io.InputStream;
49
import java.net.URL;
49
import java.net.URL;
50
import java.util.Arrays;
50
import java.util.Arrays;
51
import java.util.Collections;
51
import java.util.List;
52
import java.util.List;
52
import java.util.Map;
53
import java.util.Map;
53
import org.netbeans.junit.NbTestCase;
54
import org.netbeans.junit.NbTestCase;
Lines 55-60 Link Here
55
import org.openide.filesystems.FileSystem;
56
import org.openide.filesystems.FileSystem;
56
import org.openide.filesystems.FileUtil;
57
import org.openide.filesystems.FileUtil;
57
import org.openide.filesystems.MultiFileSystem;
58
import org.openide.filesystems.MultiFileSystem;
59
import org.openide.filesystems.Repository;
58
/** Test layer cache managers generally.
60
/** Test layer cache managers generally.
59
 * @author Jesse Glick
61
 * @author Jesse Glick
60
 */
62
 */
Lines 153-167 Link Here
153
        assertEquals("val/map2", attr(mfs, "foo/29356", "map2"));
155
        assertEquals("val/map2", attr(mfs, "foo/29356", "map2"));
154
        assertEquals("Ahoj", attr(mfs, "foo/29356", "mapDisplayName"));
156
        assertEquals("Ahoj", attr(mfs, "foo/29356", "mapDisplayName"));
155
157
158
        FileSystem.Status s = Repository.createDefaultFileSystemStatus();
156
        FileObject annot = f.findResource("foo/29356");
159
        FileObject annot = f.findResource("foo/29356");
157
        String annotName = SystemFileSystem.annotateName(annot);
160
        String annotName = s.annotateName(null, Collections.singleton(annot));
158
        assertEquals("Ahoj", annotName);
161
        assertEquals("Ahoj", annotName);
159
162
160
        Image img = SystemFileSystem.annotateIcon(annot, BeanInfo.ICON_COLOR_16x16);
163
        Image img = s.annotateIcon(null, BeanInfo.ICON_COLOR_16x16, Collections.singleton(annot));
161
        assertNotNull("Icon provided", img);
164
        assertNotNull("Icon provided", img);
162
        assertEquals("height", 16, img.getHeight(this));
165
        assertEquals("height", 16, img.getHeight(this));
163
        assertEquals("width", 16, img.getHeight(this));
166
        assertEquals("width", 16, img.getHeight(this));
164
        Image img32 = SystemFileSystem.annotateIcon(annot, BeanInfo.ICON_COLOR_32x32);
167
        Image img32 = s.annotateIcon(null, BeanInfo.ICON_COLOR_32x32, Collections.singleton(annot));
165
        assertNotNull("Icon 32 provided", img32);
168
        assertNotNull("Icon 32 provided", img32);
166
        assertEquals("height", 32, img32.getHeight(this));
169
        assertEquals("height", 32, img32.getHeight(this));
167
        assertEquals("width", 32, img32.getHeight(this));
170
        assertEquals("width", 32, img32.getHeight(this));
(-)a/openide.filesystems/src/org/openide/filesystems/Repository.java (+139 lines)
Lines 41-46 Link Here
41
41
42
package org.openide.filesystems;
42
package org.openide.filesystems;
43
43
44
import java.awt.Image;
45
import java.awt.Toolkit;
46
import java.beans.BeanInfo;
44
import java.beans.PropertyChangeEvent;
47
import java.beans.PropertyChangeEvent;
45
import java.beans.PropertyChangeListener;
48
import java.beans.PropertyChangeListener;
46
import java.beans.PropertyVetoException;
49
import java.beans.PropertyVetoException;
Lines 54-72 Link Here
54
import java.io.Serializable;
57
import java.io.Serializable;
55
import java.net.URL;
58
import java.net.URL;
56
import java.util.ArrayList;
59
import java.util.ArrayList;
60
import java.util.Arrays;
57
import java.util.Enumeration;
61
import java.util.Enumeration;
58
import java.util.HashSet;
62
import java.util.HashSet;
59
import java.util.Hashtable;
63
import java.util.Hashtable;
60
import java.util.Iterator;
64
import java.util.Iterator;
61
import java.util.List;
65
import java.util.List;
66
import java.util.MissingResourceException;
67
import java.util.ResourceBundle;
68
import java.util.Set;
62
import java.util.Vector;
69
import java.util.Vector;
63
import java.util.concurrent.atomic.AtomicReference;
70
import java.util.concurrent.atomic.AtomicReference;
64
import java.util.jar.Manifest;
71
import java.util.jar.Manifest;
65
import java.util.logging.Level;
72
import java.util.logging.Level;
66
import java.util.logging.Logger;
73
import java.util.logging.Logger;
74
import org.openide.filesystems.FileSystem.Status;
75
import org.openide.util.Exceptions;
76
import org.openide.util.ImageUtilities;
67
import org.openide.util.Lookup;
77
import org.openide.util.Lookup;
68
import org.openide.util.LookupEvent;
78
import org.openide.util.LookupEvent;
69
import org.openide.util.LookupListener;
79
import org.openide.util.LookupListener;
80
import org.openide.util.NbBundle;
70
import org.openide.util.NbCollections;
81
import org.openide.util.NbCollections;
71
import org.openide.util.io.NbMarshalledObject;
82
import org.openide.util.io.NbMarshalledObject;
72
83
Lines 198-203 Link Here
198
        public void resultChanged(LookupEvent ev) {
209
        public void resultChanged(LookupEvent ev) {
199
            setDelegates(computeDelegates());
210
            setDelegates(computeDelegates());
200
        }
211
        }
212
213
        public @Override Status getStatus() {
214
            return createDefaultFileSystemStatus();
215
        }
216
201
    } // end of MainFS
217
    } // end of MainFS
202
218
203
    static final long serialVersionUID = -6344768369160069704L;
219
    static final long serialVersionUID = -6344768369160069704L;
Lines 820-823 Link Here
820
            return getDefault();
836
            return getDefault();
821
        }
837
        }
822
    }
838
    }
839
840
    /**
841
     * Factory for a standard implementation of name/icon annotation for the system filesystem.
842
     * Intended for use from core, not modules.
843
     * @return a status object suitable for {@link FileSystem#getStatus()}
844
     * @since XXX
845
     */
846
    public static FileSystem.Status createDefaultFileSystemStatus() {
847
        return new SFSStatus();
848
    }
849
    private static final class SFSStatus implements FileSystem.Status {
850
        /** name of file attribute with localizing bundle */
851
        private static final String ATTR_BUNDLE = "SystemFileSystem.localizingBundle"; // NOI18N
852
        /** name of file attribute with URL to 16x16 color icon */
853
        private static final String ATTR_ICON_16 = "SystemFileSystem.icon"; // NOI18N
854
        /** name of file attribute with URL to 32x32 color icon */
855
        private static final String ATTR_ICON_32 = "SystemFileSystem.icon32"; // NOI18N
856
857
        static final String annotateName(FileObject fo) {
858
859
            String bundleName = (String) fo.getAttribute(ATTR_BUNDLE); // NOI18N
860
            if (bundleName != null) {
861
                try {
862
                    bundleName = org.openide.util.Utilities.translate(bundleName);
863
                    ResourceBundle b = NbBundle.getBundle(bundleName);
864
                    try {
865
                        return b.getString(fo.getPath());
866
                    } catch (MissingResourceException ex) {
867
                        // ignore--normal
868
                    }
869
                } catch (MissingResourceException ex) {
870
                    Exceptions.attachMessage(ex, warningMessage(bundleName, fo));
871
                    LOG.log(Level.WARNING, null, ex);
872
                    // ignore
873
                }
874
            }
875
            return (String) fo.getAttribute("displayName"); // NOI18N
876
        }
877
878
        private static String warningMessage(String name, FileObject fo) {
879
            Object by = fo.getAttribute("layers"); // NOI18N
880
            if (by instanceof Object[]) {
881
                by = Arrays.toString((Object[]) by);
882
            }
883
            return "Cannot load " + name + " for " + fo + " defined by " + by; // NOI18N
884
        }
885
886
        /** Annotate name
887
         */
888
        public String annotateName(String s, Set<? extends FileObject> files) {
889
890
            // Look for a localized file name.
891
            // Note: all files in the set are checked. But please only place the attribute
892
            // on the primary file, and use this primary file name as the bundle key.
893
            for (FileObject fo : files) {
894
                // annotate a name
895
                String displayName = annotateName(fo);
896
                if (displayName != null) {
897
                    return displayName;
898
                }
899
            }
900
901
            return s;
902
        }
903
904
        static Image annotateIcon(FileObject fo, int type) {
905
            String attr = null;
906
            if (type == BeanInfo.ICON_COLOR_16x16) {
907
                attr = ATTR_ICON_16;
908
            } else if (type == BeanInfo.ICON_COLOR_32x32) {
909
                attr = ATTR_ICON_32;
910
            }
911
912
            if (attr != null) {
913
                Object value = fo.getAttribute(attr);
914
                if (value != null) {
915
                    if (value instanceof URL) {
916
                        return Toolkit.getDefaultToolkit().getImage((URL) value);
917
                    } else if (value instanceof Image) {
918
                        // #18832
919
                        return (Image) value;
920
                    } else {
921
                        LOG.warning("Attribute " + attr + " on " + fo + " expected to be a URL or Image; was: " + value);
922
                    }
923
                }
924
            }
925
926
            String base = (String) fo.getAttribute("iconBase"); // NOI18N
927
            if (base != null) {
928
                if (type == BeanInfo.ICON_COLOR_16x16) {
929
                    return ImageUtilities.loadImage(base, true);
930
                } else if (type == BeanInfo.ICON_COLOR_32x32) {
931
                    return ImageUtilities.loadImage(insertBeforeSuffix(base, "_32"), true); // NOI18N
932
                }
933
            }
934
            return null;
935
        }
936
937
        private static String insertBeforeSuffix(String path, String toInsert) {
938
            String withoutSuffix = path;
939
            String suffix = ""; // NOI18N
940
941
            if (path.lastIndexOf('.') >= 0) {
942
                withoutSuffix = path.substring(0, path.lastIndexOf('.'));
943
                suffix = path.substring(path.lastIndexOf('.'), path.length());
944
            }
945
946
            return withoutSuffix + toInsert + suffix;
947
        }
948
949
        /** Annotate icon
950
         */
951
        public Image annotateIcon(Image im, int type, Set<? extends FileObject> files) {
952
            for (FileObject fo : files) {
953
                Image img = annotateIcon(fo, type);
954
                if (img != null) {
955
                    return img;
956
                }
957
            }
958
            return im;
959
        }
960
    }
961
823
}
962
}
(-)a/openide.filesystems/test/unit/src/org/openide/filesystems/RepositoryTest.java (+10 lines)
Lines 51-56 Link Here
51
import java.net.URLConnection;
51
import java.net.URLConnection;
52
import java.net.URLStreamHandler;
52
import java.net.URLStreamHandler;
53
import java.util.Arrays;
53
import java.util.Arrays;
54
import java.util.Collections;
54
import java.util.Enumeration;
55
import java.util.Enumeration;
55
import java.util.concurrent.atomic.AtomicInteger;
56
import java.util.concurrent.atomic.AtomicInteger;
56
import java.util.concurrent.atomic.AtomicReference;
57
import java.util.concurrent.atomic.AtomicReference;
Lines 193-196 Link Here
193
        os.close();
194
        os.close();
194
    }
195
    }
195
196
197
    public void testStatus() throws Exception {
198
        FileObject r = FileUtil.getConfigRoot();
199
        FileSystem.Status s = r.getFileSystem().getStatus();
200
        FileObject f = r.createData("f");
201
        f.setAttribute("displayName", "F!");
202
        assertEquals("F!", s.annotateName("f", Collections.singleton(f)));
203
        // XXX test SystemFileSystem.localizingBundle, iconBase, SystemFileSystem.icon
204
    }
205
196
}
206
}
(-)a/projectuiapi/test/unit/src/org/netbeans/spi/project/ui/support/ProjectCustomizerTest.java (-4 lines)
Lines 125-133 Link Here
125
        assertEquals("One", categories[0].getDisplayName());
125
        assertEquals("One", categories[0].getDisplayName());
126
        assertEquals("one", dcp.create(categories[0]).getName());
126
        assertEquals("one", dcp.create(categories[0]).getName());
127
        assertEquals("Category1", categories[1].getName());
127
        assertEquals("Category1", categories[1].getName());
128
        /* XXX does not work yet because ExternalUtil.MainFS does not provide a FS.Status:
129
        assertEquals("Category #1", categories[1].getDisplayName());
128
        assertEquals("Category #1", categories[1].getDisplayName());
130
         */
131
        assertEquals("two", dcp.create(categories[1]).getName());
129
        assertEquals("two", dcp.create(categories[1]).getName());
132
        Category[] subcategories = categories[1].getSubcategories();
130
        Category[] subcategories = categories[1].getSubcategories();
133
        assertEquals(1, subcategories.length);
131
        assertEquals(1, subcategories.length);
Lines 135-143 Link Here
135
        assertEquals("Three", subcategories[0].getDisplayName());
133
        assertEquals("Three", subcategories[0].getDisplayName());
136
        assertEquals("three", dcp.create(subcategories[0]).getName());
134
        assertEquals("three", dcp.create(subcategories[0]).getName());
137
        assertEquals("Category2", categories[2].getName());
135
        assertEquals("Category2", categories[2].getName());
138
        /*
139
        assertEquals("Category #2", categories[2].getDisplayName());
136
        assertEquals("Category #2", categories[2].getDisplayName());
140
         */
141
        assertEquals(null, dcp.create(categories[2]).getName());
137
        assertEquals(null, dcp.create(categories[2]).getName());
142
        subcategories = categories[2].getSubcategories();
138
        subcategories = categories[2].getSubcategories();
143
        assertEquals(1, subcategories.length);
139
        assertEquals(1, subcategories.length);

Return to bug 171092