Fixes #2361
[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.CdmPropertyChangeEvent;
17 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
18 import eu.etaxonomy.taxeditor.ui.forms.LanguageStringWithLabelElement;
19 import eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement;
20 import eu.etaxonomy.taxeditor.ui.forms.PointElement;
21 import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
22 import eu.etaxonomy.taxeditor.ui.forms.TimePeriodElement;
23 import eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement;
24 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
25 import eu.etaxonomy.taxeditor.ui.selection.AgentSelectionElement;
26 import eu.etaxonomy.taxeditor.ui.selection.CollectionSelectionElement;
27 import eu.etaxonomy.taxeditor.ui.selection.NamedAreaSelectionElement;
28
29 /**
30 * @author n.hoffmann
31 * @created Dec 16, 2010
32 * @version 1.0
33 */
34 public class GeneralDetailElement extends
35 AbstractCdmDetailElement<DerivedUnitFacade> {
36
37 private ToggleableTextElement toggleableText_titleCache;
38
39 private NamedAreaSelectionElement selection_country;
40 private LanguageStringWithLabelElement languageText_locality;
41 private PointElement element_point;
42 private NumberWithLabelElement number_elevation;
43 private TimePeriodElement element_date;
44 private AgentSelectionElement selection_collector;
45 private TextWithLabelElement text_collectingNumber;
46 private CollectionSelectionElement selection_collection;
47 private TextWithLabelElement text_barcode;
48
49 /**
50 * @param formFactory
51 * @param formElement
52 */
53 public GeneralDetailElement(CdmFormFactory formFactory,
54 ICdmFormElement formElement) {
55 super(formFactory, formElement);
56 }
57
58 /*
59 * (non-Javadoc)
60 *
61 * @see
62 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
63 * (eu.etaxonomy.taxeditor.forms.ICdmFormElement, java.lang.Object, int)
64 */
65 @Override
66 protected void createControls(ICdmFormElement formElement,
67 DerivedUnitFacade entity, int style) {
68 toggleableText_titleCache = formFactory.createToggleableTextField(
69 formElement, "Title Cache", entity.getTitleCache(),
70 entity.isProtectedTitleCache(), style);
71
72 selection_country = formFactory.createNamedAreaSelectionElement(
73 formElement, getConversationHolder(), "Country",
74 entity.getCountry(), style);
75 languageText_locality = formFactory
76 .createLanguageStringWithLabelElement(formElement, "Locality",
77 entity.getLocality(), style);
78 element_point = formFactory.createPointElement(formElement,
79 entity.getExactLocation(), style);
80 number_elevation = formFactory.createIntegerTextWithLabelElement(
81 formElement, "Absolute Elevation (m)",
82 entity.getAbsoluteElevation(), style);
83 element_date = formFactory.createTimePeriodElement(formElement, "Date",
84 entity.getGatheringPeriod(), style);
85 selection_collector = (AgentSelectionElement) formFactory
86 .createSelectionElement(SelectionType.AGENT,
87 getConversationHolder(), formElement, "Collector",
88 entity.getCollector(), AgentSelectionElement.DEFAULT,
89 style);
90 text_collectingNumber = formFactory.createTextWithLabelElement(formElement,
91 "Collecting number", entity.getFieldNumber(), style);
92 selection_collection = (CollectionSelectionElement) formFactory
93 .createSelectionElement(SelectionType.COLLECTION,
94 getConversationHolder(), formElement, "Collection",
95 entity.getCollection(),
96 CollectionSelectionElement.DEFAULT, style);
97 text_barcode = formFactory.createTextWithLabelElement(formElement,
98 "Barcode", entity.getBarcode(), 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(),
112 toggleableText_titleCache.getState());
113 } else if (eventSource == selection_country) {
114 getEntity().setCountry(selection_country.getSelection());
115 } else if (eventSource == languageText_locality) {
116 getEntity().setLocality(languageText_locality.getLanguageString());
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 == selection_collection) {
128 getEntity().setCollection(selection_collection.getSelection());
129 } else if (eventSource == text_barcode) {
130 getEntity().setBarcode(text_barcode.getText());
131 }
132
133 if (eventSource != toggleableText_titleCache) {
134 toggleableText_titleCache.setText(getEntity().getTitleCache());
135 }
136 firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
137 }
138
139 }