adaption for error handling of delete methods
[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 combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement, style);
69 combo_specorobstype.setSelection(entity.getType());
70 selection_country = formFactory.createSelectionElement(NamedArea.class, getConversationHolder(), formElement,
71 "Country", entity.getCountry(), EntitySelectionElement.NOTHING, style);
72 languageText_locality = formFactory.createLanguageStringWithLabelElement(formElement, "Locality",
73 entity.getLocality(), style);
74 element_point = formFactory.createPointElement(formElement, entity.getExactLocation(), style);
75 element_elevation = formFactory.createGatheringEventUnitElement(
76 formElement, "Elevation : ", entity, MinMaxTextSection.UnitType.ELEVATION, style);
77
78 element_date = formFactory.createTimePeriodElement(formElement, "Date", entity.getGatheringPeriod(), style);
79 selection_collector = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), formElement,
80 "Collector", entity.getCollector(), EntitySelectionElement.ALL, style);
81 text_collectingNumber = formFactory.createTextWithLabelElement(formElement, "Collecting number",
82 entity.getFieldNumber(), style);
83 }
84
85 /*
86 * (non-Javadoc)
87 *
88 * @see
89 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
90 * .lang.Object)
91 */
92 @Override
93 public void handleEvent(Object eventSource) {
94 if (eventSource == toggleableText_titleCache) {
95 getEntity().setTitleCache(toggleableText_titleCache.getText(), toggleableText_titleCache.getState());
96 } else if (eventSource == selection_country) {
97 getEntity().setCountry(selection_country.getSelection());
98 } else if (eventSource == languageText_locality) {
99 LanguageString locality = languageText_locality.getLanguageString();
100 getEntity().setLocality(locality);
101 } else if (eventSource == element_point) {
102 getEntity().setExactLocation(element_point.getPoint());
103 } else if (eventSource == number_elevation) {
104 getEntity().setAbsoluteElevation(number_elevation.getInteger());
105 } else if (eventSource == element_date) {
106 getEntity().setGatheringPeriod(element_date.getTimePeriod());
107 } else if (eventSource == selection_collector) {
108 getEntity().setCollector(selection_collector.getSelection());
109 } else if (eventSource == text_collectingNumber) {
110 getEntity().setFieldNumber(text_collectingNumber.getText());
111 } else if (eventSource == combo_specorobstype) {
112 getEntity().setType(combo_specorobstype.getSelection());
113 }
114
115 if (eventSource != toggleableText_titleCache) {
116 toggleableText_titleCache.setText(getEntity().getTitleCache());
117 }
118 }
119 }