◐ Shell
clean mode source ↗

Create Pref Service by hinerm · Pull Request #102 · scijava/scijava-common

This was referenced

Jul 23, 2014

This was referenced

Jul 25, 2014

and others added 16 commits

July 25, 2014 10:33
Using a static utility method for Prefs is limiting - it provides no way
to override preference saving/loading behavior. This creates problems
when there are errors or negative interactions with the Preferences
implementation - for example, in MATLAB there are known bugs regarding
the Java Preferences implementation.

By converting to a PrefService we can now control this behavior more
precisely, as needed. The Prefs utility class will remain for now, but
will delegate to the PrefService when it has been created - allowing the
utility method behavior to be overridden similarly.
All Contextual classes that used the Prefs static utility class should
now be using PrefService.
Added API to save/load ModuleItems. This will allow Contextual classes
to move away from ModuleItem#loadValue and ModuleItem#saveValue, which
are not Contextual and go directly through the Prefs utility class.

Adds a default implementation in DefaultModuleService, using the
PrefService if able (which requires an AbstractModuleItem). If
necessary, still falls back to ModuleItem's saveValue and loadValue
methods.
ModuleItem#saveValue and ModuleItem#loadValue are now deprecated in
favor of ModuleService methods, which can be called from a Contextual
environment and thus use the new PrefService API.
Updated classes that were using ModuleItem#saveValue and
ModuleItem#loadValue to use the appropriate ModuleService methods.
It was discovered that the initialize method of multiple PrefService
impls was being invoked - leading to the LOWEST priority overwriting the
static service field in the Prefs utility class (since it was the last
initialize method to execute).

Added a check for priority so that lower priority services don't
overwrite higher.
Appled Source > Clean Up in Eclipse, to update newest classes with the
IJ2 style template.
Added comments detailing planned future for the pref service.
The Prefs utility class is now deprecated. PrefService should be used
instead.
This was an unnecessary method. Originally thought that each service
would need a reminder to set itself as the static PrefService... but
that's exactly what the initialize method of AbstractPrefService is for.
The whole point of the PrefService is to allow for any preference
implementation, while the DefaultPrefService uses java.util.Preferences.

Thus the java.util.Preferences imports have been removed from the
PrefService, and the necessary Class and String-based indexing methods
have been added.

Updated the DefaultPrefService implementation and usage of the service
accordingly.
We have a short name PrefService, so we should use a short package name
instead of a long package name.
The Prefs class is deprecated and we should not reference it in any way
from non-deprecated code.
Added suppress warnings for the Prefs deprecation.

hinerm added a commit that referenced this pull request

Jul 25, 2014
Migrates the static utility `Prefs` class to an extensible `PrefService`.

@hinerm hinerm deleted the create_pref_service branch

July 25, 2014 16:09