Project

General

Profile

Download (9.07 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.preference;
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
import org.eclipse.swt.widgets.Label;
20

    
21
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
22
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
23
import eu.etaxonomy.taxeditor.l10n.Messages;
24
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26
import eu.etaxonomy.taxeditor.ui.element.CommandHandlerButton;
27

    
28
/**
29
 * @author a.oppermann
30
 * @date 21.07.2014
31
 *
32
 */
33
public class ChecklistEditorGeneralPreference extends CdmPreferencePage {
34

    
35
    boolean isEditorActivated;
36
    boolean isUseLocal;
37
    boolean isShowRank;
38
    boolean isSortByVocabularyOrder;
39
    boolean isShowSymbol;
40
    boolean isShowIdInVocabulary;
41
    boolean isShowSymbol1;
42
    boolean isShowSymbol2;
43
    boolean isShowTitle;
44
    Composite child ;
45
    boolean isAllowOverride;
46

    
47
    @Override
48
    protected Control createContents(Composite parent) {
49

    
50
        Composite composite = new Composite(parent, SWT.NULL);
51
        composite.setLayout(new GridLayout());
52

    
53
        CdmPreference distributionEditorPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
54
        isAllowOverride = false;
55
            if (distributionEditorPref != null){
56
                isAllowOverride = distributionEditorPref.isAllowOverride();
57
            }
58

    
59

    
60
            if (isAllowOverride){
61
            isEditorActivated = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE);
62
            final Button activateCheckButton = new Button(composite, SWT.CHECK);
63
            activateCheckButton.setText("Enable Distribution Editor");
64
            activateCheckButton.setSelection(isEditorActivated);
65
            activateCheckButton.addSelectionListener(new SelectionAdapter(){
66
                @Override
67
                public void widgetSelected(SelectionEvent e) {
68
                    isEditorActivated = activateCheckButton.getSelection();
69

    
70
                    if(isEditorActivated){
71
                        child.setVisible(true);
72
                        child.setEnabled(true);
73
                    }else{
74
                        child.setVisible(false);
75
                        child.setEnabled(false);
76
                    }
77

    
78
                }
79
            });
80

    
81
            child  = new Composite(composite, SWT.NULL);
82
            child.setLayout(new GridLayout());
83
            child.setVisible(isEditorActivated);
84
            final CLabel label = new CLabel(child, SWT.NULL);
85
            label.setText("Please open the wizard below, in order to \n" + "choose the area vocabularies for the Distribution Editor");
86
            final CommandHandlerButton button_openFeatureTree = new CommandHandlerButton(child, SWT.PUSH,
87
                    "eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardHandler");
88

    
89
            button_openFeatureTree.setText("Open Distribution Selection Wizard");
90

    
91
            final CLabel description = new CLabel(child, SWT.NULL);
92
            description.setText(Messages.ChecklistEditorGeneralPreference_Configure_display_of_Areas);
93

    
94
            final Button showIdInVocabulary = new Button(child, SWT.RADIO);
95
            isShowIdInVocabulary = PreferencesUtil.isShowIdInVocabularyInChecklistEditor();
96
            showIdInVocabulary.setText("Show Id in Vocabulary instead of full title of the areas");
97
            showIdInVocabulary.setSelection(isShowIdInVocabulary);
98
            showIdInVocabulary.addSelectionListener(new SelectionAdapter(){
99
                @Override
100
                public void widgetSelected(SelectionEvent e) {
101
                    isShowIdInVocabulary = showIdInVocabulary.getSelection();
102

    
103
                 }
104
            });
105

    
106

    
107
            final Button showSymbol1 = new Button(child, SWT.RADIO);
108
            isShowSymbol1 = PreferencesUtil.isShowSymbol1InChecklistEditor();
109

    
110
            showSymbol1.setText(Messages.ChecklistEditorGeneralPreference_show_symbol1);
111
            showSymbol1.setSelection(isShowSymbol1);
112
            showSymbol1.addSelectionListener(new SelectionAdapter(){
113
                @Override
114
                public void widgetSelected(SelectionEvent e) {
115
                    isShowSymbol1 = showSymbol1.getSelection();
116

    
117
                 }
118
            });
119
            final Button showSymbol2 = new Button(child, SWT.RADIO);
120
            isShowSymbol2 = PreferencesUtil.isShowSymbol2InChecklistEditor();
121

    
122
            showSymbol2.setText(Messages.ChecklistEditorGeneralPreference_show_symbol2);
123
            showSymbol2.setSelection(isShowSymbol2);
124
            showSymbol2.addSelectionListener(new SelectionAdapter(){
125
                @Override
126
                public void widgetSelected(SelectionEvent e) {
127
                    isShowSymbol2 = showSymbol2.getSelection();
128

    
129
                 }
130
            });
131

    
132
            final Button showTitle = new Button(child, SWT.RADIO);
133
            isShowTitle = !(isShowIdInVocabulary || isShowSymbol1 || isShowSymbol2);
134

    
135
            showTitle.setText(Messages.ChecklistEditorGeneralPreference_show_title);
136
            showTitle.setSelection(isShowTitle);
137
            showTitle.addSelectionListener(new SelectionAdapter(){
138
                @Override
139
                public void widgetSelected(SelectionEvent e) {
140
                    isShowTitle = showTitle.getSelection();
141

    
142
                 }
143
            });
144

    
145

    
146
            final Button showSymbol = new Button(child, SWT.CHECK);
147
            isShowSymbol = PreferencesUtil.isShowSymbolInChecklistEditor();
148
            showSymbol.setText("Show Symbol of the Status, if existing");
149
            showSymbol.setSelection(isShowSymbol);
150
            showSymbol.addSelectionListener(new SelectionAdapter(){
151
                @Override
152
                public void widgetSelected(SelectionEvent e) {
153
                    isShowSymbol = showSymbol.getSelection();
154
                 }
155
            });
156
            PreferencesUtil.recursiveSetEnabled(button_openFeatureTree, CdmStore.isActive());
157
            isShowRank = PreferencesUtil.isShowRankInChecklistEditor();
158
            final Button activateRankButton = new Button(child, SWT.CHECK);
159
            activateRankButton.setText("Show Rank in Distribution Editor");
160
            activateRankButton.setSelection(isShowRank);
161
            activateRankButton.addSelectionListener(new SelectionAdapter(){
162
                @Override
163
                public void widgetSelected(SelectionEvent e) {
164
                    isShowRank = activateRankButton.getSelection();
165
                }
166
            });
167
            final Button sortNamedAreaByVocabularyOrder = new Button(child, SWT.CHECK);
168
            isSortByVocabularyOrder = PreferencesUtil.isSortNamedAreaByOrderInVocabulary();
169
            sortNamedAreaByVocabularyOrder.setText("Sort Areas by Order in Vocabulary");
170
            sortNamedAreaByVocabularyOrder.setSelection(isSortByVocabularyOrder);
171
            sortNamedAreaByVocabularyOrder.addSelectionListener(new SelectionAdapter(){
172
                @Override
173
                public void widgetSelected(SelectionEvent e) {
174
                    isSortByVocabularyOrder = sortNamedAreaByVocabularyOrder.getSelection();
175
                 }
176
            });
177

    
178
            if(isEditorActivated){
179
                child.setEnabled(true);
180
            }else{
181
                child.setEnabled(false);
182
            }
183
        }else{
184
           Label label = new Label(composite, SWT.NONE);
185
           label.setText("The CDM settings don't allow to set the preferences for using the distribution editor locally. If you need to make local settings, please ask an administrator.");
186

    
187
        }
188

    
189
        return composite;
190
    }
191

    
192
    @Override
193
    public boolean performOk() {
194
        if (isAllowOverride){
195
            PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE, isEditorActivated);
196
            PreferencesUtil.setSortNamedAreasByOrderInVocabulary(isSortByVocabularyOrder);
197
            PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
198
            PreferencesUtil.setShowSymbolInChecklistEditor(isShowSymbol);
199
            String displayString;
200
            if (isShowIdInVocabulary){
201
                displayString = IPreferenceKeys.CHECKLIST_AREA_DISPLAY_TITLE;
202
            }else if (isShowSymbol1){
203
                displayString = IPreferenceKeys.CHECKLIST_AREA_DISPLAY_SYMBOL1;
204
            }else if (isShowSymbol2){
205
                displayString = IPreferenceKeys.CHECKLIST_AREA_DISPLAY_SYMBOL2;
206
            }else{
207
                displayString = IPreferenceKeys.CHECKLIST_AREA_DISPLAY_TITLE;
208
            }
209
            PreferencesUtil.setShowIdInVocabularyInChecklistEditor(displayString);
210
        }
211
        return true;
212
    }
213

    
214
}
(3-3/25)