Project

General

Profile

Download (5.48 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.jface.preference.BooleanFieldEditor;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.layout.GridData;
14
import org.eclipse.swt.widgets.Label;
15

    
16
import eu.etaxonomy.cdm.api.application.ICdmRepository;
17
import eu.etaxonomy.cdm.api.service.IPreferenceService;
18
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
19
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
20
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
21
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
22
import eu.etaxonomy.taxeditor.preference.menu.FieldEditorPreferencePageE4;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

    
25
/**
26
 * @author pplitzner
27
 * @date 13.02.2014
28
 *
29
 */
30
public class SpecimenOrObservationPreferences extends FieldEditorPreferencePageE4 {
31

    
32
    private static final String LOCAL_SETTINGS_NOT_ALLOWED = "The CDM settings don't allow to set the preferences for the display of specimen and obeservations locally. If you need to make local settings, please ask an administrator.";
33
    private static final String DESCRIPTION = "Set the preferences for the display of specimen and observations.";
34

    
35
    public SpecimenOrObservationPreferences(){
36
        super();
37

    
38
        if (PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_SPECIMEN_ALLOW_OVERRIDE)){
39
            setDescription(DESCRIPTION);
40
        }else{
41
            setDescription(LOCAL_SETTINGS_NOT_ALLOWED);
42
        }
43
    }
44

    
45

    
46
    @Override
47
    public void init() {
48
        super.init();
49
//        setPreferenceStore(PreferencesUtil.getPreferenceStore());
50
        if(!CdmStore.isActive()){
51
            return;
52
        }
53
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
54
        if (controller != null){
55
            IPreferenceService service = controller.getPreferenceService();
56
            PrefKey keyTaxonAssociation = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonAssociations);
57
            CdmPreference prefTaxonAssociation = service.find(keyTaxonAssociation);
58
            PreferencesUtil.setBooleanValue(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS_ALLOW_OVERRIDE, prefTaxonAssociation == null? true : prefTaxonAssociation.isAllowOverride());
59

    
60
            PrefKey keyDeterminationFieldUnit = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
61
            CdmPreference prefDeterminationFieldUnit = service.find(keyDeterminationFieldUnit);
62
            PreferencesUtil.setBooleanValue(IPreferenceKeys.DETERMINATIONS_ONLY_FOR_FIELDUNITS_ALLOW_OVERRIDE, prefDeterminationFieldUnit == null? true : prefDeterminationFieldUnit.isAllowOverride());
63

    
64
            PrefKey keyCollectingAreas = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
65
            CdmPreference prefCollectingAreas = service.find(keyCollectingAreas);
66
            PreferencesUtil.setBooleanValue(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION_ALLOW_OVERRIDE, prefCollectingAreas == null? true : prefCollectingAreas.isAllowOverride());
67

    
68
            PrefKey keyShowLifeForm = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowLifeForm);
69
            CdmPreference prefShowLifeForm = service.find(keyShowLifeForm);
70
            PreferencesUtil.setBooleanValue(IPreferenceKeys.SHOW_LIFE_FORM_ALLOW_OVERRIDE, prefShowLifeForm == null? true : prefShowLifeForm.isAllowOverride());
71
         }
72
        if (PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS_OVERRIDE)) {
73
            setDescription(DESCRIPTION);
74
        }else{
75
            setDescription(LOCAL_SETTINGS_NOT_ALLOWED);
76

    
77
        }
78
    }
79

    
80
    @Override
81
    protected void createFieldEditors() {
82
        if (PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_SPECIMEN_ALLOW_OVERRIDE)) {
83
            addField(new BooleanFieldEditor(PreferencesUtil.createPreferenceString(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS),
84
                    "Taxon determination only on FieldUnit level",
85
                    getFieldEditorParent()));
86
            addField(new BooleanFieldEditor(PreferencesUtil.createPreferenceString(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION),
87
                    "Show \"Collecting Areas\" in \"General\" section of details view",
88
                    getFieldEditorParent()));
89
            addField(new BooleanFieldEditor(PreferencesUtil.createPreferenceString(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS),
90
                    "Show taxon associations of a specimen in the details view",
91
                    getFieldEditorParent()));
92
            addField(new BooleanFieldEditor(PreferencesUtil.createPreferenceString(IPreferenceKeys.SHOW_LIFE_FORM),
93
                    "Show life form of a specimen in the details view",
94
                    getFieldEditorParent()));
95
            Label label = new Label(getFieldEditorParent(), SWT.NONE);
96

    
97
            label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
98

    
99
            addField(new BooleanFieldEditor(
100
                    PreferencesUtil.createPreferenceString(IPreferenceKeys.SHOW_SPECIMEN_OVERRIDE),
101
                    "Use local specimen preferences",
102
                    getFieldEditorParent()));
103

    
104

    
105
        }
106

    
107
    }
108

    
109

    
110
}
(22-22/25)