Project

General

Profile

Download (8.42 KB) Statistics
| Branch: | Tag: | Revision:
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 (showSpecimenPref == null){
106
            return true;
107
        }
108
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
109
        if (controller != null){
110
            IPreferenceService service = controller.getPreferenceService();
111

    
112
            CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, Boolean.toString(this.isShowCollectingAreaInGeneralSection));
113
            pref.setAllowOverride(allowOverrideShowCollectingAreaInGeneralSection);
114
            service.set(pref);
115
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(this.isShowSpecimenRelatedIssues));
116
            pref.setAllowOverride(allowOverrideShowSpecimenRelatedIssues);
117
            service.set(pref);
118

    
119
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, Boolean.toString(this.isDeterminationOnlyForFieldUnits));
120
            pref.setAllowOverride(allowOverrideDeterminationOnlyForFieldUnits);
121
            service.set(pref);
122

    
123
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, Boolean.toString(this.isShowTaxonAssociation));
124
            pref.setAllowOverride(allowOverrideShowTaxonAssociation);
125
            service.set(pref);
126

    
127
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, Boolean.toString(this.isShowLifeForm));
128
            pref.setAllowOverride(allowOverrideShowLifeForm);
129
            service.set(pref);
130
            PreferencesUtil.updateDBPreferences();
131

    
132

    
133
        }
134
        return true;
135
    }
136

    
137
    @Override
138
    protected void performDefaults() {
139
        isShowSpecimenRelatedIssues = (Boolean)PreferencePredicate.ShowSpecimen.getDefaultValue();
140
        showSpecimenButton.setSelection(isShowSpecimenRelatedIssues);
141

    
142
        allowOverrideShowSpecimenRelatedIssues = true;
143
        allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
144

    
145
        isShowCollectingAreaInGeneralSection = (Boolean)PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue();
146
        showCollectingAreaInGeneralSectionButton.setSelection(isShowCollectingAreaInGeneralSection);
147

    
148
        allowOverrideShowCollectingAreaInGeneralSection = true;
149
        allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowCollectingAreaInGeneralSection);
150

    
151
        isDeterminationOnlyForFieldUnits = (Boolean) PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue();
152
        determinationOnlyForFieldUnitsButton.setSelection(isDeterminationOnlyForFieldUnits);
153

    
154
        allowOverrideDeterminationOnlyForFieldUnits = true;
155
        allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideDeterminationOnlyForFieldUnits);
156

    
157
        isShowTaxonAssociation = (Boolean) PreferencePredicate.ShowTaxonAssociations.getDefaultValue();
158
        showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
159

    
160
        allowOverrideShowTaxonAssociation = true;
161
        allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowTaxonAssociation);
162

    
163
        isShowLifeForm = (Boolean) PreferencePredicate.ShowLifeForm.getDefaultValue();
164
        showLifeFormButton.setSelection(isShowLifeForm);
165

    
166
        allowOverrideShowLifeForm = true;
167
        allowOverrideShowLifeFormButton.setSelection(allowOverrideShowLifeForm);
168

    
169
        super.performDefaults();
170
    }
171

    
172
}
(12-12/13)