|
Re: Storing multidimensional String arrays in preferences [message #260798 is a reply to message #260763] |
Mon, 12 July 2004 12:36   |
Eclipse User |
|
|
|
Moritz,
Preferences are always stored as strings - regardless of what object
they represent. To handle objects other than strings, you need a way of
converting them into strings for storage, and then a way of turning
those strings back into objects.
(NB - this is conceptually similar to pickling; has anyone tried using
pickle to do this job?)
In the preferences article, an array {"a","b","c"} is changed into the
string "a;b;c" (where PREFERENCE_DELIMITER=";") by setBadWordsPreference
Conversely, "a;b;c" is converted into an array {"a","b","c"} by the
convert method.
You could extend this approach to handle 2-dimensional arrays by having
an end of row delimiter.
eg. store a b c as "a;b;c|d;e;f"
d e f
where the column delimiter is ";" and the row delimiter is "|"
So to handle multi-dimensional arrays, you need to:
a) create a widget on your preference page that will allow the user to
edit the array
b) define a method to convert your arrays into strings, and another
method to reverse the process, converting your strings into arrays.
Hope that helps,
- Dan
Moritz Post wrote:
> hi there
>
> i want to store a multidimensional string array in the preferences. so far
> i read through this article
> http://www.eclipse.org/articles/Article-Preferences/preferen ces.htm which
> explains how to store an one dimensional array.
>
> but i want to store values in a table kind of structure. i think it can be
> done since the usual java preferences use a table layout as well sometimes.
>
> anyone who can hint me to the right path? :)
>
> thx in advance
> moritz post
>
|
|
|
Re: Storing multidimensional String arrays in preferences [message #260803 is a reply to message #260798] |
Mon, 12 July 2004 12:40  |
Eclipse User |
|
|
|
hello
thx for the swift answer...
after reading through some sources of the jdt and examining the exported
preferences i realized, that the jdt converts the data into an xml tree
and stores that tree. i will go for that apropach.
btw... thx for your explanaition :)
moritz
> Preferences are always stored as strings - regardless of what object
> they represent. To handle objects other than strings, you need a way of
> converting them into strings for storage, and then a way of turning
> those strings back into objects.
> (NB - this is conceptually similar to pickling; has anyone tried using
> pickle to do this job?)
> In the preferences article, an array {"a","b","c"} is changed into the
> string "a;b;c" (where PREFERENCE_DELIMITER=";") by setBadWordsPreference
> Conversely, "a;b;c" is converted into an array {"a","b","c"} by the
> convert method.
> You could extend this approach to handle 2-dimensional arrays by having
> an end of row delimiter.
> eg. store a b c as "a;b;c|d;e;f"
> d e f
> where the column delimiter is ";" and the row delimiter is "|"
> So to handle multi-dimensional arrays, you need to:
> a) create a widget on your preference page that will allow the user to
> edit the array
> b) define a method to convert your arrays into strings, and another
> method to reverse the process, converting your strings into arrays.
> Hope that helps,
> - Dan
> Moritz Post wrote:
> > hi there
> >
> > i want to store a multidimensional string array in the preferences. so far
> > i read through this article
> > http://www.eclipse.org/articles/Article-Preferences/preferen ces.htm which
> > explains how to store an one dimensional array.
> >
> > but i want to store values in a table kind of structure. i think it can be
> > done since the usual java preferences use a table layout as well sometimes.
> >
> > anyone who can hint me to the right path? :)
> >
> > thx in advance
> > moritz post
> >
|
|
|
Powered by
FUDForum. Page generated in 0.25193 seconds