Project

General

Profile

Download (6.3 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.taxeditor.preference.ChecklistEditorGeneralPreference;
18
import eu.etaxonomy.taxeditor.preference.EditorPreferencePredicate;
19
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21

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

    
29

    
30
    @Override
31
    protected Control createContents(Composite parent) {
32
        return super.createContents(parent);
33

    
34
    }
35

    
36
    @Override
37
    public boolean performOk() {
38
        if (!isValid()){
39
            return true;
40
        }
41
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
42
        if (controller == null){
43
            return false;
44
        }
45
        IPreferenceService service = controller.getPreferenceService();
46

    
47
        CdmPreference pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.DistributionEditorActivated, Boolean.toString(isEditorActivated));
48
        pref.setAllowOverride(this.allowOverrideActivated);
49
        service.set(pref);
50

    
51
        pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.DisplayOfAreasInDistributionEditor, this.displayArea);
52
        pref.setAllowOverride(this.allowOverrideAreaDisplay);
53
        service.set(pref);
54

    
55
        pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.DisplayOfStatus, this.displayStatus);
56
        pref.setAllowOverride(this.allowOverrideStatusDisplay);
57
        service.set(pref);
58

    
59
        pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.ShowRankInDistributionEditor, Boolean.toString(isShowRank));
60
        pref.setAllowOverride(this.allowOverrideRank);
61
        service.set(pref);
62

    
63
        pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.AreasSortedInDistributionEditor, this.orderAreas);
64
        pref.setAllowOverride(this.allowOverrideOrderAreas);
65
        service.set(pref);
66

    
67
        pref = CdmPreference.NewTaxEditorInstance( EditorPreferencePredicate.OwnDescriptionForDistributionEditor, Boolean.toString(ownDescriptionForDistributionEditor));
68
        pref.setAllowOverride(this.allowOverrideOwnDescriptionForDistributionEditor);
69
        service.set(pref);
70

    
71
        PreferencesUtil.updateDBPreferences();
72

    
73
        return true;
74
    }
75

    
76
    @Override
77
    public void getValues() {
78

    
79
        distributionEditorPref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.DistributionEditorActivated);
80
        if (distributionEditorPref == null){
81
            distributionEditorPref = CdmPreference.NewTaxEditorInstance(EditorPreferencePredicate.DistributionEditorActivated, EditorPreferencePredicate.DistributionEditorActivated.getDefaultValue().toString());
82
        }
83
        isEditorActivated = Boolean.valueOf(distributionEditorPref.getValue());
84
        allowOverrideActivated = distributionEditorPref.isAllowOverride();
85
        isAdminPreference = true;
86

    
87
        CdmPreference pref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.DisplayOfAreasInDistributionEditor);
88
        if (pref != null){
89
            this.displayArea = pref.getValue();
90
            this.allowOverrideAreaDisplay = pref.isAllowOverride();
91
        }else{
92
            this.displayArea = EditorPreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString();
93
            this.allowOverrideAreaDisplay = true;
94
        }
95

    
96
        pref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.DisplayOfStatus);
97
        if (pref != null){
98
            this.displayStatus = pref.getValue();
99
            this.allowOverrideStatusDisplay = pref.isAllowOverride();
100
        }else{
101
            this.displayStatus = EditorPreferencePredicate.DisplayOfStatus.getDefaultValue().toString();
102
            this.allowOverrideStatusDisplay = true;
103
        }
104

    
105
        pref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.AreasSortedInDistributionEditor);
106
        if (pref != null){
107
            if (pref.getValue() != null){
108
                this.orderAreas = pref.getValue().toString();
109
            }else{
110
                this.orderAreas = EditorPreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue().toString();
111
            }
112
            this.allowOverrideOrderAreas = pref.isAllowOverride();
113
        }else{
114
            this.orderAreas = EditorPreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue().toString();
115
            this.allowOverrideOrderAreas = true;
116
        }
117

    
118
        pref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.ShowRankInDistributionEditor);
119
        if (pref != null){
120
            this.isShowRank = Boolean.valueOf(pref.getValue().toString());
121
            this.allowOverrideRank = pref.isAllowOverride();
122
        }else{
123
            this.isShowRank = Boolean.valueOf(EditorPreferencePredicate.ShowRankInDistributionEditor.getDefaultValue().toString());
124
            this.allowOverrideRank = true;
125
        }
126

    
127
        pref = PreferencesUtil.getPreferenceFromDB(EditorPreferencePredicate.OwnDescriptionForDistributionEditor);
128
        if (pref != null){
129
            this.ownDescriptionForDistributionEditor = Boolean.valueOf(pref.getValue().toString());
130
            this.allowOverrideOwnDescriptionForDistributionEditor= pref.isAllowOverride();
131
        }else{
132
            this.ownDescriptionForDistributionEditor = Boolean.valueOf(EditorPreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue().toString());
133
            this.allowOverrideOwnDescriptionForDistributionEditor = true;
134
        }
135

    
136
        commandHandlerString = "eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardAdminHandler";
137
        commandHandlerStringStatus = "eu.etaxonomy.taxeditor.store.open.OpenDistributionStatusWizardAdminHandler";
138

    
139
        setValid(false);
140
    }
141

    
142
}
(3-3/13)