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