fix #9066: visibility of specimen list editor configurable
[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 = showSpecimenPref.getValue() != null? Boolean.valueOf(showSpecimenPref.getValue()): null;
54 this.allowOverrideShowSpecimenRelatedIssues = showSpecimenPref.isAllowOverride();
55 }else{
56 this.allowOverrideShowSpecimenRelatedIssues = true;
57 }
58
59 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimenListEditor);
60 CdmPreference isShowSpecimenListEditorPref = service.find(key);
61 if (isShowSpecimenListEditorPref != null){
62 this.isShowListEditor = isShowSpecimenListEditorPref.getValue() != null? Boolean.valueOf(isShowSpecimenListEditorPref.getValue()): null;
63 this.allowOverrideShowListEditor = isShowSpecimenListEditorPref.isAllowOverride();
64 }else{
65 // this.isShowCollectingAreaInGeneralSection = (Boolean) PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue();
66 this.allowOverrideShowListEditor = true;
67 }
68
69
70 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
71 CdmPreference isShowCollectingAreaInGeneralSectionPref = service.find(key);
72 if (isShowCollectingAreaInGeneralSectionPref != null){
73 this.isShowCollectingAreaInGeneralSection = isShowCollectingAreaInGeneralSectionPref.getValue() != null? Boolean.valueOf(isShowCollectingAreaInGeneralSectionPref.getValue()): null;
74 this.allowOverrideShowCollectingAreaInGeneralSection = isShowCollectingAreaInGeneralSectionPref.isAllowOverride();
75 }else{
76 // this.isShowCollectingAreaInGeneralSection = (Boolean) PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue();
77 this.allowOverrideShowCollectingAreaInGeneralSection = true;
78 }
79
80 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
81 CdmPreference isDeterminationOnlyForFieldUnitsPref = service.find(key);
82 if (isDeterminationOnlyForFieldUnitsPref != null){
83 this.isDeterminationOnlyForFieldUnits = isDeterminationOnlyForFieldUnitsPref.getValue() != null? Boolean.valueOf(isDeterminationOnlyForFieldUnitsPref.getValue()): null;
84 this.allowOverrideDeterminationOnlyForFieldUnits = isDeterminationOnlyForFieldUnitsPref.isAllowOverride();
85 }else{
86 this.allowOverrideDeterminationOnlyForFieldUnits = true;
87 }
88 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
89 CdmPreference isShowTaxonAssociationPref = service.find(key);
90 if (isShowTaxonAssociationPref != null){
91 this.isShowTaxonAssociation = isShowTaxonAssociationPref.getValue() != null? Boolean.valueOf(isShowTaxonAssociationPref.getValue()): null;
92 this.allowOverrideShowTaxonAssociation = isShowTaxonAssociationPref.isAllowOverride();
93 }else{
94 this.allowOverrideShowTaxonAssociation = true;
95 }
96
97 key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
98 CdmPreference isShowLifeFormPref = service.find(key);
99 if (isShowLifeFormPref != null){
100 this.isShowLifeForm = isShowLifeFormPref.getValue() != null? Boolean.valueOf(isShowLifeFormPref.getValue()): null;
101 this.allowOverrideShowLifeForm = isShowLifeFormPref.isAllowOverride();
102 } else{
103 this.allowOverrideShowLifeForm = true;
104 }
105
106 }
107 }
108
109 @Override
110 public boolean performOk() {
111 if (!isApply()){
112 return true;
113 }
114 ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
115 if (controller != null){
116 IPreferenceService service = controller.getPreferenceService();
117 CdmPreference pref;
118 if (isShowCollectingAreaInGeneralSection == null && allowOverrideShowCollectingAreaInGeneralSection){
119 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection));
120 }else{
121 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, this.isShowCollectingAreaInGeneralSection != null? Boolean.toString(this.isShowCollectingAreaInGeneralSection): null);
122 pref.setAllowOverride(allowOverrideShowCollectingAreaInGeneralSection);
123 service.set(pref);
124 }
125
126 if (isShowListEditor == null && allowOverrideShowListEditor){
127 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimenListEditor));
128 }else{
129 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimenListEditor, this.isShowListEditor != null? Boolean.toString(this.isShowListEditor): null);
130 pref.setAllowOverride(allowOverrideShowListEditor);
131 service.set(pref);
132 }
133
134 if (isShowSpecimenRelatedIssues == null && allowOverrideShowSpecimenRelatedIssues){
135 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen));
136 }else{
137 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, isShowSpecimenRelatedIssues != null? Boolean.toString(this.isShowSpecimenRelatedIssues): null);
138 pref.setAllowOverride(allowOverrideShowSpecimenRelatedIssues);
139 service.set(pref);
140 }
141
142 if (isDeterminationOnlyForFieldUnits == null && allowOverrideDeterminationOnlyForFieldUnits){
143 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits));
144 }else{
145 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, isDeterminationOnlyForFieldUnits != null? Boolean.toString(this.isDeterminationOnlyForFieldUnits): null);
146 pref.setAllowOverride(allowOverrideDeterminationOnlyForFieldUnits);
147 service.set(pref);
148 }
149 if (isShowTaxonAssociation == null && allowOverrideShowTaxonAssociation){
150 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations));
151 }else{
152 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, isShowTaxonAssociation != null? Boolean.toString(this.isShowTaxonAssociation): null);
153 pref.setAllowOverride(allowOverrideShowTaxonAssociation);
154 service.set(pref);
155 }
156 if (isShowLifeForm == null && allowOverrideShowLifeForm){
157 service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm));
158 }else{
159 pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, isShowLifeForm != null? Boolean.toString(this.isShowLifeForm): null);
160 pref.setAllowOverride(allowOverrideShowLifeForm);
161 service.set(pref);
162 }
163 PreferencesUtil.updateDBPreferences();
164
165
166 }
167 return true;
168 }
169
170 }