merge-update from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / FieldUnitGeneralDetailElement.java
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 eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
13 import eu.etaxonomy.cdm.model.agent.AgentBase;
14 import eu.etaxonomy.cdm.model.common.LanguageString;
15 import eu.etaxonomy.cdm.model.location.NamedArea;
16 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
17 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
18 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
19 import eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement;
20 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21 import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
22 import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection;
23 import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
24 import eu.etaxonomy.taxeditor.ui.element.PointElement;
25 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
26 import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
27 import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
28 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
29 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
30
31 /**
32 * @author pplitzner
33 * @date 05.11.2013
34 *
35 */
36 public class FieldUnitGeneralDetailElement extends AbstractCdmDetailElement<DerivedUnitFacade> {
37
38 private ToggleableTextElement toggleableText_titleCache;
39 private EnumComboElement<SpecimenOrObservationType> combo_specorobstype;
40 private EntitySelectionElement<NamedArea> selection_country;
41 private LanguageStringWithLabelElement languageText_locality;
42 private PointElement element_point;
43 private NumberWithLabelElement number_elevation;
44 private TimePeriodElement element_date;
45 private EntitySelectionElement<AgentBase> selection_collector;
46 private TextWithLabelElement text_collectingNumber;
47 private GatheringEventUnitElement element_elevation;
48
49 /**
50 * @param formFactory
51 * @param formElement
52 */
53 public FieldUnitGeneralDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
54 super(formFactory, formElement);
55 }
56
57 /*
58 * (non-Javadoc)
59 *
60 * @see
61 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
62 * (eu.etaxonomy.taxeditor.forms.ICdmFormElement, java.lang.Object, int)
63 */
64 @Override
65 protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
66 toggleableText_titleCache = formFactory.createToggleableTextField(formElement, "Title Cache",
67 entity.getTitleCache(), entity.isProtectedTitleCache(), style);
68
69 combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement, style);
70 combo_specorobstype.setSelection(entity.getType());
71 selection_country = formFactory.createSelectionElement(NamedArea.class, getConversationHolder(), formElement,
72 "Country", entity.getCountry(), EntitySelectionElement.NOTHING, style);
73 languageText_locality = formFactory.createLanguageStringWithLabelElement(formElement, "Locality",
74 entity.getLocality(), style);
75 element_point = formFactory.createPointElement(formElement, entity.getExactLocation(), style);
76 element_elevation = formFactory.createGatheringEventUnitElement(
77 formElement, "Elevation : ", entity, MinMaxTextSection.UnitType.ELEVATION, style);
78
79 element_date = formFactory.createTimePeriodElement(formElement, "Date", entity.getGatheringPeriod(), style);
80 selection_collector = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), formElement,
81 "Collector", entity.getCollector(), EntitySelectionElement.ALL, style);
82 text_collectingNumber = formFactory.createTextWithLabelElement(formElement, "Collecting number",
83 entity.getFieldNumber(), style);
84 }
85
86 /*
87 * (non-Javadoc)
88 *
89 * @see
90 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
91 * .lang.Object)
92 */
93 @Override
94 public void handleEvent(Object eventSource) {
95 if (eventSource == toggleableText_titleCache) {
96 getEntity().setTitleCache(toggleableText_titleCache.getText(), toggleableText_titleCache.getState());
97 } else if (eventSource == selection_country) {
98 getEntity().setCountry(selection_country.getSelection());
99 } else if (eventSource == languageText_locality) {
100 LanguageString locality = languageText_locality.getLanguageString();
101 getEntity().setLocality(locality);
102 } else if (eventSource == element_point) {
103 getEntity().setExactLocation(element_point.getPoint());
104 } else if (eventSource == number_elevation) {
105 getEntity().setAbsoluteElevation(number_elevation.getInteger());
106 } else if (eventSource == element_date) {
107 getEntity().setGatheringPeriod(element_date.getTimePeriod());
108 } else if (eventSource == selection_collector) {
109 getEntity().setCollector(selection_collector.getSelection());
110 } else if (eventSource == text_collectingNumber) {
111 getEntity().setFieldNumber(text_collectingNumber.getText());
112 } else if (eventSource == combo_specorobstype) {
113 getEntity().setType(combo_specorobstype.getSelection());
114 }
115
116 if (eventSource != toggleableText_titleCache) {
117 toggleableText_titleCache.setText(getEntity().getTitleCache());
118 }
119 }
120 }