Project

General

Profile

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

    
11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.events.SelectionAdapter;
13
import org.eclipse.swt.events.SelectionEvent;
14
import org.eclipse.swt.events.SelectionListener;
15
import org.eclipse.swt.layout.GridData;
16
import org.eclipse.swt.widgets.Button;
17
import org.eclipse.swt.widgets.Combo;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.Label;
21

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

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

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

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

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

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

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

    
82

    
83
    }
84

    
85
    /**
86
     * {@inheritDoc}
87
     */
88
    @Override
89
    protected Control createContents(Composite parent) {
90
        getValues();
91

    
92
        boolean isEditingAllowed = true;
93
        if(!isAdminPreference){
94
            CdmPreferenceCache cache = CdmPreferenceCache.instance();
95
            PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
96
            CdmPreference showSpecimenPref = cache.findBestMatching(key);
97
            if (showSpecimenPref != null){
98
                if (!showSpecimenPref.isAllowOverride() ){
99
                    Label label = new Label(parent, SWT.NONE);
100
                    label.setText(LOCAL_SETTINGS_NOT_ALLOWED);
101
                    isEditingAllowed = false;
102

    
103
                }
104
            }
105
        }
106

    
107
        Label label = new Label(parent, SWT.NONE);
108
        label.setText(DESCRIPTION);
109
        Composite titleComp = createComposite(parent);
110
        GridData gridData = createTextGridData();
111

    
112
        Label separator= new Label(titleComp, SWT.HORIZONTAL | SWT.SEPARATOR);
113
        separator.setLayoutData(gridData);
114
        separator.setVisible(false);
115
        showSpecimenButton = createBooleanCombo(titleComp, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowSpecimen, Messages.DatabasePreferncesPage_Show_Specimen, isAdminPreference);
116

    
117
        showSpecimenButton.addSelectionListener(this);
118
        if (isShowSpecimenRelatedIssues){
119
            showSpecimenButton.select(0);
120
        }else{
121
            showSpecimenButton.select(1);
122
        }
123

    
124

    
125
        if (isAdminPreference){
126
            allowOverrideIsShowSpecimenRelatedIssuesButton = createAllowOverrideButton(titleComp);
127
            allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
128
            allowOverrideIsShowSpecimenRelatedIssuesButton.addSelectionListener(new SelectionAdapter(){
129
                @Override
130
                public void widgetSelected(SelectionEvent e) {
131
                    setApply(true);
132
                    allowOverrideShowSpecimenRelatedIssues = allowOverrideIsShowSpecimenRelatedIssuesButton.getSelection();
133
                }
134
            });
135
        }
136

    
137
        composite = createComposite(parent);
138
        //composite.setEnabled(isShowSpecimenRelatedIssues);
139
        gridData = createTextGridData();
140

    
141
        separator= new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
142
        separator.setLayoutData(gridData);
143

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

    
146
        showCollectingAreaInGeneralSectionButton.addSelectionListener(this);
147
        if (isShowCollectingAreaInGeneralSection){
148
            showCollectingAreaInGeneralSectionButton.select(0);
149
        }else{
150
            showCollectingAreaInGeneralSectionButton.select(1);
151
        }
152
        if (isAdminPreference){
153
            allowOverrideShowCollectingAreaButton = createAllowOverrideButton(composite);
154
            allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowCollectingAreaInGeneralSection);
155
            allowOverrideShowCollectingAreaButton.addSelectionListener(new SelectionAdapter(){
156
                @Override
157
                public void widgetSelected(SelectionEvent e) {
158
                    setApply(true);
159
                    allowOverrideShowCollectingAreaInGeneralSection = allowOverrideShowCollectingAreaButton.getSelection();
160
                }
161
            });
162
        }
163

    
164
        determinationOnlyForFieldUnitsButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.DeterminationOnlyForFieldUnits, Messages.DatabasePreferncesPage_Determination_only_for_field_unnits, isAdminPreference);
165

    
166

    
167
        determinationOnlyForFieldUnitsButton.addSelectionListener(this);
168
        if (isDeterminationOnlyForFieldUnits){
169
            determinationOnlyForFieldUnitsButton.select(0);
170
        }else{
171
            determinationOnlyForFieldUnitsButton.select(1);
172
        }
173

    
174
        if (isAdminPreference){
175
            allowOverridesDeterminationOnlyForFieldUnitsButton = createAllowOverrideButton(composite);
176
            allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideDeterminationOnlyForFieldUnits);
177
            allowOverridesDeterminationOnlyForFieldUnitsButton.addSelectionListener(new SelectionAdapter(){
178
                @Override
179
                public void widgetSelected(SelectionEvent e) {
180
                    setApply(true);
181
                    allowOverrideDeterminationOnlyForFieldUnits = allowOverridesDeterminationOnlyForFieldUnitsButton.getSelection();
182
                }
183
            });
184
        }
185

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

    
188

    
189
        showTaxonAssociationButton.addSelectionListener(this);
190
        if (isShowTaxonAssociation){
191
            showTaxonAssociationButton.select(0);
192
        }else{
193
            showTaxonAssociationButton.select(1);
194
        }
195
        if (isAdminPreference){
196
            allowOverrideIsShowTaxonAssociationButton = createAllowOverrideButton(composite);
197
            allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowTaxonAssociation);
198
            allowOverrideIsShowTaxonAssociationButton.addSelectionListener(new SelectionAdapter(){
199
                @Override
200
                public void widgetSelected(SelectionEvent e) {
201
                    setApply(true);
202
                    allowOverrideShowTaxonAssociation = allowOverrideIsShowTaxonAssociationButton.getSelection();
203
                }
204
            });
205
        }
206

    
207
        showLifeFormButton = createBooleanCombo(composite, Messages.GeneralPreference_yes, Messages.GeneralPreference_no, PreferencePredicate.ShowLifeForm, Messages.DatabasePreferncesPage_Life_Form, isAdminPreference);
208
        showLifeFormButton.addSelectionListener(this);
209

    
210
        if (isShowLifeForm){
211
            showLifeFormButton.select(0);
212
        }else{
213
            showLifeFormButton.select(1);
214
        }
215

    
216
        if (isAdminPreference){
217
            allowOverrideShowLifeFormButton = createAllowOverrideButton(composite);
218
            allowOverrideShowLifeFormButton.setSelection(allowOverrideShowLifeForm);
219
            allowOverrideShowLifeFormButton.addSelectionListener(new SelectionAdapter(){
220
                @Override
221
                public void widgetSelected(SelectionEvent e) {
222
                    setApply(true);
223
                    allowOverrideShowLifeForm = allowOverrideShowLifeFormButton.getSelection();
224
                }
225
            });
226
        }
227

    
228
        if (!isEditingAllowed){
229
            PreferencesUtil.recursiveSetEnabled(composite, false);
230
        }
231

    
232
        return composite;
233
    }
234

    
235

    
236
    /**
237
     * {@inheritDoc}
238
     */
239
    @Override
240
    protected void getValues() {
241
        CdmPreferenceCache cache = CdmPreferenceCache.instance();
242

    
243
        isShowSpecimenRelatedIssues = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimen.getKey());
244
        PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowSpecimen);
245
        showSpecimenPref = cache.findBestMatching(key);
246
        if (showSpecimenPref == null){
247
            showSpecimenPref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowSpecimen, PreferencePredicate.ShowSpecimen.getDefaultValue() != null ?  PreferencePredicate.ShowSpecimen.getDefaultValue().toString(): null);
248
        }
249
        allowOverrideShowSpecimenRelatedIssues = showSpecimenPref != null ? showSpecimenPref.isAllowOverride():true;
250

    
251

    
252

    
253
        isShowCollectingAreaInGeneralSection = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), true);
254
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
255
        showCollectingAreaInGeneralSection = cache.findBestMatching(key);
256
        if (showCollectingAreaInGeneralSection == null){
257
            showCollectingAreaInGeneralSection = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowCollectingAreasInGeneralSection, PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue() != null ?  PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue().toString(): null);
258
        }
259
        allowOverrideShowCollectingAreaInGeneralSection = showCollectingAreaInGeneralSection != null ? showCollectingAreaInGeneralSection.isAllowOverride():true;
260

    
261

    
262
        isDeterminationOnlyForFieldUnits = PreferencesUtil.getBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey());
263
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
264
        showDeterminationOnlyForFieldUnits = cache.findBestMatching(key);
265
        if (showDeterminationOnlyForFieldUnits == null){
266
            showDeterminationOnlyForFieldUnits = CdmPreference.NewTaxEditorInstance(PreferencePredicate.DeterminationOnlyForFieldUnits, PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue() != null ?  PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue().toString(): null);
267
        }
268
        allowOverrideDeterminationOnlyForFieldUnits = showDeterminationOnlyForFieldUnits != null ? showDeterminationOnlyForFieldUnits.isAllowOverride():true;
269

    
270
        isShowTaxonAssociation = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey());
271
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
272
        showTaxonAssociation = cache.findBestMatching(key);
273
        if (showTaxonAssociation == null){
274
            showTaxonAssociation = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonAssociations, PreferencePredicate.ShowTaxonAssociations.getDefaultValue() != null ?  PreferencePredicate.ShowTaxonAssociations.getDefaultValue().toString(): null);
275
        }
276
        allowOverrideShowTaxonAssociation = showTaxonAssociation != null ? showTaxonAssociation.isAllowOverride():true;
277

    
278
        isShowLifeForm = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowLifeForm.getKey());
279
        key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
280
        showLifeForm = cache.findBestMatching(key);
281
        if (showLifeForm == null){
282
            showLifeForm = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowLifeForm, PreferencePredicate.ShowLifeForm.getDefaultValue() != null ?  PreferencePredicate.ShowLifeForm.getDefaultValue().toString(): null);
283
        }
284
        allowOverrideShowLifeForm = showLifeForm != null ? showLifeForm.isAllowOverride():true;
285

    
286

    
287
    }
288

    
289
    @Override
290
    public boolean performOk() {
291
        if (allowOverrideShowSpecimenRelatedIssues){
292
            PreferencesUtil.setBooleanValue(PreferencePredicate.ShowSpecimen.getKey(), isShowSpecimenRelatedIssues);
293
            boolean test = isShowSpecimenRelatedIssues != Boolean.parseBoolean(showSpecimenPref.getValue());
294
            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowSpecimen.getKey()), isShowSpecimenRelatedIssues != Boolean.parseBoolean(showSpecimenPref.getValue()));
295
        }
296
        if (allowOverrideShowCollectingAreaInGeneralSection){
297
            PreferencesUtil.setBooleanValue(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey(), isShowCollectingAreaInGeneralSection);
298
            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowCollectingAreasInGeneralSection.getKey()), isShowCollectingAreaInGeneralSection != Boolean.parseBoolean(showCollectingAreaInGeneralSection.getValue()));
299
        }
300
        if (allowOverrideDeterminationOnlyForFieldUnits){
301
            PreferencesUtil.setBooleanValue(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey(), isDeterminationOnlyForFieldUnits);
302
            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.DeterminationOnlyForFieldUnits.getKey()), isDeterminationOnlyForFieldUnits != Boolean.parseBoolean(showDeterminationOnlyForFieldUnits.getValue()));
303
        }
304
        if (allowOverrideShowTaxonAssociation){
305
            PreferencesUtil.setBooleanValue(PreferencePredicate.ShowTaxonAssociations.getKey(), isShowTaxonAssociation);
306
            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowTaxonAssociations.getKey()), isShowTaxonAssociation != Boolean.parseBoolean(showTaxonAssociation.getValue()));
307
        }
308
        if (allowOverrideShowLifeForm){
309
            PreferencesUtil.setBooleanValue(PreferencePredicate.ShowLifeForm.getKey(), isShowLifeForm);
310
            PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.ShowLifeForm.getKey()), isShowLifeForm != Boolean.parseBoolean(showLifeForm.getValue()));
311
        }
312
        return true;
313
    }
314

    
315

    
316

    
317
    @Override
318
    protected void performDefaults() {
319
        isShowSpecimenRelatedIssues = (Boolean)PreferencePredicate.ShowSpecimen.getDefaultValue();
320
        if (isShowSpecimenRelatedIssues){
321
            showSpecimenButton.select(0);
322
        }else{
323
            showSpecimenButton.select(1);
324
        }
325
        if (allowOverrideIsShowSpecimenRelatedIssuesButton != null){
326
            allowOverrideShowSpecimenRelatedIssues = true;
327
            allowOverrideIsShowSpecimenRelatedIssuesButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
328
        }
329
        isShowCollectingAreaInGeneralSection = (Boolean)PreferencePredicate.ShowCollectingAreasInGeneralSection.getDefaultValue();
330
        if (isShowCollectingAreaInGeneralSection){
331
            showCollectingAreaInGeneralSectionButton.select(0);
332
        }else{
333
            showCollectingAreaInGeneralSectionButton.select(1);
334
        }
335
        if (allowOverrideShowCollectingAreaButton != null){
336
            allowOverrideShowCollectingAreaInGeneralSection = true;
337
            allowOverrideShowCollectingAreaButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
338
        }
339
        isDeterminationOnlyForFieldUnits = (Boolean) PreferencePredicate.DeterminationOnlyForFieldUnits.getDefaultValue();
340
        if (isDeterminationOnlyForFieldUnits){
341
            determinationOnlyForFieldUnitsButton.select(0);
342
        }else{
343
            determinationOnlyForFieldUnitsButton.select(1);
344
        }
345
        if (allowOverridesDeterminationOnlyForFieldUnitsButton != null){
346
            allowOverrideDeterminationOnlyForFieldUnits = true;
347
            allowOverridesDeterminationOnlyForFieldUnitsButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
348
        }
349

    
350
        isShowTaxonAssociation = (Boolean) PreferencePredicate.ShowTaxonAssociations.getDefaultValue();
351
        if (isShowTaxonAssociation){
352
            showTaxonAssociationButton.select(0);
353
        }else{
354
            showTaxonAssociationButton.select(1);
355
        }
356
        if (allowOverrideIsShowTaxonAssociationButton != null){
357
            allowOverrideShowTaxonAssociation = true;
358
            allowOverrideIsShowTaxonAssociationButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
359
        }
360

    
361

    
362
        isShowLifeForm = (Boolean) PreferencePredicate.ShowLifeForm.getDefaultValue();
363

    
364
        if (isShowLifeForm){
365
            showLifeFormButton.select(0);
366
        }else{
367
            showLifeFormButton.select(1);
368
        }
369
        if (allowOverrideShowLifeFormButton != null){
370
            allowOverrideShowLifeForm = true;
371
            allowOverrideShowLifeFormButton.setSelection(allowOverrideShowSpecimenRelatedIssues);
372
        }
373

    
374

    
375
        super.performDefaults();
376
    }
377

    
378
    /**
379
     * {@inheritDoc}
380
     */
381
    @Override
382
    public void widgetSelected(SelectionEvent e) {
383
       setApply(true);
384
       if (e.getSource().equals(showSpecimenButton)){
385
           String text = showSpecimenButton.getText();
386
           text = text.replace(Messages.Preference_Use_Default, "");
387
           if (text.equals(Messages.GeneralPreference_yes)){
388
               isShowSpecimenRelatedIssues = true;
389
           }else{
390
               isShowSpecimenRelatedIssues = false;
391
           }
392
       }
393
       if (e.getSource().equals(showCollectingAreaInGeneralSectionButton)){
394
           String text = showCollectingAreaInGeneralSectionButton.getText();
395
           text = text.replace(" (Use default)", "");
396
           if (text.equals(Messages.GeneralPreference_yes)){
397
               isShowCollectingAreaInGeneralSection = true;
398
           }else{
399
               isShowCollectingAreaInGeneralSection = false;
400
           }
401
       }
402

    
403
       if (e.getSource().equals(determinationOnlyForFieldUnitsButton)){
404
           String text = determinationOnlyForFieldUnitsButton.getText();
405
           text = text.replace(" (Use default)", "");
406
           if (text.equals(Messages.GeneralPreference_yes)){
407
               isDeterminationOnlyForFieldUnits = true;
408
           }else{
409
               isDeterminationOnlyForFieldUnits = false;
410
           }
411
       }
412
       if (e.getSource().equals(showTaxonAssociationButton)){
413
           String text = showTaxonAssociationButton.getText();
414
           text = text.replace(" (Use default)", "");
415
           if (text.equals(Messages.GeneralPreference_yes)){
416
               isShowTaxonAssociation = true;
417
           }else{
418
               isShowTaxonAssociation = false;
419
           }
420
       }
421
       if (e.getSource().equals(showLifeFormButton)){
422
           String text = showLifeFormButton.getText();
423
           text = text.replace(" (Use default)", "");
424
           if (text.equals(Messages.GeneralPreference_yes)){
425
               isShowLifeForm = true;
426
           }else{
427
               isShowLifeForm = false;
428
           }
429
       }
430
    }
431

    
432
    /**
433
     * {@inheritDoc}
434
     */
435
    @Override
436
    public void widgetDefaultSelected(SelectionEvent e) {
437
        // TODO Auto-generated method stub
438

    
439
    }
440

    
441

    
442

    
443

    
444
}
(33-33/41)