Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / FieldUnitGeneralDetailElement.java
1 /**
2 * Copyright (C) 2013 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.ui.section.occurrence;
10
11 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
12 import eu.etaxonomy.cdm.model.agent.AgentBase;
13 import eu.etaxonomy.cdm.model.common.LanguageString;
14 import eu.etaxonomy.cdm.model.location.NamedArea;
15 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
16 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
17 import eu.etaxonomy.taxeditor.store.StoreUtil;
18 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
19 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
21 import eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement;
22 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
23 import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
24 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
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 pplitzner
36 * @date 05.11.2013
37 */
38 public class FieldUnitGeneralDetailElement extends AbstractCdmDetailElement<DerivedUnitFacade> {
39
40 private ToggleableTextElement toggleableText_titleCache;
41 private EnumComboElement<SpecimenOrObservationType> combo_specorobstype;
42 private EntitySelectionElement<NamedArea> selection_country;
43 private CollectingAreasDetailSection section_collectingAreas;
44 private LanguageStringWithLabelElement languageText_locality;
45 private PointElement element_point;
46 private NumberWithLabelElement number_elevation;
47 private TimePeriodElement element_date;
48 private EntitySelectionElement<AgentBase> selection_collector;
49 private TextWithLabelElement text_collectingNumber;
50 private GatheringEventUnitElement element_elevation;
51 private CheckboxElement checkIsPublish;
52
53 public FieldUnitGeneralDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
54 super(formFactory, formElement);
55 }
56
57 @Override
58 protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
59 toggleableText_titleCache = formFactory.createToggleableTextField(formElement, "Title Cache",
60 entity.getTitleCache(), entity.isProtectedTitleCache(), style);
61
62 combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement, style);
63 combo_specorobstype.setSelection(entity.getType());
64 selection_country = formFactory.createSelectionElement(NamedArea.class, //getConversationHolder(),
65 formElement, "Country", entity.getCountry(), EntitySelectionElement.DELETABLE, style);
66 if(PreferencesUtil.isCollectingAreaInGeneralSection()){
67 section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(CollectingAreasDetailSection.class, entity.getClass().getCanonicalName()));
68 section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
69 section_collectingAreas.setEntity(entity);
70 }
71
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(),
80 formElement, "Collector", entity.getCollector(), EntitySelectionElement.ALL, style);
81 text_collectingNumber = formFactory.createTextWithLabelElement(formElement, "Collecting number",
82 entity.getFieldNumber(), style);
83 checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.isPublish(), style);
84 }
85
86 @Override
87 public void handleEvent(Object eventSource) {
88 if (eventSource == toggleableText_titleCache) {
89 getEntity().setTitleCache(toggleableText_titleCache.getText(), toggleableText_titleCache.getState());
90 } else if (eventSource == selection_country) {
91 getEntity().setCountry(selection_country.getSelection());
92 } else if (eventSource == languageText_locality) {
93 LanguageString locality = languageText_locality.updateLanguageString(getEntity().getLocality());
94 getEntity().setLocality(locality);
95 } else if (eventSource == element_point) {
96 getEntity().setExactLocation(element_point.getPoint());
97 } else if (eventSource == number_elevation) {
98 getEntity().setAbsoluteElevation(number_elevation.getInteger());
99 } else if (eventSource == element_date) {
100 getEntity().setGatheringPeriod(element_date.getTimePeriod());
101 } else if (eventSource == selection_collector) {
102 getEntity().setCollector(selection_collector.getSelection());
103 } else if (eventSource == text_collectingNumber) {
104 getEntity().setFieldNumber(text_collectingNumber.getText());
105 } else if (eventSource == combo_specorobstype) {
106 getEntity().setType(combo_specorobstype.getSelection());
107 } else if (eventSource == checkIsPublish) {
108 getEntity().innerFieldUnit().setPublish(checkIsPublish.getSelection());
109 }
110
111 if (eventSource != toggleableText_titleCache) {
112 toggleableText_titleCache.setText(getEntity().getTitleCache());
113 }
114 }
115 }