2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.databaseAdmin
.preferencePage
;
11 import org
.eclipse
.swt
.widgets
.Composite
;
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
;
28 public class SpecimenAdminPreferences
extends SpecimenOrObservationPreferences
implements IE4AdminPreferencePage
{
33 CdmPreference showSpecimenPref
= null;
38 if(!CdmStore
.isActive()){
44 protected void getValues(){
45 isAdminPreference
= true;
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();
56 this.allowOverrideShowSpecimenRelatedIssues
= true;
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();
65 // this.isShowCollectingAreaInGeneralSection = (Boolean) PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue();
66 this.allowOverrideShowListEditor
= true;
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();
76 // this.isShowCollectingAreaInGeneralSection = (Boolean) PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue();
77 this.allowOverrideShowCollectingAreaInGeneralSection
= true;
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();
86 this.allowOverrideDeterminationOnlyForFieldUnits
= true;
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();
94 this.allowOverrideShowTaxonAssociation
= true;
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();
103 this.allowOverrideShowLifeForm
= true;
110 public boolean performOk() {
114 ICdmRepository controller
= CdmStore
.getCurrentApplicationConfiguration();
115 if (controller
!= null){
116 IPreferenceService service
= controller
.getPreferenceService();
118 if (isShowCollectingAreaInGeneralSection
== null && allowOverrideShowCollectingAreaInGeneralSection
){
119 service
.remove(CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowCollectingAreasInGeneralSection
));
121 pref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.ShowCollectingAreasInGeneralSection
, this.isShowCollectingAreaInGeneralSection
!= null? Boolean
.toString(this.isShowCollectingAreaInGeneralSection
): null);
122 pref
.setAllowOverride(allowOverrideShowCollectingAreaInGeneralSection
);
126 if (isShowListEditor
== null && allowOverrideShowListEditor
){
127 service
.remove(CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowSpecimenListEditor
));
129 pref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.ShowSpecimenListEditor
, this.isShowListEditor
!= null? Boolean
.toString(this.isShowListEditor
): null);
130 pref
.setAllowOverride(allowOverrideShowListEditor
);
134 if (isShowSpecimenRelatedIssues
== null && allowOverrideShowSpecimenRelatedIssues
){
135 service
.remove(CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowSpecimen
));
137 pref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.ShowSpecimen
, isShowSpecimenRelatedIssues
!= null? Boolean
.toString(this.isShowSpecimenRelatedIssues
): null);
138 pref
.setAllowOverride(allowOverrideShowSpecimenRelatedIssues
);
142 if (isDeterminationOnlyForFieldUnits
== null && allowOverrideDeterminationOnlyForFieldUnits
){
143 service
.remove(CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.DeterminationOnlyForFieldUnits
));
145 pref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.DeterminationOnlyForFieldUnits
, isDeterminationOnlyForFieldUnits
!= null? Boolean
.toString(this.isDeterminationOnlyForFieldUnits
): null);
146 pref
.setAllowOverride(allowOverrideDeterminationOnlyForFieldUnits
);
149 if (isShowTaxonAssociation
== null && allowOverrideShowTaxonAssociation
){
150 service
.remove(CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowTaxonAssociations
));
152 pref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.ShowTaxonAssociations
, isShowTaxonAssociation
!= null? Boolean
.toString(this.isShowTaxonAssociation
): null);
153 pref
.setAllowOverride(allowOverrideShowTaxonAssociation
);
156 if (isShowLifeForm
== null && allowOverrideShowLifeForm
){
157 service
.remove(CdmPreference
.NewKey(PreferenceSubject
.NewTaxEditorInstance(), PreferencePredicate
.ShowLifeForm
));
159 pref
= CdmPreference
.NewTaxEditorInstance(PreferencePredicate
.ShowLifeForm
, isShowLifeForm
!= null? Boolean
.toString(this.isShowLifeForm
): null);
160 pref
.setAllowOverride(allowOverrideShowLifeForm
);
163 PreferencesUtil
.updateDBPreferences();