Project

General

Profile

Download (6.29 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2014 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
import org.eclipse.swt.widgets.Control;
13

    
14
import eu.etaxonomy.cdm.api.application.ICdmRepository;
15
import eu.etaxonomy.cdm.api.service.IPreferenceService;
16
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
17
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
18
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
19
import eu.etaxonomy.taxeditor.l10n.Messages;
20
import eu.etaxonomy.taxeditor.preference.ChecklistEditorGeneralPreference;
21
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
22
import eu.etaxonomy.taxeditor.store.CdmStore;
23

    
24
/**
25
 * @author a.oppermann
26
 * @date 21.07.2014
27
 *
28
 */
29
public class ChecklistEditorGeneralAdminPreference extends ChecklistEditorGeneralPreference implements IE4AdminPreferencePage {
30

    
31
    Composite parent;
32

    
33

    
34
    @Override
35
    protected Control createContents(Composite parent) {
36
        this.parent = parent;
37
        return super.createContents(parent);
38

    
39
    }
40

    
41
    @Override
42
    public boolean performOk() {
43
        if (!isApply()){
44
            return true;
45
        }
46
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
47
        if (controller == null){
48
            return false;
49
        }
50
        IPreferenceService service = controller.getPreferenceService();
51
        CdmPreference pref;
52
        if (isEditorActivated == null){
53
            service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DistributionEditorActivated));
54
        }else{
55
            pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DistributionEditorActivated, Boolean.toString(isEditorActivated));
56
            pref.setAllowOverride(allowOverrideActivatedButton.getSelection());
57
            service.set(pref);
58
        }
59
        if(displayArea.equals(Messages.Preference_Use_Default)){
60
            service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfAreasInDistributionEditor));
61
        }else{
62
            pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfAreasInDistributionEditor, this.displayArea);
63
            pref.setAllowOverride(allowOverrideAreaDisplayButton.getSelection());
64
            service.set(pref);
65
        }
66

    
67
        if (displayStatus.equals(Messages.Preference_Use_Default)){
68
            service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfStatus));
69
        }else{
70
            pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfStatus, this.displayStatus);
71
            pref.setAllowOverride(allowOverrideStatusDisplayButton.getSelection());
72
            service.set(pref);
73
        }
74

    
75
        if (isShowRank == null){
76
            service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowRankInDistributionEditor));
77
        }else{
78
            pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.ShowRankInDistributionEditor, Boolean.toString(isShowRank));
79
            pref.setAllowOverride(allowOverrideRankButton.getSelection());
80
            service.set(pref);
81
        }
82
        if (orderAreas.equals(Messages.Preference_Use_Default)){
83
            service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.AreasSortedInDistributionEditor));
84
        }else{
85
            pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.AreasSortedInDistributionEditor, this.orderAreas);
86
            pref.setAllowOverride(allowOverrideOrderAreasButton.getSelection());
87
            service.set(pref);
88
        }
89

    
90
        if (displayStatusCombo == null){
91
            service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfStatusInCombo));
92
        }else{
93
            pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfStatusInCombo, displayStatusCombo);
94
            if (prefStatusDisplayInCombo == null){
95
                prefStatusDisplayInCombo = pref;
96
            }
97
            pref.setAllowOverride(prefStatusDisplayInCombo.isAllowOverride());
98
            service.set(pref);
99
        }
100

    
101
        PreferencesUtil.updateDBPreferences();
102

    
103
        return true;
104
    }
105

    
106
    @Override
107
    public void getValues() {
108
        super.getValues();
109
        //distributionEditorPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
110
        if (distributionEditorPref != null){
111
            isEditorActivated = Boolean.valueOf(distributionEditorPref.getValue());
112
        }
113

    
114

    
115
        isAdminPreference = true;
116

    
117
        if (prefAreaDisplay != null){
118
            this.displayArea = prefAreaDisplay.getValue();
119
        }else{
120
            this.displayArea = Messages.Preference_Use_Default;
121
        }
122

    
123

    
124
        if (prefStatusDisplay != null){
125
            this.displayStatus = prefStatusDisplay.getValue();
126
        }else{
127
            this.displayStatus = Messages.Preference_Use_Default;
128
        }
129

    
130
        if (prefStatusDisplayInCombo != null){
131
            this.displayStatusCombo = prefStatusDisplayInCombo.getValue();
132
        }else{
133
            this.displayStatusCombo = Messages.Preference_Use_Default;
134
        }
135

    
136

    
137
        if (prefAreaSort != null){
138
            if (prefAreaSort.getValue() != null){
139
                this.orderAreas = prefAreaSort.getValue().toString();
140
            }else{
141
                this.orderAreas = Messages.Preference_Use_Default;
142
            }
143

    
144
        }else{
145
            this.orderAreas = Messages.Preference_Use_Default;
146

    
147
        }
148

    
149

    
150
        if (prefRank != null){
151
            this.isShowRank = Boolean.valueOf(prefRank.getValue().toString());
152

    
153
        }else{
154
            this.isShowRank = null;
155
        }
156

    
157

    
158
        if (prefOwnDescription != null){
159
            this.ownDescriptionForDistributionEditor = Boolean.valueOf(prefOwnDescription.getValue().toString());
160
        }else{
161
            this.ownDescriptionForDistributionEditor = Boolean.valueOf(PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue().toString());
162
        }
163

    
164

    
165

    
166
        setValid(false);
167
    }
168

    
169

    
170

    
171
}
(3-3/17)