Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.events.SelectionAdapter;
13
import org.eclipse.swt.events.SelectionEvent;
14
import org.eclipse.swt.layout.GridData;
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.api.application.ICdmRepository;
22
import eu.etaxonomy.cdm.api.service.IPreferenceService;
23
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
24
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
25
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
26
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
27
import eu.etaxonomy.taxeditor.l10n.Messages;
28
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
29
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
30
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
31
import eu.etaxonomy.taxeditor.store.CdmStore;
32

    
33
/**
34
 * @author k.luther
35
 * @since 27.04.2018
36
 *
37
 */
38
public class SpecimenAdminPreferences extends CdmPreferencePage implements IE4AdminPreferencePage {
39
    public SpecimenAdminPreferences() {
40
    }
41

    
42

    
43
    boolean isShowSpecimenRelatedIssues;
44
    boolean isShowCollectingAreaInGeneralSection;
45
    boolean isDeterminationOnlyForFieldUnits;
46
    boolean isShowTaxonAssociation;
47
    boolean isShowLifeForm;
48
    boolean isUseLocalPreference;
49
    Composite composite;
50
    CdmPreference isShowSpecimenPref = null;
51

    
52
    @Override
53
    protected Control createContents(Composite parent) {
54

    
55
        getValues();
56

    
57

    
58
        final Button showSpecimenButton = new Button(parent, SWT.CHECK);
59

    
60
        showSpecimenButton.setText(Messages.DatabasePreferncesPage_Show_Specimen);
61

    
62
        showSpecimenButton.setSelection(isShowSpecimenRelatedIssues);
63
        showSpecimenButton.addSelectionListener(new SelectionAdapter(){
64
             @Override
65
             public void widgetSelected(SelectionEvent e) {
66
                 isShowSpecimenRelatedIssues = showSpecimenButton.getSelection();
67
                 if(isShowSpecimenRelatedIssues){
68
                     composite.setVisible(true);
69
                     composite.setEnabled(true);
70
                 }else{
71
                     composite.setVisible(false);
72
                     composite.setEnabled(false);
73
                 }
74
              }
75
         });
76
        composite = new Composite(parent, SWT.NULL);
77
        GridLayout gridLayout = new GridLayout();
78
        composite.setLayout(gridLayout);
79
        composite.setEnabled(isShowSpecimenRelatedIssues);
80
        Label separator= new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
81
        separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
82

    
83
        final Button showCollectingAreaInGeneralSectionButton = new Button(composite, SWT.CHECK);
84

    
85
        showCollectingAreaInGeneralSectionButton.setText(Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section);
86

    
87
        showCollectingAreaInGeneralSectionButton.setSelection(isShowCollectingAreaInGeneralSection);
88
        showCollectingAreaInGeneralSectionButton.addSelectionListener(new SelectionAdapter(){
89
             @Override
90
             public void widgetSelected(SelectionEvent e) {
91
                 isShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSectionButton.getSelection();
92

    
93
              }
94
         });
95

    
96
        final Button determinationOnlyForFieldUnitsButton = new Button(composite, SWT.CHECK);
97

    
98
        determinationOnlyForFieldUnitsButton.setText(Messages.DatabasePreferncesPage_Determination_only_for_field_unnits);
99

    
100
        determinationOnlyForFieldUnitsButton.setSelection(isDeterminationOnlyForFieldUnits);
101
        determinationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
102
             @Override
103
             public void widgetSelected(SelectionEvent e) {
104
                 isDeterminationOnlyForFieldUnits = determinationOnlyForFieldUnitsButton.getSelection();
105
             }
106
         });
107

    
108
        final Button showTaxonAssociationButton = new Button(composite, SWT.CHECK);
109

    
110
        showTaxonAssociationButton.setText(Messages.DatabasePreferncesPage_Taxon_Associations);
111

    
112
        showTaxonAssociationButton.setSelection(isShowTaxonAssociation);
113
        showTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
114
             @Override
115
             public void widgetSelected(SelectionEvent e) {
116
                 isShowTaxonAssociation = showTaxonAssociationButton.getSelection();
117

    
118
              }
119
         });
120

    
121
        final Button showLifeFormButton = new Button(composite, SWT.CHECK);
122
        showLifeFormButton.setText(Messages.DatabasePreferncesPage_Life_Form);
123
        showLifeFormButton.setSelection(isShowLifeForm);
124
        showLifeFormButton.addSelectionListener(new SelectionAdapter(){
125
             @Override
126
             public void widgetSelected(SelectionEvent e) {
127
                 isShowLifeForm = showLifeFormButton.getSelection();
128

    
129
              }
130
         });
131

    
132
    //    Composite useLocalComp = new Composite(composite, SWT.NONE);
133

    
134

    
135
        final Button useLocalPreference = new Button(composite, SWT.CHECK);
136

    
137
        useLocalPreference.setText(Messages.DatabasePreferencesPage_UseLocalPreferences);
138
        GridData gridData = new GridData(SWT.FILL, SWT.BOTTOM, false, false);
139
        gridData.verticalIndent = 10;
140
        useLocalPreference.setLayoutData(gridData);
141

    
142
        useLocalPreference.setSelection(isUseLocalPreference);
143
        useLocalPreference.addSelectionListener(new SelectionAdapter(){
144
             @Override
145
             public void widgetSelected(SelectionEvent e) {
146
                 isUseLocalPreference = useLocalPreference.getSelection();
147
                 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.SHOW_SPECIMEN_ALLOW_OVERRIDE, isUseLocalPreference);
148
              }
149
         });
150
        return composite;
151
    }
152

    
153
    @Override
154
    public void init() {
155
        super.init();
156
        if(!CdmStore.isActive()){
157
            return;
158
        }
159

    
160

    
161

    
162
    }
163

    
164
    private void getValues(){
165
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
166
        if (controller != null){
167
            IPreferenceService service = controller.getPreferenceService();
168
            PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
169
            isShowSpecimenPref = service.find(key);
170
            if (isShowSpecimenPref != null){
171
                this.isShowSpecimenRelatedIssues = Boolean.valueOf(isShowSpecimenPref.getValue());
172
            }else{
173
                isShowSpecimenPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(true));
174
                this.isShowSpecimenRelatedIssues = true;
175
            }
176

    
177

    
178
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
179
            CdmPreference isShowCollectingAreaInGeneralSectionPref = service.find(key);
180
            if (isShowCollectingAreaInGeneralSectionPref != null){
181
                this.isShowCollectingAreaInGeneralSection = Boolean.valueOf(isShowCollectingAreaInGeneralSectionPref.getValue());
182
            }
183

    
184
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
185
            CdmPreference isDeterminationOnlyForFieldUnitsPref = service.find(key);
186
            if (isDeterminationOnlyForFieldUnitsPref != null){
187
                this.isDeterminationOnlyForFieldUnits = Boolean.valueOf(isDeterminationOnlyForFieldUnitsPref.getValue());
188
            }
189
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
190
            CdmPreference isShowTaxonAssociationPref = service.find(key);
191
            if (isShowTaxonAssociationPref != null){
192
                this.isShowTaxonAssociation = Boolean.valueOf(isShowTaxonAssociationPref.getValue());
193
               // isUseLocalPreference = isShowTaxonAssociationPref.isAllowOverride();
194
            }
195

    
196
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
197
            CdmPreference isShowLifeFormPref = service.find(key);
198
            if (isShowLifeFormPref != null){
199
                this.isShowLifeForm = Boolean.valueOf(isShowLifeFormPref.getValue());
200
            }
201

    
202

    
203

    
204

    
205
        }
206
    }
207

    
208
    @Override
209
     public boolean performOk() {
210
        if (isShowSpecimenPref == null){
211
            return true;
212
        }
213
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
214
        if (controller != null){
215
            IPreferenceService service = controller.getPreferenceService();
216

    
217
            CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, Boolean.toString(this.isShowCollectingAreaInGeneralSection));
218
            pref.setAllowOverride(isUseLocalPreference);
219
            service.set(pref);
220
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, Boolean.toString(this.isShowSpecimenRelatedIssues));
221
            pref.setAllowOverride(isUseLocalPreference);
222
            service.set(pref);
223

    
224
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, Boolean.toString(this.isDeterminationOnlyForFieldUnits));
225
            pref.setAllowOverride(isUseLocalPreference);
226
            service.set(pref);
227

    
228
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, Boolean.toString(this.isShowTaxonAssociation));
229
            pref.setAllowOverride(isUseLocalPreference);
230
            service.set(pref);
231

    
232
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, Boolean.toString(this.isShowLifeForm));
233
            pref.setAllowOverride(isUseLocalPreference);
234
            service.set(pref);
235
            PreferencesUtil.updateDBPreferences();
236

    
237

    
238
        }
239
        return true;
240
    }
241

    
242
}
(11-11/12)