Project

General

Profile

Download (6.73 KB) Statistics
| Branch: | Tag: | Revision:
1 74b82668 Katja Luther
/**
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.PreferenceSubject;
18 c11a2278 Katja Luther
import eu.etaxonomy.taxeditor.preference.EditorPreferencePredicate;
19 3b975922 Katja Luther
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20 185eb33b Katja Luther
import eu.etaxonomy.taxeditor.preference.SpecimenOrObservationPreferences;
21 74b82668 Katja Luther
import eu.etaxonomy.taxeditor.store.CdmStore;
22
23
/**
24
 * @author k.luther
25
 * @since 27.04.2018
26
 *
27
 */
28 185eb33b Katja Luther
public class SpecimenAdminPreferences extends SpecimenOrObservationPreferences implements IE4AdminPreferencePage {
29
30 74b82668 Katja Luther
31 239530ee Katja Luther
32 3b975922 Katja Luther
    Composite composite;
33 5e3a2c94 Patrick Plitzner
    CdmPreference showSpecimenPref = null;
34 74b82668 Katja Luther
35
    @Override
36
    public void init() {
37
        super.init();
38
        if(!CdmStore.isActive()){
39
            return;
40
        }
41 240ff660 Katja Luther
    }
42 74b82668 Katja Luther
43 185eb33b Katja Luther
    @Override
44
    protected void getValues(){
45
        isAdminPreference = true;
46 9181d281 Katja Luther
47 240ff660 Katja Luther
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
48
        if (controller != null){
49
            IPreferenceService service = controller.getPreferenceService();
50 c11a2278 Katja Luther
            PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowSpecimen);
51 5e3a2c94 Patrick Plitzner
            showSpecimenPref = service.find(key);
52
            if (showSpecimenPref != null){
53
                this.isShowSpecimenRelatedIssues = Boolean.valueOf(showSpecimenPref.getValue());
54 239530ee Katja Luther
                this.allowOverrideShowSpecimenRelatedIssues = showSpecimenPref.isAllowOverride();
55 f2efb095 Katja Luther
            }else{
56 c11a2278 Katja Luther
                showSpecimenPref = CdmPreference.NewTaxEditorInstance(EditorPreferencePredicate.ShowSpecimen, Boolean.toString(true));
57 f2efb095 Katja Luther
                this.isShowSpecimenRelatedIssues = true;
58 239530ee Katja Luther
                this.allowOverrideShowSpecimenRelatedIssues = true;
59 3b975922 Katja Luther
            }
60
61 c11a2278 Katja Luther
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowCollectingAreasInGeneralSection);
62 240ff660 Katja Luther
            CdmPreference isShowCollectingAreaInGeneralSectionPref = service.find(key);
63
            if (isShowCollectingAreaInGeneralSectionPref != null){
64
                this.isShowCollectingAreaInGeneralSection = Boolean.valueOf(isShowCollectingAreaInGeneralSectionPref.getValue());
65 239530ee Katja Luther
                this.allowOverrideShowCollectingAreaInGeneralSection = isShowCollectingAreaInGeneralSectionPref.isAllowOverride();
66 ebb78401 Katja Luther
            }else{
67
                this.isShowCollectingAreaInGeneralSection = (Boolean) EditorPreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue();
68
                this.allowOverrideShowCollectingAreaInGeneralSection = true;
69 240ff660 Katja Luther
            }
70
71 c11a2278 Katja Luther
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.DeterminationOnlyForFieldUnits);
72 240ff660 Katja Luther
            CdmPreference isDeterminationOnlyForFieldUnitsPref = service.find(key);
73
            if (isDeterminationOnlyForFieldUnitsPref != null){
74
                this.isDeterminationOnlyForFieldUnits = Boolean.valueOf(isDeterminationOnlyForFieldUnitsPref.getValue());
75 239530ee Katja Luther
                this.allowOverrideDeterminationOnlyForFieldUnits = isDeterminationOnlyForFieldUnitsPref.isAllowOverride();
76 ebb78401 Katja Luther
            }else{
77
                this.isDeterminationOnlyForFieldUnits =(Boolean)EditorPreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue();
78
                this.allowOverrideDeterminationOnlyForFieldUnits = true;
79 240ff660 Katja Luther
            }
80 c11a2278 Katja Luther
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowTaxonAssociations);
81 240ff660 Katja Luther
            CdmPreference isShowTaxonAssociationPref = service.find(key);
82
            if (isShowTaxonAssociationPref != null){
83
                this.isShowTaxonAssociation = Boolean.valueOf(isShowTaxonAssociationPref.getValue());
84 239530ee Katja Luther
                this.allowOverrideShowTaxonAssociation = isShowTaxonAssociationPref.isAllowOverride();
85 ebb78401 Katja Luther
            }else{
86
                this.isShowTaxonAssociation = (Boolean)EditorPreferencePredicate.ShowTaxonAssociations.getDefaultValue();
87
                this.allowOverrideShowTaxonAssociation = true;
88 240ff660 Katja Luther
            }
89 74b82668 Katja Luther
90 c11a2278 Katja Luther
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), EditorPreferencePredicate.ShowLifeForm);
91 240ff660 Katja Luther
            CdmPreference isShowLifeFormPref = service.find(key);
92
            if (isShowLifeFormPref != null){
93
                this.isShowLifeForm = Boolean.valueOf(isShowLifeFormPref.getValue());
94 239530ee Katja Luther
                this.allowOverrideShowLifeForm = isShowLifeFormPref.isAllowOverride();
95 ebb78401 Katja Luther
            } else{
96
                this.isShowLifeForm = (Boolean)EditorPreferencePredicate.ShowLifeForm.getDefaultValue();
97
                this.allowOverrideShowLifeForm = true;
98 240ff660 Katja Luther
            }
99 74b82668 Katja Luther
100 240ff660 Katja Luther
        }
101 74b82668 Katja Luther
    }
102
103
    @Override
104
     public boolean performOk() {
105 5e3a2c94 Patrick Plitzner
        if (showSpecimenPref == null){
106 4e6f2196 Katja Luther
            return true;
107
        }
108 6c7e59f3 Katja Luther
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
109
        if (controller != null){
110
            IPreferenceService service = controller.getPreferenceService();
111
112 c11a2278 Katja Luther
            CdmPreference pref = CdmPreference.NewTaxEditorInstance(EditorPreferencePredicate.ShowCollectingAreasInGeneralSection, Boolean.toString(this.isShowCollectingAreaInGeneralSection));
113 239530ee Katja Luther
            pref.setAllowOverride(allowOverrideShowCollectingAreaInGeneralSection);
114 6c7e59f3 Katja Luther
            service.set(pref);
115 c11a2278 Katja Luther
            pref = CdmPreference.NewTaxEditorInstance(EditorPreferencePredicate.ShowSpecimen, Boolean.toString(this.isShowSpecimenRelatedIssues));
116 239530ee Katja Luther
            pref.setAllowOverride(allowOverrideShowSpecimenRelatedIssues);
117 69be3e73 Katja Luther
            service.set(pref);
118 6c7e59f3 Katja Luther
119 c11a2278 Katja Luther
            pref = CdmPreference.NewTaxEditorInstance(EditorPreferencePredicate.DeterminationOnlyForFieldUnits, Boolean.toString(this.isDeterminationOnlyForFieldUnits));
120 239530ee Katja Luther
            pref.setAllowOverride(allowOverrideDeterminationOnlyForFieldUnits);
121 6c7e59f3 Katja Luther
            service.set(pref);
122 74b82668 Katja Luther
123 c11a2278 Katja Luther
            pref = CdmPreference.NewTaxEditorInstance(EditorPreferencePredicate.ShowTaxonAssociations, Boolean.toString(this.isShowTaxonAssociation));
124 239530ee Katja Luther
            pref.setAllowOverride(allowOverrideShowTaxonAssociation);
125 6c7e59f3 Katja Luther
            service.set(pref);
126 74b82668 Katja Luther
127 c11a2278 Katja Luther
            pref = CdmPreference.NewTaxEditorInstance(EditorPreferencePredicate.ShowLifeForm, Boolean.toString(this.isShowLifeForm));
128 239530ee Katja Luther
            pref.setAllowOverride(allowOverrideShowLifeForm);
129 6c7e59f3 Katja Luther
            service.set(pref);
130 3b975922 Katja Luther
            PreferencesUtil.updateDBPreferences();
131 6c7e59f3 Katja Luther
132
133
        }
134 74b82668 Katja Luther
        return true;
135
    }
136
137
}