PersistentStateComponent problem

Hi,

I have a problem with using default plugin configuration. I have a default plugin configuration in my plugin_name.xml file on the classpath and a project component that implements PersistentStateComponent. (I am not using JDOMExternalizable because it's deprecated). The documentation (here http://www.jetbrains.com/idea/plugins/plugin_structure.html under "defaults") states that "If component has defaults, the readExternal() method is called twice: the first time for defaults and the second time for saved configuration." (it's about JDOMExternalizable, but I believed PersistentStateComponent should act similarly). But it simply doesn't work - my plugin has default settings and when I am opening a project with its own settings for this plugin, the data isn't loaded again - loading default configuration from XML on classpath "blocks" somehow and the "real" configuration from project files is not being loaded afterwards. Any suggestions? I would extremely appreciate your help.

3 comments
Comment actions Permalink

Hello Michal,

Actually PersistentStateComponent doesn't assume the loading of default settings
from XML similarly to how JDOMExternalizable handles this. Instead, you should
initialize the default state of your component through Java code in the constructor
of your PersistentStateComponent, and then it will be overwritten with the
state loaded form the project file if the user has changed some part of the
state to non-default values.

I have a problem with using default plugin configuration. I have a
default plugin configuration in my plugin_name.xml file on the
classpath and a project component that implements
PersistentStateComponent. (I am not using JDOMExternalizable because
it's deprecated). The documentation (here
http://www.jetbrains.com/idea/plugins/plugin_structure.html under
"defaults") states that "If component has defaults, the readExternal()
method is called twice: the first time for defaults and the second
time for saved configuration." (it's about JDOMExternalizable, but I
believed PersistentStateComponent should act similarly). But it simply
doesn't work - my plugin has default settings and when I am opening a
project with its own settings for this plugin, the data isn't loaded
again - loading default configuration from XML on classpath "blocks"
somehow and the "real" configuration from project files is not being
loaded afterwards. Any suggestions? I would extremely appreciate your
help.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

OK, I did it that way, but now I have another problem - although the component state is properly saved in IDEA project configuration file, it is never loaded. When I run IDEA with my plugin, do some changes and exit the IDE - I can see that settings are properly saved in IPR file. But when I start IDE again, the state is not loaded from the IPR file (the loadState method is never called).

0
Comment actions Permalink

OK, I resolved it. I figured out that 'name' attribute of @State annotation must be equal to the component name(?). Anyway it worked when I changed it this way. It would be nice if the plugin development javadoc's were more comprehensive... ;)

0

Please sign in to leave a comment.