Project

General

Profile

Download (4.69 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.jface.preference.FieldEditorPreferencePage;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.layout.GridData;
15
import org.eclipse.swt.widgets.Label;
16
import org.eclipse.ui.IWorkbench;
17
import org.eclipse.ui.IWorkbenchPreferencePage;
18

    
19
import eu.etaxonomy.cdm.api.application.ICdmRepository;
20
import eu.etaxonomy.cdm.api.service.IPreferenceService;
21
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
22
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
23
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
24
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

    
27
/**
28
 * @author pplitzner
29
 * @date 13.02.2014
30
 *
31
 */
32
public class SpecimenOrObservationPreferences extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
33

    
34
    public SpecimenOrObservationPreferences(){
35
        super();
36
        setPreferenceStore(PreferencesUtil.getPreferenceStore());
37
        if (getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY)){
38
            setDescription("Set the preferences for the display of specimen and obeservations.");
39
        }else{
40
            setDescription("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.");
41
        }
42
    }
43

    
44

    
45
    @Override
46
    public void init(IWorkbench workbench) {
47
//        setPreferenceStore(PreferencesUtil.getPreferenceStore());
48
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
49
        if (controller != null){
50
            IPreferenceService service = controller.getPreferenceService();
51
            PrefKey keyTaxonAssociation = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.ShowTaxonAssociations);
52
            CdmPreference prefTaxonAssociation = service.find(keyTaxonAssociation);
53
            PrefKey keyDeterminationFieldUnit = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
54
            CdmPreference prefDeterminationFieldUnit = service.find(keyDeterminationFieldUnit);
55
            PrefKey keyCollectingAreas = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
56
            CdmPreference prefCollectingAreas = service.find(keyCollectingAreas);
57

    
58
            getPreferenceStore().setValue(IPreferenceKeys.ALLOW_OVERRIDE_SPECIMEN_PREF, prefTaxonAssociation == null? true : prefTaxonAssociation.isAllowOverride());
59
         }
60
        if (getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY)) {
61
            setDescription("Set the preferences for the display of specimen and obeservations.");
62
        }else{
63
            setDescription("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.");
64

    
65
        }
66
    }
67

    
68
    @Override
69
    protected void createFieldEditors() {
70
        if (getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_SPECIMEN_PREF)) {
71
            addField(new BooleanFieldEditor(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS,
72
                    "Taxon determination only on FieldUnit level",
73
                    getFieldEditorParent()));
74
            addField(new BooleanFieldEditor(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION,
75
                    "Show \"Collecting Areas\" in \"General\" section of details view",
76
                    getFieldEditorParent()));
77
            addField(new BooleanFieldEditor(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS,
78
                    "Show taxon associations of a specimen in the details view",
79
                    getFieldEditorParent()));
80
            addField(new BooleanFieldEditor(IPreferenceKeys.SHOW_LIFE_FORM,
81
                    "Show taxon associations of a specimen in the details view",
82
                    getFieldEditorParent()));
83
            Label label = new Label(getFieldEditorParent(), SWT.NONE);
84

    
85
            label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
86

    
87
            addField(new BooleanFieldEditor(
88
                    IPreferenceKeys.OVERRIDE_SPECIMEN_PREF,
89
                    "Use local specimen preferences",
90
                    getFieldEditorParent()));
91

    
92

    
93
        }
94

    
95
    }
96

    
97

    
98
}
(21-21/25)