saving init data [message #459674] |
Wed, 06 December 2006 06:14  |
Eclipse User |
|
|
|
Originally posted by: peter_ossipov.mail.ru
Hi everybody!
The situation is as follows. One of our programmers likes to write
application data in xml files in directory obtained using the
getUserHome() method.
I do not like this approach for some reason. I would prefer saving data
using preferences and org.eclipse.ui.IMemento for views, as it seems
more secure and appropriate to me in terms of multi-platform
programming. Are there any drawbacks with using the approach my
fellow-comrade uses?
Thanks very much in advance.
public static String getUserHome()
{
if (System.getProperty("os.name").startsWith("Windows"))
{
String myDocsPath = "";
//Call native function which uses wrapper dll to access
//Windows API function SHGetFolderPath to obtain My Docs path
try
{
myDocsPath = Utility.getMyDocsPath();
}
catch (UnsatisfiedLinkError e)
{
//something went wrong obtaining My Docs path
//log error and use default My docs location.....
myDocsPath = System.getProperty("user.home") + Utility.fileSep
+ "My documents";
logger
.error(
"Failed to obtain My Documents path from Operating
System. Using default My Documents location of: "
+ myDocsPath, e);
}
if (myDocsPath == null || myDocsPath.equals(""))
{
//something went wrong obtaining My Docs path
//log error and use default My docs location.....
myDocsPath = System.getProperty("user.home") + Utility.fileSep
+ "My documents";
logger
.error("Failed to obtain My Documents path from Operating
System. Using default My Documents location of: "
+ myDocsPath);
}
return myDocsPath;
}
else
{
return System.getProperty("user.home");
}
}
description of function used above
/**
* Native method to obtain the Windows "My documents" path using
Windows API
* function SHGetFolder.
*
* @return The current "My Documents" path
*/
public static native String getMyDocsPath();
|
|
|
Re: saving init data [message #459681 is a reply to message #459674] |
Wed, 06 December 2006 07:35   |
Eclipse User |
|
|
|
It's one of those things. It's a well known pattern to store some
program config information in a users $HOME/.application directory (of
course, not at the top level of their home directory :-)
But Eclipse has a number of locations to store state that your plugin
needs, and they all have different properties.
Eclipse provides preferences for user configurable data, so that it can
be saved in the workspace and changed by the user. Preferences can also
be exported.
Eclipse provides the init(*) and IMemento to persist a view's state
between sessions. i.e. if you close a view and then open it, your
IMemento is null, but if you shut down eclipse while the view is open
then the IMemento is XML from the last session.
Eclipse provides a plugin state location, returned from
Plugin#getStateLocation(). This is just a file location for that
workspace where the plugin can save information. Obvious uses are to
save plugin model information on shutdown and read it on startup, but
the plugin can access the state location any time.
You would probably look at splitting out preferences from the XML files,
and then storing what's left of the config files in the state location.
Later,
PW
|
|
|
Re: saving init data [message #459682 is a reply to message #459681] |
Wed, 06 December 2006 07:50   |
Eclipse User |
|
|
|
Originally posted by: peter_ossipov.mail.ru
Hi Paul.
Thanks again for you detailed answer very much!
Paul Webster wrote:
> It's one of those things. It's a well known pattern to store some
> program config information in a users $HOME/.application directory (of
> course, not at the top level of their home directory :-)
>
> But Eclipse has a number of locations to store state that your plugin
> needs, and they all have different properties.
>
> Eclipse provides preferences for user configurable data, so that it can
> be saved in the workspace and changed by the user. Preferences can also
> be exported.
How can I export preferences? :-)
>
> Eclipse provides the init(*) and IMemento to persist a view's state
> between sessions. i.e. if you close a view and then open it, your
> IMemento is null, but if you shut down eclipse while the view is open
> then the IMemento is XML from the last session.
>
> Eclipse provides a plugin state location, returned from
> Plugin#getStateLocation(). This is just a file location for that
> workspace where the plugin can save information. Obvious uses are to
> save plugin model information on shutdown and read it on startup, but
> the plugin can access the state location any time.
>
> You would probably look at splitting out preferences from the XML files,
> and then storing what's left of the config files in the state location.
>
> Later,
> PW
|
|
|
|
Re: saving init data [message #459705 is a reply to message #459702] |
Wed, 06 December 2006 10:05  |
Eclipse User |
|
|
|
Originally posted by: peter_ossipov.mail.ru
Hi Paul!
Thanks very much for your answer!
Paul Webster wrote:
> Peter Osipov wrote:
>> How can I export preferences? :-)
>>
>
> Just provide them.
A, okay! thanks! I will try.
> Then the user can use File>Export...>Preferences and
> File>Import...>Preferences.
>
> You can create a preference transfer to group preferences together to
> allow them to be targetted specifically. For example, you can choose to
> only export/import the CVS preferences.
>
> Later,
> PW
|
|
|
Powered by
FUDForum. Page generated in 0.04717 seconds