ref #8045: further implementation for default/explicit value selection preference...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / databaseAdmin / preferencePage / SpecimenAdminPreferences.java
1 /**
2 * Copyright (C) 2018 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 org.eclipse.swt.widgets.Composite;
12
13 import eu.etaxonomy.cdm.api.application.ICdmRepository;
14 import eu.etaxonomy.cdm.api.service.IPreferenceService;
15 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
16 import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
17 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
18 import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
19 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20 import eu.etaxonomy.taxeditor.preference.SpecimenOrObservationPreferences;
21 import eu.etaxonomy.taxeditor.store.CdmStore;
22
23 /**
24 * @author k.luther
25 * @since 27.04.2018
26 *
27 */
28 public class SpecimenAdminPreferences extends SpecimenOrObservationPreferences implements IE4AdminPreferencePage {
29
30
31
32 Composite composite;
33 CdmPreference showSpecimenPref = null;
34
35 @Override
36 public void init() {
37 super.init();
38 if(!CdmStore.isActive()){
39 return;
40 }
41 }
42
43 @Override
44 protected void getValues(){
45 isAdminPreference = true;
46
47 ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
48 if (controller != null){
49 IPreferenceService service = controller.getPreferenceService();
50 PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
51 showSpecimenPref = service.find(key);
52 if (showSpecimenPref != null){
53 this.isShowSpecimenRelatedIssues = Boolean.valueOf(showSpecimenPref.getValue());
54 this.allowOverrideShowSpecimenRelatedIssues = showSpecimenPref.isAllowOverride();
55 }else{
56 //showSpecimenPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(true));
57 // this.isShowSpecimenRelatedIssues = true;
58 this.allowOverrideShowSpecimenRelatedIssues = true;
59 }
60
61 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
62 CdmPreference isShowCollectingAreaInGeneralSectionPref = service.find(key);
63 if (isShowCollectingAreaInGeneralSectionPref != null){
64 this.isShowCollectingAreaInGeneralSection = Boolean.valueOf(isShowCollectingAreaInGeneralSectionPref.getValue());
65 this.allowOverrideShowCollectingAreaInGeneralSection = isShowCollectingAreaInGeneralSectionPref.isAllowOverride();
66 }else{
67 // this.isShowCollectingAreaInGeneralSection = (Boolean) PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue();
68 this.allowOverrideShowCollectingAreaInGeneralSection = true;
69 }
70
71 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
72 CdmPreference isDeterminationOnlyForFieldUnitsPref = service.find(key);
73 if (isDeterminationOnlyForFieldUnitsPref != null){
74 this.isDeterminationOnlyForFieldUnits = Boolean.valueOf(isDeterminationOnlyForFieldUnitsPref.getValue());
75 this.allowOverrideDeterminationOnlyForFieldUnits = isDeterminationOnlyForFieldUnitsPref.isAllowOverride();
76 }else{
77 // this.isDeterminationOnlyForFieldUnits =(Boolean)PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue();
78 this.allowOverrideDeterminationOnlyForFieldUnits = true;
79 }
80 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
81 CdmPreference isShowTaxonAssociationPref = service.find(key);
82 if (isShowTaxonAssociationPref != null){
83 this.isShowTaxonAssociation = Boolean.valueOf(isShowTaxonAssociationPref.getValue());
84 this.allowOverrideShowTaxonAssociation = isShowTaxonAssociationPref.isAllowOverride();
85 }else{
86 // this.isShowTaxonAssociation = (Boolean)PreferencePredicate.ShowTaxonAssociations.getDefaultValue();
87 this.allowOverrideShowTaxonAssociation = true;
88 }
89
90 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
91 CdmPreference isShowLifeFormPref = service.find(key);
92 if (isShowLifeFormPref != null){
93 this.isShowLifeForm = Boolean.valueOf(isShowLifeFormPref.getValue());
94 this.allowOverrideShowLifeForm = isShowLifeFormPref.isAllowOverride();
95 } else{
96 // this.isShowLifeForm = (Boolean)PreferencePredicate.ShowLifeForm.getDefaultValue();
97 this.allowOverrideShowLifeForm = true;
98 }
99
100 }
101 }
102
103 @Override
104 public boolean performOk() {
105 if (!isApply()){
106 return true;
107 }
108 ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
109 if (controller != null){
110 IPreferenceService service = controller.getPreferenceService();
111 CdmPreference pref;
112 if (isShowCollectingAreaInGeneralSection == null){
113 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection));
114 }else{
115 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, Boolean.toString(this.isShowCollectingAreaInGeneralSection));
116 pref.setAllowOverride(allowOverrideShowCollectingAreaInGeneralSection);
117 service.set(pref);
118 }
119 if (isShowSpecimenRelatedIssues == null){
120 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen));
121 }else{
122 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(this.isShowSpecimenRelatedIssues));
123 pref.setAllowOverride(allowOverrideShowSpecimenRelatedIssues);
124 service.set(pref);
125 }
126
127 if (isDeterminationOnlyForFieldUnits == null){
128 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits));
129 }else{
130 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, Boolean.toString(this.isDeterminationOnlyForFieldUnits));
131 pref.setAllowOverride(allowOverrideDeterminationOnlyForFieldUnits);
132 service.set(pref);
133 }
134 if (isShowTaxonAssociation == null){
135 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations));
136 }else{
137 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, Boolean.toString(this.isShowTaxonAssociation));
138 pref.setAllowOverride(allowOverrideShowTaxonAssociation);
139 service.set(pref);
140 }
141 if (isShowLifeForm == null){
142 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm));
143 }else{
144 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, Boolean.toString(this.isShowLifeForm));
145 pref.setAllowOverride(allowOverrideShowLifeForm);
146 service.set(pref);
147 }
148 PreferencesUtil.updateDBPreferences();
149
150
151 }
152 return true;
153 }
154
155 }