Quick Tip 25: New Persistence in 6.7 Window System
When creating a new TopComponent in 6.7 the Template has changed. It autocreates an annotation like this for you:
@ConvertAsProperties(dtd = “-//com.mizu.modules.taskeditor//TaskEditor//EN”, autostore = false)
You can then store and retrieve the persistence data of your application via modifying the two methods readPropertiesImpl and writeProperties:
void writeProperties(java.util.Properties p) {
// better to version settings since initial version as advocated at
// http://wiki.apidesign.org/wiki/PropertyFiles
p.setProperty(”version”, “1.0″);
p.setProperty(”nameValue”, taskEditorPanel1.getNameValue());
}
private void readPropertiesImpl(java.util.Properties p) {
String version = p.getProperty(”version”);
taskEditorPanel1.setNameValue(p.getProperty(”nameValue”));
}
This new functionality is meant to replace storing data via java.io.Externalizable, so a ResolvableHelper and the related skeleton code is no longer generated for you. I’ve played a little bit with the new functionality and added the old Externalizable code manually to see if they play together, but it didn’t work (must find out if that’s a bug or intended behaviour). In a way that makes sense, because one should either use this or ConvertAsProperties. So I guessed that it would work when I remove the annotation. I tried it and it worked, the data is stored in the TopCompoents settings file…
So if you want to use the old persistence functionality instead of the new one, make sure you remove the annotation…

Hi!
The current created TopComponent template by the wizard is buggy. The current template destroys the singleton pattern (the TopComponent is created twice). I’ve a solution described in my (german) blog:
http://www.sepix.de/blogs/blogrittner/blog/archive/2009/august/21/beandev_convertasproperties_zerstoeren_singleton_pattern_von_topcomponents/index.html
In short, please replace the generated readProperties method by this little correction:
Object readProperties(java.util.Properties p) {
if ( instance == null ) {
instance = this;
}
instance.readPropertiesImpl(p);
return instance;
}
br, josh.
Comment by Aljoscha Rittner
— 21. August 2009 @ 09:51
I also ran into the “Twingleton” bug several times in the meantime :-). It’s really ugly. Thanks a lot for the update.
Comment by Toni
— 21. August 2009 @ 09:55