f358256bdb59cc78ef1ad0809dc3c64c66e3761a
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / GeneralDetailElement.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.taxeditor.ui.forms.CdmFormFactory;
15 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType;
16 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
17 import eu.etaxonomy.taxeditor.ui.forms.LanguageStringWithLabelElement;
18 import eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement;
19 import eu.etaxonomy.taxeditor.ui.forms.PointElement;
20 import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
21 import eu.etaxonomy.taxeditor.ui.forms.TimePeriodElement;
22 import eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement;
23 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
24 import eu.etaxonomy.taxeditor.ui.selection.AgentSelectionElement;
25 import eu.etaxonomy.taxeditor.ui.selection.CollectionSelectionElement;
26 import eu.etaxonomy.taxeditor.ui.selection.NamedAreaSelectionElement;
27
28 /**
29 * @author n.hoffmann
30 * @created Dec 16, 2010
31 * @version 1.0
32 */
33 public class GeneralDetailElement extends
34 AbstractCdmDetailElement<DerivedUnitFacade> {
35
36 private ToggleableTextElement toggleableText_titleCache;
37
38 private NamedAreaSelectionElement selection_country;
39 private LanguageStringWithLabelElement languageText_locality;
40 private PointElement element_point;
41 private NumberWithLabelElement number_elevation;
42 private TimePeriodElement element_date;
43 private AgentSelectionElement selection_collector;
44 private TextWithLabelElement text_fieldNumber;
45 private CollectionSelectionElement selection_collection;
46 private TextWithLabelElement text_barcode;
47
48 /**
49 * @param formFactory
50 * @param formElement
51 */
52 public GeneralDetailElement(CdmFormFactory formFactory,
53 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,
66 DerivedUnitFacade entity, int style) {
67 toggleableText_titleCache = formFactory.createToggleableTextField(
68 formElement, "Title Cache", entity.getTitleCache(),
69 entity.isProtectedTitleCache(), style);
70
71 selection_country = formFactory.createNamedAreaSelectionElement(
72 formElement, getConversationHolder(), "Country",
73 entity.getCountry(), style);
74 languageText_locality = formFactory
75 .createLanguageStringWithLabelElement(formElement, "Locality",
76 entity.getLocality(), style);
77 element_point = formFactory.createPointElement(formElement,
78 entity.getExactLocation(), style);
79 number_elevation = formFactory.createIntegerTextWithLabelElement(
80 formElement, "Absolute Elevation (m)",
81 entity.getAbsoluteElevation(), style);
82 element_date = formFactory.createTimePeriodElement(formElement, "Date",
83 entity.getGatheringPeriod(), style);
84 selection_collector = (AgentSelectionElement) formFactory
85 .createSelectionElement(SelectionType.AGENT,
86 getConversationHolder(), formElement, "Collector",
87 entity.getCollector(), AgentSelectionElement.DEFAULT,
88 style);
89 text_fieldNumber = formFactory.createTextWithLabelElement(formElement,
90 "Field Number", entity.getFieldNumber(), style);
91 selection_collection = (CollectionSelectionElement) formFactory
92 .createSelectionElement(SelectionType.COLLECTION,
93 getConversationHolder(), formElement, "Collection",
94 entity.getCollection(),
95 CollectionSelectionElement.DEFAULT, style);
96 text_barcode = formFactory.createTextWithLabelElement(formElement,
97 "Barcode", entity.getBarcode(), style);
98 }
99
100 /*
101 * (non-Javadoc)
102 *
103 * @see
104 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
105 * .lang.Object)
106 */
107 @Override
108 public void handleEvent(Object eventSource) {
109 if (eventSource == toggleableText_titleCache) {
110 getEntity().setTitleCache(toggleableText_titleCache.getText(),
111 toggleableText_titleCache.getState());
112 } else if (eventSource == selection_country) {
113 getEntity().setCountry(selection_country.getSelection());
114 } else if (eventSource == languageText_locality) {
115 getEntity().setLocality(languageText_locality.getLanguageString());
116 } else if (eventSource == element_point) {
117 getEntity().setExactLocation(element_point.getPoint());
118 } else if (eventSource == number_elevation) {
119 getEntity().setAbsoluteElevation(number_elevation.getInteger());
120 } else if (eventSource == element_date) {
121 getEntity().setGatheringPeriod(element_date.getTimePeriod());
122 } else if (eventSource == selection_collector) {
123 getEntity().setCollector(selection_collector.getSelection());
124 } else if (eventSource == text_fieldNumber) {
125 getEntity().setFieldNumber(text_fieldNumber.getText());
126 } else if (eventSource == selection_collection) {
127 getEntity().setCollection(selection_collection.getSelection());
128 } else if (eventSource == text_barcode) {
129 getEntity().setBarcode(text_barcode.getText());
130 }
131
132 if (eventSource != toggleableText_titleCache) {
133 toggleableText_titleCache.setText(getEntity().getTitleCache());
134 }
135 }
136
137 }