Merge branch 'develop' into LibrAlign
[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 org.eclipse.ui.forms.widgets.ExpandableComposite;
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.SpecimenOrObservationType;
18 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
19 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
21 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
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.LayoutConstants;
27 import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection;
28 import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
29 import eu.etaxonomy.taxeditor.ui.element.PointElement;
30 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
31 import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
32 import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
33 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
34 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
35
36 /**
37 * @author pplitzner
38 * @date 05.11.2013
39 *
40 */
41 public class FieldUnitGeneralDetailElement extends AbstractCdmDetailElement<DerivedUnitFacade> {
42
43 private ToggleableTextElement toggleableText_titleCache;
44 private EnumComboElement<SpecimenOrObservationType> combo_specorobstype;
45 private EntitySelectionElement<NamedArea> selection_country;
46 private CollectingAreasDetailSection section_collectingAreas;
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 GatheringEventUnitElement element_elevation;
54 private CheckboxElement checkIsPublish;
55
56 /**
57 * @param formFactory
58 * @param formElement
59 */
60 public FieldUnitGeneralDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
61 super(formFactory, formElement);
62 }
63
64 /*
65 * (non-Javadoc)
66 *
67 * @see
68 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#createControls
69 * (eu.etaxonomy.taxeditor.forms.ICdmFormElement, java.lang.Object, int)
70 */
71 @Override
72 protected void createControls(ICdmFormElement formElement, DerivedUnitFacade entity, int style) {
73 toggleableText_titleCache = formFactory.createToggleableTextField(formElement, "Title Cache",
74 entity.getTitleCache(), entity.isProtectedTitleCache(), style);
75
76 combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement, style);
77 combo_specorobstype.setSelection(entity.getType());
78 selection_country = formFactory.createSelectionElement(NamedArea.class, getConversationHolder(), formElement,
79 "Country", entity.getCountry(), EntitySelectionElement.NOTHING, style);
80 if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION)){
81 section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
82 section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
83 section_collectingAreas.setEntity(entity);
84 }
85
86 languageText_locality = formFactory.createLanguageStringWithLabelElement(formElement, "Locality",
87 entity.getLocality(), style);
88 element_point = formFactory.createPointElement(formElement, entity.getExactLocation(), style);
89 element_elevation = formFactory.createGatheringEventUnitElement(
90 formElement, "Elevation : ", entity, MinMaxTextSection.UnitType.ELEVATION, style);
91
92 element_date = formFactory.createTimePeriodElement(formElement, "Date", entity.getGatheringPeriod(), style);
93 selection_collector = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), formElement,
94 "Collector", entity.getCollector(), EntitySelectionElement.ALL, style);
95 text_collectingNumber = formFactory.createTextWithLabelElement(formElement, "Collecting number",
96 entity.getFieldNumber(), style);
97 checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.isPublish(), style);
98 }
99
100 /*
101 * (non-Javadoc)
102 *
103 * @see
104 * eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement#handleEvent(java
105 * .lang.Object)
106 */
107 @Override
108 public void handleEvent(Object eventSource) {
109 if (eventSource == toggleableText_titleCache) {
110 getEntity().setTitleCache(toggleableText_titleCache.getText(), toggleableText_titleCache.getState());
111 } else if (eventSource == selection_country) {
112 getEntity().setCountry(selection_country.getSelection());
113 } else if (eventSource == languageText_locality) {
114 LanguageString locality = languageText_locality.updateLanguageString(getEntity().getLocality());
115 getEntity().setLocality(locality);
116 } else if (eventSource == element_point) {
117 getEntity().setExactLocation(element_point.getPoint());
118 } else if (eventSource == number_elevation) {
119 getEntity().setAbsoluteElevation(number_elevation.getInteger());
120 } else if (eventSource == element_date) {
121 getEntity().setGatheringPeriod(element_date.getTimePeriod());
122 } else if (eventSource == selection_collector) {
123 getEntity().setCollector(selection_collector.getSelection());
124 } else if (eventSource == text_collectingNumber) {
125 getEntity().setFieldNumber(text_collectingNumber.getText());
126 } else if (eventSource == combo_specorobstype) {
127 getEntity().setType(combo_specorobstype.getSelection());
128 } else if (eventSource == checkIsPublish) {
129 getEntity().innerFieldUnit().setPublish(checkIsPublish.getSelection());
130 }
131
132 if (eventSource != toggleableText_titleCache) {
133 toggleableText_titleCache.setText(getEntity().getTitleCache());
134 }
135 }
136 }