Changes between Version 11 and Version 12 of Grits_ProjectPreferenceStore


Ignore:
Timestamp:
03/09/2017 07:06:18 PM (5 years ago)
Author:
shan
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Grits_ProjectPreferenceStore

    v11 v12  
    11= Project Preference Store =
    2 
    32''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.
    43
     
    109These 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.
    1110
     11
    1212== Implementation ==
    13 ''ProjectPreferenceStore'' works with enums and string. It takes enums as parameters and returns values in enums (that contain single/multi-choice list).
    14 
     13''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.
    1514
    1615=== Preferences in Project Preference store ===
    1716[[BR]]
    1817[[Image(project_preference_store.jpg, 700)]][[BR]]
    19 Class diagram for project preferences
     18__''Class diagram for project preferences''__
    2019[[BR]]
    2120
    2221
    23 Currently there are four types of preferences for projects. Each of these preference is an enum object and has all the information needed to get a preference value.
     22Currently 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.
    2423
    25 - ''StringPreference'' - Simplest type of preference that has a '''string''' value. All information related to it is available in the enum object
     24- ''StringPreference'' - Simplest type of preference that has a '''string''' value. All the information is available in the enum object
    2625
    27 - ''Preference'' - Types of preference whose values are a '''list of string'''
     26- ''Preference'' - Type of preference whose values are a '''list of string'''
    2827
    29 - ''ParameterizedPreference'' - Types of preference whose values are a '''list of objects of a particular class'''
     28- ''ParameterizedPreference'' - Type of preference whose values are a '''list of objects of a particular class'''
    3029
    3130- ''IntegerPreference'' - A special case of ''ParameterizedPreference'' whose values are a '''list of integer'''
    3231
    33 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 a generic ''SingleChoicePreference'' or ''MultiChoicePreference'' (or its special case ''MultiChoiceInteger'') enum object.
     32By 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 a generic ''SingleChoicePreference'' or ''MultiChoicePreference'' (or its special case ''MultiChoiceInteger'') object.
    3433
    3534- ''SingleChoicePreference''
     
    4342 - a special case of MultiChoicePreference
    4443
    45 __Note:__ The simplest ''StringPreference'' is self-contained. It has a single string value that can be directly accessed from the enum object.
    46 == Project Preference store==
     44__Note:__ The simplest ''StringPreference'' is self-contained. It has a single string value that is available in the enum object itself.
     45=== ProjectPreferenceStore class ===
    4746[[BR]]
    4847[[Image(project_preference_all.png, 1000)]][[BR]]
    49 Class diagram for project preference store
     48__''Class diagram for ProjectPreferenceStore''__
    5049[[BR]]
    5150
    5251
    53 == Preference and their values ==
     52=== Preference and their values ===
    5453Currently 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:
    5554
    56 ||= Preference type       =||= Preference values     =||
     55||=  Preference type      =||=  Preference values    =||
    5756|| StringPreference        ||    -                    ||
    5857|| Preference              || SingleChoicePreference  ||
     
    6362__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.
    6463
    65 == Code Snippet ==
     64
     65== Example Code ==
    6666
    6767{{{
    6868
    69 public class ProjectPreferenceStore
    70 {
    71         @Inject private static IGritsPreferenceStore gritsPreferenceStore;
    72         private static Map<String, SingleChoicePreference> singleSelectionTypeMap =
    73                         new HashMap<String, SingleChoicePreference>();
    74         private static Map<String, MultiChoicePreference<?>> multiSelectionTypeMap =
    75                         new HashMap<String, MultiChoicePreference<?>>();
     69// string preference value
     70String defaultCountry = ProjectPreferenceStore.StringPreference.COUNTRY.getValue();
    7671
    77         public static SingleChoicePreference getSingleChoicePreference(Preference preference)
    78         {
    79                 String preferenceName = preference.getPreferenceName();
    80                 logger.info("Getting preference : " + preferenceName);
    81                 SingleChoicePreference preferenceObject = singleSelectionTypeMap.get(preferenceName);
    82                 if(preferenceObject == null)
    83                 {
    84                         preferenceObject = new SingleChoicePreference(gritsPreferenceStore, preference);
    85                         singleSelectionTypeMap.put(preferenceName, preferenceObject);
    86                 }
    87                 return preferenceObject;
    88         }
     72// single choice preference values
     73SingleChoicePreference actionPreference = ProjectPreferenceStore.getSingleChoicePreference(ProjectPreferenceStore.Preference.ACTION);
     74List<String> allActions = actionPreference.getAllValues();
     75String defaultAction = actionPreference.getDefaultValue();
    8976
    90         @SuppressWarnings("unchecked")
    91         public static <T> MultiChoicePreference <T> getMultiChoicePreference(
    92                         ParameterizedPreference parameterizedPreference)
    93         {
    94                 String preferenceName = parameterizedPreference.getPreferenceName();
    95                 logger.info("Getting preference : " + preferenceName);
    96                 MultiChoicePreference<T> preferenceObject = (MultiChoicePreference<T>) multiSelectionTypeMap.get(preferenceName);
    97                 if(preferenceObject == null)
    98                 {
    99                         preferenceObject = new MultiChoicePreference<T>(gritsPreferenceStore, parameterizedPreference);
    100                         multiSelectionTypeMap.put(preferenceName, preferenceObject);
    101                 }
    102                 return preferenceObject;
    103         }
     77// multi choice preference values
     78MultiChoicePreference<ProjectCollaborator> collaboratorPreference = ProjectPreferenceStore.getMultiChoicePreference(ProjectPreferenceStore.ParameterizedPreference.COLLABORATOR);
     79List<ProjectCollaborator> defaultCollaborators = collaboratorPreference.getSelectedValues();
     80List<ProjectCollaborator> otherCollaborators = collaboratorPreference.getOtherValues();
    10481
    105 ....
    106 }
     82// multi choice integer values
     83MultiChoiceInteger tableColumnPreference = ProjectPreferenceStore.getMultiChoiceInteger(ProjectPreferenceStore.IntegerPreference.COLLABORATORS_TABLE);
     84List<Integer> visibleColumns = tableColumnPreference.getSelectedValues();
     85
    10786}}}
    10887