Project

General

Profile

Download (37.7 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.layout.GridLayout;
17
import org.eclipse.swt.widgets.Button;
18
import org.eclipse.swt.widgets.Combo;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Label;
22

    
23
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
24
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
25
import eu.etaxonomy.cdm.model.metadata.TermComboEnum;
26
import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
27
import eu.etaxonomy.cdm.model.metadata.TermOrder;
28
import eu.etaxonomy.taxeditor.l10n.Messages;
29
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
30

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

    
38

    
39

    
40
    protected Boolean isEditorActivated;
41

    
42
    protected boolean overrideActivated;
43
    boolean isUseLocal;
44
    protected Boolean isShowRank;
45
    protected TermOrder orderAreas;
46
    protected TermDisplayEnum displayStatus;
47
    protected TermComboEnum displayStatusCombo;
48
    protected TermDisplayEnum displayArea;
49
    protected Boolean ownDescriptionForDistributionEditor;
50

    
51
    protected boolean overrideOwnDescriptionForDistributionEditor;
52
    protected boolean overrideAreaVoc;
53
    protected boolean overrideRank;
54
    protected boolean overrideOrderAreas;
55
    protected boolean overrideAreaDisplay;
56
    protected boolean overrideStatusDisplay;
57
    protected boolean overrideStatusDisplayCombo;
58

    
59
    protected Combo areaOrderSelectionCombo;
60
    protected Button allowOverrideOrderAreasButton;
61
    protected Combo statusDisplaySelectionCombo;
62
    protected Button allowOverrideStatusDisplayButton;
63
    protected Combo statusDisplayInComboSelectionCombo;
64
    protected Button allowOverrideStatusDisplayInComboButton;
65
    protected Combo areaDisplaySelectionCombo;
66
    protected Button allowOverrideAreaDisplayButton;
67

    
68

    
69
    protected CdmPreference distributionEditorPref;
70

    
71
    protected CdmPreference prefStatusDisplay;
72
    protected CdmPreference prefAreaDisplay;
73

    
74
    protected CdmPreference prefStatusDisplayInCombo;
75
    protected CdmPreference prefAreaSort;
76
    protected CdmPreference prefRank;
77
    protected CdmPreference prefOwnDescription;
78
    Composite child;
79

    
80
    protected Combo activateCombo;
81
    protected Button allowOverrideActivatedButton;
82
    final String ENABLE = "Enable";
83
    final String DISABLE = "Disable";
84

    
85
    protected Combo activateRankCombo;
86
    protected Button allowOverrideRankButton;
87
    final String SHOW_RANK = "Yes";
88
    final String NO_RANK = "No";
89

    
90

    
91

    
92

    
93
    @Override
94
    protected Control createContents(Composite parent) {
95
        getValues();
96
        Composite composite = new Composite(parent, SWT.NULL);
97
        composite.setLayout(new GridLayout());
98
        if (!isAdminPreference && distributionEditorPref != null && !distributionEditorPref.isAllowOverride() ) {
99
            Label label = new Label(composite, SWT.NONE);
100
            label.setText(
101
                    "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.");
102
            this.setDefaultButtonActivated(false);
103
        } else {
104
            Composite activateComp = createComposite(composite);
105
            Label separator = new Label(activateComp, SWT.HORIZONTAL | SWT.SEPARATOR);
106
            GridData sepGrid = createTextGridData();
107
            separator.setLayoutData(sepGrid);
108
            separator.setVisible(false);
109
            CdmPreference dbPref;
110
            GridData textGrid = createTextGridData();
111
            textGrid.verticalSpan = 2;
112
            separator.setLayoutData(sepGrid);
113

    
114
            activateCombo = createBooleanCombo(activateComp, ENABLE, DISABLE, PreferencePredicate.DistributionEditorActivated, Messages.ChecklistEditorGeneralPreference_enable, isAdminPreference);
115

    
116
            int index = 0;
117
            for (String itemLabel : activateCombo.getItems()) {
118
                if (isEditorActivated == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
119
                    activateCombo.select(index);
120
                    break;
121
                }
122
                if (isEditorActivated != null && itemLabel.equals(ENABLE) && isEditorActivated){
123
                    activateCombo.select(index);
124
                    break;
125
                }
126
                if (isEditorActivated != null && itemLabel.equals(DISABLE) && !isEditorActivated){
127
                    activateCombo.select(index);
128
                    break;
129
                }
130
                index++;
131
            }
132

    
133

    
134
            activateCombo.addSelectionListener(this);
135
            if (isAdminPreference) {
136
                allowOverrideActivatedButton = createAllowOverrideButton(activateComp);
137
                allowOverrideActivatedButton.setSelection(this.distributionEditorPref != null? this.distributionEditorPref.isAllowOverride(): true);
138
                allowOverrideActivatedButton.addSelectionListener(new SelectionAdapter() {
139
                    @Override
140
                    public void widgetSelected(SelectionEvent e) {
141
                        setApply(true);
142
                        if (distributionEditorPref == null){
143
                            distributionEditorPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DistributionEditorActivated, PreferencePredicate.DistributionEditorActivated.getDefaultValue() != null ?  PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString(): null);
144
                        }
145
                        distributionEditorPref.setAllowOverride(!distributionEditorPref.isAllowOverride());
146
                    }
147
                });
148
            }
149
            child = createComposite(composite);
150

    
151
            if (!isAdminPreference) {
152
                if (isEditorActivated != null){
153
                    child.setEnabled(isEditorActivated);
154
                }else{
155
                    child.setEnabled(distributionEditorPref.getValue() != null?Boolean.parseBoolean(distributionEditorPref.getValue().toString()): true);
156
                }
157
            }
158
            separator = new Label(child, SWT.HORIZONTAL | SWT.SEPARATOR);
159
            sepGrid = createTextGridData();
160
            separator.setLayoutData(sepGrid);
161

    
162
            activateRankCombo = createBooleanCombo(child, SHOW_RANK, NO_RANK,
163
                    PreferencePredicate.ShowRankInDistributionEditor, Messages.ChecklistEditorGeneralPreference_show_rank, isAdminPreference);
164
            index = 0;
165
            for (String itemLabel : activateRankCombo.getItems()) {
166
                if (isShowRank == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
167
                    activateRankCombo.select(index);
168
                    break;
169
                }
170
                if (isShowRank != null && itemLabel.equals(SHOW_RANK) && isShowRank){
171
                    activateRankCombo.select(index);
172
                    break;
173
                }
174
                if (isShowRank != null && itemLabel.equals(NO_RANK) && !isShowRank){
175
                    activateRankCombo.select(index);
176
                    break;
177
                }
178
                index++;
179
            }
180
            activateRankCombo.addSelectionListener(this);
181
            if (isAdminPreference) {
182
                allowOverrideRankButton = createAllowOverrideButton(child);
183
                allowOverrideRankButton.setSelection(prefRank != null? prefRank.isAllowOverride():true);
184
               // allowOverrideRankButton.setEnabled(prefRank != null);
185
                allowOverrideRankButton.addSelectionListener(new SelectionAdapter() {
186
                    @Override
187
                    public void widgetSelected(SelectionEvent e) {
188
                        setApply(true);
189
                        if (prefRank == null){
190
                            prefRank = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowRankInDistributionEditor, PreferencePredicate.ShowRankInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.ShowRankInDistributionEditor.getDefaultValue().toString(): null);
191
                        }
192
                        prefRank.setAllowOverride(allowOverrideRankButton.getSelection());
193
                    }
194
                });
195
            }
196
            areaOrderSelectionCombo = createCombo(child, TermOrder.values(), PreferencePredicate.AreasSortedInDistributionEditor, Messages.ChecklistEditorGeneralPreference_Configure_area_order, isAdminPreference);
197

    
198
            index = 0;
199

    
200
            for (String itemLabel : areaOrderSelectionCombo.getItems()) {
201
                if (itemLabel.startsWith(Messages.Preference_Use_Default) && orderAreas == null){
202
                    areaOrderSelectionCombo.select(index);
203
                    break;
204
                }
205
                if (itemLabel.equals(orderAreas.getLabel())) {
206
                    areaOrderSelectionCombo.select(index);
207
                    break;
208
                }
209

    
210
                index++;
211
            }
212

    
213
            areaOrderSelectionCombo.addSelectionListener(this);
214

    
215
            if (isAdminPreference) {
216
                allowOverrideOrderAreasButton = createAllowOverrideButton(child);
217
                allowOverrideOrderAreasButton.setSelection(prefAreaSort != null? prefAreaSort.isAllowOverride(): true);
218
                //allowOverrideOrderAreasButton.setEnabled(prefAreaSort != null);
219
                allowOverrideOrderAreasButton.addSelectionListener(new SelectionAdapter() {
220
                    @Override
221
                    public void widgetSelected(SelectionEvent e) {
222
                        setApply(true);
223
                        if (prefAreaSort == null){
224
                            prefAreaSort = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AreasSortedInDistributionEditor, PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue().toString(): null);
225
                        }
226
                        prefAreaSort.setAllowOverride(allowOverrideOrderAreasButton.getSelection());
227
                    }
228
                });
229
            }
230

    
231
            separator = new Label(child, SWT.HORIZONTAL | SWT.SEPARATOR);
232
            separator.setLayoutData(sepGrid);
233
            areaDisplaySelectionCombo = createCombo(child, TermDisplayEnum.values(), PreferencePredicate.DisplayOfAreasInDistributionEditor, Messages.ChecklistEditorGeneralPreference_Configure_display_of_Areas, isAdminPreference);
234

    
235

    
236
            index = 0;
237

    
238
            for (String itemLabel : areaDisplaySelectionCombo.getItems()) {
239
                if (itemLabel.startsWith(Messages.Preference_Use_Default) && displayArea == null){
240
                    areaDisplaySelectionCombo.select(index);
241
                    break;
242
                }else if (itemLabel.equals(displayArea.getLabel())) {
243
                    areaDisplaySelectionCombo.select(index);
244
                    break;
245
                }
246

    
247
                index++;
248
            }
249
            areaDisplaySelectionCombo.addSelectionListener(this);
250

    
251
            if (isAdminPreference) {
252
                allowOverrideAreaDisplayButton = createAllowOverrideButton(child);
253
                allowOverrideAreaDisplayButton.setSelection(prefAreaDisplay != null? prefAreaDisplay.isAllowOverride(): true);
254
                //allowOverrideAreaDisplayButton.setEnabled(prefAreaDisplay != null);
255
                allowOverrideAreaDisplayButton.addSelectionListener(new SelectionAdapter() {
256
                    @Override
257
                    public void widgetSelected(SelectionEvent e) {
258
                        setApply(true);
259
                        if (prefAreaDisplay == null){
260
                            prefAreaDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfAreasInDistributionEditor, PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString(): null);
261
                        }
262
                        prefAreaDisplay.setAllowOverride(allowOverrideOrderAreasButton.getSelection());
263
                    }
264
                });
265
            }
266

    
267
            statusDisplaySelectionCombo = createCombo(child, TermDisplayEnum.values(), PreferencePredicate.DisplayOfStatus, Messages.ChecklistEditorGeneralPreference_Configure_display_of_Status, isAdminPreference);
268

    
269
            index = 0;
270

    
271
            for (String itemLabel : statusDisplaySelectionCombo.getItems()) {
272
                if (itemLabel.startsWith(Messages.Preference_Use_Default) && displayStatus == null){
273
                    statusDisplaySelectionCombo.select(index);
274
                    break;
275
                }
276
                if (itemLabel.equals(displayStatus.getLabel())) {
277
                    statusDisplaySelectionCombo.select(index);
278
                    break;
279
                }
280

    
281
                index++;
282
            }
283

    
284
            statusDisplaySelectionCombo.addSelectionListener(this);
285

    
286
            if (isAdminPreference) {
287
                allowOverrideStatusDisplayButton = createAllowOverrideButton(child);
288
                allowOverrideStatusDisplayButton.setSelection(prefStatusDisplay != null ? prefStatusDisplay.isAllowOverride(): true);
289
                //allowOverrideStatusDisplayButton.setEnabled(prefStatusDisplay != null);
290
                allowOverrideStatusDisplayButton.addSelectionListener(new SelectionAdapter() {
291
                    @Override
292
                    public void widgetSelected(SelectionEvent e) {
293
                        setApply(true);
294
                        if (prefStatusDisplay == null){
295
                            prefStatusDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfStatus, PreferencePredicate.DisplayOfStatus.getDefaultValue() != null ?  PreferencePredicate.DisplayOfStatus.getDefaultValue().toString(): null);
296
                        }
297
                        prefStatusDisplay.setAllowOverride(allowOverrideStatusDisplayButton.getSelection());
298
                    }
299
                });
300
            }
301

    
302
            statusDisplayInComboSelectionCombo = createCombo(child, TermComboEnum.values(), PreferencePredicate.DisplayOfStatusInCombo, Messages.ChecklistEditorGeneralPreference_Configure_display_of_Status_in_Combo, isAdminPreference);
303

    
304
            index = 0;
305

    
306
            for (String itemLabel : statusDisplayInComboSelectionCombo.getItems()) {
307
                if (itemLabel.startsWith(Messages.Preference_Use_Default) && displayStatusCombo == null){
308
                    statusDisplayInComboSelectionCombo.select(index);
309
                    break;
310
                }
311
                if (itemLabel.equals(displayStatusCombo.getLabel())) {
312
                    statusDisplayInComboSelectionCombo.select(index);
313
                    break;
314
                }
315

    
316
                index++;
317
            }
318

    
319
            statusDisplayInComboSelectionCombo.addSelectionListener(this);
320

    
321
            if (isAdminPreference) {
322
                allowOverrideStatusDisplayInComboButton = createAllowOverrideButton(child);
323
                allowOverrideStatusDisplayInComboButton.setSelection(prefStatusDisplayInCombo != null ? prefStatusDisplayInCombo.isAllowOverride(): true);
324
                //allowOverrideStatusDisplayInComboButton.setEnabled(prefStatusDisplayInCombo != null);
325
                allowOverrideStatusDisplayInComboButton.addSelectionListener(new SelectionAdapter() {
326
                    @Override
327
                    public void widgetSelected(SelectionEvent e) {
328
                        setApply(true);
329
                        if (prefStatusDisplayInCombo == null){
330
                            prefStatusDisplayInCombo = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfStatusInCombo, PreferencePredicate.DisplayOfStatusInCombo.getDefaultValue() != null ?  PreferencePredicate.DisplayOfStatusInCombo.getDefaultValue().toString(): null);
331
                        }
332
                        prefStatusDisplayInCombo.setAllowOverride(allowOverrideStatusDisplayInComboButton.getSelection());
333
                    }
334
                });
335
            }
336

    
337

    
338

    
339

    
340
            if (!isAdminPreference) {
341

    
342

    
343
                if (distributionEditorPref != null && !distributionEditorPref.isAllowOverride()){
344
                    activateComp.setEnabled(false);
345
                }
346

    
347

    
348
                if (prefRank != null && !prefRank.isAllowOverride()) {
349
                    activateRankCombo.setEnabled(false);
350
                }
351
                if (prefAreaSort != null && !prefAreaSort.isAllowOverride()) {
352
                    areaOrderSelectionCombo.setEnabled(false);
353
                }
354
                if (prefAreaDisplay != null && !prefAreaDisplay.isAllowOverride()) {
355
                    areaDisplaySelectionCombo.setEnabled(false);
356
                }
357
                if (prefStatusDisplay != null && !prefStatusDisplay.isAllowOverride()) {
358
                    statusDisplaySelectionCombo.setEnabled(false);
359
                }
360
                if (prefStatusDisplayInCombo != null && !prefStatusDisplayInCombo.isAllowOverride()) {
361
                    statusDisplayInComboSelectionCombo.setEnabled(false);
362
                }
363
            }
364

    
365
        }
366
        setValid(true);
367
        return composite;
368
    }
369

    
370
    @Override
371
    public boolean performOk() {
372
        if (!isApply()){
373
            return true;
374
        }
375
            boolean override = false;
376
            if (isEditorActivated != null ) {
377
                override = true;
378
                PreferencesUtil.setStringValue(PreferencePredicate.DistributionEditorActivated.getKey(), isEditorActivated.toString());
379
            }
380
            PreferencesUtil.setBooleanValue(
381
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey()),
382
                    override);
383

    
384

    
385
            override = false;
386
            if (orderAreas != null ) {
387
                override = true;
388
                PreferencesUtil.setSortNamedAreasInDistributionEditor(orderAreas.getKey());
389
            }
390
            PreferencesUtil.setBooleanValue(
391
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.AreasSortedInDistributionEditor.getKey()),
392
                    override);
393

    
394
            override = false;
395
            if (isShowRank != null ) {
396
                override = true;
397
                PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
398
            }
399
            PreferencesUtil.setBooleanValue(
400
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowRankInDistributionEditor.getKey()),
401
                    override);
402

    
403

    
404
            override = false;
405
            if (displayStatus != null) {
406
               override = true;
407
               PreferencesUtil.setDisplayStatusInChecklistEditor(displayStatus.getKey());
408
            }
409
            PreferencesUtil.setBooleanValue(
410
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatus.getKey()),
411
                    override);
412

    
413
            override = false;
414
            if (displayStatusCombo != null) {
415
               override = true;
416
               PreferencesUtil.setStringValue(PreferencePredicate.DisplayOfStatusInCombo.getKey(), displayStatusCombo.getKey());
417
            }
418
            PreferencesUtil.setBooleanValue(
419
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatusInCombo.getKey()),
420
                    override);
421

    
422

    
423

    
424
            override = false;
425
            if (displayArea != null) {
426
                override = true;
427
                PreferencesUtil.setAreaDisplayInChecklistEditor(displayArea.getKey());
428
            }
429
            PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(
430
                    PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), override);
431

    
432

    
433
            PreferencesUtil.firePreferencesChanged(this.getClass());
434

    
435
        return true;
436
    }
437

    
438
    /**
439
     * {@inheritDoc}
440
     */
441
    @Override
442
    public void widgetSelected(SelectionEvent e) {
443
        setApply(true);
444
        if (e.getSource().equals(statusDisplaySelectionCombo)) {
445
            String text = statusDisplaySelectionCombo.getText();
446
            if(text.startsWith(Messages.Preference_Use_Default)){
447
                displayStatus = null;
448
                return;
449
            }
450

    
451
            for (TermDisplayEnum display : TermDisplayEnum.values()) {
452
                if (text.startsWith(display.getLabel())) {
453
                    displayStatus = display;
454
                    break;
455
                }
456

    
457
            }
458
        }
459
        if (e.getSource().equals(statusDisplayInComboSelectionCombo)) {
460
            String text = statusDisplayInComboSelectionCombo.getText();
461
            if(text.startsWith(Messages.Preference_Use_Default)){
462
                displayStatusCombo = null;
463
                return;
464
            }
465

    
466
            for (TermComboEnum display : TermComboEnum.values()) {
467
                if (text.startsWith(display.getLabel())) {
468
                    displayStatusCombo = display;
469
                    break;
470
                }
471

    
472
            }
473
        }
474
        if (e.getSource().equals(areaDisplaySelectionCombo)) {
475
            String text = areaDisplaySelectionCombo.getText();
476
            if(text.startsWith(Messages.Preference_Use_Default)){
477
                displayArea = null;
478
                return;
479
            }
480

    
481
            for (TermDisplayEnum display : TermDisplayEnum.values()) {
482
                if (text.startsWith(display.getLabel())) {
483
                    displayArea = display;
484
                    break;
485
                }
486
            }
487
        }
488
        if (e.getSource().equals(areaOrderSelectionCombo)) {
489
            String text = areaOrderSelectionCombo.getText();
490
            if(text.startsWith(Messages.Preference_Use_Default)){
491
                orderAreas = null;
492
                return;
493
            }
494

    
495
            for (TermOrder display : TermOrder.values()) {
496
                if (text.startsWith(display.getLabel())) {
497
                    orderAreas = display;
498
                    break;
499
                }
500
            }
501
        }
502
        if (e.getSource().equals(this.activateRankCombo)) {
503
            String text = activateRankCombo.getText();
504
            if(text.startsWith(Messages.Preference_Use_Default)){
505
                isShowRank = null;
506
                return;
507
            }
508

    
509
            if (text.equals(SHOW_RANK)){
510
                isShowRank = true;
511
            }else{
512
                isShowRank = false;
513
            }
514
        }
515

    
516
        if (e.getSource().equals(this.activateCombo)) {
517
            String text = activateCombo.getText();
518
            if(text.startsWith(Messages.Preference_Use_Default)){
519
                isEditorActivated = null;
520
                if (!isAdminPreference) {
521
                    if (isEditorActivated != null){
522
                        child.setEnabled(isEditorActivated);
523
                    }else{
524
                        child.setEnabled(distributionEditorPref.getValue() != null?Boolean.parseBoolean(distributionEditorPref.getValue().toString()): true);
525
                    }
526
                }
527
                return;
528
            }
529

    
530
            if (text.equals(ENABLE)){
531
                isEditorActivated = true;
532
            }else{
533
                isEditorActivated = false;
534
            }
535
            if (!isAdminPreference) {
536
                if (isEditorActivated != null){
537
                    child.setEnabled(isEditorActivated);
538
                }else{
539
                    child.setEnabled(distributionEditorPref.getValue() != null?Boolean.parseBoolean(distributionEditorPref.getValue().toString()): true);
540
                }
541
            }
542

    
543
        }
544

    
545
    }
546

    
547
    /**
548
     * {@inheritDoc}
549
     */
550
    @Override
551
    public void widgetDefaultSelected(SelectionEvent e) {
552
        // TODO Auto-generated method stub
553

    
554
    }
555

    
556
    /**
557
     * {@inheritDoc}
558
     */
559
    @Override
560
    public void getValues() {
561
        isAdminPreference = false;
562
        setPreferenceStore(PreferencesUtil.getPreferenceStore());
563
        distributionEditorPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
564
        overrideActivated = PreferencesUtil.getBooleanValue(
565
                PreferencesUtil.prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey()), true) != null? PreferencesUtil.getBooleanValue(
566
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey()), true):false;
567

    
568
        if (distributionEditorPref != null) {
569
            if (distributionEditorPref.isAllowOverride() ) {
570
                if (overrideActivated){
571
                    isEditorActivated = PreferencesUtil.getBooleanValue(PreferencePredicate.DistributionEditorActivated.getKey(), true);
572
                }
573

    
574
            } else {
575
                isEditorActivated = distributionEditorPref.getValue() != null? Boolean.valueOf(distributionEditorPref.getValue()): null;
576
            }
577

    
578
        } else {
579
            if(!overrideActivated){
580
                isEditorActivated = null;
581
            }else{
582
                isEditorActivated = PreferencesUtil.getBooleanValue(PreferencePredicate.DistributionEditorActivated.getKey(), true);
583
            }
584
            distributionEditorPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DistributionEditorActivated, PreferencePredicate.DistributionEditorActivated.getDefaultValue() != null ?  PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString(): null);
585
        }
586

    
587

    
588

    
589

    
590
        prefAreaDisplay = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DisplayOfAreasInDistributionEditor);
591
        overrideAreaDisplay = PreferencesUtil.getBooleanValue(
592
                PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), true) != null? PreferencesUtil.getBooleanValue(
593
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), true): false;
594

    
595
        if (prefAreaDisplay != null) {
596
            if (prefAreaDisplay.isAllowOverride()){
597
                if (overrideActivated) {
598
                    displayArea = PreferencesUtil.displayAreaInChecklistEditor();
599
                }else{
600
                    displayArea = null;
601
                }
602
            } else {
603
                displayArea = prefAreaDisplay.getValue() != null? TermDisplayEnum.byKey(prefAreaDisplay.getValue()): null;
604
            }
605
        } else {
606
            if (overrideAreaDisplay){
607
                displayArea = PreferencesUtil.displayAreaInChecklistEditor();
608
            } else{
609
                displayArea = null;
610
            }
611
            //prefAreaDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfAreasInDistributionEditor, PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString(): null);
612
        }
613

    
614
        prefStatusDisplay = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DisplayOfStatus);
615
        overrideStatusDisplay = PreferencesUtil
616
                .getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatus.getKey()), true) != null? PreferencesUtil
617
                        .getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatus.getKey()), true): false;
618
        if (prefStatusDisplay != null) {
619
            if (prefStatusDisplay.isAllowOverride()){
620
                if (overrideStatusDisplay) {
621
                    displayStatus = PreferencesUtil.displayStatusInChecklistEditor();
622
                }else{
623
                    displayStatus = null;
624
                }
625
            } else {
626
                this.displayStatus = prefStatusDisplay.getValue() != null? TermDisplayEnum.byKey(prefStatusDisplay.getValue()): null;
627
            }
628
        } else {
629
            if (overrideStatusDisplay){
630
                displayStatus = PreferencesUtil.displayStatusInChecklistEditor();
631
            } else{
632
                displayStatus = null;
633
            }
634
            //prefStatusDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfStatus, PreferencePredicate.DisplayOfStatus.getDefaultValue() != null ?  PreferencePredicate.DisplayOfStatus.getDefaultValue().toString(): null);
635
        }
636

    
637
        prefStatusDisplayInCombo = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DisplayOfStatusInCombo);
638
        overrideStatusDisplayCombo = PreferencesUtil
639
                .getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatusInCombo.getKey()), true) != null? PreferencesUtil
640
                        .getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatusInCombo.getKey()), true): false;
641
        if (prefStatusDisplayInCombo != null) {
642
            if (prefStatusDisplayInCombo.isAllowOverride()){
643
                if (overrideStatusDisplayCombo) {
644
                    displayStatusCombo = TermComboEnum.byKey(PreferencesUtil.getStringValue(PreferencePredicate.DisplayOfStatusInCombo.getKey()));
645
                }else{
646
                    displayStatusCombo = null;
647
                }
648
            } else {
649
                this.displayStatusCombo = prefStatusDisplayInCombo.getValue() != null? TermComboEnum.byKey(prefStatusDisplayInCombo.getValue()): null;
650
            }
651
        } else {
652
            if (overrideStatusDisplayCombo){
653
                displayStatusCombo = TermComboEnum.byKey(PreferencesUtil.getStringValue(PreferencePredicate.DisplayOfStatusInCombo.getKey()));
654
            } else{
655
                displayStatusCombo = null;
656
            }
657

    
658
        }
659

    
660

    
661
        prefAreaSort = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AreasSortedInDistributionEditor);
662
        overrideOrderAreas = PreferencesUtil.getBooleanValue(
663
                PreferencesUtil.prefOverrideKey(PreferencePredicate.AreasSortedInDistributionEditor.getKey()), true) != null? PreferencesUtil.getBooleanValue(
664
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.AreasSortedInDistributionEditor.getKey()), true): false;
665
        if (prefAreaSort != null) {
666
            if (prefAreaSort.isAllowOverride()){
667
                if(overrideOrderAreas) {
668
                    orderAreas = PreferencesUtil.getSortNamedAreasInDistributionEditor();
669
                }else{
670
                    orderAreas = null;
671
                }
672
            } else {
673
                if (prefAreaSort.getValue() != null) {
674
                    orderAreas = prefAreaSort.getValue() != null? TermOrder.valueOf(prefAreaSort.getValue().toString()): null;
675
                } else {
676
                    orderAreas = ((TermOrder) PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue());
677
                }
678

    
679
            }
680
        } else {
681
            if (overrideOrderAreas){
682
                orderAreas = PreferencesUtil.getSortNamedAreasInDistributionEditor();
683
            }else{
684
                orderAreas = null;
685
            }
686
            //prefAreaSort = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AreasSortedInDistributionEditor, PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue().toString(): null);
687
        }
688

    
689
        prefRank = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowRankInDistributionEditor);
690
        overrideRank = PreferencesUtil.getBooleanValue(
691
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowRankInDistributionEditor.getKey()), true) != null? PreferencesUtil.getBooleanValue(
692
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowRankInDistributionEditor.getKey()), true): false;
693
        if (prefRank != null) {
694
            if (prefRank.isAllowOverride()){
695
                if(overrideRank) {
696
                    isShowRank = PreferencesUtil.isShowRankInChecklistEditor();
697
                }
698

    
699
            } else {
700
                this.isShowRank = prefRank.getValue() != null? Boolean.valueOf(prefRank.getValue().toString()): null;
701
            }
702
        } else {
703
            if (overrideRank){
704
                isShowRank = PreferencesUtil.isShowRankInChecklistEditor();
705
            } else {
706
                isShowRank = null;
707
            }
708

    
709
            //refRank = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowRankInDistributionEditor, PreferencePredicate.ShowRankInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.ShowRankInDistributionEditor.getDefaultValue().toString(): null);
710
        }
711

    
712
        prefOwnDescription = PreferencesUtil
713
                .getPreferenceFromDB(PreferencePredicate.OwnDescriptionForDistributionEditor);
714
        if (prefOwnDescription != null) {
715
            if (prefOwnDescription.isAllowOverride()) {
716
                ownDescriptionForDistributionEditor = PreferencesUtil.isOwnDescriptionForChecklistEditor();
717
            } else {
718
                ownDescriptionForDistributionEditor = prefOwnDescription.getValue() != null? Boolean.valueOf(prefOwnDescription.getValue().toString()): null;
719
            }
720
        } else {
721
            ownDescriptionForDistributionEditor = PreferencesUtil.isShowRankInChecklistEditor();
722
            // allowOverrideOwnDescriptionForDistributionEditor = true;
723
            overrideOwnDescriptionForDistributionEditor = PreferencesUtil.getBooleanValue(
724
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey()), true) != null? PreferencesUtil.getBooleanValue(
725
                            PreferencesUtil.prefOverrideKey(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey()), true): false;
726
            //prefOwnDescription = CdmPreference.NewTaxEditorInstance(PreferencePredicate.OwnDescriptionForDistributionEditor, PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue().toString(): null);
727
        }
728

    
729

    
730
    }
731

    
732
    @Override
733
    protected void performDefaults() {
734

    
735
        setApply(true);
736
        isEditorActivated = null;
737
        activateCombo.select(0);
738

    
739

    
740
        displayArea = null;
741

    
742
        int index = 0;
743
        for (String itemLabel : areaDisplaySelectionCombo.getItems()) {
744
            if (itemLabel.startsWith(Messages.Preference_Use_Default)) {
745
                areaDisplaySelectionCombo.select(index);
746
                break;
747
            }
748
            index++;
749
        }
750

    
751
        displayStatus = null;
752

    
753

    
754

    
755
        index = 0;
756
        for (String itemLabel : statusDisplaySelectionCombo.getItems()) {
757
            if (itemLabel.startsWith(Messages.Preference_Use_Default)) {
758
                statusDisplaySelectionCombo.select(index);
759
                break;
760
            }
761
            index++;
762
        }
763

    
764
        orderAreas = null;
765

    
766

    
767
        index = 0;
768
        for (String itemLabel : areaOrderSelectionCombo.getItems()) {
769
            if (itemLabel.startsWith(Messages.Preference_Use_Default)) {
770
                areaOrderSelectionCombo.select(index);
771
                break;
772
            }
773
            index++;
774
        }
775

    
776

    
777
        isShowRank = null;
778

    
779
        index = 0;
780
        for (String itemLabel : activateRankCombo.getItems()) {
781
            if (itemLabel.startsWith(Messages.Preference_Use_Default)) {
782
                activateRankCombo.select(index);
783
                break;
784
            }
785
            index++;
786
        }
787

    
788
        displayStatusCombo = null;
789
        index = 0;
790
        for (String itemLabel : statusDisplayInComboSelectionCombo.getItems()) {
791
            if (itemLabel.startsWith(Messages.Preference_Use_Default)) {
792
                statusDisplayInComboSelectionCombo.select(index);
793
                break;
794
            }
795
            index++;
796
        }
797

    
798
        ownDescriptionForDistributionEditor = null;
799

    
800
        if (isAdminPreference){
801
            allowOverrideActivatedButton.setSelection(true);
802
            allowOverrideAreaDisplayButton.setSelection(true);
803
            allowOverrideStatusDisplayButton.setSelection(true);
804
            allowOverrideOrderAreasButton.setSelection(true);
805
            allowOverrideRankButton.setSelection(true);
806
        }
807
        overrideActivated = true;
808
        overrideAreaDisplay = true;
809
        overrideStatusDisplay = true;
810
        overrideOrderAreas = true;
811
        overrideRank = true;
812
        overrideOwnDescriptionForDistributionEditor = true;
813

    
814

    
815
        if (!isAdminPreference) {
816
            PreferencesUtil.recursiveSetEnabled(child, Boolean.parseBoolean(distributionEditorPref.getValue()));
817
//            if (!prefRank.isAllowOverride()) {
818
//                activateRankCombo.setEnabled(false);
819
//
820
//                if (!prefAreaSort.isAllowOverride()) {
821
//                    areaOrderSelectionCombo.setEnabled(false);
822
//                }
823
//                if (!prefAreaDisplay.isAllowOverride()) {
824
//                    allowOverrideAreaDisplayButton.setEnabled(false);
825
//                }
826
//                if (!prefStatusDisplay.isAllowOverride()) {
827
//                    allowOverrideStatusDisplayButton.setEnabled(false);
828
//                }
829
//            }
830
            super.performDefaults();
831
        }
832
    }
833

    
834
}
(7-7/56)