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