Project

General

Profile

Download (7.95 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 = 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.ShowCollectingAreasInGeneralSection);
60
            CdmPreference isShowCollectingAreaInGeneralSectionPref = service.find(key);
61
            if (isShowCollectingAreaInGeneralSectionPref != null){
62
                this.isShowCollectingAreaInGeneralSection = isShowCollectingAreaInGeneralSectionPref.getValue() != null? Boolean.valueOf(isShowCollectingAreaInGeneralSectionPref.getValue()): null;
63
                this.allowOverrideShowCollectingAreaInGeneralSection = isShowCollectingAreaInGeneralSectionPref.isAllowOverride();
64
            }else{
65
//                this.isShowCollectingAreaInGeneralSection = (Boolean) PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue();
66
                this.allowOverrideShowCollectingAreaInGeneralSection = true;
67
            }
68

    
69
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
70
            CdmPreference isDeterminationOnlyForFieldUnitsPref = service.find(key);
71
            if (isDeterminationOnlyForFieldUnitsPref != null){
72
                this.isDeterminationOnlyForFieldUnits = isDeterminationOnlyForFieldUnitsPref.getValue() != null? Boolean.valueOf(isDeterminationOnlyForFieldUnitsPref.getValue()): null;
73
                this.allowOverrideDeterminationOnlyForFieldUnits = isDeterminationOnlyForFieldUnitsPref.isAllowOverride();
74
            }else{
75
                this.allowOverrideDeterminationOnlyForFieldUnits = true;
76
            }
77
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
78
            CdmPreference isShowTaxonAssociationPref = service.find(key);
79
            if (isShowTaxonAssociationPref != null){
80
                this.isShowTaxonAssociation = isShowTaxonAssociationPref.getValue() != null? Boolean.valueOf(isShowTaxonAssociationPref.getValue()): null;
81
                this.allowOverrideShowTaxonAssociation = isShowTaxonAssociationPref.isAllowOverride();
82
            }else{
83
                this.allowOverrideShowTaxonAssociation = true;
84
            }
85

    
86
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
87
            CdmPreference isShowLifeFormPref = service.find(key);
88
            if (isShowLifeFormPref != null){
89
                this.isShowLifeForm = isShowLifeFormPref.getValue() != null? Boolean.valueOf(isShowLifeFormPref.getValue()): null;
90
                this.allowOverrideShowLifeForm = isShowLifeFormPref.isAllowOverride();
91
            } else{
92
                this.allowOverrideShowLifeForm = true;
93
            }
94

    
95
        }
96
    }
97

    
98
    @Override
99
     public boolean performOk() {
100
        if (!isApply()){
101
            return true;
102
        }
103
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
104
        if (controller != null){
105
            IPreferenceService service = controller.getPreferenceService();
106
            CdmPreference pref;
107
            if (isShowCollectingAreaInGeneralSection == null && allowOverrideShowCollectingAreaInGeneralSection){
108
                service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection));
109
            }else{
110
                pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, this.isShowCollectingAreaInGeneralSection != null? Boolean.toString(this.isShowCollectingAreaInGeneralSection): null);
111
                pref.setAllowOverride(allowOverrideShowCollectingAreaInGeneralSection);
112
                service.set(pref);
113
            }
114
            if (isShowSpecimenRelatedIssues == null && allowOverrideShowSpecimenRelatedIssues){
115
                service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen));
116
            }else{
117
                pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, isShowSpecimenRelatedIssues != null? Boolean.toString(this.isShowSpecimenRelatedIssues): null);
118
                pref.setAllowOverride(allowOverrideShowSpecimenRelatedIssues);
119
                service.set(pref);
120
            }
121

    
122
            if (isDeterminationOnlyForFieldUnits == null && allowOverrideDeterminationOnlyForFieldUnits){
123
                service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits));
124
            }else{
125
                pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, isDeterminationOnlyForFieldUnits != null? Boolean.toString(this.isDeterminationOnlyForFieldUnits): null);
126
                pref.setAllowOverride(allowOverrideDeterminationOnlyForFieldUnits);
127
                service.set(pref);
128
            }
129
            if (isShowTaxonAssociation == null && allowOverrideShowTaxonAssociation){
130
                service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations));
131
            }else{
132
                pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, isShowTaxonAssociation != null? Boolean.toString(this.isShowTaxonAssociation): null);
133
                pref.setAllowOverride(allowOverrideShowTaxonAssociation);
134
                service.set(pref);
135
            }
136
            if (isShowLifeForm == null && allowOverrideShowLifeForm){
137
                service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm));
138
            }else{
139
                pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, isShowLifeForm != null? Boolean.toString(this.isShowLifeForm): null);
140
                pref.setAllowOverride(allowOverrideShowLifeForm);
141
                service.set(pref);
142
            }
143
            PreferencesUtil.updateDBPreferences();
144

    
145

    
146
        }
147
        return true;
148
    }
149

    
150
}
(16-16/19)