Project

General

Profile

Download (6.29 KB) Statistics
| Branch: | Tag: | Revision:
1 432276e4 Katja Luther
/**
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 9b8d1a1c Katja Luther
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
18 63732a7c Katja Luther
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
19
import eu.etaxonomy.taxeditor.l10n.Messages;
20 432276e4 Katja Luther
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 85bd68d3 Katja Luther
    Composite parent;
32 dd2e9b75 Katja Luther
33 432276e4 Katja Luther
34
    @Override
35
    protected Control createContents(Composite parent) {
36 85bd68d3 Katja Luther
        this.parent = parent;
37 432276e4 Katja Luther
        return super.createContents(parent);
38
39
    }
40
41
    @Override
42
    public boolean performOk() {
43 63732a7c Katja Luther
        if (!isApply()){
44 432276e4 Katja Luther
            return true;
45
        }
46
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
47
        if (controller == null){
48
            return false;
49
        }
50
        IPreferenceService service = controller.getPreferenceService();
51 63732a7c Katja Luther
        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 432276e4 Katja Luther
67 63732a7c Katja Luther
        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 432276e4 Katja Luther
75 63732a7c Katja Luther
        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 432276e4 Katja Luther
90 11847891 Katja Luther
        if (displayStatusCombo == null){
91
            service.remove(CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DisplayOfStatusInCombo));
92 63732a7c Katja Luther
        }else{
93 11847891 Katja Luther
            pref = CdmPreference.NewTaxEditorInstance( PreferencePredicate.DisplayOfStatusInCombo, displayStatusCombo);
94
            if (prefStatusDisplayInCombo == null){
95
                prefStatusDisplayInCombo = pref;
96
            }
97
            pref.setAllowOverride(prefStatusDisplayInCombo.isAllowOverride());
98 63732a7c Katja Luther
            service.set(pref);
99
        }
100 198c9340 Katja Luther
101 432276e4 Katja Luther
        PreferencesUtil.updateDBPreferences();
102
103
        return true;
104
    }
105
106
    @Override
107 6285cec5 Katja Luther
    public void getValues() {
108 755105d4 Katja Luther
        super.getValues();
109 63732a7c Katja Luther
        //distributionEditorPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
110
        if (distributionEditorPref != null){
111
            isEditorActivated = Boolean.valueOf(distributionEditorPref.getValue());
112 432276e4 Katja Luther
        }
113 63732a7c Katja Luther
114
115 432276e4 Katja Luther
        isAdminPreference = true;
116
117 755105d4 Katja Luther
        if (prefAreaDisplay != null){
118
            this.displayArea = prefAreaDisplay.getValue();
119 432276e4 Katja Luther
        }else{
120 63732a7c Katja Luther
            this.displayArea = Messages.Preference_Use_Default;
121 432276e4 Katja Luther
        }
122
123 755105d4 Katja Luther
124
        if (prefStatusDisplay != null){
125
            this.displayStatus = prefStatusDisplay.getValue();
126 432276e4 Katja Luther
        }else{
127 63732a7c Katja Luther
            this.displayStatus = Messages.Preference_Use_Default;
128 432276e4 Katja Luther
        }
129
130 11847891 Katja Luther
        if (prefStatusDisplayInCombo != null){
131
            this.displayStatusCombo = prefStatusDisplayInCombo.getValue();
132
        }else{
133
            this.displayStatusCombo = Messages.Preference_Use_Default;
134
        }
135
136
137 755105d4 Katja Luther
        if (prefAreaSort != null){
138
            if (prefAreaSort.getValue() != null){
139
                this.orderAreas = prefAreaSort.getValue().toString();
140 19633083 Katja Luther
            }else{
141 63732a7c Katja Luther
                this.orderAreas = Messages.Preference_Use_Default;
142 19633083 Katja Luther
            }
143 755105d4 Katja Luther
144 432276e4 Katja Luther
        }else{
145 63732a7c Katja Luther
            this.orderAreas = Messages.Preference_Use_Default;
146 755105d4 Katja Luther
147 432276e4 Katja Luther
        }
148
149 755105d4 Katja Luther
150
        if (prefRank != null){
151
            this.isShowRank = Boolean.valueOf(prefRank.getValue().toString());
152
153 432276e4 Katja Luther
        }else{
154 63732a7c Katja Luther
            this.isShowRank = null;
155 432276e4 Katja Luther
        }
156 239530ee Katja Luther
157 755105d4 Katja Luther
158
        if (prefOwnDescription != null){
159
            this.ownDescriptionForDistributionEditor = Boolean.valueOf(prefOwnDescription.getValue().toString());
160 239530ee Katja Luther
        }else{
161 9b8d1a1c Katja Luther
            this.ownDescriptionForDistributionEditor = Boolean.valueOf(PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue().toString());
162 239530ee Katja Luther
        }
163
164 198c9340 Katja Luther
165 9181d281 Katja Luther
166 c130c5fe Katja Luther
        setValid(false);
167 432276e4 Katja Luther
    }
168
169 85bd68d3 Katja Luther
170
171 432276e4 Katja Luther
}