Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: PreferencesFx.of(java.util.prefs.Preferences... #132

Open
trixon opened this issue Sep 15, 2019 · 3 comments
Open

Feature request: PreferencesFx.of(java.util.prefs.Preferences... #132

trixon opened this issue Sep 15, 2019 · 3 comments

Comments

@trixon
Copy link

trixon commented Sep 15, 2019

While adding PreferencesFX to a NetBeans Platform application I noticed that my settings where scattered.

On Linux, a NetBeans Platform application store its settings in a directory like ~/.MYAPP while PreferencesFX defaults to ~/.java/.userPrefs/...

With NbPreferences.forModule(Class c)
https://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/NbPreferences.html#forModule-java.lang.Class-
I get a java.util.prefs.Preferences object I would like to use when calling PreferencesFx.of().
Is it possible to add that functionality to the framework?

While reading the code I got to PreferencesBasedStorageHandler and the row

So, I guess I could make my own StorageHandler, but I believe it makes more sence to have a simple PreferencesFx.of(java.util.prefs.Preferences... in the framework.

@fujohnwang
Copy link

+1, in order to export preferences, I have to use java reflection to access model -> storage handler -> preferences, may be a public StorageHandler ref will suffice.

@marvk
Copy link

marvk commented Dec 31, 2020

+1 for this, I'd really prefer my settings to be saved in a settings file, not the registry.

@ghost
Copy link

ghost commented Dec 19, 2021

First, inject a custom storage handler that overrides the default behaviours:

PreferencesFx.of( createStorageHandler(), createCategories() )
  .instantPersistent( false )

  // ... along with ...

  private StorageHandler createStorageHandler() {
    return new XmlStorageHandler();
  }

Next, implement that custom XmlStorageHandler to perform no actions. That is, PreferencesFX will no longer use its own storage handling routines.

Then, define application Keys to help ensure type safety when referencing settings. This avoids hard-coding strings for key names everywhere and allows for defining structured relationships between keys, such as a hierarchy of settings.

Following that, create a Workspace concept that handles persisting of settings data. This is where you'd populate default values for every setting (to be null-hostile).

Up next, map the keys to PreferencesFX settings and widgets. Check out the PreferencesController class to see one way to accomplish this mapping.

Finally, when persisting the data, you now have control over the settings file format, the file location and name, and the ability to maintain backwards compatibility with previous versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants