a2be5ed29e1f1417ad5bb9efae318074bb3b323a
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / DerivedUnitGeneralDetailElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 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
11 package eu.etaxonomy.taxeditor.ui.section.occurrence;
12
13 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
14 import eu.etaxonomy.cdm.model.agent.AgentBase;
15 import eu.etaxonomy.cdm.model.common.LanguageString;
16 import eu.etaxonomy.cdm.model.location.NamedArea;
17 import eu.etaxonomy.cdm.model.occurrence.Collection;
18 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
19 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
20 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
21 import eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement;
22 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
23 import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
24 import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection;
25 import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
26 import eu.etaxonomy.taxeditor.ui.element.PointElement;
27 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
28 import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
29 import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
30 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
31 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
32
33 /**
34 * @author n.hoffmann
35 * @created Dec 16, 2010
36 * @version 1.0
37 */
38 public class DerivedUnitGeneralDetailElement extends
39 AbstractCdmDetailElement<DerivedUnitFacade> {
40
41 private ToggleableTextElement toggleableText_titleCache;
42 private EnumComboElement<SpecimenOrObservationType> combo_specorobstype;
43 private EntitySelectionElement<NamedArea> selection_country;
44 private LanguageStringWithLabelElement languageText_locality;
45 private PointElement element_point;
46 private NumberWithLabelElement number_elevation;
47 private TimePeriodElement element_date;
48 private EntitySelectionElement<AgentBase> selection_collector;
49 private TextWithLabelElement text_collectingNumber;
50 private EntitySelectionElement<Collection> selection_collection;
51 private TextWithLabelElement text_accessionNumber;
52 private GatheringEventUnitElement element_elevation;
53
54
55
56 /**
57 * @param formFactory
58 * @param formElement
59 */
60 public DerivedUnitGeneralDetailElement(CdmFormFactory formFactory,
61 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,
74 DerivedUnitFacade entity, int style) {
75 toggleableText_titleCache = formFactory.createToggleableTextField(
76 formElement, "Title Cache", entity.getTitleCache(),
77 entity.isProtectedTitleCache(), style);
78
79 combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement, style);
80 combo_specorobstype.setSelection(entity.getType());
81 selection_country = formFactory.createSelectionElement(NamedArea.class, getConversationHolder(),
82 formElement, "Country",
83 entity.getCountry(), EntitySelectionElement.NOTHING, style);
84 languageText_locality = formFactory
85 .createLanguageStringWithLabelElement(formElement, "Locality",
86 entity.getLocality(), style);
87 element_point = formFactory.createPointElement(formElement,
88 entity.getExactLocation(), style);
89 element_elevation = formFactory.createGatheringEventUnitElement(
90 formElement, "Elevation : ", entity, MinMaxTextSection.UnitType.ELEVATION, style);
91
92 element_date = formFactory.createTimePeriodElement(formElement, "Date",
93 entity.getGatheringPeriod(), style);
94 selection_collector = formFactory
95 .createSelectionElement(AgentBase.class,
96 getConversationHolder(), formElement, "Collector",
97 entity.getCollector(), EntitySelectionElement.ALL,
98 style);
99 text_collectingNumber = formFactory.createTextWithLabelElement(formElement,
100 "Collecting number", entity.getFieldNumber(), style);
101 selection_collection = formFactory
102 .createSelectionElement(Collection.class,
103 getConversationHolder(), formElement, "Collection",
104 entity.getCollection(),
105 EntitySelectionElement.ALL, style);
106 text_accessionNumber = formFactory.createTextWithLabelElement(
107 formElement, "Accession Number", entity.getAccessionNumber(),
108 style);
109
110 }
111
112 /*
113 * (non-Javadoc)
114 *
115 * @see
116 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
117 * .lang.Object)
118 */
119 @Override
120 public void handleEvent(Object eventSource) {
121 if (eventSource == toggleableText_titleCache) {
122 getEntity().setTitleCache(toggleableText_titleCache.getText(),
123 toggleableText_titleCache.getState());
124 } else if (eventSource == selection_country) {
125 getEntity().setCountry(selection_country.getSelection());
126 } else if (eventSource == languageText_locality) {
127 LanguageString locality = languageText_locality.getLanguageString();
128 getEntity().setLocality(locality);
129 } else if (eventSource == element_point) {
130 getEntity().setExactLocation(element_point.getPoint());
131 } else if (eventSource == number_elevation) {
132 getEntity().setAbsoluteElevation(number_elevation.getInteger());
133 } else if (eventSource == element_date) {
134 getEntity().setGatheringPeriod(element_date.getTimePeriod());
135 } else if (eventSource == selection_collector) {
136 getEntity().setCollector(selection_collector.getSelection());
137 } else if (eventSource == text_collectingNumber) {
138 getEntity().setFieldNumber(text_collectingNumber.getText());
139 }
140 else if (eventSource == selection_collection) {
141 getEntity().setCollection(selection_collection.getSelection());
142 } else if (eventSource == text_accessionNumber) {
143 getEntity().setAccessionNumber(text_accessionNumber.getText());
144 } else if (eventSource == combo_specorobstype) {
145 getEntity().setType(combo_specorobstype.getSelection());
146 }
147
148 if (eventSource != toggleableText_titleCache) {
149 toggleableText_titleCache.setText(getEntity().getTitleCache());
150 }
151 }
152
153 }