Project

General

Profile

Download (30.1 KB) Statistics
| Branch: | Tag: | Revision:
1 6b5ad34c Patric Plitzner
/**
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 256fbc69 Katja Luther
import org.eclipse.swt.SWT;
12 185eb33b Katja Luther
import org.eclipse.swt.events.SelectionAdapter;
13
import org.eclipse.swt.events.SelectionEvent;
14 cc1302bd Katja Luther
import org.eclipse.swt.events.SelectionListener;
15 256fbc69 Katja Luther
import org.eclipse.swt.layout.GridData;
16 185eb33b Katja Luther
import org.eclipse.swt.widgets.Button;
17 cc1302bd Katja Luther
import org.eclipse.swt.widgets.Combo;
18 185eb33b Katja Luther
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20 256fbc69 Katja Luther
import org.eclipse.swt.widgets.Label;
21 6b5ad34c Patric Plitzner
22 256fbc69 Katja Luther
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
23 9fe7e119 Katja Luther
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
24 9b8d1a1c Katja Luther
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
25 9fe7e119 Katja Luther
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
26 185eb33b Katja Luther
import eu.etaxonomy.taxeditor.l10n.Messages;
27
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
28 256fbc69 Katja Luther
import eu.etaxonomy.taxeditor.store.CdmStore;
29
30 6b5ad34c Patric Plitzner
/**
31
 * @author pplitzner
32
 * @date 13.02.2014
33
 *
34
 */
35 cc1302bd Katja Luther
public class SpecimenOrObservationPreferences extends CdmPreferencePage implements SelectionListener{
36 6b5ad34c Patric Plitzner
37 473f7b01 Katja Luther
    private static final String LOCAL_SETTINGS_NOT_ALLOWED = Messages.SpecimenOrObservationPreferences_0;
38
    private static final String DESCRIPTION = Messages.SpecimenOrObservationPreferences_1;
39 c4c36f8e Patrick Plitzner
40 63732a7c Katja Luther
    protected Boolean isShowSpecimenRelatedIssues;
41 185eb33b Katja Luther
    protected boolean allowOverrideShowSpecimenRelatedIssues;
42
    protected boolean overrideShowSpecimenRelatedIssues;
43 63732a7c Katja Luther
    protected Boolean isShowCollectingAreaInGeneralSection;
44 185eb33b Katja Luther
    protected boolean allowOverrideShowCollectingAreaInGeneralSection;
45
    protected boolean overrideShowCollectionAreaInGeneralSection;
46 63732a7c Katja Luther
    protected Boolean isDeterminationOnlyForFieldUnits;
47 185eb33b Katja Luther
    protected boolean allowOverrideDeterminationOnlyForFieldUnits;
48
    protected boolean overrideDeterminationOnlyForFieldUnits;
49 63732a7c Katja Luther
    protected Boolean isShowTaxonAssociation;
50 185eb33b Katja Luther
    protected boolean allowOverrideShowTaxonAssociation;
51
    protected boolean overrideShowTaxonAssociation;
52 63732a7c Katja Luther
    protected Boolean isShowLifeForm;
53 185eb33b Katja Luther
    protected boolean allowOverrideShowLifeForm;
54
    protected boolean overrideShowLifeForm;
55
    Composite composite;
56 06699fe1 Katja Luther
57 cc1302bd Katja Luther
    protected Combo showSpecimenButton;
58 85bd68d3 Katja Luther
    protected Button allowOverrideIsShowSpecimenRelatedIssuesButton;
59 cc1302bd Katja Luther
    protected Combo showCollectingAreaInGeneralSectionButton;
60 85bd68d3 Katja Luther
    protected Button allowOverrideShowCollectingAreaButton;
61 cc1302bd Katja Luther
    protected Combo determinationOnlyForFieldUnitsButton;
62 85bd68d3 Katja Luther
    protected Button allowOverridesDeterminationOnlyForFieldUnitsButton;
63 cc1302bd Katja Luther
    protected Combo showTaxonAssociationButton;
64 85bd68d3 Katja Luther
    protected Button allowOverrideIsShowTaxonAssociationButton;
65
    protected Button allowOverrideShowLifeFormButton;
66 cc1302bd Katja Luther
    protected Combo showLifeFormButton;
67 85bd68d3 Katja Luther
68 cc1302bd Katja Luther
    CdmPreference showSpecimenPref;
69
    CdmPreference showCollectingAreaInGeneralSection;
70
    CdmPreference showDeterminationOnlyForFieldUnits;
71
    CdmPreference showTaxonAssociation;
72
    CdmPreference showLifeForm;
73 06699fe1 Katja Luther
74 6b5ad34c Patric Plitzner
    @Override
75 672874ab Patrick Plitzner
    public void init() {
76
        super.init();
77 06699fe1 Katja Luther
//        setPreferenceStore(PreferencesUtil.getPreferenceStore());
78 c786c70d Patrick Plitzner
        if(!CdmStore.isActive()){
79
            return;
80
        }
81 185eb33b Katja Luther
82
83
    }
84
85
    /**
86
     * {@inheritDoc}
87
     */
88
    @Override
89
    protected Control createContents(Composite parent) {
90
        getValues();
91
92
        boolean isEditingAllowed = true;
93
        if(!isAdminPreference){
94 1faab189 Katja Luther
            CdmPreferenceCache cache = CdmPreferenceCache.instance();
95 63732a7c Katja Luther
96 185eb33b Katja Luther
            if (showSpecimenPref != null){
97
                if (!showSpecimenPref.isAllowOverride() ){
98 63732a7c Katja Luther
99 185eb33b Katja Luther
                    isEditingAllowed = false;
100
101
                }
102
            }
103
        }
104 63732a7c Katja Luther
        if (isEditingAllowed){
105
            Label label = new Label(parent, SWT.NONE);
106
            label.setText(DESCRIPTION);
107
        }else{
108
            Label label = new Label(parent, SWT.NONE);
109
            label.setText(LOCAL_SETTINGS_NOT_ALLOWED);
110
            this.noDefaultAndApplyButton();
111
            return parent;
112
        }
113 185eb33b Katja Luther
        Composite titleComp = createComposite(parent);
114 914fe91d Katja Luther
        GridData gridData = createTextGridData();
115 185eb33b Katja Luther
116 914fe91d Katja Luther
        Label separator= new Label(titleComp, SWT.HORIZONTAL | SWT.SEPARATOR);
117
        separator.setLayoutData(gridData);
118
        separator.setVisible(false);
119 cc1302bd Katja Luther
        showSpecimenButton = createBooleanCombo(titleComp, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowSpecimen, Messages.DatabasePreferncesPage_Show_Specimen, isAdminPreference);
120
121
        showSpecimenButton.addSelectionListener(this);
122 63732a7c Katja Luther
        int index = 0;
123
        for (String itemLabel : showSpecimenButton.getItems()) {
124 c2a446b0 Katja Luther
            if (isShowSpecimenRelatedIssues == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
125 63732a7c Katja Luther
                showSpecimenButton.select(index);
126
                break;
127
            }
128
            if (isShowSpecimenRelatedIssues != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowSpecimenRelatedIssues){
129
                showSpecimenButton.select(index);
130
                break;
131
            }
132
            if (isShowSpecimenRelatedIssues != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowSpecimenRelatedIssues){
133
                showSpecimenButton.select(index);
134
                break;
135
            }
136
            index++;
137 cc1302bd Katja Luther
        }
138 63732a7c Katja Luther
        showSpecimenButton.setEnabled(isEditingAllowed);
139 914fe91d Katja Luther
140 185eb33b Katja Luther
        if (isAdminPreference){
141 cc1302bd Katja Luther
            allowOverrideIsShowSpecimenRelatedIssuesButton = createAllowOverrideButton(titleComp);
142 185eb33b Katja Luther
            allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
143
            allowOverrideIsShowSpecimenRelatedIssuesButton.addSelectionListener(new SelectionAdapter(){
144
                @Override
145
                public void widgetSelected(SelectionEvent e) {
146 fbd932cc Katja Luther
                    setApply(true);
147 185eb33b Katja Luther
                    allowOverrideShowSpecimenRelatedIssues = allowOverrideIsShowSpecimenRelatedIssuesButton.getSelection();
148
                }
149
            });
150
        }
151 cc1302bd Katja Luther
152 185eb33b Katja Luther
        composite = createComposite(parent);
153 e5b6bb85 Katja Luther
        //composite.setEnabled(isShowSpecimenRelatedIssues);
154 914fe91d Katja Luther
        gridData = createTextGridData();
155 185eb33b Katja Luther
156 914fe91d Katja Luther
        separator= new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
157 185eb33b Katja Luther
        separator.setLayoutData(gridData);
158
159 cc1302bd Katja Luther
        showCollectingAreaInGeneralSectionButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowCollectingAreasInGeneralSection, Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section, isAdminPreference);
160 185eb33b Katja Luther
161 cc1302bd Katja Luther
        showCollectingAreaInGeneralSectionButton.addSelectionListener(this);
162 63732a7c Katja Luther
        index = 0;
163
        for (String itemLabel : showCollectingAreaInGeneralSectionButton.getItems()) {
164 c2a446b0 Katja Luther
            if (isShowCollectingAreaInGeneralSection == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
165 63732a7c Katja Luther
                showCollectingAreaInGeneralSectionButton.select(index);
166
                break;
167
            }
168
            if (isShowCollectingAreaInGeneralSection != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowCollectingAreaInGeneralSection){
169
                showCollectingAreaInGeneralSectionButton.select(index);
170
                break;
171
            }
172
            if (isShowCollectingAreaInGeneralSection != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowCollectingAreaInGeneralSection){
173
                showCollectingAreaInGeneralSectionButton.select(index);
174
                break;
175
            }
176
            index++;
177 cc1302bd Katja Luther
        }
178 185eb33b Katja Luther
        if (isAdminPreference){
179 cc1302bd Katja Luther
            allowOverrideShowCollectingAreaButton = createAllowOverrideButton(composite);
180 185eb33b Katja Luther
            allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowCollectingAreaInGeneralSection);
181
            allowOverrideShowCollectingAreaButton.addSelectionListener(new SelectionAdapter(){
182
                @Override
183
                public void widgetSelected(SelectionEvent e) {
184 fbd932cc Katja Luther
                    setApply(true);
185 185eb33b Katja Luther
                    allowOverrideShowCollectingAreaInGeneralSection = allowOverrideShowCollectingAreaButton.getSelection();
186
                }
187
            });
188
        }
189 63732a7c Katja Luther
        if (showCollectingAreaInGeneralSection != null && !showCollectingAreaInGeneralSection.isAllowOverride() ){
190
               isEditingAllowed = false;
191
        }
192
        showCollectingAreaInGeneralSectionButton.setEnabled(isEditingAllowed);
193 cc1302bd Katja Luther
        determinationOnlyForFieldUnitsButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.DeterminationOnlyForFieldUnits, Messages.DatabasePreferncesPage_Determination_only_for_field_unnits, isAdminPreference);
194
195
196
        determinationOnlyForFieldUnitsButton.addSelectionListener(this);
197 63732a7c Katja Luther
        index = 0;
198
        for (String itemLabel : determinationOnlyForFieldUnitsButton.getItems()) {
199 c2a446b0 Katja Luther
            if (isDeterminationOnlyForFieldUnits == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
200 63732a7c Katja Luther
                determinationOnlyForFieldUnitsButton.select(index);
201
                break;
202
            }
203
            if (isDeterminationOnlyForFieldUnits != null && itemLabel.equals(Messages.GeneralPreference_yes) && isDeterminationOnlyForFieldUnits){
204
                determinationOnlyForFieldUnitsButton.select(index);
205
                break;
206
            }
207
            if (isDeterminationOnlyForFieldUnits != null && itemLabel.equals(Messages.GeneralPreference_no) && !isDeterminationOnlyForFieldUnits){
208
                determinationOnlyForFieldUnitsButton.select(index);
209
                break;
210
            }
211
            index++;
212 cc1302bd Katja Luther
        }
213 63732a7c Katja Luther
        if (showDeterminationOnlyForFieldUnits != null && !showDeterminationOnlyForFieldUnits.isAllowOverride() ){
214
            isEditingAllowed = false;
215
        }
216
        determinationOnlyForFieldUnitsButton.setEnabled(isEditingAllowed);
217 185eb33b Katja Luther
        if (isAdminPreference){
218 cc1302bd Katja Luther
            allowOverridesDeterminationOnlyForFieldUnitsButton = createAllowOverrideButton(composite);
219 185eb33b Katja Luther
            allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideDeterminationOnlyForFieldUnits);
220
            allowOverridesDeterminationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
221
                @Override
222
                public void widgetSelected(SelectionEvent e) {
223 fbd932cc Katja Luther
                    setApply(true);
224 185eb33b Katja Luther
                    allowOverrideDeterminationOnlyForFieldUnits = allowOverridesDeterminationOnlyForFieldUnitsButton.getSelection();
225
                }
226
            });
227
        }
228
229 cc1302bd Katja Luther
        showTaxonAssociationButton =createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowTaxonAssociations, Messages.DatabasePreferncesPage_Taxon_Associations, isAdminPreference);
230 185eb33b Katja Luther
231
232 cc1302bd Katja Luther
        showTaxonAssociationButton.addSelectionListener(this);
233 63732a7c Katja Luther
        index = 0;
234
        for (String itemLabel : showTaxonAssociationButton.getItems()) {
235 c2a446b0 Katja Luther
            if (isShowTaxonAssociation == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
236 63732a7c Katja Luther
                showTaxonAssociationButton.select(index);
237
                break;
238
            }
239
            if (isShowTaxonAssociation != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowTaxonAssociation){
240
                showTaxonAssociationButton.select(index);
241
                break;
242
            }
243
            if (isShowTaxonAssociation != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowTaxonAssociation){
244
                showTaxonAssociationButton.select(index);
245
                break;
246
            }
247
            index++;
248
        }
249
        if (showTaxonAssociation != null && !showTaxonAssociation.isAllowOverride() ){
250
            isEditingAllowed = false;
251 cc1302bd Katja Luther
        }
252 63732a7c Katja Luther
        showTaxonAssociationButton.setEnabled(isEditingAllowed);
253 185eb33b Katja Luther
        if (isAdminPreference){
254 cc1302bd Katja Luther
            allowOverrideIsShowTaxonAssociationButton = createAllowOverrideButton(composite);
255 185eb33b Katja Luther
            allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowTaxonAssociation);
256
            allowOverrideIsShowTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
257
                @Override
258
                public void widgetSelected(SelectionEvent e) {
259 fbd932cc Katja Luther
                    setApply(true);
260 185eb33b Katja Luther
                    allowOverrideShowTaxonAssociation = allowOverrideIsShowTaxonAssociationButton.getSelection();
261
                }
262
            });
263
        }
264
265 cc1302bd Katja Luther
        showLifeFormButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowLifeForm, Messages.DatabasePreferncesPage_Life_Form, isAdminPreference);
266
        showLifeFormButton.addSelectionListener(this);
267 185eb33b Katja Luther
268 63732a7c Katja Luther
        index = 0;
269
        for (String itemLabel: showLifeFormButton.getItems()) {
270 c2a446b0 Katja Luther
            if (isShowLifeForm == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
271 63732a7c Katja Luther
                showLifeFormButton.select(index);
272
                break;
273
            }
274
            if (isShowLifeForm != null && itemLabel.equals(Messages.GeneralPreference_yes) && isShowLifeForm){
275
                showLifeFormButton.select(index);
276
                break;
277
            }
278
            if (isShowLifeForm != null && itemLabel.equals(Messages.GeneralPreference_no) && !isShowLifeForm){
279
                showLifeFormButton.select(index);
280
                break;
281
            }
282
            index++;
283 cc1302bd Katja Luther
        }
284 63732a7c Katja Luther
        if (showLifeForm != null && !showLifeForm.isAllowOverride() ){
285
            isEditingAllowed = false;
286
        }
287
        showLifeFormButton.setEnabled(isEditingAllowed);
288 185eb33b Katja Luther
        if (isAdminPreference){
289 cc1302bd Katja Luther
            allowOverrideShowLifeFormButton = createAllowOverrideButton(composite);
290 185eb33b Katja Luther
            allowOverrideShowLifeFormButton.setSelection(allowOverrideShowLifeForm);
291
            allowOverrideShowLifeFormButton.addSelectionListener(new SelectionAdapter(){
292
                @Override
293
                public void widgetSelected(SelectionEvent e) {
294 fbd932cc Katja Luther
                    setApply(true);
295 185eb33b Katja Luther
                    allowOverrideShowLifeForm = allowOverrideShowLifeFormButton.getSelection();
296
                }
297
            });
298
        }
299 256fbc69 Katja Luther
300 185eb33b Katja Luther
        if (!isEditingAllowed){
301
            PreferencesUtil.recursiveSetEnabled(composite, false);
302 256fbc69 Katja Luther
        }
303 cc1302bd Katja Luther
304 185eb33b Katja Luther
        return composite;
305 6b5ad34c Patric Plitzner
    }
306
307 185eb33b Katja Luther
308
    /**
309
     * {@inheritDoc}
310
     */
311 6b5ad34c Patric Plitzner
    @Override
312 185eb33b Katja Luther
    protected void getValues() {
313
        CdmPreferenceCache cache = CdmPreferenceCache.instance();
314 256fbc69 Katja Luther
315 63732a7c Katja Luther
316
        overrideShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(
317 a4f3f99c Katja Luther
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey()), true) != null? PreferencesUtil.getBooleanValue(
318
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey()), true): false;
319 63732a7c Katja Luther
320 9fe7e119 Katja Luther
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
321 63732a7c Katja Luther
        showSpecimenPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowSpecimen);
322
323
324
        if (showSpecimenPref != null) {
325
            if (showSpecimenPref.isAllowOverride() ) {
326
                if (overrideShowSpecimenRelatedIssues){
327
                    isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimen.getKey(), true);
328
                }
329
            } else {
330
                isShowSpecimenRelatedIssues = Boolean.valueOf(showSpecimenPref.getValue());
331
            }
332
333
        } else {
334
            if(!overrideShowSpecimenRelatedIssues){
335
                isShowSpecimenRelatedIssues = null;
336
            }else{
337
                isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimen.getKey(), true);
338
            }
339 cc1302bd Katja Luther
            showSpecimenPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, PreferencePredicate.ShowSpecimen.getDefaultValue() != null ?  PreferencePredicate.ShowSpecimen.getDefaultValue().toString(): null);
340
        }
341 42aae678 Katja Luther
342 cc1302bd Katja Luther
343 42aae678 Katja Luther
344 63732a7c Katja Luther
345 9fe7e119 Katja Luther
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
346 63732a7c Katja Luther
        showCollectingAreaInGeneralSection = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
347
        overrideShowCollectionAreaInGeneralSection = PreferencesUtil.getBooleanValue(
348 a4f3f99c Katja Luther
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), true) != null? PreferencesUtil.getBooleanValue(
349
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), true): false;
350 63732a7c Katja Luther
        allowOverrideShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSection != null ? showCollectingAreaInGeneralSection.isAllowOverride():true;
351
        if (showCollectingAreaInGeneralSection != null) {
352
            if (showCollectingAreaInGeneralSection.isAllowOverride() ) {
353
                if (overrideShowCollectionAreaInGeneralSection){
354
                    isShowCollectingAreaInGeneralSection = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), true);
355
                }
356
357
            } else {
358
                isShowCollectingAreaInGeneralSection = Boolean.valueOf(showCollectingAreaInGeneralSection.getValue());
359
360
            }
361
362
        } else {
363
            if(!overrideShowCollectionAreaInGeneralSection){
364
                isShowCollectingAreaInGeneralSection = null;
365
            }else{
366
                isShowCollectingAreaInGeneralSection = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), true);
367
            }
368 cc1302bd Katja Luther
            showCollectingAreaInGeneralSection = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue() != null ?  PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue().toString(): null);
369
        }
370
371 185eb33b Katja Luther
372 9fe7e119 Katja Luther
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
373 63732a7c Katja Luther
        showDeterminationOnlyForFieldUnits = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
374
        overrideDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(
375 a4f3f99c Katja Luther
                PreferencesUtil.prefOverrideKey(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), true) != null? PreferencesUtil.getBooleanValue(
376
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), true): false;
377 63732a7c Katja Luther
        if (showDeterminationOnlyForFieldUnits != null) {
378
            if (showDeterminationOnlyForFieldUnits.isAllowOverride() ) {
379
                if (overrideDeterminationOnlyForFieldUnits){
380
                    isDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
381
                }
382
383
            } else {
384
                isDeterminationOnlyForFieldUnits = Boolean.valueOf(showDeterminationOnlyForFieldUnits.getValue());
385
386
            }
387
388
        } else {
389
            if(!overrideDeterminationOnlyForFieldUnits){
390
                isDeterminationOnlyForFieldUnits = null;
391
            }else{
392
                isDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey(), true);
393
            }
394 cc1302bd Katja Luther
            showDeterminationOnlyForFieldUnits = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue() != null ?  PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue().toString(): null);
395
        }
396 63732a7c Katja Luther
397 9fe7e119 Katja Luther
        allowOverrideDeterminationOnlyForFieldUnits = showDeterminationOnlyForFieldUnits != null ? showDeterminationOnlyForFieldUnits.isAllowOverride():true;
398 185eb33b Katja Luther
399 63732a7c Katja Luther
400 cc1302bd Katja Luther
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
401 63732a7c Katja Luther
        showTaxonAssociation = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
402
        overrideShowTaxonAssociation =  PreferencesUtil.getBooleanValue(
403 a4f3f99c Katja Luther
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonAssociations.getKey()), true) != null? PreferencesUtil.getBooleanValue(
404
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonAssociations.getKey()), true): false;
405 63732a7c Katja Luther
        if (showTaxonAssociation != null) {
406
            if (showTaxonAssociation.isAllowOverride() ) {
407
                if (overrideShowTaxonAssociation){
408
                    isShowTaxonAssociation = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
409
                }
410
411
            } else {
412
                isShowTaxonAssociation = Boolean.valueOf(showTaxonAssociation.getValue());
413
414
            }
415
416
        } else {
417
            if(!overrideShowTaxonAssociation){
418
                isShowTaxonAssociation = null;
419
            }else{
420
                isShowTaxonAssociation = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey(), true);
421
            }
422 cc1302bd Katja Luther
            showTaxonAssociation = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, PreferencePredicate.ShowTaxonAssociations.getDefaultValue() != null ?  PreferencePredicate.ShowTaxonAssociations.getDefaultValue().toString(): null);
423
        }
424 63732a7c Katja Luther
425 9fe7e119 Katja Luther
        allowOverrideShowTaxonAssociation = showTaxonAssociation != null ? showTaxonAssociation.isAllowOverride():true;
426 185eb33b Katja Luther
427 63732a7c Katja Luther
428 cc1302bd Katja Luther
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
429 63732a7c Katja Luther
        showLifeForm = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
430
        overrideShowLifeForm =  PreferencesUtil.getBooleanValue(
431 a4f3f99c Katja Luther
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()), true) != null? PreferencesUtil.getBooleanValue(
432
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()), true): false;
433 63732a7c Katja Luther
        if (showLifeForm != null) {
434
            if (showLifeForm.isAllowOverride() ) {
435
                if (overrideShowLifeForm){
436
                    isShowLifeForm = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
437
                }
438
439
            } else {
440
                isShowLifeForm = Boolean.valueOf(showLifeForm.getValue());
441
442
            }
443
444
        } else {
445
            if(!overrideShowLifeForm){
446
                isShowLifeForm = null;
447
            }else{
448
                isShowLifeForm = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowLifeForm.getKey(), true);
449
            }
450 cc1302bd Katja Luther
            showLifeForm = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, PreferencePredicate.ShowLifeForm.getDefaultValue() != null ?  PreferencePredicate.ShowLifeForm.getDefaultValue().toString(): null);
451
        }
452 63732a7c Katja Luther
453 9fe7e119 Katja Luther
        allowOverrideShowLifeForm = showLifeForm != null ? showLifeForm.isAllowOverride():true;
454 9181d281 Katja Luther
455 185eb33b Katja Luther
456
    }
457 9e5747be Katja Luther
458 185eb33b Katja Luther
    @Override
459
    public boolean performOk() {
460 63732a7c Katja Luther
461
        boolean override = false;
462
        if (isShowSpecimenRelatedIssues != null ) {
463
            override = true;
464
            PreferencesUtil.setStringValue(PreferencePredicate.ShowSpecimen.getKey(), isShowSpecimenRelatedIssues.toString());
465 185eb33b Katja Luther
        }
466 63732a7c Katja Luther
        PreferencesUtil.setBooleanValue(
467
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey()),
468
                override);
469
470
        override = false;
471
        if (isShowCollectingAreaInGeneralSection != null ) {
472
            override = true;
473
            PreferencesUtil.setStringValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), isShowCollectingAreaInGeneralSection.toString());
474 185eb33b Katja Luther
        }
475 63732a7c Katja Luther
        PreferencesUtil.setBooleanValue(
476
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()),
477
                override);
478
479
        override = false;
480
        if (isDeterminationOnlyForFieldUnits != null ) {
481
            override = true;
482
            PreferencesUtil.setStringValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey(), isDeterminationOnlyForFieldUnits.toString());
483 185eb33b Katja Luther
        }
484 63732a7c Katja Luther
        PreferencesUtil.setBooleanValue(
485
                PreferencesUtil.prefOverrideKey(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()),
486
                override);
487
488
        override = false;
489
        if (isShowTaxonAssociation != null ) {
490
            override = true;
491
            PreferencesUtil.setStringValue(PreferencePredicate.ShowTaxonAssociations.getKey(), isShowTaxonAssociation.toString());
492 185eb33b Katja Luther
        }
493 63732a7c Katja Luther
        PreferencesUtil.setBooleanValue(
494
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonAssociations.getKey()),
495
                override);
496
497
        override = false;
498
        if (isShowLifeForm != null ) {
499
            override = true;
500
            PreferencesUtil.setStringValue(PreferencePredicate.ShowLifeForm.getKey(), isShowLifeForm.toString());
501 185eb33b Katja Luther
        }
502 63732a7c Katja Luther
        PreferencesUtil.setBooleanValue(
503
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()),
504
                override);
505
506 185eb33b Katja Luther
        return true;
507 6b5ad34c Patric Plitzner
    }
508
509
510 dd2e9b75 Katja Luther
511
    @Override
512
    protected void performDefaults() {
513 c2a446b0 Katja Luther
        isShowSpecimenRelatedIssues = null;
514
        showSpecimenButton.select(0);
515
516 cc1302bd Katja Luther
        if (allowOverrideIsShowSpecimenRelatedIssuesButton != null){
517
            allowOverrideShowSpecimenRelatedIssues = true;
518
            allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
519
        }
520 c2a446b0 Katja Luther
        isShowCollectingAreaInGeneralSection = null;
521
        showCollectingAreaInGeneralSectionButton.select(0);
522
523 cc1302bd Katja Luther
        if (allowOverrideShowCollectingAreaButton != null){
524
            allowOverrideShowCollectingAreaInGeneralSection = true;
525
            allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
526
        }
527 c2a446b0 Katja Luther
        isDeterminationOnlyForFieldUnits = null;
528
        determinationOnlyForFieldUnitsButton.select(0);
529
530 cc1302bd Katja Luther
        if (allowOverridesDeterminationOnlyForFieldUnitsButton != null){
531
            allowOverrideDeterminationOnlyForFieldUnits = true;
532
            allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
533
        }
534 dd2e9b75 Katja Luther
535 c2a446b0 Katja Luther
        isShowTaxonAssociation = null;
536
        showTaxonAssociationButton.select(0);
537
538 cc1302bd Katja Luther
        if (allowOverrideIsShowTaxonAssociationButton != null){
539
            allowOverrideShowTaxonAssociation = true;
540
            allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
541
        }
542 dd2e9b75 Katja Luther
543
544 c2a446b0 Katja Luther
        isShowLifeForm = null;
545
546
        showLifeFormButton.select(0);
547 dd2e9b75 Katja Luther
548 cc1302bd Katja Luther
        if (allowOverrideShowLifeFormButton != null){
549
            allowOverrideShowLifeForm = true;
550
            allowOverrideShowLifeFormButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
551
        }
552
553 dd2e9b75 Katja Luther
554
        super.performDefaults();
555
    }
556
557 cc1302bd Katja Luther
    /**
558
     * {@inheritDoc}
559
     */
560
    @Override
561
    public void widgetSelected(SelectionEvent e) {
562
       setApply(true);
563 63732a7c Katja Luther
       if (e.getSource().equals(this.showSpecimenButton)) {
564 cc1302bd Katja Luther
           String text = showSpecimenButton.getText();
565 c2a446b0 Katja Luther
           if(text.startsWith(Messages.Preference_Use_Default)){
566 63732a7c Katja Luther
               isShowSpecimenRelatedIssues = null;
567
               if (isAdminPreference){
568
                   allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(true);
569
               }
570
               return;
571
           }
572 cc1302bd Katja Luther
           if (text.equals(Messages.GeneralPreference_yes)){
573
               isShowSpecimenRelatedIssues = true;
574
           }else{
575
               isShowSpecimenRelatedIssues = false;
576
           }
577
       }
578 63732a7c Katja Luther
579
       if (e.getSource().equals(this.showCollectingAreaInGeneralSectionButton)) {
580 cc1302bd Katja Luther
           String text = showCollectingAreaInGeneralSectionButton.getText();
581 c2a446b0 Katja Luther
           if(text.startsWith(Messages.Preference_Use_Default)){
582 63732a7c Katja Luther
               isShowCollectingAreaInGeneralSection = null;
583
               if (isAdminPreference){
584
                   //showCollectingAreaInGeneralSection.setAllowOverride(true);
585
                   allowOverrideShowCollectingAreaButton.setSelection(true);
586
               }
587
               return;
588
           }
589 cc1302bd Katja Luther
           if (text.equals(Messages.GeneralPreference_yes)){
590
               isShowCollectingAreaInGeneralSection = true;
591
           }else{
592
               isShowCollectingAreaInGeneralSection = false;
593
           }
594
       }
595
596 63732a7c Katja Luther
       if (e.getSource().equals(this.determinationOnlyForFieldUnitsButton)) {
597 cc1302bd Katja Luther
           String text = determinationOnlyForFieldUnitsButton.getText();
598 c2a446b0 Katja Luther
           if(text.startsWith(Messages.Preference_Use_Default)){
599 63732a7c Katja Luther
               isDeterminationOnlyForFieldUnits = null;
600
               if (isAdminPreference){
601
                   //showDeterminationOnlyForFieldUnits.setAllowOverride(true);
602
                   allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(true);
603
               }
604
               return;
605
           }
606 cc1302bd Katja Luther
           if (text.equals(Messages.GeneralPreference_yes)){
607
               isDeterminationOnlyForFieldUnits = true;
608
           }else{
609
               isDeterminationOnlyForFieldUnits = false;
610
           }
611
       }
612 63732a7c Katja Luther
613
       if (e.getSource().equals(this.showTaxonAssociationButton)) {
614 cc1302bd Katja Luther
           String text = showTaxonAssociationButton.getText();
615 c2a446b0 Katja Luther
           if(text.startsWith(Messages.Preference_Use_Default)){
616 63732a7c Katja Luther
               isShowTaxonAssociation = null;
617
               if (isAdminPreference){
618
                   //showTaxonAssociation.setAllowOverride(true);
619
                   allowOverrideIsShowTaxonAssociationButton.setSelection(true);
620
               }
621
               return;
622
           }
623 cc1302bd Katja Luther
           if (text.equals(Messages.GeneralPreference_yes)){
624
               isShowTaxonAssociation = true;
625
           }else{
626
               isShowTaxonAssociation = false;
627
           }
628
       }
629 63732a7c Katja Luther
630
       if (e.getSource().equals(this.showLifeFormButton)) {
631 cc1302bd Katja Luther
           String text = showLifeFormButton.getText();
632 c2a446b0 Katja Luther
           if(text.startsWith(Messages.Preference_Use_Default)){
633 63732a7c Katja Luther
               isShowLifeForm = null;
634
               if (isAdminPreference){
635
                   //showLifeForm.setAllowOverride(true);
636
                   allowOverrideShowLifeFormButton.setSelection(true);
637
               }
638
               return;
639
           }
640 cc1302bd Katja Luther
           if (text.equals(Messages.GeneralPreference_yes)){
641
               isShowLifeForm = true;
642
           }else{
643
               isShowLifeForm = false;
644
           }
645
       }
646 63732a7c Katja Luther
647 cc1302bd Katja Luther
    }
648
649
    /**
650
     * {@inheritDoc}
651
     */
652
    @Override
653
    public void widgetDefaultSelected(SelectionEvent e) {
654
        // TODO Auto-generated method stub
655
656
    }
657
658
659
660 dd2e9b75 Katja Luther
661 6b5ad34c Patric Plitzner
}