Project

General

Profile

Download (4.14 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
    @Override
35
    public void init(IWorkbench workbench) {
36
        setPreferenceStore(PreferencesUtil.getPreferenceStore());
37
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
38
        if (controller != null){
39
            IPreferenceService service = controller.getPreferenceService();
40
            PrefKey keyTaxonAssociation = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.ShowTaxonAssociations);
41
            CdmPreference prefTaxonAssociation = service.find(keyTaxonAssociation);
42
            PrefKey keyDeterminationFieldUnit = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.DeterminationOnlyForFieldUnits);
43
            CdmPreference prefDeterminationFieldUnit = service.find(keyDeterminationFieldUnit);
44
            PrefKey keyCollectingAreas = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.ShowCollectingAreasInGeneralSection);
45
            CdmPreference prefCollectingAreas = service.find(keyCollectingAreas);
46

    
47
            getPreferenceStore().setValue(IPreferenceKeys.ALLOW_OVERRIDE_SPECIMEN_PREF, prefTaxonAssociation == null? true : prefTaxonAssociation.isAllowOverride());
48
         }
49
        if (getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_NOMENCLATURAL_CODE_KEY)) {
50
            setDescription("Set the preferences for the display of specimen and obeservations.");
51
        }else{
52
            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.");
53

    
54
        }
55
    }
56

    
57
    @Override
58
    protected void createFieldEditors() {
59
        if (getPreferenceStore().getBoolean(IPreferenceKeys.ALLOW_OVERRIDE_SPECIMEN_PREF)) {
60
            addField(new BooleanFieldEditor(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS,
61
                    "Taxon determination only on FieldUnit level",
62
                    getFieldEditorParent()));
63
            addField(new BooleanFieldEditor(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION,
64
                    "Show \"Collecting Areas\" in \"General\" section of details view",
65
                    getFieldEditorParent()));
66
            addField(new BooleanFieldEditor(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS,
67
                    "Show taxon associations of a specimen in the details view",
68
                    getFieldEditorParent()));
69
            addField(new BooleanFieldEditor(IPreferenceKeys.SHOW_LIFE_FORM,
70
                    "Show taxon associations of a specimen in the details view",
71
                    getFieldEditorParent()));
72
            Label label = new Label(getFieldEditorParent(), SWT.NONE);
73

    
74
            label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
75

    
76
            addField(new BooleanFieldEditor(
77
                    IPreferenceKeys.OVERRIDE_SPECIMEN_PREF,
78
                    "Use local specimen preferences",
79
                    getFieldEditorParent()));
80

    
81

    
82
        }
83

    
84
    }
85

    
86

    
87
}
(21-21/25)