Project

General

Profile

« Previous | Next » 

Revision 11847891

Added by Katja Luther almost 5 years ago

ref #8047: configurable display of status in drop down

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java
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.SelectionAdapter;
14
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.events.SelectionListener;
16
import org.eclipse.swt.layout.GridData;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.widgets.Button;
19
import org.eclipse.swt.widgets.Combo;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Event;
23
import org.eclipse.swt.widgets.Label;
24
import org.eclipse.swt.widgets.Listener;
25

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

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

  
41

  
42

  
43
    protected Boolean isEditorActivated;
44

  
45
    protected boolean overrideActivated;
46
    boolean isUseLocal;
47
    protected Boolean isShowRank;
48
    protected String orderAreas;
49
    protected String displayStatus;
50
    protected String displayArea;
51
    protected Boolean ownDescriptionForDistributionEditor;
52

  
53
    protected boolean overrideOwnDescriptionForDistributionEditor;
54
    protected boolean overrideAreaVoc;
55
    protected boolean overrideRank;
56
    protected boolean overrideOrderAreas;
57
    protected boolean overrideAreaDisplay;
58
    protected boolean overrideStatusDisplay;
59

  
60
    protected Combo areaOrderSelectionCombo;
61
    protected Button allowOverrideOrderAreasButton;
62
    protected Combo statusDisplaySelectionCombo;
63
    protected Button allowOverrideStatusDisplayButton;
64
    protected Combo areaDisplaySelectionCombo;
65
    protected Button allowOverrideAreaDisplayButton;
66
    protected String commandHandlerString;
67
    protected String commandHandlerStringStatus;
68

  
69
    protected CdmPreference distributionEditorPref;
70
    protected CdmPreference prefStatus;
71
    protected CdmPreference prefAreaVoc;
72
    protected CdmPreference prefAreaDisplay;
73
    protected CdmPreference prefStatusDisplay;
74
    protected CdmPreference prefAreaSort;
75
    protected CdmPreference prefRank;
76
    protected CdmPreference prefOwnDescription;
77
    Composite child;
78

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

  
84
    protected Combo activateRankCombo;
85
    protected Button allowOverrideRankButton;
86
    final String SHOW_RANK = "Show Rank";
87
    final String NO_RANK = "No Rank";
88

  
89
    protected CdmPreference areaVocPref = null;
90
    protected CdmPreference statusPref = null;
91
    private CommandHandlerButton button_openSelectAreaVocabularies;
92

  
93
    private CommandHandlerButton button_openStatusWizard;
94

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

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

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

  
135

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

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

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

  
195
            GridData gridData = new GridData();
196
            gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
197

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

  
200
            index = 0;
201
            TermOrder areaOrder;
202
            try {
203
                if (orderAreas != null) {
204
                    areaOrder = TermOrder.valueOf(orderAreas);
205
                } else {
206
                    areaOrder = TermOrder.IdInVoc;
207
                }
208
            } catch (IllegalArgumentException e) {
209
                areaOrder = TermOrder.IdInVoc;
210
            }
211
            for (String itemLabel : areaOrderSelectionCombo.getItems()) {
212
                if (itemLabel.equals(Messages.Preference_Use_Default) && orderAreas.equals(Messages.Preference_Use_Default)){
213
                    areaOrderSelectionCombo.select(index);
214
                    break;
215
                }
216
                if (itemLabel.startsWith(areaOrder.getLabel())) {
217
                    areaOrderSelectionCombo.select(index);
218
                    break;
219
                }
220

  
221
                index++;
222
            }
223

  
224
            areaOrderSelectionCombo.addSelectionListener(this);
225

  
226
            if (isAdminPreference) {
227
                allowOverrideOrderAreasButton = createAllowOverrideButton(child);
228
                allowOverrideOrderAreasButton.setSelection(prefAreaSort != null? prefAreaSort.isAllowOverride(): true);
229
                allowOverrideOrderAreasButton.addSelectionListener(new SelectionAdapter() {
230
                    @Override
231
                    public void widgetSelected(SelectionEvent e) {
232
                        setApply(true);
233
                        prefAreaSort.setAllowOverride(allowOverrideOrderAreasButton.getSelection());
234
                    }
235
                });
236
            }
237

  
238
            separator = new Label(child, SWT.HORIZONTAL | SWT.SEPARATOR);
239
            separator.setLayoutData(sepGrid);
240
            areaDisplaySelectionCombo = createCombo(child, TermDisplayEnum.values(), PreferencePredicate.DisplayOfAreasInDistributionEditor, Messages.ChecklistEditorGeneralPreference_Configure_display_of_Areas, isAdminPreference);
241

  
242

  
243
            index = 0;
244
            TermDisplayEnum areaDisplay;
245
            try {
246
                if (displayArea != null) {
247
                    areaDisplay = TermDisplayEnum.valueOf(displayArea);
248
                } else {
249
                    areaDisplay = TermDisplayEnum.Title;
250
                }
251
            } catch (IllegalArgumentException e) {
252
                areaDisplay = TermDisplayEnum.Title;
253
            }
254
            for (String itemLabel : areaDisplaySelectionCombo.getItems()) {
255
                if (itemLabel.equals(Messages.Preference_Use_Default) && displayArea.equals(Messages.Preference_Use_Default)){
256
                    areaDisplaySelectionCombo.select(index);
257
                    break;
258
                }
259
                if (itemLabel.startsWith(areaDisplay.getLabel())) {
260
                    areaDisplaySelectionCombo.select(index);
261
                    break;
262
                }
263

  
264
                index++;
265
            }
266
            areaDisplaySelectionCombo.addSelectionListener(this);
267

  
268
            if (isAdminPreference) {
269
                allowOverrideAreaDisplayButton = createAllowOverrideButton(child);
270
                allowOverrideAreaDisplayButton.setSelection(prefAreaDisplay != null? prefAreaDisplay.isAllowOverride(): true);
271
                allowOverrideAreaDisplayButton.addSelectionListener(new SelectionAdapter() {
272
                    @Override
273
                    public void widgetSelected(SelectionEvent e) {
274
                        setApply(true);
275
                        prefAreaDisplay.setAllowOverride(allowOverrideOrderAreasButton.getSelection());
276
                    }
277
                });
278
            }
279

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

  
282
            index = 0;
283
            TermDisplayEnum statusDisplay;
284
            try {
285
                if (displayStatus != null) {
286
                    statusDisplay = TermDisplayEnum.valueOf(displayStatus);
287
                } else {
288
                    statusDisplay = TermDisplayEnum.Title;
289
                }
290
            } catch (IllegalArgumentException e) {
291
                statusDisplay = TermDisplayEnum.Title;
292
            }
293
            for (String itemLabel : statusDisplaySelectionCombo.getItems()) {
294
                if (itemLabel.equals(Messages.Preference_Use_Default) && displayStatus.equals(Messages.Preference_Use_Default)){
295
                    statusDisplaySelectionCombo.select(index);
296
                    break;
297
                }
298
                if (itemLabel.startsWith(statusDisplay.getLabel())) {
299
                    statusDisplaySelectionCombo.select(index);
300
                    break;
301
                }
302

  
303
                index++;
304
            }
305

  
306
            statusDisplaySelectionCombo.addSelectionListener(this);
307

  
308
            if (isAdminPreference) {
309
                allowOverrideStatusDisplayButton = createAllowOverrideButton(child);
310
                allowOverrideStatusDisplayButton.setSelection(prefStatusDisplay != null ? prefStatusDisplay.isAllowOverride(): true);
311
                allowOverrideStatusDisplayButton.addSelectionListener(new SelectionAdapter() {
312
                    @Override
313
                    public void widgetSelected(SelectionEvent e) {
314
                        setApply(true);
315
                        prefStatusDisplay.setAllowOverride(allowOverrideStatusDisplayButton.getSelection());
316
                    }
317
                });
318
            }
319

  
320
            final CLabel labelStatus = new CLabel(child, SWT.NULL);
321
            labelStatus.setText(Messages.DistributionAdminPreferences_SELECT_STATUS);
322
            labelStatus.setLayoutData(textGrid);
323

  
324
            button_openStatusWizard = new CommandHandlerButton(child, SWT.PUSH, commandHandlerStringStatus);
325

  
326
            button_openStatusWizard.setText(Messages.Distribution_status_selection);
327
            button_openStatusWizard.addListener(SWT.Selection, new Listener() {
328
                @Override
329
                public void handleEvent(Event e) {
330
                    switch (e.type) {
331
                    case SWT.Selection:
332
                        setApply(true);
333
                        break;
334
                    }
335
                }
336
            });
337

  
338
            final CLabel label = new CLabel(child, SWT.NULL);
339
            label.setText(Messages.ChecklistEditorGeneralPreference_open_wizard);
340
            label.setLayoutData(textGrid);
341

  
342
            button_openSelectAreaVocabularies = new CommandHandlerButton(child, SWT.PUSH, commandHandlerString);
343
            button_openSelectAreaVocabularies
344
                    .setText(Messages.ChecklistEditorGeneralPreference_open_distribution_selection);
345

  
346
            if (!isAdminPreference) {
347

  
348
                //PreferencesUtil.recursiveSetEnabled(child, isEditorActivated);
349
                if (distributionEditorPref != null && !distributionEditorPref.isAllowOverride()){
350
                    activateComp.setEnabled(false);
351
                }
352

  
353
                if (prefAreaVoc != null && !prefAreaVoc.isAllowOverride()) {
354
                    button_openSelectAreaVocabularies.setButtonEnabled(false);
355
                }
356
                if (prefStatus != null && !prefStatus.isAllowOverride()) {
357
                    button_openStatusWizard.setButtonEnabled(false);
358
                }
359
                if (prefRank != null && !prefRank.isAllowOverride()) {
360
                    activateRankCombo.setEnabled(false);
361
                }
362
                if (prefAreaSort != null && !prefAreaSort.isAllowOverride()) {
363
                    areaOrderSelectionCombo.setEnabled(false);
364
                    //allowOverrideOrderAreasButton.setEnabled(false);
365
                }
366
                if (prefAreaDisplay != null && !prefAreaDisplay.isAllowOverride()) {
367
                    areaDisplaySelectionCombo.setEnabled(false);
368
                }
369
                if (prefStatusDisplay != null && !prefStatusDisplay.isAllowOverride()) {
370
                    statusDisplaySelectionCombo.setEnabled(false);
371
                }
372
            }
373

  
374
        }
375
        setValid(true);
376
        return composite;
377
    }
378

  
379
    @Override
380
    public boolean performOk() {
381
        if (!isApply()){
382
            return true;
383
        }
384
            boolean override = false;
385
            if (isEditorActivated != null ) {
386
                override = true;
387
                PreferencesUtil.setStringValue(PreferencePredicate.DistributionEditorActivated.getKey(), isEditorActivated.toString());
388
            }
389
            PreferencesUtil.setBooleanValue(
390
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey()),
391
                    override);
392

  
393

  
394
            override = false;
395
            if (!orderAreas.equals(Messages.Preference_Use_Default) ) {
396
                override = true;
397
                PreferencesUtil.setSortNamedAreasInDistributionEditor(orderAreas);
398
            }
399
            PreferencesUtil.setBooleanValue(
400
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.AreasSortedInDistributionEditor.getKey()),
401
                    override);
402

  
403

  
404

  
405

  
406

  
407
            override = false;
408
            if (isShowRank != null ) {
409
                override = true;
410
                PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
411
            }
412
            PreferencesUtil.setBooleanValue(
413
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowRankInDistributionEditor.getKey()),
414
                    override);
415

  
416

  
417
            override = false;
418
            if (!displayStatus.equals(Messages.Preference_Use_Default)) {
419
               override = true;
420
               PreferencesUtil.setDisplayStatusInChecklistEditor(displayStatus);
421
            }
422
            PreferencesUtil.setBooleanValue(
423
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatus.getKey()),
424
                    override);
425

  
426

  
427

  
428

  
429
            override = false;
430
            if (!displayArea.equals(Messages.Preference_Use_Default) ) {
431
                override = true;
432
                PreferencesUtil.setAreaDisplayInChecklistEditor(displayArea);
433
            }
434
            PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(
435
                    PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), override);
436

  
437

  
438

  
439

  
440
            PreferencesUtil.setOwnDescriptionForChecklistEditor(ownDescriptionForDistributionEditor);
441
            PreferencesUtil.setBooleanValue(
442
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey()),
443
                    true);
444

  
445
            PreferencesUtil.firePreferencesChanged(this.getClass());
446

  
447
        return true;
448
    }
449

  
450
    /**
451
     * {@inheritDoc}
452
     */
453
    @Override
454
    public void widgetSelected(SelectionEvent e) {
455
        setApply(true);
456
        if (e.getSource().equals(statusDisplaySelectionCombo)) {
457
            String text = statusDisplaySelectionCombo.getText();
458
            if(text.equals(Messages.Preference_Use_Default)){
459
                displayStatus = Messages.Preference_Use_Default;
460
                if(isAdminPreference){
461
                    prefStatusDisplay.setAllowOverride(true);
462
                    allowOverrideStatusDisplayButton.setSelection(true);
463
                }
464

  
465
                return;
466
            }
467
            for (TermDisplayEnum display : TermDisplayEnum.values()) {
468
                if (text.startsWith(display.getLabel())) {
469
                    displayStatus = display.getKey();
470
                    break;
471
                }
472

  
473
            }
474
        }
475
        if (e.getSource().equals(areaDisplaySelectionCombo)) {
476
            String text = areaDisplaySelectionCombo.getText();
477
            if(text.equals(Messages.Preference_Use_Default)){
478
                displayArea = Messages.Preference_Use_Default;
479
                if (isAdminPreference){
480
                    prefAreaDisplay.setAllowOverride(true);
481
                    allowOverrideAreaDisplayButton.setSelection(true);
482
                }
483
                return;
484
            }
485
            for (TermDisplayEnum display : TermDisplayEnum.values()) {
486
                if (text.startsWith(display.getLabel())) {
487
                    displayArea = display.getKey();
488
                    break;
489
                }
490
            }
491
        }
492
        if (e.getSource().equals(areaOrderSelectionCombo)) {
493
            String text = areaOrderSelectionCombo.getText();
494
            if(text.equals(Messages.Preference_Use_Default)){
495
                orderAreas = Messages.Preference_Use_Default;
496
                if (isAdminPreference){
497
                    prefAreaSort.setAllowOverride(true);
498
                    allowOverrideOrderAreasButton.setSelection(true);
499
                }
500
                return;
501
            }
502
            for (TermOrder display : TermOrder.values()) {
503
                if (text.startsWith(display.getLabel())) {
504
                    orderAreas = display.getKey();
505
                    break;
506
                }
507
            }
508
        }
509
        if (e.getSource().equals(this.activateRankCombo)) {
510
            String text = activateRankCombo.getText();
511
            if(text.equals(Messages.Preference_Use_Default)){
512
                isShowRank = null;
513
                if (isAdminPreference){
514
                    prefRank.setAllowOverride(true);
515
                    allowOverrideRankButton.setSelection(true);
516
                }
517
                return;
518
            }
519
            if (text.equals(SHOW_RANK)){
520
                isShowRank = true;
521
            }else{
522
                isShowRank = false;
523
            }
524
        }
525

  
526
        if (e.getSource().equals(this.activateCombo)) {
527
            String text = activateCombo.getText();
528
            if(text.equals(Messages.Preference_Use_Default)){
529
                isEditorActivated = null;
530
                if (isAdminPreference){
531
                    if (distributionEditorPref == null){
532
                        distributionEditorPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DistributionEditorActivated, PreferencePredicate.DistributionEditorActivated.getDefaultValue() != null ?  PreferencePredicate.DistributionEditorActivated.getDefaultValue().toString(): null);
533
                    }
534
                    distributionEditorPref.setAllowOverride(true);
535
                    allowOverrideActivatedButton.setSelection(true);
536
                }
537
                return;
538
            }
539
            if (text.equals(ENABLE)){
540
                isEditorActivated = true;
541
            }else{
542
                isEditorActivated = false;
543
            }
544

  
545
        }
546
        //PreferencesUtil.recursiveSetEnabled(child, isEditorActivated);
547
    }
548

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

  
556
    }
557

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

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

  
575
            } else {
576
                isEditorActivated = Boolean.valueOf(distributionEditorPref.getValue());
577

  
578
            }
579

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

  
589
        prefAreaVoc = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies);
590
        if (prefAreaVoc == null){
591
            prefAreaVoc = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AvailableDistributionAreaVocabularies, PreferencePredicate.AvailableDistributionAreaVocabularies.getDefaultValue() != null ?  PreferencePredicate.AvailableDistributionAreaVocabularies.getDefaultValue().toString(): null);
592
        }
593

  
594

  
595
        prefStatus = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionStatus);
596
        if (prefStatus == null){
597
            prefStatus = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AvailableDistributionStatus, PreferencePredicate.AvailableDistributionStatus.getDefaultValue() != null ?  PreferencePredicate.AvailableDistributionStatus.getDefaultValue().toString(): null);
598
        }
599

  
600

  
601
        prefAreaDisplay = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DisplayOfAreasInDistributionEditor);
602
        overrideAreaDisplay = PreferencesUtil.getBooleanValue(
603
                PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), true);
604
        if (prefAreaDisplay != null) {
605
            if (prefAreaDisplay.isAllowOverride()){
606
                if (overrideActivated) {
607
                    displayArea = PreferencesUtil.displayAreaInChecklistEditor();
608
                }else{
609
                    displayArea = Messages.Preference_Use_Default;
610
                }
611
            } else {
612
                displayArea = prefAreaDisplay.getValue();
613
            }
614
        } else {
615
            if (overrideAreaDisplay){
616
                displayArea = PreferencesUtil.displayAreaInChecklistEditor();
617
            } else{
618
                displayArea = Messages.Preference_Use_Default;
619
            }
620
            //prefAreaDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfAreasInDistributionEditor, PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString(): null);
621
        }
622

  
623
        prefStatusDisplay = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DisplayOfStatus);
624
        overrideStatusDisplay = PreferencesUtil
625
                .getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatus.getKey()), true);
626
        if (prefStatusDisplay != null) {
627
            if (prefStatusDisplay.isAllowOverride()){
628
                if (overrideStatusDisplay) {
629
                    displayStatus = PreferencesUtil.displayStatusInChecklistEditor();
630
                }else{
631
                    displayStatus = Messages.Preference_Use_Default;
632
                }
633
            } else {
634
                this.displayStatus = prefStatusDisplay.getValue();
635
            }
636
        } else {
637
            if (overrideStatusDisplay){
638
                displayStatus = PreferencesUtil.displayStatusInChecklistEditor();
639
            } else{
640
                displayStatus = Messages.Preference_Use_Default;
641
            }
642
            //prefStatusDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfStatus, PreferencePredicate.DisplayOfStatus.getDefaultValue() != null ?  PreferencePredicate.DisplayOfStatus.getDefaultValue().toString(): null);
643
        }
644

  
645
        prefAreaSort = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AreasSortedInDistributionEditor);
646
        overrideOrderAreas = PreferencesUtil.getBooleanValue(
647
                PreferencesUtil.prefOverrideKey(PreferencePredicate.AreasSortedInDistributionEditor.getKey()), true);
648
        if (prefAreaSort != null) {
649
            if (prefAreaSort.isAllowOverride()){
650
                if(overrideOrderAreas) {
651
                    orderAreas = PreferencesUtil.getSortNamedAreasInDistributionEditor();
652
                }else{
653
                    orderAreas = Messages.Preference_Use_Default;
654
                }
655
            } else {
656
                if (prefAreaSort.getValue() != null) {
657
                    orderAreas = prefAreaSort.getValue().toString();
658
                } else {
659
                    orderAreas = ((TermOrder) PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue())
660
                            .getKey();
661
                }
662

  
663
            }
664
        } else {
665
            if (overrideOrderAreas){
666
                orderAreas = PreferencesUtil.getSortNamedAreasInDistributionEditor();
667
            }else{
668
                orderAreas = Messages.Preference_Use_Default;
669
            }
670
            //prefAreaSort = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AreasSortedInDistributionEditor, PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue().toString(): null);
671
        }
672

  
673
        prefRank = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowRankInDistributionEditor);
674
        overrideRank = PreferencesUtil.getBooleanValue(
675
                PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowRankInDistributionEditor.getKey()), true);
676
        if (prefRank != null) {
677
            if (prefRank.isAllowOverride()){
678
                if(overrideRank) {
679
                    isShowRank = PreferencesUtil.isShowRankInChecklistEditor();
680
                }
681

  
682
            } else {
683
                this.isShowRank = Boolean.valueOf(prefRank.getValue().toString());
684
            }
685
        } else {
686
            if (overrideRank){
687
                isShowRank = PreferencesUtil.isShowRankInChecklistEditor();
688
            } else {
689
                isShowRank = null;
690
            }
691

  
692
            //refRank = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowRankInDistributionEditor, PreferencePredicate.ShowRankInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.ShowRankInDistributionEditor.getDefaultValue().toString(): null);
693
        }
694

  
695
        prefOwnDescription = PreferencesUtil
696
                .getPreferenceFromDB(PreferencePredicate.OwnDescriptionForDistributionEditor);
697
        if (prefOwnDescription != null) {
698
            if (prefOwnDescription.isAllowOverride()) {
699
                ownDescriptionForDistributionEditor = PreferencesUtil.isOwnDescriptionForChecklistEditor();
700
            } else {
701
                ownDescriptionForDistributionEditor = Boolean.valueOf(prefOwnDescription.getValue().toString());
702
            }
703
        } else {
704
            ownDescriptionForDistributionEditor = PreferencesUtil.isShowRankInChecklistEditor();
705
            // allowOverrideOwnDescriptionForDistributionEditor = true;
706
            overrideOwnDescriptionForDistributionEditor = PreferencesUtil.getBooleanValue(
707
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey()), true);
708
            //prefOwnDescription = CdmPreference.NewTaxEditorInstance(PreferencePredicate.OwnDescriptionForDistributionEditor, PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue().toString(): null);
709
        }
710

  
711
        commandHandlerString = "eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardHandler";
712
        commandHandlerStringStatus = "eu.etaxonomy.taxeditor.store.open.OpenDistributionStatusWizardHandler";
713
    }
714

  
715
    @Override
716
    protected void performDefaults() {
717
        if (isAdminPreference){
718
            isEditorActivated = (Boolean) PreferencePredicate.DistributionEditorActivated.getDefaultValue();
719
        }else{
720
            isEditorActivated = Boolean.parseBoolean(distributionEditorPref.getValue().toString());
721
        }
722
        if (isEditorActivated) {
723
            activateCombo.select(0);
724
        } else {
725
            activateCombo.select(1);
726
        }
727

  
728
        if (isAdminPreference){
729
            displayArea = ((TermDisplayEnum) PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue())
730
                    .getKey();
731
        }else{
732
            displayArea = prefAreaDisplay.getValue().toString();
733
        }
734

  
735
        TermDisplayEnum areaDisplay;
736
        try {
737
            if (displayArea != null) {
738
                areaDisplay = TermDisplayEnum.byKey(displayArea);
739
            } else {
740
                areaDisplay = TermDisplayEnum.Title;
741
            }
742
        } catch (IllegalArgumentException e) {
743
            areaDisplay = TermDisplayEnum.Title;
744
        }
745
        int index = 0;
746
        for (String itemLabel : areaDisplaySelectionCombo.getItems()) {
747
            if (itemLabel.equalsIgnoreCase(areaDisplay.getLabel())) {
748
                areaDisplaySelectionCombo.select(index);
749
                break;
750
            }
751
            index++;
752
        }
753

  
754
        if (isAdminPreference){
755
            displayStatus = ((TermDisplayEnum) PreferencePredicate.DisplayOfStatus.getDefaultValue()).getKey();
756
        }else{
757
            displayStatus = prefStatusDisplay.getValue().toString();
758
        }
759

  
760
        TermDisplayEnum statusDisplay;
761
        try {
762
            if (displayStatus != null) {
763
                statusDisplay = TermDisplayEnum.byKey(displayStatus);
764
            } else {
765
                statusDisplay = TermDisplayEnum.Title;
766
            }
767
        } catch (IllegalArgumentException e) {
768
            statusDisplay = TermDisplayEnum.Title;
769
        }
770
        index = 0;
771
        for (String itemLabel : statusDisplaySelectionCombo.getItems()) {
772
            if (itemLabel.equalsIgnoreCase(statusDisplay.getLabel())) {
773
                statusDisplaySelectionCombo.select(index);
774
                break;
775
            }
776
            index++;
777
        }
778
        if (isAdminPreference){
779
            orderAreas = ((TermOrder) PreferencePredicate.AreasSortedInDistributionEditor.getDefaultValue()).getKey();
780
        }else{
781
            orderAreas = prefAreaSort.getValue().toString();
782
        }
783

  
784
        index = 0;
785
        if (PreferencesUtil.getStringValue(PreferencePredicate.DistributionEditorActivated.getKey()) != null) {
786
            TermOrder areaOrder;
787
            try {
788
                if (orderAreas != null) {
789
                    areaOrder = TermOrder.valueOf(orderAreas);
790
                } else {
791
                    areaOrder = TermOrder.IdInVoc;
792
                }
793
            } catch (IllegalArgumentException e) {
794
                areaOrder = TermOrder.IdInVoc;
795
            }
796
            for (String itemLabel : areaOrderSelectionCombo.getItems()) {
797
                if (itemLabel.equalsIgnoreCase(areaOrder.getLabel())) {
798
                    areaOrderSelectionCombo.select(index);
799
                    break;
800
                }
801
                index++;
802
            }
803
        }
804

  
805
        if (isAdminPreference){
806
            isShowRank = Boolean.valueOf(PreferencePredicate.ShowRankInDistributionEditor.getDefaultValue().toString());
807
        }else{
808
            isShowRank = Boolean.parseBoolean(prefRank.getValue().toString());
809
        }
810

  
811
        if (isShowRank) {
812
            activateRankCombo.select(0);
813
        } else {
814
            activateRankCombo.select(1);
815
        }
816

  
817
        ownDescriptionForDistributionEditor = Boolean
818
                .valueOf(PreferencePredicate.OwnDescriptionForDistributionEditor.getDefaultValue().toString());
819

  
820
        allowOverrideActivatedButton.setSelection(true);
821
        overrideActivated = true;
822

  
823
        overrideAreaDisplay = true;
824
        allowOverrideAreaDisplayButton.setSelection(true);
825

  
826
        overrideStatusDisplay = true;
827
        allowOverrideStatusDisplayButton.setSelection(true);
828

  
829
        overrideOrderAreas = true;
830
        allowOverrideOrderAreasButton.setSelection(true);
831

  
832
        overrideRank = true;
833
        allowOverrideRankButton.setSelection(true);
834

  
835
        overrideOwnDescriptionForDistributionEditor = true;
836

  
837
        this.statusPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AvailableDistributionStatus, null);
838
        this.areaVocPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AvailableDistributionAreaVocabularies,
839
                null);
840
        if (!isAdminPreference) {
841
            PreferencesUtil.recursiveSetEnabled(child, isEditorActivated);
842

  
843
            if (!prefAreaVoc.isAllowOverride()) {
844
                button_openSelectAreaVocabularies.setButtonEnabled(false);
845
            }
846
            if (!prefStatus.isAllowOverride()) {
847
                button_openStatusWizard.setButtonEnabled(false);
848
            }
849
            if (!prefRank.isAllowOverride()) {
850
                activateRankCombo.setEnabled(false);
851

  
852
                if (!prefAreaSort.isAllowOverride()) {
853
                    areaOrderSelectionCombo.setEnabled(false);
854
                    allowOverrideOrderAreasButton.setEnabled(false);
855
                }
856
                if (!prefAreaDisplay.isAllowOverride()) {
857
                    allowOverrideAreaDisplayButton.setEnabled(false);
858
                }
859
                if (!prefStatusDisplay.isAllowOverride()) {
860
                    allowOverrideStatusDisplayButton.setEnabled(false);
861
                }
862
            }
863
            super.performDefaults();
864
        }
865
    }
866

  
867
}
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.SelectionAdapter;
14
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.events.SelectionListener;
16
import org.eclipse.swt.layout.GridData;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.widgets.Button;
19
import org.eclipse.swt.widgets.Combo;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Event;
23
import org.eclipse.swt.widgets.Label;
24
import org.eclipse.swt.widgets.Listener;
25

  
26
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
27
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
28
import eu.etaxonomy.cdm.model.metadata.TermComboEnum;
29
import eu.etaxonomy.cdm.model.metadata.TermDisplayEnum;
30
import eu.etaxonomy.cdm.model.metadata.TermOrder;
31
import eu.etaxonomy.taxeditor.l10n.Messages;
32
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
33
import eu.etaxonomy.taxeditor.ui.element.CommandHandlerButton;
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 String orderAreas;
50
    protected String displayStatus;
51
    protected String displayStatusCombo;
52
    protected String displayArea;
53
    protected Boolean ownDescriptionForDistributionEditor;
54

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

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

  
74
    protected CdmPreference distributionEditorPref;
75
    protected CdmPreference prefStatus;
76
    protected CdmPreference prefAreaVoc;
77
    protected CdmPreference prefAreaDisplay;
78
    protected CdmPreference prefStatusDisplay;
79
    protected CdmPreference prefStatusDisplayInCombo;
80
    protected CdmPreference prefAreaSort;
81
    protected CdmPreference prefRank;
82
    protected CdmPreference prefOwnDescription;
83
    Composite child;
84

  
85
    protected Combo activateCombo;
86
    protected Button allowOverrideActivatedButton;
87
    final String ENABLE = "Enable";
88
    final String DISABLE = "Disable";
89

  
90
    protected Combo activateRankCombo;
91
    protected Button allowOverrideRankButton;
92
    final String SHOW_RANK = "Show Rank";
93
    final String NO_RANK = "No Rank";
94

  
95
    protected CdmPreference areaVocPref = null;
96
    protected CdmPreference statusPref = null;
97
    private CommandHandlerButton button_openSelectAreaVocabularies;
98

  
99
    private CommandHandlerButton button_openStatusWizard;
100

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

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

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

  
141

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

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

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

  
204
            GridData gridData = new GridData();
205
            gridData = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
206

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

  
209
            index = 0;
210
            TermOrder areaOrder;
211
            try {
212
                if (orderAreas != null) {
213
                    areaOrder = TermOrder.valueOf(orderAreas);
214
                } else {
215
                    areaOrder = TermOrder.IdInVoc;
216
                }
217
            } catch (IllegalArgumentException e) {
218
                areaOrder = TermOrder.IdInVoc;
219
            }
220
            for (String itemLabel : areaOrderSelectionCombo.getItems()) {
221
                if (itemLabel.equals(Messages.Preference_Use_Default) && orderAreas.equals(Messages.Preference_Use_Default)){
222
                    areaOrderSelectionCombo.select(index);
223
                    break;
224
                }
225
                if (itemLabel.startsWith(areaOrder.getLabel())) {
226
                    areaOrderSelectionCombo.select(index);
227
                    break;
228
                }
229

  
230
                index++;
231
            }
232

  
233
            areaOrderSelectionCombo.addSelectionListener(this);
234

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

  
250
            separator = new Label(child, SWT.HORIZONTAL | SWT.SEPARATOR);
251
            separator.setLayoutData(sepGrid);
252
            areaDisplaySelectionCombo = createCombo(child, TermDisplayEnum.values(), PreferencePredicate.DisplayOfAreasInDistributionEditor, Messages.ChecklistEditorGeneralPreference_Configure_display_of_Areas, isAdminPreference);
253

  
254

  
255
            index = 0;
256
            TermDisplayEnum areaDisplay;
257
            try {
258
                if (displayArea != null) {
259
                    areaDisplay = TermDisplayEnum.valueOf(displayArea);
260
                } else {
261
                    areaDisplay = TermDisplayEnum.Title;
262
                }
263
            } catch (IllegalArgumentException e) {
264
                areaDisplay = TermDisplayEnum.Title;
265
            }
266
            for (String itemLabel : areaDisplaySelectionCombo.getItems()) {
267
                if (itemLabel.equals(Messages.Preference_Use_Default) && displayArea.equals(Messages.Preference_Use_Default)){
268
                    areaDisplaySelectionCombo.select(index);
269
                    break;
270
                }
271
                if (itemLabel.startsWith(areaDisplay.getLabel())) {
272
                    areaDisplaySelectionCombo.select(index);
273
                    break;
274
                }
275

  
276
                index++;
277
            }
278
            areaDisplaySelectionCombo.addSelectionListener(this);
279

  
280
            if (isAdminPreference) {
281
                allowOverrideAreaDisplayButton = createAllowOverrideButton(child);
282
                allowOverrideAreaDisplayButton.setSelection(prefAreaDisplay != null? prefAreaDisplay.isAllowOverride(): true);
283
                allowOverrideAreaDisplayButton.addSelectionListener(new SelectionAdapter() {
284
                    @Override
285
                    public void widgetSelected(SelectionEvent e) {
286
                        setApply(true);
287
                        if (prefAreaDisplay == null){
288
                            prefAreaDisplay = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfAreasInDistributionEditor, PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue() != null ?  PreferencePredicate.DisplayOfAreasInDistributionEditor.getDefaultValue().toString(): null);
289
                        }
290
                        prefAreaDisplay.setAllowOverride(allowOverrideOrderAreasButton.getSelection());
291
                    }
292
                });
293
            }
294

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

  
297
            index = 0;
298
            TermDisplayEnum statusDisplay;
299
            try {
300
                if (displayStatus != null) {
301
                    statusDisplay = TermDisplayEnum.valueOf(displayStatus);
302
                } else {
303
                    statusDisplay = TermDisplayEnum.Title;
304
                }
305
            } catch (IllegalArgumentException e) {
306
                statusDisplay = TermDisplayEnum.Title;
307
            }
308
            for (String itemLabel : statusDisplaySelectionCombo.getItems()) {
309
                if (itemLabel.equals(Messages.Preference_Use_Default) && displayStatus.equals(Messages.Preference_Use_Default)){
310
                    statusDisplaySelectionCombo.select(index);
311
                    break;
312
                }
313
                if (itemLabel.startsWith(statusDisplay.getLabel())) {
314
                    statusDisplaySelectionCombo.select(index);
315
                    break;
316
                }
317

  
318
                index++;
319
            }
320

  
321
            statusDisplaySelectionCombo.addSelectionListener(this);
322

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

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

  
340
            index = 0;
341
            TermComboEnum statusComboDisplay;
342
            try {
343
                if (displayStatusCombo != null) {
344
                    statusComboDisplay = TermComboEnum.byKey(displayStatusCombo);
345
                } else {
346
                    statusComboDisplay = TermComboEnum.Title;
347
                }
348
            } catch (IllegalArgumentException e) {
349
                statusComboDisplay = TermComboEnum.Title;
350
            }
351
            for (String itemLabel : statusDisplayInComboSelectionCombo.getItems()) {
352
                if (itemLabel.equals(Messages.Preference_Use_Default) && displayStatusCombo.equals(Messages.Preference_Use_Default)){
353
                    statusDisplayInComboSelectionCombo.select(index);
354
                    break;
355
                }
356
                if (itemLabel.startsWith(statusComboDisplay.getLabel())) {
357
                    statusDisplayInComboSelectionCombo.select(index);
358
                    break;
359
                }
360

  
361
                index++;
362
            }
363

  
364
            statusDisplayInComboSelectionCombo.addSelectionListener(this);
365

  
366
            if (isAdminPreference) {
367
                allowOverrideStatusDisplayInComboButton = createAllowOverrideButton(child);
368
                allowOverrideStatusDisplayInComboButton.setSelection(prefStatusDisplayInCombo != null ? prefStatusDisplayInCombo.isAllowOverride(): true);
369
                allowOverrideStatusDisplayInComboButton.addSelectionListener(new SelectionAdapter() {
370
                    @Override
371
                    public void widgetSelected(SelectionEvent e) {
372
                        setApply(true);
373
                        if (prefStatusDisplayInCombo == null){
374
                            prefStatusDisplayInCombo = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DisplayOfStatusInCombo, PreferencePredicate.DisplayOfStatusInCombo.getDefaultValue() != null ?  PreferencePredicate.DisplayOfStatusInCombo.getDefaultValue().toString(): null);
375
                        }
376
                        prefStatusDisplayInCombo.setAllowOverride(allowOverrideStatusDisplayInComboButton.getSelection());
377
                    }
378
                });
379
            }
380

  
381

  
382
            final CLabel labelStatus = new CLabel(child, SWT.NULL);
383
            labelStatus.setText(Messages.DistributionAdminPreferences_SELECT_STATUS);
384
            labelStatus.setLayoutData(textGrid);
385

  
386
            button_openStatusWizard = new CommandHandlerButton(child, SWT.PUSH, commandHandlerStringStatus);
387

  
388
            button_openStatusWizard.setText(Messages.Distribution_status_selection);
389
            button_openStatusWizard.addListener(SWT.Selection, new Listener() {
390
                @Override
391
                public void handleEvent(Event e) {
392
                    switch (e.type) {
393
                    case SWT.Selection:
394
                        setApply(true);
395
                        break;
396
                    }
397
                }
398
            });
399

  
400
            final CLabel label = new CLabel(child, SWT.NULL);
401
            label.setText(Messages.ChecklistEditorGeneralPreference_open_wizard);
402
            label.setLayoutData(textGrid);
403

  
404
            button_openSelectAreaVocabularies = new CommandHandlerButton(child, SWT.PUSH, commandHandlerString);
405
            button_openSelectAreaVocabularies
406
                    .setText(Messages.ChecklistEditorGeneralPreference_open_distribution_selection);
407

  
408
            if (!isAdminPreference) {
409

  
410
                //PreferencesUtil.recursiveSetEnabled(child, isEditorActivated);
411
                if (distributionEditorPref != null && !distributionEditorPref.isAllowOverride()){
412
                    activateComp.setEnabled(false);
413
                }
414

  
415
                if (prefAreaVoc != null && !prefAreaVoc.isAllowOverride()) {
416
                    button_openSelectAreaVocabularies.setButtonEnabled(false);
417
                }
418
                if (prefStatus != null && !prefStatus.isAllowOverride()) {
419
                    button_openStatusWizard.setButtonEnabled(false);
420
                }
421
                if (prefRank != null && !prefRank.isAllowOverride()) {
422
                    activateRankCombo.setEnabled(false);
423
                }
424
                if (prefAreaSort != null && !prefAreaSort.isAllowOverride()) {
425
                    areaOrderSelectionCombo.setEnabled(false);
426
                    //allowOverrideOrderAreasButton.setEnabled(false);
427
                }
428
                if (prefAreaDisplay != null && !prefAreaDisplay.isAllowOverride()) {
429
                    areaDisplaySelectionCombo.setEnabled(false);
430
                }
431
                if (prefStatusDisplay != null && !prefStatusDisplay.isAllowOverride()) {
432
                    statusDisplaySelectionCombo.setEnabled(false);
433
                }
434
                if (prefStatusDisplayInCombo != null && !prefStatusDisplayInCombo.isAllowOverride()) {
435
                    statusDisplayInComboSelectionCombo.setEnabled(false);
436
                }
437
            }
438

  
439
        }
440
        setValid(true);
441
        return composite;
442
    }
443

  
444
    @Override
445
    public boolean performOk() {
446
        if (!isApply()){
447
            return true;
448
        }
449
            boolean override = false;
450
            if (isEditorActivated != null ) {
451
                override = true;
452
                PreferencesUtil.setStringValue(PreferencePredicate.DistributionEditorActivated.getKey(), isEditorActivated.toString());
453
            }
454
            PreferencesUtil.setBooleanValue(
455
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DistributionEditorActivated.getKey()),
456
                    override);
457

  
458

  
459
            override = false;
460
            if (!orderAreas.equals(Messages.Preference_Use_Default) ) {
461
                override = true;
462
                PreferencesUtil.setSortNamedAreasInDistributionEditor(orderAreas);
463
            }
464
            PreferencesUtil.setBooleanValue(
465
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.AreasSortedInDistributionEditor.getKey()),
466
                    override);
467

  
468

  
469

  
470

  
471

  
472
            override = false;
473
            if (isShowRank != null ) {
474
                override = true;
475
                PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
476
            }
477
            PreferencesUtil.setBooleanValue(
478
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.ShowRankInDistributionEditor.getKey()),
479
                    override);
480

  
481

  
482
            override = false;
483
            if (!displayStatus.equals(Messages.Preference_Use_Default)) {
484
               override = true;
485
               PreferencesUtil.setDisplayStatusInChecklistEditor(displayStatus);
486
            }
487
            PreferencesUtil.setBooleanValue(
488
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatus.getKey()),
489
                    override);
490

  
491
            override = false;
492
            if (!displayStatusCombo.equals(Messages.Preference_Use_Default)) {
493
               override = true;
494
               PreferencesUtil.setStringValue(PreferencePredicate.DisplayOfStatusInCombo.getKey(), displayStatusCombo);
495
            }
496
            PreferencesUtil.setBooleanValue(
497
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.DisplayOfStatusInCombo.getKey()),
498
                    override);
499

  
500

  
501

  
502
            override = false;
503
            if (!displayArea.equals(Messages.Preference_Use_Default) ) {
504
                override = true;
505
                PreferencesUtil.setAreaDisplayInChecklistEditor(displayArea);
506
            }
507
            PreferencesUtil.setBooleanValue(PreferencesUtil.prefOverrideKey(
508
                    PreferencePredicate.DisplayOfAreasInDistributionEditor.getKey()), override);
509

  
510

  
511

  
512

  
513
            PreferencesUtil.setOwnDescriptionForChecklistEditor(ownDescriptionForDistributionEditor);
514
            PreferencesUtil.setBooleanValue(
515
                    PreferencesUtil.prefOverrideKey(PreferencePredicate.OwnDescriptionForDistributionEditor.getKey()),
516
                    true);
517

  
518
            PreferencesUtil.firePreferencesChanged(this.getClass());
519

  
520
        return true;
521
    }
522

  
523
    /**
524
     * {@inheritDoc}
525
     */
526
    @Override
527
    public void widgetSelected(SelectionEvent e) {
528
        setApply(true);
529
        if (e.getSource().equals(statusDisplaySelectionCombo)) {
530
            String text = statusDisplaySelectionCombo.getText();
531
            if(text.equals(Messages.Preference_Use_Default)){
532
                displayStatus = Messages.Preference_Use_Default;
533
                if(isAdminPreference){
534
                    prefStatusDisplay.setAllowOverride(true);
535
                    allowOverrideStatusDisplayButton.setSelection(true);
536
                }
537

  
538
                return;
539
            }
540
            for (TermDisplayEnum display : TermDisplayEnum.values()) {
541
                if (text.startsWith(display.getLabel())) {
542
                    displayStatus = display.getKey();
543
                    break;
544
                }
545

  
546
            }
547
        }
548
        if (e.getSource().equals(statusDisplayInComboSelectionCombo)) {
549
            String text = statusDisplayInComboSelectionCombo.getText();
550
            if(text.equals(Messages.Preference_Use_Default)){
551
                displayStatusCombo = Messages.Preference_Use_Default;
552
                if(isAdminPreference){
553
                    prefStatusDisplayInCombo.setAllowOverride(true);
554
                    allowOverrideStatusDisplayInComboButton.setSelection(true);
555
                }
556

  
557
                return;
558
            }
559
            for (TermComboEnum display : TermComboEnum.values()) {
560
                if (text.startsWith(display.getLabel())) {
561
                    displayStatusCombo = display.getKey();
562
                    break;
563
                }
564

  
565
            }
566
        }
567
        if (e.getSource().equals(areaDisplaySelectionCombo)) {
568
            String text = areaDisplaySelectionCombo.getText();
569
            if(text.equals(Messages.Preference_Use_Default)){
570
                displayArea = Messages.Preference_Use_Default;
571
                if (isAdminPreference){
572
                    prefAreaDisplay.setAllowOverride(true);
573
                    allowOverrideAreaDisplayButton.setSelection(true);
574
                }
575
                return;
576
            }
577
            for (TermDisplayEnum display : TermDisplayEnum.values()) {
578
                if (text.startsWith(display.getLabel())) {
579
                    displayArea = display.getKey();
580
                    break;
581
                }
582
            }
583
        }
584
        if (e.getSource().equals(areaOrderSelectionCombo)) {
585
            String text = areaOrderSelectionCombo.getText();
586
            if(text.equals(Messages.Preference_Use_Default)){
587
                orderAreas = Messages.Preference_Use_Default;
588
                if (isAdminPreference){
589
                    prefAreaSort.setAllowOverride(true);
590
                    allowOverrideOrderAreasButton.setSelection(true);
591
                }
592
                return;
593
            }
594
            for (TermOrder display : TermOrder.values()) {
595
                if (text.startsWith(display.getLabel())) {
596
                    orderAreas = display.getKey();
597
                    break;
598
                }
599
            }
600
        }
601
        if (e.getSource().equals(this.activateRankCombo)) {
602
            String text = activateRankCombo.getText();
603
            if(text.equals(Messages.Preference_Use_Default)){
604
                isShowRank = null;
605
                if (isAdminPreference){
606
                    prefRank.setAllowOverride(true);
607
                    allowOverrideRankButton.setSelection(true);
608
                }
609
                return;
610
            }
611
            if (text.equals(SHOW_RANK)){
612
                isShowRank = true;
613
            }else{
614
                isShowRank = false;
615
            }
616
        }
617

  
618
        if (e.getSource().equals(this.activateCombo)) {
619
            String text = activateCombo.getText();
620
            if(text.equals(Messages.Preference_Use_Default)){
621
                isEditorActivated = null;
622
                if (isAdminPreference){
623
                    if (distributionEditorPref == null){
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff