2ce896e13175e0588645f59bc0bbc55cb6643da5
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / databaseAdmin / preferencePage / SearchDialogAdminPreferences.java
1 /**
2 * Copyright (C) 2019 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.databaseAdmin.preferencePage;
10
11 import eu.etaxonomy.cdm.api.application.ICdmRepository;
12 import eu.etaxonomy.cdm.api.service.IPreferenceService;
13 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
14 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
15 import eu.etaxonomy.taxeditor.preference.SearchDialogPreferences;
16 import eu.etaxonomy.taxeditor.store.CdmStore;
17
18 /**
19 * @author k.luther
20 * @since 08.08.2019
21 */
22 public class SearchDialogAdminPreferences extends SearchDialogPreferences implements IE4AdminPreferencePage {
23
24
25
26
27 @Override
28 public void getValues(){
29 super.getValues();
30 isAdminPreference = true;
31 if(showIdInSelectionDialogPref != null){
32 showIdInSelectionDialog = showIdInSelectionDialogPref.getValue() != null? Boolean.parseBoolean(showIdInSelectionDialogPref.getValue()): null;
33 }else{
34 showIdInSelectionDialog = null;
35 showIdInSelectionDialogPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowIdInSelectionDialog, null);
36 }
37 if (searchForIdentifierAsDefaultPref != null){
38 searchForIdentifierAsDefault = searchForIdentifierAsDefaultPref.getValue() != null? Boolean.parseBoolean(searchForIdentifierAsDefaultPref.getValue()): null;
39 }else{
40 searchForIdentifierAsDefault = null;
41 searchForIdentifierAsDefaultPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.SearchForIdentifierAsDefault, null);
42 }
43 if (searchForIdentifierAndTitleCachePref != null){
44 searchForIdentifierAndTitleCache = searchForIdentifierAndTitleCachePref.getValue() != null? Boolean.parseBoolean(searchForIdentifierAndTitleCachePref.getValue()): null;
45 }else{
46 searchForIdentifierAndTitleCache = null;
47 searchForIdentifierAndTitleCachePref =CdmPreference.NewTaxEditorInstance(PreferencePredicate.SearchForIdentifierAndTitleCache, null);
48 }
49 if (sortTaxaByRankAndNamePref != null){
50 sortTaxaByRankAndName = sortTaxaByRankAndNamePref.getValue() != null? Boolean.parseBoolean(sortTaxaByRankAndNamePref.getValue()): null;
51 }else{
52 sortTaxaByRankAndName = null;
53 sortTaxaByRankAndNamePref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.SortTaxaByRankAndName, null);
54 }
55 if (filterCommonNameReferencesPref != null){
56 filterCommonNameReferences = filterCommonNameReferencesPref.getValue() != null? Boolean.parseBoolean(filterCommonNameReferencesPref.getValue()): null;
57 }else{
58 filterCommonNameReferences = null;
59 filterCommonNameReferencesPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.CommonNameReferencesWithMarker, null);
60 }
61 }
62
63 @Override
64 public boolean performOk(){
65 if (!isApply()){
66 return true;
67 }
68 ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
69 if (controller != null){
70 IPreferenceService service = controller.getPreferenceService();
71 CdmPreference pref;
72 if (showIdInSelectionDialog != null || !showIdInSelectionDialogPref.isAllowOverride()) {
73 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowIdInSelectionDialog, showIdInSelectionDialog != null? showIdInSelectionDialog.toString():null);
74 pref.setAllowOverride(showIdInSelectionDialogPref.isAllowOverride());
75 service.set(pref);
76 }else{
77 service.remove(showIdInSelectionDialogPref.getKey());
78 }
79
80
81 if(searchForIdentifierAsDefault != null || !searchForIdentifierAsDefaultPref.isAllowOverride()){
82 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.SearchForIdentifierAsDefault, searchForIdentifierAsDefault!= null? searchForIdentifierAsDefault.toString():null);
83 pref.setAllowOverride(searchForIdentifierAsDefaultPref.isAllowOverride());
84 service.set(pref);
85 }else{
86 service.remove(searchForIdentifierAsDefaultPref.getKey());
87 }
88
89
90 if(searchForIdentifierAndTitleCache != null || !searchForIdentifierAndTitleCachePref.isAllowOverride()){
91 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.SearchForIdentifierAndTitleCache, searchForIdentifierAndTitleCache!= null? searchForIdentifierAndTitleCache.toString():null);
92 pref.setAllowOverride(searchForIdentifierAndTitleCachePref.isAllowOverride());
93 service.set(pref);
94 }else{
95 service.remove(searchForIdentifierAndTitleCachePref.getKey());
96 }
97
98 if(sortTaxaByRankAndName != null || !sortTaxaByRankAndNamePref.isAllowOverride()){
99
100 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.SortTaxaByRankAndName, sortTaxaByRankAndName!= null? sortTaxaByRankAndName.toString():null);
101 pref.setAllowOverride(sortTaxaByRankAndNamePref.isAllowOverride());
102 service.set(pref);
103 }else{
104 service.remove(sortTaxaByRankAndNamePref.getKey());
105 }
106
107
108
109 if(filterCommonNameReferences != null || !filterCommonNameReferencesPref.isAllowOverride()){
110 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.CommonNameReferencesWithMarker, filterCommonNameReferences!= null? filterCommonNameReferences.toString():null);
111 pref.setAllowOverride(filterCommonNameReferencesPref.isAllowOverride());
112 service.set(pref);
113 }else{
114 service.remove(filterCommonNameReferencesPref.getKey());
115 }
116 }
117
118 return true;
119 }
120
121
122
123 }