Project

General

Profile

Download (30.1 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.events.SelectionAdapter;
13
import org.eclipse.swt.events.SelectionEvent;
14
import org.eclipse.swt.events.SelectionListener;
15
import org.eclipse.swt.layout.GridData;
16
import org.eclipse.swt.widgets.Button;
17
import org.eclipse.swt.widgets.Combo;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.Label;
21

    
22
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
23
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
24
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
25
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
26
import eu.etaxonomy.taxeditor.l10n.Messages;
27
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

    
30
/**
31
 * @author pplitzner
32
 * @date 13.02.2014
33
 *
34
 */
35
public class SpecimenOrObservationPreferences extends CdmPreferencePage implements SelectionListener{
36

    
37
    private static final String LOCAL_SETTINGS_NOT_ALLOWED = Messages.SpecimenOrObservationPreferences_0;
38
    private static final String DESCRIPTION = Messages.SpecimenOrObservationPreferences_1;
39

    
40
    protected Boolean isShowSpecimenRelatedIssues;
41
    protected boolean allowOverrideShowSpecimenRelatedIssues;
42
    protected boolean overrideShowSpecimenRelatedIssues;
43
    protected Boolean isShowCollectingAreaInGeneralSection;
44
    protected boolean allowOverrideShowCollectingAreaInGeneralSection;
45
    protected boolean overrideShowCollectionAreaInGeneralSection;
46
    protected Boolean isDeterminationOnlyForFieldUnits;
47
    protected boolean allowOverrideDeterminationOnlyForFieldUnits;
48
    protected boolean overrideDeterminationOnlyForFieldUnits;
49
    protected Boolean isShowTaxonAssociation;
50
    protected boolean allowOverrideShowTaxonAssociation;
51
    protected boolean overrideShowTaxonAssociation;
52
    protected Boolean isShowLifeForm;
53
    protected boolean allowOverrideShowLifeForm;
54
    protected boolean overrideShowLifeForm;
55
    Composite composite;
56

    
57
    protected Combo showSpecimenButton;
58
    protected Button allowOverrideIsShowSpecimenRelatedIssuesButton;
59
    protected Combo showCollectingAreaInGeneralSectionButton;
60
    protected Button allowOverrideShowCollectingAreaButton;
61
    protected Combo determinationOnlyForFieldUnitsButton;
62
    protected Button allowOverridesDeterminationOnlyForFieldUnitsButton;
63
    protected Combo showTaxonAssociationButton;
64
    protected Button allowOverrideIsShowTaxonAssociationButton;
65
    protected Button allowOverrideShowLifeFormButton;
66
    protected Combo showLifeFormButton;
67

    
68
    CdmPreference showSpecimenPref;
69
    CdmPreference showCollectingAreaInGeneralSection;
70
    CdmPreference showDeterminationOnlyForFieldUnits;
71
    CdmPreference showTaxonAssociation;
72
    CdmPreference showLifeForm;
73

    
74
    @Override
75
    public void init() {
76
        super.init();
77
//        setPreferenceStore(PreferencesUtil.getPreferenceStore());
78
        if(!CdmStore.isActive()){
79
            return;
80
        }
81

    
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
            CdmPreferenceCache cache = CdmPreferenceCache.instance();
95

    
96
            if (showSpecimenPref != null){
97
                if (!showSpecimenPref.isAllowOverride() ){
98

    
99
                    isEditingAllowed = false;
100

    
101
                }
102
            }
103
        }
104
        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
        Composite titleComp = createComposite(parent);
114
        GridData gridData = createTextGridData();
115

    
116
        Label separator= new Label(titleComp, SWT.HORIZONTAL | SWT.SEPARATOR);
117
        separator.setLayoutData(gridData);
118
        separator.setVisible(false);
119
        showSpecimenButton = createBooleanCombo(titleComp, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowSpecimen, Messages.DatabasePreferncesPage_Show_Specimen, isAdminPreference);
120

    
121
        showSpecimenButton.addSelectionListener(this);
122
        int index = 0;
123
        for (String itemLabel : showSpecimenButton.getItems()) {
124
            if (isShowSpecimenRelatedIssues == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
125
                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
        }
138
        showSpecimenButton.setEnabled(isEditingAllowed);
139

    
140
        if (isAdminPreference){
141
            allowOverrideIsShowSpecimenRelatedIssuesButton = createAllowOverrideButton(titleComp);
142
            allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
143
            allowOverrideIsShowSpecimenRelatedIssuesButton.addSelectionListener(new SelectionAdapter(){
144
                @Override
145
                public void widgetSelected(SelectionEvent e) {
146
                    setApply(true);
147
                    allowOverrideShowSpecimenRelatedIssues = allowOverrideIsShowSpecimenRelatedIssuesButton.getSelection();
148
                }
149
            });
150
        }
151

    
152
        composite = createComposite(parent);
153
        //composite.setEnabled(isShowSpecimenRelatedIssues);
154
        gridData = createTextGridData();
155

    
156
        separator= new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
157
        separator.setLayoutData(gridData);
158

    
159
        showCollectingAreaInGeneralSectionButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowCollectingAreasInGeneralSection, Messages.DatabasePreferncesPage_Show_Collecting_Areas_in_general_section, isAdminPreference);
160

    
161
        showCollectingAreaInGeneralSectionButton.addSelectionListener(this);
162
        index = 0;
163
        for (String itemLabel : showCollectingAreaInGeneralSectionButton.getItems()) {
164
            if (isShowCollectingAreaInGeneralSection == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
165
                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
        }
178
        if (isAdminPreference){
179
            allowOverrideShowCollectingAreaButton = createAllowOverrideButton(composite);
180
            allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowCollectingAreaInGeneralSection);
181
            allowOverrideShowCollectingAreaButton.addSelectionListener(new SelectionAdapter(){
182
                @Override
183
                public void widgetSelected(SelectionEvent e) {
184
                    setApply(true);
185
                    allowOverrideShowCollectingAreaInGeneralSection = allowOverrideShowCollectingAreaButton.getSelection();
186
                }
187
            });
188
        }
189
        if (showCollectingAreaInGeneralSection != null && !showCollectingAreaInGeneralSection.isAllowOverride() ){
190
               isEditingAllowed = false;
191
        }
192
        showCollectingAreaInGeneralSectionButton.setEnabled(isEditingAllowed);
193
        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
        index = 0;
198
        for (String itemLabel : determinationOnlyForFieldUnitsButton.getItems()) {
199
            if (isDeterminationOnlyForFieldUnits == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
200
                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
        }
213
        if (showDeterminationOnlyForFieldUnits != null && !showDeterminationOnlyForFieldUnits.isAllowOverride() ){
214
            isEditingAllowed = false;
215
        }
216
        determinationOnlyForFieldUnitsButton.setEnabled(isEditingAllowed);
217
        if (isAdminPreference){
218
            allowOverridesDeterminationOnlyForFieldUnitsButton = createAllowOverrideButton(composite);
219
            allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideDeterminationOnlyForFieldUnits);
220
            allowOverridesDeterminationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
221
                @Override
222
                public void widgetSelected(SelectionEvent e) {
223
                    setApply(true);
224
                    allowOverrideDeterminationOnlyForFieldUnits = allowOverridesDeterminationOnlyForFieldUnitsButton.getSelection();
225
                }
226
            });
227
        }
228

    
229
        showTaxonAssociationButton =createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowTaxonAssociations, Messages.DatabasePreferncesPage_Taxon_Associations, isAdminPreference);
230

    
231

    
232
        showTaxonAssociationButton.addSelectionListener(this);
233
        index = 0;
234
        for (String itemLabel : showTaxonAssociationButton.getItems()) {
235
            if (isShowTaxonAssociation == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
236
                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
        }
252
        showTaxonAssociationButton.setEnabled(isEditingAllowed);
253
        if (isAdminPreference){
254
            allowOverrideIsShowTaxonAssociationButton = createAllowOverrideButton(composite);
255
            allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowTaxonAssociation);
256
            allowOverrideIsShowTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
257
                @Override
258
                public void widgetSelected(SelectionEvent e) {
259
                    setApply(true);
260
                    allowOverrideShowTaxonAssociation = allowOverrideIsShowTaxonAssociationButton.getSelection();
261
                }
262
            });
263
        }
264

    
265
        showLifeFormButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowLifeForm, Messages.DatabasePreferncesPage_Life_Form, isAdminPreference);
266
        showLifeFormButton.addSelectionListener(this);
267

    
268
        index = 0;
269
        for (String itemLabel: showLifeFormButton.getItems()) {
270
            if (isShowLifeForm == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
271
                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
        }
284
        if (showLifeForm != null && !showLifeForm.isAllowOverride() ){
285
            isEditingAllowed = false;
286
        }
287
        showLifeFormButton.setEnabled(isEditingAllowed);
288
        if (isAdminPreference){
289
            allowOverrideShowLifeFormButton = createAllowOverrideButton(composite);
290
            allowOverrideShowLifeFormButton.setSelection(allowOverrideShowLifeForm);
291
            allowOverrideShowLifeFormButton.addSelectionListener(new SelectionAdapter(){
292
                @Override
293
                public void widgetSelected(SelectionEvent e) {
294
                    setApply(true);
295
                    allowOverrideShowLifeForm = allowOverrideShowLifeFormButton.getSelection();
296
                }
297
            });
298
        }
299

    
300
        if (!isEditingAllowed){
301
            PreferencesUtil.recursiveSetEnabled(composite, false);
302
        }
303

    
304
        return composite;
305
    }
306

    
307

    
308
    /**
309
     * {@inheritDoc}
310
     */
311
    @Override
312
    protected void getValues() {
313
        CdmPreferenceCache cache = CdmPreferenceCache.instance();
314

    
315

    
316
        overrideShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(
317
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey()), true) != null? PreferencesUtil.getBooleanValue(
318
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowSpecimen.getKey()), true): false;
319

    
320
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
321
        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
            showSpecimenPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, PreferencePredicate.ShowSpecimen.getDefaultValue() != null ?  PreferencePredicate.ShowSpecimen.getDefaultValue().toString(): null);
340
        }
341

    
342

    
343

    
344

    
345
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
346
        showCollectingAreaInGeneralSection = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowCollectingAreasInGeneralSection);
347
        overrideShowCollectionAreaInGeneralSection = PreferencesUtil.getBooleanValue(
348
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), true) != null? PreferencesUtil.getBooleanValue(
349
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), true): false;
350
        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
            showCollectingAreaInGeneralSection = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue() != null ?  PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue().toString(): null);
369
        }
370

    
371

    
372
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
373
        showDeterminationOnlyForFieldUnits = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DeterminationOnlyForFieldUnits);
374
        overrideDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(
375
                PreferencesUtil.prefOverrideKey(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), true) != null? PreferencesUtil.getBooleanValue(
376
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), true): false;
377
        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
            showDeterminationOnlyForFieldUnits = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue() != null ?  PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue().toString(): null);
395
        }
396

    
397
        allowOverrideDeterminationOnlyForFieldUnits = showDeterminationOnlyForFieldUnits != null ? showDeterminationOnlyForFieldUnits.isAllowOverride():true;
398

    
399

    
400
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
401
        showTaxonAssociation = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowTaxonAssociations);
402
        overrideShowTaxonAssociation =  PreferencesUtil.getBooleanValue(
403
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonAssociations.getKey()), true) != null? PreferencesUtil.getBooleanValue(
404
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowTaxonAssociations.getKey()), true): false;
405
        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
            showTaxonAssociation = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, PreferencePredicate.ShowTaxonAssociations.getDefaultValue() != null ?  PreferencePredicate.ShowTaxonAssociations.getDefaultValue().toString(): null);
423
        }
424

    
425
        allowOverrideShowTaxonAssociation = showTaxonAssociation != null ? showTaxonAssociation.isAllowOverride():true;
426

    
427

    
428
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
429
        showLifeForm = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowLifeForm);
430
        overrideShowLifeForm =  PreferencesUtil.getBooleanValue(
431
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()), true) != null? PreferencesUtil.getBooleanValue(
432
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()), true): false;
433
        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
            showLifeForm = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, PreferencePredicate.ShowLifeForm.getDefaultValue() != null ?  PreferencePredicate.ShowLifeForm.getDefaultValue().toString(): null);
451
        }
452

    
453
        allowOverrideShowLifeForm = showLifeForm != null ? showLifeForm.isAllowOverride():true;
454

    
455

    
456
    }
457

    
458
    @Override
459
    public boolean performOk() {
460

    
461
        boolean override = false;
462
        if (isShowSpecimenRelatedIssues != null ) {
463
            override = true;
464
            PreferencesUtil.setStringValue(PreferencePredicate.ShowSpecimen.getKey(), isShowSpecimenRelatedIssues.toString());
465
        }
466
        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
        }
475
        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
        }
484
        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
        }
493
        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
        }
502
        PreferencesUtil.setBooleanValue(
503
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowLifeForm.getKey()),
504
                override);
505

    
506
        return true;
507
    }
508

    
509

    
510

    
511
    @Override
512
    protected void performDefaults() {
513
        isShowSpecimenRelatedIssues = null;
514
        showSpecimenButton.select(0);
515

    
516
        if (allowOverrideIsShowSpecimenRelatedIssuesButton != null){
517
            allowOverrideShowSpecimenRelatedIssues = true;
518
            allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
519
        }
520
        isShowCollectingAreaInGeneralSection = null;
521
        showCollectingAreaInGeneralSectionButton.select(0);
522

    
523
        if (allowOverrideShowCollectingAreaButton != null){
524
            allowOverrideShowCollectingAreaInGeneralSection = true;
525
            allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
526
        }
527
        isDeterminationOnlyForFieldUnits = null;
528
        determinationOnlyForFieldUnitsButton.select(0);
529

    
530
        if (allowOverridesDeterminationOnlyForFieldUnitsButton != null){
531
            allowOverrideDeterminationOnlyForFieldUnits = true;
532
            allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
533
        }
534

    
535
        isShowTaxonAssociation = null;
536
        showTaxonAssociationButton.select(0);
537

    
538
        if (allowOverrideIsShowTaxonAssociationButton != null){
539
            allowOverrideShowTaxonAssociation = true;
540
            allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
541
        }
542

    
543

    
544
        isShowLifeForm = null;
545

    
546
        showLifeFormButton.select(0);
547

    
548
        if (allowOverrideShowLifeFormButton != null){
549
            allowOverrideShowLifeForm = true;
550
            allowOverrideShowLifeFormButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
551
        }
552

    
553

    
554
        super.performDefaults();
555
    }
556

    
557
    /**
558
     * {@inheritDoc}
559
     */
560
    @Override
561
    public void widgetSelected(SelectionEvent e) {
562
       setApply(true);
563
       if (e.getSource().equals(this.showSpecimenButton)) {
564
           String text = showSpecimenButton.getText();
565
           if(text.startsWith(Messages.Preference_Use_Default)){
566
               isShowSpecimenRelatedIssues = null;
567
               if (isAdminPreference){
568
                   allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(true);
569
               }
570
               return;
571
           }
572
           if (text.equals(Messages.GeneralPreference_yes)){
573
               isShowSpecimenRelatedIssues = true;
574
           }else{
575
               isShowSpecimenRelatedIssues = false;
576
           }
577
       }
578

    
579
       if (e.getSource().equals(this.showCollectingAreaInGeneralSectionButton)) {
580
           String text = showCollectingAreaInGeneralSectionButton.getText();
581
           if(text.startsWith(Messages.Preference_Use_Default)){
582
               isShowCollectingAreaInGeneralSection = null;
583
               if (isAdminPreference){
584
                   //showCollectingAreaInGeneralSection.setAllowOverride(true);
585
                   allowOverrideShowCollectingAreaButton.setSelection(true);
586
               }
587
               return;
588
           }
589
           if (text.equals(Messages.GeneralPreference_yes)){
590
               isShowCollectingAreaInGeneralSection = true;
591
           }else{
592
               isShowCollectingAreaInGeneralSection = false;
593
           }
594
       }
595

    
596
       if (e.getSource().equals(this.determinationOnlyForFieldUnitsButton)) {
597
           String text = determinationOnlyForFieldUnitsButton.getText();
598
           if(text.startsWith(Messages.Preference_Use_Default)){
599
               isDeterminationOnlyForFieldUnits = null;
600
               if (isAdminPreference){
601
                   //showDeterminationOnlyForFieldUnits.setAllowOverride(true);
602
                   allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(true);
603
               }
604
               return;
605
           }
606
           if (text.equals(Messages.GeneralPreference_yes)){
607
               isDeterminationOnlyForFieldUnits = true;
608
           }else{
609
               isDeterminationOnlyForFieldUnits = false;
610
           }
611
       }
612

    
613
       if (e.getSource().equals(this.showTaxonAssociationButton)) {
614
           String text = showTaxonAssociationButton.getText();
615
           if(text.startsWith(Messages.Preference_Use_Default)){
616
               isShowTaxonAssociation = null;
617
               if (isAdminPreference){
618
                   //showTaxonAssociation.setAllowOverride(true);
619
                   allowOverrideIsShowTaxonAssociationButton.setSelection(true);
620
               }
621
               return;
622
           }
623
           if (text.equals(Messages.GeneralPreference_yes)){
624
               isShowTaxonAssociation = true;
625
           }else{
626
               isShowTaxonAssociation = false;
627
           }
628
       }
629

    
630
       if (e.getSource().equals(this.showLifeFormButton)) {
631
           String text = showLifeFormButton.getText();
632
           if(text.startsWith(Messages.Preference_Use_Default)){
633
               isShowLifeForm = null;
634
               if (isAdminPreference){
635
                   //showLifeForm.setAllowOverride(true);
636
                   allowOverrideShowLifeFormButton.setSelection(true);
637
               }
638
               return;
639
           }
640
           if (text.equals(Messages.GeneralPreference_yes)){
641
               isShowLifeForm = true;
642
           }else{
643
               isShowLifeForm = false;
644
           }
645
       }
646

    
647
    }
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

    
661
}
(43-43/52)