Project Preference Store

ProjectPreferenceStore is a local preference store for storing preference values related to project, e.g. preference for project's Task information. This local store caches the preference values in maps (the id of the preference variable is map's key). It calls GritsPreferenceStore only if the value is not found in its map.

Major Advantages

  1. Currently the central GritsPreferenceStore does not store any preference value in maps and reads from file each time a preference value is read. This local preference store minimizes multiple read from file by keeping a cache of preference values in memory that have been read once.
  1. Currently preference values are stored as string in the preference file. Each time a preference is read, a generic PreferenceEntity object is created by GritsPreference store. This PreferenceEntity object is later converted to more specific preference object for getting preference values. ProjectPreferenceStore reduces multiple unnecessary de-serialization of preference values from strings stored in file.
    For example, if there were four tasks, ProjectPreferenceStore would cache a list of four tasks (along with its default information) which would be otherwise each time read as string from file, unmarshalled to PreferenceEntity object and then converted to list of tasks.

These advantages are general for any similar cached-local preference store in GRITS. Plugins that would use preferences are recommended to maintain a local preference store.


ProjectPreferenceStore uses enums as parameters for getting preference values. The enum object contains important information such as preference variable name and file name. Below is a detailed description of different types of preferences that it contains and different types of values it returns.

Preferences in Project Preference store

Class diagram for project preferences

Currently there are four types of preferences for projects. Each of these preference is an enum and has all the information needed to get a preference value.

  • StringPreference - Simplest type of preference that has a string value (all the information is available in the enum object)
  • Preference - Type of preference whose values are a list of string
  • ParameterizedPreference - Type of preference whose values are a list of objects of a particular class
  • IntegerPreference - A special case of ParameterizedPreference whose values are a list of integer

By using the above enum objects as parameter, the need of knowing the preference variable name or the need of knowing filename for default values (when a preference is not found in the preference file) is removed. When one of the above enum is passed as a parameter then user can get SingleChoicePreference or MultiChoicePreference (or its special case MultiChoiceInteger) object.

  • SingleChoicePreference
    • characterized by a list of values and one default value (currently it only supports string values)
  • MultiChoicePreference
    • characterized by a list of selected values and a list of unselected values
  • MultiChoiceInteger
    • characterized by a list of selected integers and a list of unselected integers
    • a special case of MultiChoicePreference

ProjectPreferenceStore Enum and Values

Note: The simplest StringPreference is self-contained. It has a single string value that is available in the enum object itself.

ProjectPreferenceStore class

Class diagram for ProjectPreferenceStore

Preference and their values

Currently it happens to be the case that certain preference types have certain preference values. Here is the mapping of current preference type and their values:

Preference type Preference values
StringPreference -
Preference SingleChoicePreference
ParameterizedPreference MultiChoicePreference
IntegerPreference MultiChoiceInteger

Note: Currently SingleChoicePreference is not generic and only supports string preference values. If later some ParameterizedPreference have SingleChoicePreference values then SingleChoicePreference should be made a generic class.

Working with GritsPreferenceStore

Working with GritsPreferenceStore

In GRITS wherever a preference value related to a project is used, ProjectPreferenceStore is to be called. ProjectPreferenceStore would first look into its cache and if it is not found then it would call GritsPreferenceStore. It would add these value to its cache so that next time it need not to call GritsPreferenceStore.

Saving Preference values

The preference values returned by the ProjectPreferenceStore are editable and saveable. One can add/remove values from the preference value object and then call savePreference() method of this object. savePreference() method internally calls GritsPreferenceStore and different parts of the programs listening to changes in this preference value would automatically get notified of the change.

Note: ProjectPreferenceStore only keeps one copy of the preference values and thus if it is modified somewhere then it should be saved by calling this savePreference() method of the object. If it is not saved then different parts of the program would have different values and also the current changes would be lost next time it is read from the preference file.

Example Code

Below are some examples of using ProjectPreferenceStore for reading and editing values.

// string preference value
String defaultCountry = ProjectPreferenceStore.StringPreference.COUNTRY.getValue();
// edit and save
ProjectPreferenceStore.StringPreference.COUNTRY.setValue("Another Country");

// single choice preference values
SingleChoicePreference actionPreference = ProjectPreferenceStore.getSingleChoicePreference(
Set<String> allActions = actionPreference.getAllValues();
String defaultAction = actionPreference.getDefaultValue();
// edit and save
allActions.add("New Action");

// multi choice preference values
MultiChoicePreference<ProjectCollaborator> collaboratorPreference = ProjectPreferenceStore.getMultiChoicePreference(
List<ProjectCollaborator> defaultCollaborators = collaboratorPreference.getSelectedValues();
List<ProjectCollaborator> otherCollaborators = collaboratorPreference.getOtherValues();
// edit and save
ProjectCollaborator newCollaborator = new ProjectCollaborator();
newCollaborator.setName("New Collaborator");
// add more information if needed then add it to the list

// multi choice integer values
MultiChoiceInteger tableColumnPreference = ProjectPreferenceStore.getMultiChoiceInteger(
List<Integer> visibleColumns = tableColumnPreference.getSelectedValues();
// edit and save

Note: For editing preference values it is highly recommended to send user to a Preference dialog which has more error checking functionalities such as removing duplicate values or other validation mechanisms. The above examples of editing preference values are only for showing its usage.

Last modified 6 years ago Last modified on 03/20/2017 03:01:22 PM

Attachments (5)

Download all attachments as: .zip