Project

General

Profile

Download (6.73 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.CheckboxElement;
24
import eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement;
25
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
27
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
28
import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection;
29
import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
30
import eu.etaxonomy.taxeditor.ui.element.PointElement;
31
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
32
import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
33
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
34
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
35
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
36

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

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

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

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

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

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

    
93
        element_date = formFactory.createTimePeriodElement(formElement, "Date", entity.getGatheringPeriod(), style);
94
        selection_collector = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), formElement,
95
                "Collector", entity.getCollector(), EntitySelectionElement.ALL, style);
96
        text_collectingNumber = formFactory.createTextWithLabelElement(formElement, "Collecting number",
97
                entity.getFieldNumber(), style);
98
        checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.isPublish(), style);
99
    }
100

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

    
133
        if (eventSource != toggleableText_titleCache) {
134
            toggleableText_titleCache.setText(getEntity().getTitleCache());
135
        }
136
    }
137
}
(20-20/36)