Recommended way to store settings and data

I would like to add the facility to my plugin to store settings between sessions, so it will remember old settings when user comes back.

Is there a 'recommended' way to do this?

MArk

13 comments
Comment actions Permalink

Hello mark,

I would like to add the facility to my plugin to store settings
between sessions, so it will remember old settings when user comes
back.

Is there a 'recommended' way to do this?


Provide an application service implementing the PersistentStateComponent
interface. You can find examples of using this pattern in the sample plugin
sources.

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


0
Comment actions Permalink

Thanks. I'll give it a try.

MArkee

0
Comment actions Permalink

this is the successor of JDOMExternalizable isn't it?
How long will be the JDOMExternalizable still supported? See that it was deprecated in 7.x.

0
Comment actions Permalink

Hello Dan,

this is the successor of JDOMExternalizable isn't it?


Yes.

How long will be
the JDOMExternalizable still supported? See that it was deprecated in
7.x.


We don't currently have plans to remove it in 8.0.

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


0
Comment actions Permalink

I have been to http://www.jetbrains.com/idea/plugins/plugin_developers.html and tried to download the plugin development package.

It takes me to http://download.jetbrains.com/idea/idea-#Numberversion-dev.zip and says file not found. If this an incorrect link or a mistake on my part.

MArk

0
Comment actions Permalink

Somehow Jetbrains team seem to have forgotten substituting some variables.

have a look there
http://www.jetbrains.net/confluence/display/IDEADEV/Selena+EAP

0
Comment actions Permalink

I have my class which implements PersistentStateComponent and which stores a list of files I can then access.

I've looked at the examples which have PersistentStateComponent and I am still not clear what I actually do this this class to make it live. There is no simple example (which is what I am trying to produce).

Do I need to register the class somewhere? What am I not doing?

@State(
name="PDFDirect.Settings",
storages= {
@Storage(
id="PDF",
file = "$WORKSPACE_FILE$"
)}
)
public final class PDFSettings implements PersistentStateComponent]]> {


public String[] getPDFFiles() {
return files;
}

public void setPDFFiles(String[] files) {
this.files = files;
}

public String[] files={"a","b","c"};



public PDFSettings getState() {
return this;
}

public void loadState(PDFSettings object) {

XmlSerializerUtil.copyBean(object, this);
}
}

0
Comment actions Permalink

Hello mark,

Your class needs to be either a component (app-level, project-level or module-level)
or a service (also at one of these levels).

I have my class which implements PersistentStateComponent and which
stores a list of files I can then access.

I've looked at the examples which have PersistentStateComponent and I
am still not clear what I actually do this this class to make it
live. There is no simple example (which is what I am trying to
produce).

Do I need to register the class somewhere? What am I not doing?

@State(
name="PDFDirect.Settings",
storages= {
@Storage(
id="PDF",
file = "$WORKSPACE_FILE$"
)}
)
public final class PDFSettings implements
PersistentStateComponent<PDFSettings> {

public String[] getPDFFiles() {
return files;
}
public void setPDFFiles(String[] files) {
this.files = files;
}
public String[] files={"a","b","c"};

public PDFSettings getState() {
return this;
}
public void loadState(PDFSettings object) {

XmlSerializerUtil.copyBean(object, this);
}
}

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


0
Comment actions Permalink

Thanks. That makes sense.

All the examples I have seen have $PROJECT_FILE$ or $WORKSPACE_FILES$ in the Annotation at the top of the component.

@State(
name = PDFFileTypeManagerImpl.COMPONENT_NAME,
storages = {@Storage(id = "PDF_viewer", file = "$PROJECT_FILE$")}
)

I get an unknown macro error when I run. What is the problem?

0
Comment actions Permalink

The answer is

There are 3 types of component level. Each of them has unique, only for this level macros:

- application-level components (ApplicationComponent): $APP_CONFIG$, $OPTIONS$;
- project-level components (ProjectComponent): $PROJECT_FILE$, $WORKSPACE_FILE$, $PROJECT_CONFIG_DIR$;
- module-level components (ModuleComponent): $MODULE_FILE$

0
Comment actions Permalink

Except you then get a nullpointerException to say file does not exist when I use $APP_CONFIG :(

/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java -Xbootclasspath/p:/Applications/IntelliJ IDEA 7.0.3.app/lib/boot.jar -Didea.config.path=/Users/markee/IdeaProjects/sandbox/config -Didea.system.path=/Users/markee/IdeaProjects/sandbox/system -Didea.plugins.path=/Users/markee/IdeaProjects/sandbox/plugins -Didea.smooth.progress=false -Dapple.laf.useScreenMenuBar=true -Dfile.encoding=MacRoman -classpath /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/tools.jar:/Applications/IntelliJ IDEA 7.0.3.app/lib/idea_rt.jar:/Applications/IntelliJ IDEA 7.0.3.app/lib/idea.jar:/Applications/IntelliJ IDEA 7.0.3.app/lib/bootstrap.jar:/Applications/IntelliJ IDEA 7.0.3.app/lib/extensions.jar:/Applications/IntelliJ IDEA 7.0.3.app/lib/openapi.jar:/Applications/IntelliJ IDEA 7.0.3.app/lib/jdom.jar:/Applications/IntelliJ IDEA 7.0.3.app/lib/log4j.jar com.intellij.idea.Main
Watcher OK.
java.io.IOException: Error while loading /Users/markee/IdeaProjects/sandbox/config/options: /Users/markee/IdeaProjects/sandbox/config/options (No such file or directory)
at com.intellij.openapi.application.impl.ApplicationImpl.load(ApplicationImpl.java:317)
at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:24)
at com.intellij.idea.MainImpl$3.run(MainImpl.java:3)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at com.intellij.ide.IdeEventQueue.c(IdeEventQueue.java:131)
at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:132)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:136)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

0
Comment actions Permalink

Query on how values first set for plugin

0

Please sign in to leave a comment.