NbPreferences.root()
returns root preference node. NbPreferences.forModule(class cls)
returns
preference node which absolute path
depends whether class provided as a parameter was loaded as a
part of any module or not. If so, then absolute path corresponds to
slashified code name base of module. If not, then absolute path
corresponds to class's package
config/Preferences/
`-- UserRoot
`-- org
|-- netbeans
| `-- modules
| `-- derby
| `-- prefs.properties
`-- yourorghere
`-- mymodule
`-- prefs.properties
prefs.properties is regular properties file. See:
#Thu Sep 28 18:15:22 CEST 2006View of image of preference tree in memory(apisupprot/beanbrowser needed):
location=/tmp/location
systemHome=/tmp/systemHome
- <folder name="Services"/> - <file name="org-netbeans-modules-derby-DerbyOptions.settings" url="DerbyOptions.settings"/> - </folder>
<folder name="Services"> <folder name="IDEConfiguration"> <folder name="ServerAndExternalToolSettings"> - <file name="org-netbeans-modules-derby-DerbyOptions.shadow"> - <attr name="originalFile" stringvalue="Services/org-netbeans-modules-derby-DerbyOptions.settings"/> </file> </folder> </folder>
-public class DerbyOptions extends SystemOption { - - private static final long serialVersionUID = 1101894610105398924L; +public class DerbyOptions { + private static DerbyOptions INSTANCE = new DerbyOptions(); public static DerbyOptions getDefault() { - return (DerbyOptions)SharedClassObject.findObject(DerbyOptions.class, true); + return INSTANCE; }
public static DerbyOptions getDefault() { - return (DerbyOptions)SharedClassObject.findObject(DerbyOptions.class, true); + if (INSTANCE == null) { + INSTANCE = new DerbyOptions(); + FileObject toDel = Repository.getDefault().getDefaultFileSystem().findResource("/Services/org-netbeans-modules-derby-DerbyOptions.settings"); + if (toDel != null) { + try { + toDel.delete(); + } catch (IOException ex) { + Logger.getLogger(DerbyOptions.class.getName()).log(Level.INFO, null, ex); + } + } + } + return INSTANCE; }
+ protected final String putProperty(String key, String value, boolean notify) { + String retval = getPreferences().get(key, null); + if (value != null) { + NbPreferences.forModule(DerbyOptions.class).put(key, value); + } else { + NbPreferences.forModule(DerbyOptions.class).remove(key); + } + return retval; + } + protected final String getProperty(String key) { + return NbPreferences.forModule(DerbyOptions.class).get(key, null); + }
+ public static BeanNode createViewNode() throws IntrospectionException { + return new BeanNode(DerbyOptions.getDefault()); + } - <file name="org-netbeans-modules-derby-DerbyOptions.shadow"> - <attr name="originalFile" stringvalue="Services/org-netbeans-modules-derby-DerbyOptions.settings"/> + <file name="DerbyOptionsNode.instance"> + <attr name="instanceCreate" methodvalue="org.netbeans.modules.derby.DerbyOptions.createViewNode"/>The other way means to go a little more farther and provide and install custom options panels/categories to Options Dialog according to Options Dialog API (org.netbeans.modules.options.api) .Apisupport can help and generate boilerplate code and put registration into layer.
<answer id="resources-preferences"> <api group="preferences" name="org.netbeans.modules.derby" type="export" category="private" url="http://java.sun.com/j2se/1.4.2/docs/api/java/util/prefs/Preferences.html"> <table> <tbody> <tr> <th>key</th> <th>description</th> <th>Read</th> <th>Write</th> </tr> <tr> <td>location</td> <td>Derby location or an empty string if the Derby location is not set>/td> <td>x</td> <td>x</td> </tr> <tr> <td>systemHome</td> <td>Derby system home or an emtpy string if the system home is not set</td> <td>x</td> <td>x</td> </tr> </tbody> </table> </api> </answer>
How to start ? The best is to start with tests. But first you must have settings file that will be parsed and tested. Put this file among tests:
test/unit/src/org/netbeans/upgrade/systemoptions |-- BasicTestForImport.java |-- DerbyOptionsTest.java |-- org-netbeans-modules-derby-DerbyOptions.settingsThen write simple test that should contain assertions what actually will be parsed and imported. See:
public class DerbyOptionsTest extends BasicTestForImport { public DerbyOptionsTest(String testName) { super(testName, "org-netbeans-modules-derby-DerbyOptions.settings"); } public void testPreferencesNodePath() throws Exception { assertPreferencesNodePath("/org/netbeans/modules/derby"); } public void testPropertyNames() throws Exception { assertPropertyNames(new String[] { "systemHome", "location" }); } public void testSystemHome() throws Exception { assertPropertyType("systemHome","java.lang.String"); assertProperty("systemHome","/tmp/systemHome"); } public void testLocation() throws Exception { assertPropertyType("location","java.lang.String"); assertProperty("location","/tmp/location"); } }If the tests didn't pass then probably there is more complicated object graph serialized then you must subclass
PropertyProcessor
and put your
own code in.
(See as an example: TaskTagsProcessor
and here is a test).