I am trying to develop a plugin for Intellij IDEA, I am working with SDK 129.451.
The problem is that I cannot save user data, like some list items that it can enter into the plugin, and return data after restarting the IDE.
I am using PersistentStateComponent to save data, the getState() method getState() be called, but the loadState() method does not work.
Here is an example of a class that extends PersistentStateComponent:
@State(name = "Test", storages = {@Storage(file = StoragePathMacros.APP_CONFIG+"/other.xml" )}) public class Test implements PersistentStateComponent<Element> { String ceva; public Test() { ceva = "sad"; System.out.println("constr"); } public String getCeva() { return ceva; } public void setCeva(String ceva) { this.ceva = ceva; } public void loadState(Element state) { System.out.println("cstate load"); ceva = (String) state.getContent().get(0); } public Element getState() { System.out.println("cstate retu"); Element configurationsElement = new Element("testtt"); configurationsElement.addContent(ceva); return configurationsElement; } }
I also added this class to plugin.xml here:
<extensions defaultExtensionNs="com.intellij"> <applicationService serviceImplementation="ro.catalin.prata.testflightuploader.controller.Test"/> <toolWindow id="TF Uploader" secondary="true" icon="/general/add.png" anchor="right" factoryClass="ro.catalin.prata.testflightuploader.view.TFUploader"> </toolWindow> </extensions>
And I also have a toolbox class:
public class TFUploader implements ToolWindowFactory { private JButton buttonAction; private ToolWindow myToolWindow; final Test test = ServiceManager.getService(Test.class); public TFUploader() {
So, if I close the application or hide it, the getState method will be called as I expected. but when I open the application, the loadState method will not be called .. can someone help me, how can I solve this?
I already read this one , but it doesn’t seem to help me much. I also want to use PersistentStateComponent , because I want to keep objects more complex than a simple string.
Thank you in advance!