Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Storing multidimensional String arrays in preferences
Storing multidimensional String arrays in preferences [message #260763] Mon, 12 July 2004 11:44 Go to next message
Moritz Post is currently offline Moritz Post
Messages: 28
Registered: July 2009
Junior Member
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 #260798 is a reply to message #260763] Mon, 12 July 2004 12:36 Go to previous messageGo to next message
Dan Winterstein is currently offline Dan Winterstein
Messages: 33
Registered: July 2009
Member
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 Go to previous message
Moritz Post is currently offline Moritz Post
Messages: 28
Registered: July 2009
Junior Member
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
> >
Previous Topic:Eclipse L&F
Next Topic:how to (programmatically) not show welcome page at startup?
Goto Forum:
  


Current Time: Thu Jul 24 02:46:35 EDT 2014

Powered by FUDForum. Page generated in 0.01550 seconds