Project

General

Profile

Download (41.2 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2014 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9
package eu.etaxonomy.taxeditor.preference;
10

    
11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.custom.CLabel;
13
import org.eclipse.swt.events.ModifyEvent;
14
import org.eclipse.swt.events.ModifyListener;
15
import org.eclipse.swt.events.SelectionAdapter;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.events.SelectionListener;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.layout.GridLayout;
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.widgets.Combo;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.swt.widgets.Text;
26

    
27
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
28
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
29
import eu.etaxonomy.cdm.model.metadata.TermComboEnum;
30
import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
31
import eu.etaxonomy.cdm.model.metadata.TermOrder;
32
import eu.etaxonomy.taxeditor.l10n.Messages;
33
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
34

    
35
/**
36
 * @author a.oppermann
37
 * @date 21.07.2014
38
 *
39
 */
40
public class ChecklistEditorGeneralPreference extends CdmPreferencePage implements SelectionListener {
41

    
42

    
43

    
44
    protected Boolean isEditorActivated;
45

    
46
    protected boolean overrideActivated;
47
    boolean isUseLocal;
48
    protected Boolean isShowRank;
49
    protected TermOrder orderAreas;
50
    protected TermDisplayEnum displayStatus;
51
    protected TermComboEnum displayStatusCombo;
52
    protected TermDisplayEnum displayArea;
53
    protected Boolean ownDescriptionForDistributionEditor;
54
    protected Integer numberOfStatus;
55

    
56
    protected boolean overrideOwnDescriptionForDistributionEditor;
57
    protected boolean overrideAreaVoc;
58
    protected boolean overrideRank;
59
    protected boolean overrideOrderAreas;
60
    protected boolean overrideAreaDisplay;
61
    protected boolean overrideStatusDisplay;
62
    protected boolean overrideStatusDisplayCombo;
63
    protected boolean overrideNumberOfStatus;
64

    
65
    protected Combo areaOrderSelectionCombo;
66
    protected Button allowOverrideOrderAreasButton;
67
    protected Combo statusDisplaySelectionCombo;
68
    protected Button allowOverrideStatusDisplayButton;
69
    protected Combo statusDisplayInComboSelectionCombo;
70
    protected Button allowOverrideStatusDisplayInComboButton;
71
    protected Combo areaDisplaySelectionCombo;
72
    protected Button allowOverrideAreaDisplayButton;
73

    
74

    
75
    protected Text numberOfStatusText;
76
    protected Button allowOverrideNumberOfStatusButton;
77
    protected Label numberFormatExceptionLabel;
78

    
79
    protected CdmPreference distributionEditorPref;
80

    
81
    protected CdmPreference prefStatusDisplay;
82
    protected CdmPreference prefAreaDisplay;
83

    
84
    protected CdmPreference prefStatusDisplayInCombo;
85
    protected CdmPreference prefAreaSort;
86
    protected CdmPreference prefRank;
87
    protected CdmPreference prefOwnDescription;
88
    protected CdmPreference prefNumberStatus;
89
    Composite child;
90

    
91
    protected Combo activateCombo;
92
    protected Button allowOverrideActivatedButton;
93
    final String ENABLE = "Enable";
94
    final String DISABLE = "Disable";
95

    
96
    protected Combo activateRankCombo;
97
    protected Button allowOverrideRankButton;
98
    final String SHOW_RANK = "Yes";
99
    final String NO_RANK = "No";
100

    
101

    
102

    
103

    
104
    @Override
105
    protected Control createContents(Composite parent) {
106
        getValues();
107
        Composite composite = new Composite(parent, SWT.NULL);
108
        composite.setLayout(new GridLayout());
109
        if (!isAdminPreference && distributionEditorPref != null && !distributionEditorPref.isAllowOverride() ) {
110
            Label label = new Label(composite, SWT.NONE);
111
            label.setText(
112
                    "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.");
113
            this.setDefaultButtonActivated(false);
114
        } else {
115
            Composite activateComp = createComposite(composite);
116
            Label separator = new Label(activateComp, SWT.HORIZONTAL | SWT.SEPARATOR);
117
            GridData sepGrid = createTextGridData();
118
            separator.setLayoutData(sepGrid);
119
            separator.setVisible(false);
120
            CdmPreference dbPref;
121
            GridData textGrid = createTextGridData();
122
            textGrid.verticalSpan = 2;
123
            separator.setLayoutData(sepGrid);
124

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

    
127
            int index = 0;
128
            for (String itemLabel : activateCombo.getItems()) {
129
                if (isEditorActivated == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
130
                    activateCombo.select(index);
131
                    break;
132
                }
133
                if (isEditorActivated != null && itemLabel.equals(ENABLE) && isEditorActivated){
134
                    activateCombo.select(index);
135
                    break;
136
                }
137
                if (isEditorActivated != null && itemLabel.equals(DISABLE) && !isEditorActivated){
138
                    activateCombo.select(index);
139
                    break;
140
                }
141
                index++;
142
            }
143

    
144

    
145
            activateCombo.addSelectionListener(this);
146
            if (isAdminPreference) {
147
                allowOverrideActivatedButton = createAllowOverrideButton(activateComp);
148
                allowOverrideActivatedButton.setSelection(this.distributionEditorPref != null? this.distributionEditorPref.isAllowOverride(): true);
149
                allowOverrideActivatedButton.addSelectionListener(new SelectionAdapter() {
150
                    @Override
151
                    public void widgetSelected(SelectionEvent e) {
152
                        setApply(true);
153
                        if (distributionEditorPref == null){
154
                            distributionEditorPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DistributionEditorActivated, PreferencePredicate.DistributionEditorActivated.getDefaultValue() != null ?  PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString(): null);
155
                        }
156
                        distributionEditorPref.setAllowOverride(!distributionEditorPref.isAllowOverride());
157
                    }
158
                });
159
            }
160
            child = createComposite(composite);
161

    
162
            if (!isAdminPreference) {
163
                if (isEditorActivated != null){
164
                    child.setEnabled(isEditorActivated);
165
                }else{
166
                    child.setEnabled(distributionEditorPref.getValue() != null?Boolean.parseBoolean(distributionEditorPref.getValue().toString()): true);
167
                }
168
            }
169
            separator = new Label(child, SWT.HORIZONTAL | SWT.SEPARATOR);
170
            sepGrid = createTextGridData();
171
            separator.setLayoutData(sepGrid);
172

    
173
            activateRankCombo = createBooleanCombo(child, SHOW_RANK, NO_RANK,
174
                    PreferencePredicate.ShowRankInDistributionEditor, Messages.ChecklistEditorGeneralPreference_show_rank, isAdminPreference);
175
            index = 0;
176
            for (String itemLabel : activateRankCombo.getItems()) {
177
                if (isShowRank == null && itemLabel.startsWith(Messages.Preference_Use_Default)) {
178
                    activateRankCombo.select(index);
179
                    break;
180
                }
181
                if (isShowRank != null && itemLabel.equals(SHOW_RANK) && isShowRank){
182
                    activateRankCombo.select(index);
183
                    break;
184
                }
185
                if (isShowRank != null && itemLabel.equals(NO_RANK) && !isShowRank){
186
                    activateRankCombo.select(index);
187
                    break;
188
                }
189
                index++;
190
            }
191
            activateRankCombo.addSelectionListener(this);
192
            if (isAdminPreference) {
193
                allowOverrideRankButton = createAllowOverrideButton(child);
194
                allowOverrideRankButton.setSelection(prefRank != null? prefRank.isAllowOverride():true);
195
                allowOverrideRankButton.addSelectionListener(new SelectionAdapter() {
196
                    @Override
197
                    public void widgetSelected(SelectionEvent e) {
198
                        setApply(true);
199
                        if (prefRank == null){
200
                            prefRank = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowRankInDistributionEditor, PreferencePredicate.ShowRankInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.ShowRankInDistributionEditor.getDefaultValue().toString(): null);
201
                        }
202
                        prefRank.setAllowOverride(allowOverrideRankButton.getSelection());
203
                    }
204
                });
205
            }
206
            separator = new Label(child, SWT.HORIZONTAL | SWT.SEPARATOR);
207
            sepGrid = createTextGridData();
208
            separator.setLayoutData(sepGrid);
209

    
210
            areaOrderSelectionCombo = createCombo(child, TermOrder.values(), PreferencePredicate.AreasSortedInDistributionEditor, Messages.ChecklistEditorGeneralPreference_Configure_area_order, isAdminPreference);
211

    
212
            index = 0;
213

    
214
            for (String itemLabel : areaOrderSelectionCombo.getItems()) {
215
                if (itemLabel.startsWith(Messages.Preference_Use_Default) && orderAreas == null){
216
                    areaOrderSelectionCombo.select(index);
217
                    break;
218
                }
219
                if (itemLabel.equals(orderAreas.getLabel())) {
220
                    areaOrderSelectionCombo.select(index);
221
                    break;
222
                }
223

    
224
                index++;
225
            }
226

    
227
            areaOrderSelectionCombo.addSelectionListener(this);
228

    
229
            if (isAdminPreference) {
230
                allowOverrideOrderAreasButton = createAllowOverrideButton(child);
231
                allowOverrideOrderAreasButton.setSelection(prefAreaSort != null? prefAreaSort.isAllowOverride(): true);
232
                allowOverrideOrderAreasButton.addSelectionListener(new SelectionAdapter() {
233
                    @Override
234
                    public void widgetSelected(SelectionEvent e) {
235
                        setApply(true);
236
                        if (prefAreaSort == null){
237
                            prefAreaSort = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AreasSortedInDistributionEditor, PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue().toString(): null);
238
                        }
239
                        prefAreaSort.setAllowOverride(allowOverrideOrderAreasButton.getSelection());
240
                    }
241
                });
242
            }
243

    
244
//
245
            areaDisplaySelectionCombo = createCombo(child, TermDisplayEnum.values(), PreferencePredicate.DisplayOfAreasInDistributionEditor, Messages.ChecklistEditorGeneralPreference_Configure_display_of_Areas, isAdminPreference);
246

    
247

    
248
            index = 0;
249

    
250
            for (String itemLabel : areaDisplaySelectionCombo.getItems()) {
251
                if (itemLabel.startsWith(Messages.Preference_Use_Default) && displayArea == null){
252
                    areaDisplaySelectionCombo.select(index);
253
                    break;
254
                }else if (itemLabel.equals(displayArea.getLabel())) {
255
                    areaDisplaySelectionCombo.select(index);
256
                    break;
257
                }
258

    
259
                index++;
260
            }
261
            areaDisplaySelectionCombo.addSelectionListener(this);
262

    
263
            if (isAdminPreference) {
264
                allowOverrideAreaDisplayButton = createAllowOverrideButton(child);
265
                allowOverrideAreaDisplayButton.setSelection(prefAreaDisplay != null? prefAreaDisplay.isAllowOverride(): true);
266
                allowOverrideAreaDisplayButton.addSelectionListener(new SelectionAdapter() {
267
                    @Override
268
                    public void widgetSelected(SelectionEvent e) {
269
                        setApply(true);
270
                        if (prefAreaDisplay == null){
271
                            prefAreaDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfAreasInDistributionEditor, PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString(): null);
272
                        }
273
                        prefAreaDisplay.setAllowOverride(allowOverrideOrderAreasButton.getSelection());
274
                    }
275
                });
276
            }
277

    
278
            separator = new Label(child, SWT.HORIZONTAL | SWT.SEPARATOR);
279
            separator.setLayoutData(sepGrid);
280

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

    
283
            index = 0;
284

    
285
            for (String itemLabel : statusDisplaySelectionCombo.getItems()) {
286
                if (itemLabel.startsWith(Messages.Preference_Use_Default) && displayStatus == null){
287
                    statusDisplaySelectionCombo.select(index);
288
                    break;
289
                }
290
                if (itemLabel.equals(displayStatus.getLabel())) {
291
                    statusDisplaySelectionCombo.select(index);
292
                    break;
293
                }
294

    
295
                index++;
296
            }
297

    
298
            statusDisplaySelectionCombo.addSelectionListener(this);
299

    
300
            if (isAdminPreference) {
301
                allowOverrideStatusDisplayButton = createAllowOverrideButton(child);
302
                allowOverrideStatusDisplayButton.setSelection(prefStatusDisplay != null ? prefStatusDisplay.isAllowOverride(): true);
303
                allowOverrideStatusDisplayButton.addSelectionListener(new SelectionAdapter() {
304
                    @Override
305
                    public void widgetSelected(SelectionEvent e) {
306
                        setApply(true);
307
                        if (prefStatusDisplay == null){
308
                            prefStatusDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfStatus, PreferencePredicate.DisplayOfStatus.getDefaultValue() != null ?  PreferencePredicate.DisplayOfStatus.getDefaultValue().toString(): null);
309
                        }
310
                        prefStatusDisplay.setAllowOverride(allowOverrideStatusDisplayButton.getSelection());
311
                    }
312
                });
313
            }
314

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

    
317
            index = 0;
318

    
319
            for (String itemLabel : statusDisplayInComboSelectionCombo.getItems()) {
320
                if (itemLabel.startsWith(Messages.Preference_Use_Default) && displayStatusCombo == null){
321
                    statusDisplayInComboSelectionCombo.select(index);
322
                    break;
323
                }
324
                if (itemLabel.equals(displayStatusCombo.getLabel())) {
325
                    statusDisplayInComboSelectionCombo.select(index);
326
                    break;
327
                }
328

    
329
                index++;
330
            }
331

    
332
            statusDisplayInComboSelectionCombo.addSelectionListener(this);
333

    
334
            if (isAdminPreference) {
335
                allowOverrideStatusDisplayInComboButton = createAllowOverrideButton(child);
336
                allowOverrideStatusDisplayInComboButton.setSelection(prefStatusDisplayInCombo != null ? prefStatusDisplayInCombo.isAllowOverride(): true);
337
                //allowOverrideStatusDisplayInComboButton.setEnabled(prefStatusDisplayInCombo != null);
338
                allowOverrideStatusDisplayInComboButton.addSelectionListener(new SelectionAdapter() {
339
                    @Override
340
                    public void widgetSelected(SelectionEvent e) {
341
                        setApply(true);
342
                        if (prefStatusDisplayInCombo == null){
343
                            prefStatusDisplayInCombo = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfStatusInCombo, PreferencePredicate.DisplayOfStatusInCombo.getDefaultValue() != null ?  PreferencePredicate.DisplayOfStatusInCombo.getDefaultValue().toString(): null);
344
                        }
345
                        prefStatusDisplayInCombo.setAllowOverride(allowOverrideStatusDisplayInComboButton.getSelection());
346
                    }
347
                });
348
            }
349

    
350
            final CLabel description = new CLabel(child, SWT.NULL);
351
            description.setText("Number of status shown in drop down");
352
            GridData numberOfStatusGrid= createTextGridData();
353
            numberOfStatusGrid.verticalSpan = 1;
354
            description.setLayoutData(numberOfStatusGrid);
355
            description.setToolTipText("Number of status shown in drop down without scrollbar");
356

    
357
            numberOfStatusText = new Text(child, SWT.BORDER);
358
            if (numberOfStatus != null){
359
                numberOfStatusText.setText(this.numberOfStatus.toString());
360
            }else{
361
                numberOfStatusText.setText(PreferencePredicate.NumberOfVisibleStatusInDropDown.getDefaultValue().toString());
362
            }
363
            numberOfStatusText.addModifyListener(new ModifyListener() {
364

    
365
                @Override
366
                public void modifyText(ModifyEvent e) {
367
                   setApply(true);
368
                   String text = numberOfStatusText.getText();
369
                   try{
370
                       numberOfStatus = Integer.valueOf(text);
371
                       numberFormatExceptionLabel.setVisible(false);
372
                   }catch(NumberFormatException ex){
373
                       numberFormatExceptionLabel.setVisible(true);
374
                       numberFormatExceptionLabel.setText("The value needs to be a number.");
375
                   }
376

    
377
                }
378
            });
379
            numberFormatExceptionLabel = new Label(child, SWT.NULL);
380
//            numberFormatExceptionLabel.setForeground(Color.RED);
381
            numberFormatExceptionLabel.setVisible(false);
382

    
383
            if (!isAdminPreference) {
384

    
385

    
386
                if (distributionEditorPref != null && !distributionEditorPref.isAllowOverride()){
387
                    activateComp.setEnabled(false);
388
                }
389

    
390

    
391
                if (prefRank != null && !prefRank.isAllowOverride()) {
392
                    activateRankCombo.setEnabled(false);
393
                }
394
                if (prefAreaSort != null && !prefAreaSort.isAllowOverride()) {
395
                    areaOrderSelectionCombo.setEnabled(false);
396
                }
397
                if (prefAreaDisplay != null && !prefAreaDisplay.isAllowOverride()) {
398
                    areaDisplaySelectionCombo.setEnabled(false);
399
                }
400
                if (prefStatusDisplay != null && !prefStatusDisplay.isAllowOverride()) {
401
                    statusDisplaySelectionCombo.setEnabled(false);
402
                }
403
                if (prefStatusDisplayInCombo != null && !prefStatusDisplayInCombo.isAllowOverride()) {
404
                    statusDisplayInComboSelectionCombo.setEnabled(false);
405
                }
406
            }
407

    
408
        }
409
        setValid(true);
410
        return composite;
411
    }
412

    
413
    @Override
414
    public boolean performOk() {
415
        if (!isApply()){
416
            return true;
417
        }
418
            boolean override = false;
419
            if (isEditorActivated != null ) {
420
                override = true;
421
                PreferencesUtil.setStringValue(PreferencePredicate.DistributionEditorActivated.getKey(), isEditorActivated.toString());
422
            }
423
            PreferencesUtil.setBooleanValue(
424
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey()),
425
                    override);
426

    
427

    
428
            override = false;
429
            if (orderAreas != null ) {
430
                override = true;
431
                PreferencesUtil.setSortNamedAreasInDistributionEditor(orderAreas.getKey());
432
            }
433
            PreferencesUtil.setBooleanValue(
434
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.AreasSortedInDistributionEditor.getKey()),
435
                    override);
436

    
437
            override = false;
438
            if (isShowRank != null ) {
439
                override = true;
440
                PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
441
            }
442
            PreferencesUtil.setBooleanValue(
443
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowRankInDistributionEditor.getKey()),
444
                    override);
445

    
446

    
447
            override = false;
448
            if (displayStatus != null) {
449
               override = true;
450
               PreferencesUtil.setDisplayStatusInChecklistEditor(displayStatus.getKey());
451
            }
452
            PreferencesUtil.setBooleanValue(
453
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatus.getKey()),
454
                    override);
455

    
456
            override = false;
457
            if (displayStatusCombo != null) {
458
               override = true;
459
               PreferencesUtil.setStringValue(PreferencePredicate.DisplayOfStatusInCombo.getKey(), displayStatusCombo.getKey());
460
            }
461
            PreferencesUtil.setBooleanValue(
462
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatusInCombo.getKey()),
463
                    override);
464

    
465

    
466

    
467
            override = false;
468
            if (displayArea != null) {
469
                override = true;
470
                PreferencesUtil.setAreaDisplayInChecklistEditor(displayArea.getKey());
471
            }
472
            PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(
473
                    PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), override);
474

    
475

    
476
            PreferencesUtil.firePreferencesChanged(this.getClass());
477

    
478
            override = false;
479
            if (numberOfStatus != null) {
480
                override = true;
481
                PreferencesUtil.setIntValue(PreferencePredicate.NumberOfVisibleStatusInDropDown.getKey(), numberOfStatus);
482
            }
483
            PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(
484
                    PreferencePredicate.NumberOfVisibleStatusInDropDown.getKey()), override);
485

    
486

    
487
            PreferencesUtil.firePreferencesChanged(this.getClass());
488

    
489
        return true;
490
    }
491

    
492
    /**
493
     * {@inheritDoc}
494
     */
495
    @Override
496
    public void widgetSelected(SelectionEvent e) {
497
        setApply(true);
498
        if (e.getSource().equals(statusDisplaySelectionCombo)) {
499
            String text = statusDisplaySelectionCombo.getText();
500
            if(text.startsWith(Messages.Preference_Use_Default)){
501
                displayStatus = null;
502
                return;
503
            }
504

    
505
            for (TermDisplayEnum display : TermDisplayEnum.values()) {
506
                if (text.startsWith(display.getLabel())) {
507
                    displayStatus = display;
508
                    break;
509
                }
510

    
511
            }
512
        }
513
        if (e.getSource().equals(statusDisplayInComboSelectionCombo)) {
514
            String text = statusDisplayInComboSelectionCombo.getText();
515
            if(text.startsWith(Messages.Preference_Use_Default)){
516
                displayStatusCombo = null;
517
                return;
518
            }
519

    
520
            for (TermComboEnum display : TermComboEnum.values()) {
521
                if (text.startsWith(display.getLabel())) {
522
                    displayStatusCombo = display;
523
                    break;
524
                }
525

    
526
            }
527
        }
528
        if (e.getSource().equals(areaDisplaySelectionCombo)) {
529
            String text = areaDisplaySelectionCombo.getText();
530
            if(text.startsWith(Messages.Preference_Use_Default)){
531
                displayArea = null;
532
                return;
533
            }
534

    
535
            for (TermDisplayEnum display : TermDisplayEnum.values()) {
536
                if (text.startsWith(display.getLabel())) {
537
                    displayArea = display;
538
                    break;
539
                }
540
            }
541
        }
542
        if (e.getSource().equals(areaOrderSelectionCombo)) {
543
            String text = areaOrderSelectionCombo.getText();
544
            if(text.startsWith(Messages.Preference_Use_Default)){
545
                orderAreas = null;
546
                return;
547
            }
548

    
549
            for (TermOrder display : TermOrder.values()) {
550
                if (text.startsWith(display.getLabel())) {
551
                    orderAreas = display;
552
                    break;
553
                }
554
            }
555
        }
556
        if (e.getSource().equals(this.activateRankCombo)) {
557
            String text = activateRankCombo.getText();
558
            if(text.startsWith(Messages.Preference_Use_Default)){
559
                isShowRank = null;
560
                return;
561
            }
562

    
563
            if (text.equals(SHOW_RANK)){
564
                isShowRank = true;
565
            }else{
566
                isShowRank = false;
567
            }
568
        }
569

    
570

    
571
        if (e.getSource().equals(this.activateCombo)) {
572
            String text = activateCombo.getText();
573
            if(text.startsWith(Messages.Preference_Use_Default)){
574
                isEditorActivated = null;
575
                if (!isAdminPreference) {
576
                    if (isEditorActivated != null){
577
                        child.setEnabled(isEditorActivated);
578
                    }else{
579
                        child.setEnabled(distributionEditorPref.getValue() != null?Boolean.parseBoolean(distributionEditorPref.getValue().toString()): true);
580
                    }
581
                }
582
                return;
583
            }
584

    
585
            if (text.equals(ENABLE)){
586
                isEditorActivated = true;
587
            }else{
588
                isEditorActivated = false;
589
            }
590
            if (!isAdminPreference) {
591
                if (isEditorActivated != null){
592
                    child.setEnabled(isEditorActivated);
593
                }else{
594
                    child.setEnabled(distributionEditorPref.getValue() != null?Boolean.parseBoolean(distributionEditorPref.getValue().toString()): true);
595
                }
596
            }
597

    
598
        }
599

    
600
    }
601

    
602
    /**
603
     * {@inheritDoc}
604
     */
605
    @Override
606
    public void widgetDefaultSelected(SelectionEvent e) {
607
        // TODO Auto-generated method stub
608

    
609
    }
610

    
611
    /**
612
     * {@inheritDoc}
613
     */
614
    @Override
615
    public void getValues() {
616
        isAdminPreference = false;
617
        setPreferenceStore(PreferencesUtil.getPreferenceStore());
618
        distributionEditorPref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
619
        overrideActivated = PreferencesUtil.getBooleanValue(
620
                PreferencesUtil.prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey()), true) != null? PreferencesUtil.getBooleanValue(
621
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey()), true):false;
622

    
623
        if (distributionEditorPref != null) {
624
            if (distributionEditorPref.isAllowOverride() ) {
625
                if (overrideActivated){
626
                    isEditorActivated = PreferencesUtil.getBooleanValue(PreferencePredicate.DistributionEditorActivated.getKey(), true);
627
                }
628

    
629
            } else {
630
                isEditorActivated = distributionEditorPref.getValue() != null? Boolean.valueOf(distributionEditorPref.getValue()): null;
631
            }
632

    
633
        } else {
634
            if(!overrideActivated){
635
                isEditorActivated = null;
636
            }else{
637
                isEditorActivated = PreferencesUtil.getBooleanValue(PreferencePredicate.DistributionEditorActivated.getKey(), true);
638
            }
639
            distributionEditorPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DistributionEditorActivated, PreferencePredicate.DistributionEditorActivated.getDefaultValue() != null ?  PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString(): null);
640
        }
641

    
642

    
643

    
644

    
645
        prefAreaDisplay = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DisplayOfAreasInDistributionEditor);
646
        overrideAreaDisplay = PreferencesUtil.getBooleanValue(
647
                PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), true) != null? PreferencesUtil.getBooleanValue(
648
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), true): false;
649

    
650
        if (prefAreaDisplay != null) {
651
            if (prefAreaDisplay.isAllowOverride()){
652
                if (overrideActivated) {
653
                    displayArea = PreferencesUtil.displayAreaInChecklistEditor();
654
                }else{
655
                    displayArea = null;
656
                }
657
            } else {
658
                displayArea = prefAreaDisplay.getValue() != null? TermDisplayEnum.byKey(prefAreaDisplay.getValue()): null;
659
            }
660
        } else {
661
            if (overrideAreaDisplay){
662
                displayArea = PreferencesUtil.displayAreaInChecklistEditor();
663
            } else{
664
                displayArea = null;
665
            }
666
            //prefAreaDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfAreasInDistributionEditor, PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString(): null);
667
        }
668

    
669
        prefStatusDisplay = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DisplayOfStatus);
670
        overrideStatusDisplay = PreferencesUtil
671
                .getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatus.getKey()), true) != null? PreferencesUtil
672
                        .getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatus.getKey()), true): false;
673
        if (prefStatusDisplay != null) {
674
            if (prefStatusDisplay.isAllowOverride()){
675
                if (overrideStatusDisplay) {
676
                    displayStatus = PreferencesUtil.displayStatusInChecklistEditor();
677
                }else{
678
                    displayStatus = null;
679
                }
680
            } else {
681
                this.displayStatus = prefStatusDisplay.getValue() != null? TermDisplayEnum.byKey(prefStatusDisplay.getValue()): null;
682
            }
683
        } else {
684
            if (overrideStatusDisplay){
685
                displayStatus = PreferencesUtil.displayStatusInChecklistEditor();
686
            } else{
687
                displayStatus = null;
688
            }
689
            //prefStatusDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfStatus, PreferencePredicate.DisplayOfStatus.getDefaultValue() != null ?  PreferencePredicate.DisplayOfStatus.getDefaultValue().toString(): null);
690
        }
691

    
692
        prefStatusDisplayInCombo = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DisplayOfStatusInCombo);
693
        overrideStatusDisplayCombo = PreferencesUtil
694
                .getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatusInCombo.getKey()), true) != null? PreferencesUtil
695
                        .getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatusInCombo.getKey()), true): false;
696
        if (prefStatusDisplayInCombo != null) {
697
            if (prefStatusDisplayInCombo.isAllowOverride()){
698
                if (overrideStatusDisplayCombo) {
699
                    displayStatusCombo = TermComboEnum.byKey(PreferencesUtil.getStringValue(PreferencePredicate.DisplayOfStatusInCombo.getKey()));
700
                }else{
701
                    displayStatusCombo = null;
702
                }
703
            } else {
704
                this.displayStatusCombo = prefStatusDisplayInCombo.getValue() != null? TermComboEnum.byKey(prefStatusDisplayInCombo.getValue()): null;
705
            }
706
        } else {
707
            if (overrideStatusDisplayCombo){
708
                displayStatusCombo = TermComboEnum.byKey(PreferencesUtil.getStringValue(PreferencePredicate.DisplayOfStatusInCombo.getKey()));
709
            } else{
710
                displayStatusCombo = null;
711
            }
712

    
713
        }
714

    
715

    
716
        prefAreaSort = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AreasSortedInDistributionEditor);
717
        overrideOrderAreas = PreferencesUtil.getBooleanValue(
718
                PreferencesUtil.prefOverrideKey(PreferencePredicate.AreasSortedInDistributionEditor.getKey()), true) != null? PreferencesUtil.getBooleanValue(
719
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.AreasSortedInDistributionEditor.getKey()), true): false;
720
        if (prefAreaSort != null) {
721
            if (prefAreaSort.isAllowOverride()){
722
                if(overrideOrderAreas) {
723
                    orderAreas = PreferencesUtil.getSortNamedAreasInDistributionEditor();
724
                }else{
725
                    orderAreas = null;
726
                }
727
            } else {
728
                if (prefAreaSort.getValue() != null) {
729
                    orderAreas = prefAreaSort.getValue() != null? TermOrder.valueOf(prefAreaSort.getValue().toString()): null;
730
                } else {
731
                    orderAreas = ((TermOrder) PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue());
732
                }
733

    
734
            }
735
        } else {
736
            if (overrideOrderAreas){
737
                orderAreas = PreferencesUtil.getSortNamedAreasInDistributionEditor();
738
            }else{
739
                orderAreas = null;
740
            }
741
            //prefAreaSort = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AreasSortedInDistributionEditor, PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue().toString(): null);
742
        }
743

    
744
        prefRank = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowRankInDistributionEditor);
745
        overrideRank = PreferencesUtil.getBooleanValue(
746
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowRankInDistributionEditor.getKey()), true) != null? PreferencesUtil.getBooleanValue(
747
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowRankInDistributionEditor.getKey()), true): false;
748
        if (prefRank != null) {
749
            if (prefRank.isAllowOverride()){
750
                if(overrideRank) {
751
                    isShowRank = PreferencesUtil.isShowRankInChecklistEditor();
752
                }
753

    
754
            } else {
755
                this.isShowRank = prefRank.getValue() != null? Boolean.valueOf(prefRank.getValue().toString()): null;
756
            }
757
        } else {
758
            if (overrideRank){
759
                isShowRank = PreferencesUtil.isShowRankInChecklistEditor();
760
            } else {
761
                isShowRank = null;
762
            }
763

    
764
        }
765

    
766
        prefNumberStatus= PreferencesUtil.getPreferenceFromDB(PreferencePredicate.NumberOfVisibleStatusInDropDown);
767
        overrideNumberOfStatus = PreferencesUtil.getBooleanValue(
768
                PreferencesUtil.prefOverrideKey(PreferencePredicate.NumberOfVisibleStatusInDropDown.getKey()), true) != null? PreferencesUtil.getBooleanValue(
769
                        PreferencesUtil.prefOverrideKey(PreferencePredicate.NumberOfVisibleStatusInDropDown.getKey()), true): false;
770
        if (prefNumberStatus != null) {
771
            if (prefNumberStatus.isAllowOverride()){
772
                if(overrideNumberOfStatus) {
773
                    numberOfStatus = PreferencesUtil.getIntValue(PreferencePredicate.NumberOfVisibleStatusInDropDown.getKey(), true);
774
                }
775

    
776
            } else {
777
                this.numberOfStatus = prefNumberStatus.getValue() != null? Integer.valueOf(prefNumberStatus.getValue().toString()): null;
778
            }
779
        } else {
780
            if (overrideNumberOfStatus){
781
                numberOfStatus = PreferencesUtil.getIntValue(PreferencePredicate.NumberOfVisibleStatusInDropDown.getKey(), true);
782
            } else {
783
                numberOfStatus = null;
784
            }
785

    
786
        }
787

    
788
        prefOwnDescription = PreferencesUtil
789
                .getPreferenceFromDB(PreferencePredicate.OwnDescriptionForDistributionEditor);
790
        if (prefOwnDescription != null) {
791
            if (prefOwnDescription.isAllowOverride()) {
792
                ownDescriptionForDistributionEditor = PreferencesUtil.isOwnDescriptionForChecklistEditor();
793
            } else {
794
                ownDescriptionForDistributionEditor = prefOwnDescription.getValue() != null? Boolean.valueOf(prefOwnDescription.getValue().toString()): null;
795
            }
796
        } else {
797
            ownDescriptionForDistributionEditor = PreferencesUtil.isShowRankInChecklistEditor();
798
            // allowOverrideOwnDescriptionForDistributionEditor = true;
799
            overrideOwnDescriptionForDistributionEditor = PreferencesUtil.getBooleanValue(
800
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey()), true) != null? PreferencesUtil.getBooleanValue(
801
                            PreferencesUtil.prefOverrideKey(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey()), true): false;
802
            //prefOwnDescription = CdmPreference.NewTaxEditorInstance(PreferencePredicate.OwnDescriptionForDistributionEditor, PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue().toString(): null);
803
        }
804

    
805

    
806
    }
807

    
808
    @Override
809
    protected void performDefaults() {
810

    
811
        setApply(true);
812
        isEditorActivated = null;
813
        activateCombo.select(0);
814

    
815

    
816
        displayArea = null;
817

    
818
        int index = 0;
819
        for (String itemLabel : areaDisplaySelectionCombo.getItems()) {
820
            if (itemLabel.startsWith(Messages.Preference_Use_Default)) {
821
                areaDisplaySelectionCombo.select(index);
822
                break;
823
            }
824
            index++;
825
        }
826

    
827
        displayStatus = null;
828

    
829

    
830

    
831
        index = 0;
832
        for (String itemLabel : statusDisplaySelectionCombo.getItems()) {
833
            if (itemLabel.startsWith(Messages.Preference_Use_Default)) {
834
                statusDisplaySelectionCombo.select(index);
835
                break;
836
            }
837
            index++;
838
        }
839

    
840
        orderAreas = null;
841

    
842

    
843
        index = 0;
844
        for (String itemLabel : areaOrderSelectionCombo.getItems()) {
845
            if (itemLabel.startsWith(Messages.Preference_Use_Default)) {
846
                areaOrderSelectionCombo.select(index);
847
                break;
848
            }
849
            index++;
850
        }
851

    
852

    
853
        isShowRank = null;
854

    
855
        index = 0;
856
        for (String itemLabel : activateRankCombo.getItems()) {
857
            if (itemLabel.startsWith(Messages.Preference_Use_Default)) {
858
                activateRankCombo.select(index);
859
                break;
860
            }
861
            index++;
862
        }
863

    
864
        displayStatusCombo = null;
865
        index = 0;
866
        for (String itemLabel : statusDisplayInComboSelectionCombo.getItems()) {
867
            if (itemLabel.startsWith(Messages.Preference_Use_Default)) {
868
                statusDisplayInComboSelectionCombo.select(index);
869
                break;
870
            }
871
            index++;
872
        }
873

    
874
        ownDescriptionForDistributionEditor = null;
875

    
876
        numberOfStatusText.setText(PreferencePredicate.NumberOfVisibleStatusInDropDown.getDefaultValue().toString());
877
        numberOfStatus = null;
878

    
879
        if (isAdminPreference){
880
            allowOverrideActivatedButton.setSelection(true);
881
            allowOverrideAreaDisplayButton.setSelection(true);
882
            allowOverrideStatusDisplayButton.setSelection(true);
883
            allowOverrideOrderAreasButton.setSelection(true);
884
            allowOverrideRankButton.setSelection(true);
885
            allowOverrideNumberOfStatusButton.setSelection(true);
886
        }
887
        overrideActivated = true;
888
        overrideAreaDisplay = true;
889
        overrideStatusDisplay = true;
890
        overrideOrderAreas = true;
891
        overrideRank = true;
892
        overrideOwnDescriptionForDistributionEditor = true;
893
        overrideNumberOfStatus = true;
894

    
895
        if (!isAdminPreference) {
896
            PreferencesUtil.recursiveSetEnabled(child, Boolean.parseBoolean(distributionEditorPref.getValue()));
897
//            if (!prefRank.isAllowOverride()) {
898
//                activateRankCombo.setEnabled(false);
899
//
900
//                if (!prefAreaSort.isAllowOverride()) {
901
//                    areaOrderSelectionCombo.setEnabled(false);
902
//                }
903
//                if (!prefAreaDisplay.isAllowOverride()) {
904
//                    allowOverrideAreaDisplayButton.setEnabled(false);
905
//                }
906
//                if (!prefStatusDisplay.isAllowOverride()) {
907
//                    allowOverrideStatusDisplayButton.setEnabled(false);
908
//                }
909
//            }
910
            super.performDefaults();
911
        }
912
    }
913

    
914
}
(7-7/56)