Changes between Version 11 and Version 12 of Grits_ProjectPreferenceStore
- Timestamp:
- 03/09/2017 07:06:18 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Grits_ProjectPreferenceStore
v11 v12 1 1 = Project Preference Store = 2 3 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. 4 3 … … 10 9 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. 11 10 11 12 12 == 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. 15 14 16 15 === Preferences in Project Preference store === 17 16 [[BR]] 18 17 [[Image(project_preference_store.jpg, 700)]][[BR]] 19 Class diagram for project preferences 18 __''Class diagram for project preferences''__ 20 19 [[BR]] 21 20 22 21 23 Currently there are four types of preferences for projects. Each of these preference is an enum objectand has all the information needed to get a preference value.22 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. 24 23 25 - ''StringPreference'' - Simplest type of preference that has a '''string''' value. All information related to itis available in the enum object24 - ''StringPreference'' - Simplest type of preference that has a '''string''' value. All the information is available in the enum object 26 25 27 - ''Preference'' - Type sof preference whose values are a '''list of string'''26 - ''Preference'' - Type of preference whose values are a '''list of string''' 28 27 29 - ''ParameterizedPreference'' - Type sof 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''' 30 29 31 30 - ''IntegerPreference'' - A special case of ''ParameterizedPreference'' whose values are a '''list of integer''' 32 31 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'') enumobject.32 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'') object. 34 33 35 34 - ''SingleChoicePreference'' … … 43 42 - a special case of MultiChoicePreference 44 43 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 === 47 46 [[BR]] 48 47 [[Image(project_preference_all.png, 1000)]][[BR]] 49 Class diagram for project preference store 48 __''Class diagram for ProjectPreferenceStore''__ 50 49 [[BR]] 51 50 52 51 53 == Preference and their values==52 === Preference and their values === 54 53 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: 55 54 56 ||= Preference type =||= Preference values=||55 ||= Preference type =||= Preference values =|| 57 56 || StringPreference || - || 58 57 || Preference || SingleChoicePreference || … … 63 62 __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. 64 63 65 == Code Snippet == 64 65 == Example Code == 66 66 67 67 {{{ 68 68 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 70 String defaultCountry = ProjectPreferenceStore.StringPreference.COUNTRY.getValue(); 76 71 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 73 SingleChoicePreference actionPreference = ProjectPreferenceStore.getSingleChoicePreference(ProjectPreferenceStore.Preference.ACTION); 74 List<String> allActions = actionPreference.getAllValues(); 75 String defaultAction = actionPreference.getDefaultValue(); 89 76 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 78 MultiChoicePreference<ProjectCollaborator> collaboratorPreference = ProjectPreferenceStore.getMultiChoicePreference(ProjectPreferenceStore.ParameterizedPreference.COLLABORATOR); 79 List<ProjectCollaborator> defaultCollaborators = collaboratorPreference.getSelectedValues(); 80 List<ProjectCollaborator> otherCollaborators = collaboratorPreference.getOtherValues(); 104 81 105 .... 106 } 82 // multi choice integer values 83 MultiChoiceInteger tableColumnPreference = ProjectPreferenceStore.getMultiChoiceInteger(ProjectPreferenceStore.IntegerPreference.COLLABORATORS_TABLE); 84 List<Integer> visibleColumns = tableColumnPreference.getSelectedValues(); 85 107 86 }}} 108 87