Project

General

Profile

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

    
12
import org.eclipse.ui.forms.widgets.ExpandableComposite;
13

    
14
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
15
import eu.etaxonomy.cdm.model.agent.AgentBase;
16
import eu.etaxonomy.cdm.model.common.LanguageString;
17
import eu.etaxonomy.cdm.model.location.NamedArea;
18
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
19
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
20
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
21
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
22
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23
import eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement;
24
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25
import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
26
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
27
import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection;
28
import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
29
import eu.etaxonomy.taxeditor.ui.element.PointElement;
30
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
31
import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
32
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
33
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
34
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
35

    
36
/**
37
 * @author pplitzner
38
 * @date 05.11.2013
39
 *
40
 */
41
public class FieldUnitGeneralDetailElement extends AbstractCdmDetailElement<DerivedUnitFacade> {
42

    
43
    private ToggleableTextElement toggleableText_titleCache;
44
    private EnumComboElement<SpecimenOrObservationType> combo_specorobstype;
45
    private EntitySelectionElement<NamedArea> selection_country;
46
    private CollectingAreasDetailSection section_collectingAreas;
47
    private LanguageStringWithLabelElement languageText_locality;
48
    private PointElement element_point;
49
    private NumberWithLabelElement number_elevation;
50
    private TimePeriodElement element_date;
51
    private EntitySelectionElement<AgentBase> selection_collector;
52
    private TextWithLabelElement text_collectingNumber;
53
    private GatheringEventUnitElement element_elevation;
54

    
55
    /**
56
     * @param formFactory
57
     * @param formElement
58
     */
59
    public FieldUnitGeneralDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
60
        super(formFactory, formElement);
61
    }
62

    
63
    /*
64
     * (non-Javadoc)
65
     *
66
     * @see
67
     * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
68
     * (eu.etaxonomy.taxeditor.forms.ICdmFormElement, java.lang.Object, int)
69
     */
70
    @Override
71
    protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
72
        toggleableText_titleCache = formFactory.createToggleableTextField(formElement, "Title Cache",
73
                entity.getTitleCache(), entity.isProtectedTitleCache(), style);
74

    
75
        combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement, style);
76
        combo_specorobstype.setSelection(entity.getType());
77
        selection_country = formFactory.createSelectionElement(NamedArea.class, getConversationHolder(), formElement,
78
                "Country", entity.getCountry(), EntitySelectionElement.NOTHING, style);
79
        if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION)){
80
            section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
81
            section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
82
            section_collectingAreas.setEntity(entity);
83
        }
84

    
85
        languageText_locality = formFactory.createLanguageStringWithLabelElement(formElement, "Locality",
86
                entity.getLocality(), style);
87
        element_point = formFactory.createPointElement(formElement, entity.getExactLocation(), style);
88
        element_elevation = formFactory.createGatheringEventUnitElement(
89
				formElement, "Elevation : ", entity, MinMaxTextSection.UnitType.ELEVATION,  style);
90

    
91
        element_date = formFactory.createTimePeriodElement(formElement, "Date", entity.getGatheringPeriod(), style);
92
        selection_collector = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), formElement,
93
                "Collector", entity.getCollector(), EntitySelectionElement.ALL, style);
94
        text_collectingNumber = formFactory.createTextWithLabelElement(formElement, "Collecting number",
95
                entity.getFieldNumber(), style);
96
    }
97

    
98
    /*
99
     * (non-Javadoc)
100
     *
101
     * @see
102
     * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
103
     * .lang.Object)
104
     */
105
    @Override
106
    public void handleEvent(Object eventSource) {
107
        if (eventSource == toggleableText_titleCache) {
108
            getEntity().setTitleCache(toggleableText_titleCache.getText(), toggleableText_titleCache.getState());
109
        } else if (eventSource == selection_country) {
110
            getEntity().setCountry(selection_country.getSelection());
111
        } else if (eventSource == languageText_locality) {
112
            LanguageString locality = languageText_locality.getLanguageString();
113
            getEntity().setLocality(locality);
114
        } else if (eventSource == element_point) {
115
            getEntity().setExactLocation(element_point.getPoint());
116
        } else if (eventSource == number_elevation) {
117
            getEntity().setAbsoluteElevation(number_elevation.getInteger());
118
        } else if (eventSource == element_date) {
119
            getEntity().setGatheringPeriod(element_date.getTimePeriod());
120
        } else if (eventSource == selection_collector) {
121
            getEntity().setCollector(selection_collector.getSelection());
122
        } else if (eventSource == text_collectingNumber) {
123
            getEntity().setFieldNumber(text_collectingNumber.getText());
124
        } else if (eventSource == combo_specorobstype) {
125
            getEntity().setType(combo_specorobstype.getSelection());
126
        }
127

    
128
        if (eventSource != toggleableText_titleCache) {
129
            toggleableText_titleCache.setText(getEntity().getTitleCache());
130
        }
131
    }
132
}
(22-22/34)