Issues with PreferenceStore [message #285551] |
Wed, 18 May 2005 18:37 |
Eclipse User |
|
|
|
Originally posted by: martin.hejl.de
Hi,
I'm trying to working on a PreferenceStore implementation that saves the
data to a database instead of a file. In that process, I've come across
two issues that I don't quite get - maybe somebody here could help me out.
1. maybe it's just a misunderstanding on my side, but why doesn't
IPersistentPreferenceStore also include a declaration for a "load()"
method? My idea is that it would be nice if PreferenceStore and my new
DatabasePreferenceStore could be used interchangeably, but with
IPersistentPreferenceStore missing a means to load the data, I don't
quite see how that could work (without subclassing PreferenceStore,
which, according to the API docs, it was not designed for).
2. (and more importantly)
The API documentation of "public String[] preferenceNames()" of
PreferenceStore states:
"Returns an enumeration of all preferences known to this store which
have current values other than their default value"
Now, this would be exactly what I'd need (since I wouldn't want to save
the values that are at their default anyway), but it doesn't seem to
work that way (again, maybe I just don't understand what the docs are
actually saying).
When running the following code snippet
PreferenceStore store = new PreferenceStore();
store.setDefault("test1", true);
store.setDefault("test2", 10);
store.setDefault("test3", "something");
store.putValue("test3", "something else");
String[] names = store.preferenceNames();
for (int i = 0; i < names.length; i++) {
System.out.println(
names[i] +
": " +
store.getString(names[i]) +
" (" +
store.getDefaultString(names[i]) +
")"
);
}
I'd expect the output to be
test3: something else (something)
but instead I get
test3: something else (something)
test2: 10 (10)
test1: true (true)
Obviously, working around that issue is not a big deal, but I'd like to
understand why things aren't working they way I'd expect them to work
from reading the docs.
Can somebody enlighten me what I'm misunderstanding here?
Thanks
Martin
|
|
|
|
Powered by
FUDForum. Page generated in 0.03208 seconds