Changes between Version 13 and Version 14 of Grits_ProjectPreferenceStore


Ignore:
Timestamp:
03/10/2017 05:13:17 PM (5 years ago)
Author:
shan
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Grits_ProjectPreferenceStore

    v13 v14  
    11= Project Preference Store =
    2 ''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 (map key is the id of the preference variable). It calls ''GritsPreferenceStore'' only if the value is not found in its map.
     2[[PageOutline(1-4, Topics, pullout)]]
     3''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.
    34
    4 __Major Advantages:__
     5== Major Advantages ==
    561. 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.
    67
     
    7475
    7576=== Saving Preference values ===
    76 The preference values returned by the ''ProjectPreferenceStore'' are self editable and saveable. One can add/remove values from the existing values of the preference value object and then call '''savePreference()''' on each of the preference value objects.
     77The 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.
     78
     79__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.
    7780
    7881== Example Code ==
    79 
     82Below are some examples of using ''ProjectPreferenceStore'' for reading and editing values.
    8083{{{
    8184
    8285// string preference value
    8386String defaultCountry = ProjectPreferenceStore.StringPreference.COUNTRY.getValue();
     87// edit and save
     88ProjectPreferenceStore.StringPreference.COUNTRY.setValue("Another Country");
     89ProjectPreferenceStore.StringPreference.COUNTRY.savePreference();
     90
    8491
    8592// single choice preference values
    8693SingleChoicePreference actionPreference = ProjectPreferenceStore.getSingleChoicePreference(ProjectPreferenceStore.Preference.ACTION);
    87 List<String> allActions = actionPreference.getAllValues();
     94Set<String> allActions = actionPreference.getAllValues();
    8895String defaultAction = actionPreference.getDefaultValue();
     96// edit and save
     97allActions.add("New Action");
     98actionPreference.savePreference();
     99
    89100
    90101// multi choice preference values
    91 MultiChoicePreference<ProjectCollaborator> collaboratorPreference = ProjectPreferenceStore.getMultiChoicePreference(ProjectPreferenceStore.ParameterizedPreference.COLLABORATOR);
     102MultiChoicePreference<ProjectCollaborator> collaboratorPreference = ProjectPreferenceStore.getMultiChoicePreference(
     103                                 ProjectPreferenceStore.ParameterizedPreference.COLLABORATOR);
    92104List<ProjectCollaborator> defaultCollaborators = collaboratorPreference.getSelectedValues();
    93105List<ProjectCollaborator> otherCollaborators = collaboratorPreference.getOtherValues();
     106// edit and save
     107ProjectCollaborator newCollaborator = new ProjectCollaborator();
     108newCollaborator.setName("New Collaborator");
     109// add more information if needed then add it to the list
     110defaultCollaborators.add(newCollaborator);
     111collaboratorPreference.savePreference();
     112
    94113
    95114// multi choice integer values
    96 MultiChoiceInteger tableColumnPreference = ProjectPreferenceStore.getMultiChoiceInteger(ProjectPreferenceStore.IntegerPreference.COLLABORATORS_TABLE);
     115MultiChoiceInteger tableColumnPreference = ProjectPreferenceStore.getMultiChoiceInteger(
     116                                 ProjectPreferenceStore.IntegerPreference.COLLABORATORS_TABLE);
    97117List<Integer> visibleColumns = tableColumnPreference.getSelectedValues();
     118// edit and save
     119visibleColumns.add(5);
     120tableColumnPreference.savePreference();
    98121
    99122}}}
    100123
     124
     125__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.