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

(-)projects/projectui/src/org/netbeans/modules/project/ui/OpenProjectListSettings.java (-47 / +53 lines)
Lines 28-33 Link Here
28
import java.io.File;
28
import java.io.File;
29
import java.util.prefs.Preferences;
29
import java.util.prefs.Preferences;
30
import javax.swing.filechooser.FileSystemView;
30
import javax.swing.filechooser.FileSystemView;
31
import org.netbeans.modules.project.ui.groups.Group;
31
import org.openide.filesystems.FileUtil;
32
import org.openide.filesystems.FileUtil;
32
import org.openide.util.NbBundle;
33
import org.openide.util.NbBundle;
33
import org.openide.util.NbPreferences;
34
import org.openide.util.NbPreferences;
Lines 51-57 Link Here
51
    private static final String RECENT_PROJECTS_URLS = "recentProjectsURLs"; //NOI18N List of URLs
52
    private static final String RECENT_PROJECTS_URLS = "recentProjectsURLs"; //NOI18N List of URLs
52
    private static final String RECENT_TEMPLATES = "recentTemplates"; // NOI18N -List of Strings
53
    private static final String RECENT_TEMPLATES = "recentTemplates"; // NOI18N -List of Strings
53
    
54
    
54
    
55
    private OpenProjectListSettings() {
55
    private OpenProjectListSettings() {
56
    }
56
    }
57
    
57
    
Lines 59-80 Link Here
59
        return INSTANCE;
59
        return INSTANCE;
60
    }
60
    }
61
    
61
    
62
    protected final String putProperty(String key, String value, boolean notify) {
62
    private final String putProperty(String key, String value, boolean notify, boolean groupSensitive) {
63
        String retval = getProperty(key);
63
        String retval = getProperty(key, groupSensitive);
64
        if (value != null) {
64
        if (value != null) {
65
            getPreferences().put(key, value);
65
            getPreferences(groupSensitive).put(key, value);
66
        } else {
66
        } else {
67
            getPreferences().remove(key);
67
            getPreferences(groupSensitive).remove(key);
68
        }
68
        }
69
        return retval;
69
        return retval;
70
    }
70
    }
71
71
72
    protected final String getProperty(String key) {
72
    private final String getProperty(String key, boolean groupSensitive) {
73
        return getPreferences().get(key, null);
73
        return getPreferences(groupSensitive).get(key, null);
74
    }    
74
    }    
75
    
75
    
76
    protected final List<URL> getURLList(String key) {
76
    private final List<URL> getURLList(String key, boolean groupSensitive) {
77
        List<String> strs = getStringList(key);
77
        List<String> strs = getStringList(key, groupSensitive);
78
        List<URL> toRet = new ArrayList<URL>();
78
        List<URL> toRet = new ArrayList<URL>();
79
        for (String val : strs) {
79
        for (String val : strs) {
80
            try {
80
            try {
Lines 86-93 Link Here
86
        return toRet;
86
        return toRet;
87
    }
87
    }
88
    
88
    
89
    protected final List<String> getStringList(String key) {
89
    private final List<String> getStringList(String key, boolean groupSensitive) {
90
        Preferences pref = getPreferences();
90
        Preferences pref = getPreferences(groupSensitive);
91
        int count = 0;
91
        int count = 0;
92
        String val = pref.get(key + "." + count, null);
92
        String val = pref.get(key + "." + count, null);
93
        List<String> toRet = new ArrayList<String>();
93
        List<String> toRet = new ArrayList<String>();
Lines 99-106 Link Here
99
        return toRet;
99
        return toRet;
100
    }
100
    }
101
    
101
    
102
    protected final List<ExtIcon> getIconList(String key) {
102
    private final List<ExtIcon> getIconList(String key, boolean groupSensitive) {
103
        Preferences pref = getPreferences();
103
        Preferences pref = getPreferences(groupSensitive);
104
        int count = 0;
104
        int count = 0;
105
        byte[] val = pref.getByteArray(key + "." + count, null);
105
        byte[] val = pref.getByteArray(key + "." + count, null);
106
        List<ExtIcon> toRet = new ArrayList<ExtIcon>();
106
        List<ExtIcon> toRet = new ArrayList<ExtIcon>();
Lines 112-120 Link Here
112
        return toRet;
112
        return toRet;
113
    }
113
    }
114
    
114
    
115
    protected final void setIconList(String basekey, List<ExtIcon> list) throws IOException {
115
    private final void setIconList(String basekey, List<ExtIcon> list, boolean groupSensitive) throws IOException {
116
        assert list != null;
116
        assert list != null;
117
        Preferences pref = getPreferences();
117
        Preferences pref = getPreferences(groupSensitive);
118
        int count = 0;
118
        int count = 0;
119
        String key = basekey + "." + count;
119
        String key = basekey + "." + count;
120
        String val = pref.get(key, null);
120
        String val = pref.get(key, null);
Lines 131-140 Link Here
131
        }
131
        }
132
    }
132
    }
133
    
133
    
134
    
134
    private final void setStringList(String basekey, List<String> list, boolean groupSensitive) {
135
    protected final void setStringList(String basekey, List<String> list) {
136
        assert list != null;
135
        assert list != null;
137
        Preferences pref = getPreferences();
136
        Preferences pref = getPreferences(groupSensitive);
138
        int count = 0;
137
        int count = 0;
139
        String key = basekey + "." + count;
138
        String key = basekey + "." + count;
140
        String val = pref.get(key, null);
139
        String val = pref.get(key, null);
Lines 151-195 Link Here
151
        }
150
        }
152
    }
151
    }
153
    
152
    
154
    protected final void setURLList(String basekey, List<URL> list) {
153
    private final void setURLList(String basekey, List<URL> list, boolean groupSensitive) {
155
        assert list != null;
154
        assert list != null;
156
        List<String> strs = new ArrayList<String>(list.size());
155
        List<String> strs = new ArrayList<String>(list.size());
157
        for (URL url : list) {
156
        for (URL url : list) {
158
            strs.add(url.toExternalForm());
157
            strs.add(url.toExternalForm());
159
        }
158
        }
160
        setStringList(basekey, strs);
159
        setStringList(basekey, strs, groupSensitive);
161
    }
160
    }
162
    
161
    
163
    protected final Preferences getPreferences() {
162
    private final Preferences getPreferences(boolean groupSensitive) {
164
        return NbPreferences.forModule(OpenProjectListSettings.class);
163
        Preferences node = NbPreferences.forModule(OpenProjectListSettings.class);
164
        if (groupSensitive) {
165
            Group g = Group.getActiveGroup();
166
            if (g != null) {
167
                return g.prefs();
168
            }
169
        }
170
        return node;
165
    }
171
    }
166
172
167
    public List<URL> getOpenProjectsURLs() {
173
    public List<URL> getOpenProjectsURLs() {
168
        return getURLList(OPEN_PROJECTS_URLS);
174
        return getURLList(OPEN_PROJECTS_URLS, false);
169
    }
175
    }
170
176
171
    public void setOpenProjectsURLs( List<URL> list ) {
177
    public void setOpenProjectsURLs( List<URL> list ) {
172
        setURLList( OPEN_PROJECTS_URLS, list);
178
        setURLList(OPEN_PROJECTS_URLS, list, false);
173
    }
179
    }
174
    
180
    
175
    public boolean isOpenSubprojects() {        
181
    public boolean isOpenSubprojects() {        
176
        return getPreferences().getBoolean( OPEN_SUBPROJECTS, true);
182
        return getPreferences(true).getBoolean( OPEN_SUBPROJECTS, true);
177
    }
183
    }
178
    
184
    
179
    public void setOpenSubprojects( boolean openSubprojects ) {
185
    public void setOpenSubprojects( boolean openSubprojects ) {
180
        getPreferences().putBoolean(OPEN_SUBPROJECTS, openSubprojects);
186
        getPreferences(true).putBoolean(OPEN_SUBPROJECTS, openSubprojects);
181
    }
187
    }
182
    
188
    
183
    public boolean isOpenAsMain() {        
189
    public boolean isOpenAsMain() {        
184
        return getPreferences().getBoolean( OPEN_AS_MAIN, true);
190
        return getPreferences(true).getBoolean( OPEN_AS_MAIN, true);
185
    }
191
    }
186
    
192
    
187
    public void setOpenAsMain( boolean openAsMain ) {
193
    public void setOpenAsMain( boolean openAsMain ) {
188
        getPreferences().putBoolean(OPEN_AS_MAIN, openAsMain);
194
        getPreferences(true).putBoolean(OPEN_AS_MAIN, openAsMain);
189
    }
195
    }
190
    
196
    
191
    public URL getMainProjectURL() {
197
    public URL getMainProjectURL() {
192
        String str = getProperty(MAIN_PROJECT_URL);
198
        String str = getProperty(MAIN_PROJECT_URL, false);
193
        if (str != null) {
199
        if (str != null) {
194
            try {
200
            try {
195
                return new URL(str);
201
                return new URL(str);
Lines 201-211 Link Here
201
    }
207
    }
202
    
208
    
203
    public void setMainProjectURL( URL mainProjectURL ) {
209
    public void setMainProjectURL( URL mainProjectURL ) {
204
        putProperty( MAIN_PROJECT_URL, mainProjectURL != null ? mainProjectURL.toString() : null, true );
210
        putProperty(MAIN_PROJECT_URL, mainProjectURL != null ? mainProjectURL.toString() : null, true, false);
205
    }
211
    }
206
    
212
    
207
    public String getLastOpenProjectDir() {
213
    public String getLastOpenProjectDir() {
208
        String result = getProperty( LAST_OPEN_PROJECT_DIR );
214
        String result = getProperty(LAST_OPEN_PROJECT_DIR, true);
209
        if (result == null) {
215
        if (result == null) {
210
            result = getProjectsFolder(/* #89624 */false).getAbsolutePath();
216
            result = getProjectsFolder(/* #89624 */false).getAbsolutePath();
211
        }
217
        }
Lines 213-251 Link Here
213
    }
219
    }
214
    
220
    
215
    public void setLastOpenProjectDir( String path ) {
221
    public void setLastOpenProjectDir( String path ) {
216
        putProperty( LAST_OPEN_PROJECT_DIR, path, true  );
222
        putProperty(LAST_OPEN_PROJECT_DIR, path, true, true);
217
    }
223
    }
218
    
224
    
219
    public List<URL> getRecentProjectsURLs() {
225
    public List<URL> getRecentProjectsURLs() {
220
        return getURLList(RECENT_PROJECTS_URLS);
226
        return getURLList(RECENT_PROJECTS_URLS, true);
221
    }
227
    }
222
    
228
    
223
    public List<String> getRecentProjectsDisplayNames() {
229
    public List<String> getRecentProjectsDisplayNames() {
224
        return getStringList(RECENT_PROJECTS_DISPLAY_NAMES);
230
        return getStringList(RECENT_PROJECTS_DISPLAY_NAMES, true);
225
    }
231
    }
226
    
232
    
227
    public List<ExtIcon> getRecentProjectsIcons() {
233
    public List<ExtIcon> getRecentProjectsIcons() {
228
        return getIconList(RECENT_PROJECTS_DISPLAY_ICONS);
234
        return getIconList(RECENT_PROJECTS_DISPLAY_ICONS, true);
229
    }
235
    }
230
    
236
    
231
    public void setRecentProjectsURLs( List<URL> list ) {
237
    public void setRecentProjectsURLs( List<URL> list ) {
232
        setURLList(RECENT_PROJECTS_URLS, list);
238
        setURLList(RECENT_PROJECTS_URLS, list, true);
233
    }
239
    }
234
    
240
    
235
    public void setRecentProjectsDisplayNames(List<String> list) {
241
    public void setRecentProjectsDisplayNames(List<String> list) {
236
        setStringList(RECENT_PROJECTS_DISPLAY_NAMES, list);
242
        setStringList(RECENT_PROJECTS_DISPLAY_NAMES, list, true);
237
    }
243
    }
238
    
244
    
239
    public void setRecentProjectsIcons(List<ExtIcon> list) {
245
    public void setRecentProjectsIcons(List<ExtIcon> list) {
240
        try {
246
        try {
241
            setIconList(RECENT_PROJECTS_DISPLAY_ICONS, list);
247
            setIconList(RECENT_PROJECTS_DISPLAY_ICONS, list, true);
242
        } catch (IOException ex) {
248
        } catch (IOException ex) {
243
            ex.printStackTrace();
249
            ex.printStackTrace();
244
        }
250
        }
245
    }
251
    }
246
    
252
    
247
    public File getProjectsFolder(boolean create) {
253
    public File getProjectsFolder(boolean create) {
248
        String result = getProperty (PROP_PROJECTS_FOLDER);
254
        String result = getProperty(PROP_PROJECTS_FOLDER, true);
249
        if (result == null) {
255
        if (result == null) {
250
            // property for overriding default projects dir location
256
            // property for overriding default projects dir location
251
            String userPrjDir = System.getProperty("netbeans.projects.dir"); // NOI18N
257
            String userPrjDir = System.getProperty("netbeans.projects.dir"); // NOI18N
Lines 273-307 Link Here
273
279
274
    public void setProjectsFolder (File folder) {
280
    public void setProjectsFolder (File folder) {
275
        if (folder == null) {
281
        if (folder == null) {
276
            putProperty(PROP_PROJECTS_FOLDER, (String)null, true);
282
            putProperty(PROP_PROJECTS_FOLDER, (String)null, true, true);
277
        }
283
        }
278
        else {
284
        else {
279
            putProperty(PROP_PROJECTS_FOLDER, folder.getAbsolutePath(), true);
285
            putProperty(PROP_PROJECTS_FOLDER, folder.getAbsolutePath(), true, true);
280
        }
286
        }
281
    }
287
    }
282
    
288
    
283
    public List<String> getRecentTemplates() {        
289
    public List<String> getRecentTemplates() {        
284
        return getStringList(RECENT_TEMPLATES);
290
        return getStringList(RECENT_TEMPLATES, true);
285
    }
291
    }
286
    
292
    
287
    public void setRecentTemplates( List<String> templateNames ) {
293
    public void setRecentTemplates( List<String> templateNames ) {
288
        setStringList( RECENT_TEMPLATES, templateNames );
294
        setStringList(RECENT_TEMPLATES, templateNames, true);
289
    }
295
    }
290
    
296
    
291
    public String getLastSelectedProjectCategory () {
297
    public String getLastSelectedProjectCategory () {
292
        return getProperty (PROP_PROJECT_CATEGORY);
298
        return getProperty(PROP_PROJECT_CATEGORY, true);
293
    }
299
    }
294
    
300
    
295
    public void setLastSelectedProjectCategory (String category) {
301
    public void setLastSelectedProjectCategory (String category) {
296
        putProperty(PROP_PROJECT_CATEGORY,category,true);
302
        putProperty(PROP_PROJECT_CATEGORY, category, true, true);
297
    }
303
    }
298
    
304
    
299
    public String getLastSelectedProjectType () {
305
    public String getLastSelectedProjectType () {
300
        return getProperty (PROP_PROJECT_TYPE);
306
        return getProperty(PROP_PROJECT_TYPE, true);
301
    }
307
    }
302
    
308
    
303
    public void setLastSelectedProjectType (String type) {
309
    public void setLastSelectedProjectType (String type) {
304
        putProperty(PROP_PROJECT_TYPE,type,true);
310
        putProperty(PROP_PROJECT_TYPE, type, true, true);
305
    }
311
    }
306
312
307
}
313
}
(-)projects/projectui/src/org/netbeans/modules/project/ui/groups/Group.java (-1 / +1 lines)
Lines 185-191 Link Here
185
        assert id.indexOf('/') == -1;
185
        assert id.indexOf('/') == -1;
186
    }
186
    }
187
187
188
    protected Preferences prefs() {
188
    public Preferences prefs() {
189
        return NODE.node(id);
189
        return NODE.node(id);
190
    }
190
    }
191
191

Return to bug 91031