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