Project

General

Profile

Download (8.16 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.SWT;
12
import org.eclipse.swt.custom.CLabel;
13
import org.eclipse.swt.events.SelectionAdapter;
14
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Button;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Control;
19

    
20
import eu.etaxonomy.cdm.api.application.ICdmRepository;
21
import eu.etaxonomy.cdm.api.service.IPreferenceService;
22
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
23
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
24
import eu.etaxonomy.taxeditor.l10n.Messages;
25
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
26
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
27
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29
import eu.etaxonomy.taxeditor.ui.element.CommandHandlerButton;
30

    
31
/**
32
 * @author a.oppermann
33
 * @date 21.07.2014
34
 *
35
 */
36
public class ChecklistEditorGeneralPreference extends CdmPreferencePage implements IE4AdminPreferencePage {
37

    
38
    boolean isEditorActivated;
39
    boolean isShowRank;
40
    boolean isSortByVocabularyOrder;
41
    boolean isShowSymbol;
42
    boolean isShowIdInVocabulary;
43
    Composite child ;
44

    
45
    @Override
46
    protected Control createContents(Composite parent) {
47

    
48
        Composite composite = new Composite(parent, SWT.NULL);
49
        composite.setLayout(new GridLayout());
50
        CdmPreference pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
51
        if (pref != null){
52
            isEditorActivated = Boolean.valueOf(pref.getValue());
53
        }else{
54
            isEditorActivated = false;
55
        }
56
        final Button activateCheckButton = new Button(composite, SWT.CHECK);
57
        activateCheckButton.setText(Messages.ChecklistEditorGeneralPreference_enable);
58
        activateCheckButton.setSelection(isEditorActivated);
59
        activateCheckButton.addSelectionListener(new SelectionAdapter(){
60
            @Override
61
            public void widgetSelected(SelectionEvent e) {
62
                isEditorActivated = activateCheckButton.getSelection();
63

    
64
                if(isEditorActivated){
65
                    child.setVisible(true);
66
                    child.setEnabled(true);
67
                }else{
68
                    child.setVisible(false);
69
                    child.setEnabled(false);
70
                }
71

    
72
            }
73
        });
74

    
75
        child  = new Composite(composite, SWT.NULL);
76
        child.setLayout(new GridLayout());
77
        child.setVisible(isEditorActivated);
78

    
79

    
80

    
81
        final CLabel label = new CLabel(child, SWT.NULL);
82
        label.setText(Messages.ChecklistEditorGeneralPreference_open_wizard + Messages.ChecklistEditorGeneralPreference_2);
83

    
84

    
85

    
86
        final CommandHandlerButton button_openWizard = new CommandHandlerButton(child, SWT.PUSH,
87
                Messages.ChecklistEditorGeneralPreference_3);
88

    
89
        button_openWizard.setText(Messages.ChecklistEditorGeneralPreference_open_distribution_selection);
90

    
91
//        Table table = new Table
92

    
93
        final Button showIdInVocabulary = new Button(child, SWT.CHECK);
94
        pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowIdInVocabulary);
95
        if (pref != null){
96
            isShowIdInVocabulary = Boolean.valueOf(pref.getValue());
97
        }else{
98
            isShowIdInVocabulary = false;
99
        }
100
        showIdInVocabulary.setText(Messages.ChecklistEditorGeneralPreference_show_id_in_voc);
101
        showIdInVocabulary.setSelection(isShowIdInVocabulary);
102
        showIdInVocabulary.addSelectionListener(new SelectionAdapter(){
103
            @Override
104
            public void widgetSelected(SelectionEvent e) {
105
                isShowIdInVocabulary = showIdInVocabulary.getSelection();
106

    
107
             }
108
        });
109

    
110
        final Button showSymbol = new Button(child, SWT.CHECK);
111
        pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowSymbol);
112
        if (pref != null){
113
            isShowSymbol = Boolean.valueOf(pref.getValue());
114
        }else{
115
            isShowSymbol = false;
116
        }
117

    
118
        showSymbol.setText(Messages.ChecklistEditorGeneralPreference_show_symbol);
119
        showSymbol.setSelection(isShowSymbol);
120
        showSymbol.addSelectionListener(new SelectionAdapter(){
121
            @Override
122
            public void widgetSelected(SelectionEvent e) {
123
                isShowSymbol = showSymbol.getSelection();
124
             }
125
        });
126
//        PreferencesUtil.recursiveSetEnabled(button_openWizard, CdmStore.isActive());
127
        pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowRankInDistributionEditor);
128
        if (pref != null){
129
            isShowRank = Boolean.valueOf(pref.getValue());
130
        }else{
131
            isShowRank = false;
132
        }
133

    
134
        final Button activateRankButton = new Button(child, SWT.CHECK);
135
        activateRankButton.setText(Messages.ChecklistEditorGeneralPreference_show_rank);
136
        activateRankButton.setSelection(isShowRank);
137
        activateRankButton.addSelectionListener(new SelectionAdapter(){
138
            @Override
139
            public void widgetSelected(SelectionEvent e) {
140
                isShowRank = activateRankButton.getSelection();
141
            }
142
        });
143
        final Button sortNamedAreaByVocabularyOrder = new Button(child, SWT.CHECK);
144

    
145
        pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AreasSortedByIdInVocabulary);
146
        if (pref != null){
147
            isSortByVocabularyOrder = Boolean.valueOf(pref.getValue());
148
        }else{
149
            isSortByVocabularyOrder = false;
150
        }
151

    
152
        sortNamedAreaByVocabularyOrder.setText(Messages.ChecklistEditorGeneralPreference_sort_areas);
153
        sortNamedAreaByVocabularyOrder.setSelection(isSortByVocabularyOrder);
154
        sortNamedAreaByVocabularyOrder.addSelectionListener(new SelectionAdapter(){
155
            @Override
156
            public void widgetSelected(SelectionEvent e) {
157
                isSortByVocabularyOrder = sortNamedAreaByVocabularyOrder.getSelection();
158
             }
159
        });
160

    
161
        if(isEditorActivated){
162
            child.setEnabled(true);
163
        }else{
164
            child.setEnabled(false);
165
        }
166

    
167
        return composite;
168
    }
169

    
170
    @Override
171
    public boolean performOk() {
172
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
173
        if (controller == null){
174
            return false;
175
        }
176
        IPreferenceService service = controller.getPreferenceService();
177

    
178
        CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.DistributionEditorActivated, Boolean.toString(isEditorActivated));
179
        //ToDo
180
        pref.setAllowOverride(false);
181
        service.set(pref);
182

    
183
        pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.ShowIdInVocabulary, Boolean.toString(isShowIdInVocabulary));
184
        //ToDo
185
        pref.setAllowOverride(false);
186
        service.set(pref);
187

    
188
        pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.ShowSymbol, Boolean.toString(isShowSymbol));
189
        //ToDo
190
        pref.setAllowOverride(false);
191
        service.set(pref);
192

    
193
        pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.ShowRankInDistributionEditor, Boolean.toString(isShowRank));
194
        //ToDo
195
        pref.setAllowOverride(false);
196
        service.set(pref);
197
        pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.AreasSortedByIdInVocabulary, Boolean.toString(isSortByVocabularyOrder));
198
        //ToDo
199
        pref.setAllowOverride(false);
200
        service.set(pref);
201

    
202
        PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE, isEditorActivated);
203
        PreferencesUtil.setSortNamedAreasByOrderInVocabulary(isSortByVocabularyOrder);
204
        PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
205
        PreferencesUtil.setShowSymbolInChecklistEditor(isShowSymbol);
206
        PreferencesUtil.setShowIdInVocabularyInChecklistEditor(isShowIdInVocabulary);
207
        return true;
208
    }
209

    
210
}
(3-3/9)