ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / DerivedUnitGeneralDetailElement.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.ui.section.occurrence;
11
12 import org.eclipse.ui.forms.widgets.ExpandableComposite;
13
14 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
15 import eu.etaxonomy.cdm.model.agent.AgentBase;
16 import eu.etaxonomy.cdm.model.common.LanguageString;
17 import eu.etaxonomy.cdm.model.location.NamedArea;
18 import eu.etaxonomy.cdm.model.occurrence.Collection;
19 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
20 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
21 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
22 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
23 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
25 import eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement;
26 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
27 import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
28 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
29 import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection;
30 import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
31 import eu.etaxonomy.taxeditor.ui.element.PointElement;
32 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
33 import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
34 import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
35 import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
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 UriWithLabelElement uriPreferredStableUri;
65 private CheckboxElement checkIsPublish;
66
67
68 public DerivedUnitGeneralDetailElement(CdmFormFactory formFactory,
69 ICdmFormElement formElement) {
70 super(formFactory, formElement);
71 }
72
73 @Override
74 protected void createControls(ICdmFormElement formElement,
75 DerivedUnitFacade entity, int style) {
76 toggleableText_titleCache = formFactory.createToggleableTextField(
77 formElement, "Title Cache", entity.getTitleCache(),
78 entity.isProtectedTitleCache(), style);
79 //TODO for DerivateEditor do not use facade anymore to avoid this special case handling #4539
80 if(showOnlyDerivedUnitData){
81 toggleableText_titleCache.setEnabled(false);
82 }
83 else{
84 combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement, style);
85 combo_specorobstype.setSelection(entity.getType());
86 combo_specorobstype.setEnabled(showSpecimenType);
87 selection_country = formFactory.createSelectionElement(NamedArea.class, getConversationHolder(),
88 formElement, "Country",
89 entity.getCountry(), EntitySelectionElement.NOTHING, style);
90
91 if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_COLLECTING_AREAS_IN_GENERAL_SECTION)){
92 section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, ExpandableComposite.TWISTIE);
93 section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
94 section_collectingAreas.setEntity(entity);
95 }
96 languageText_locality = formFactory
97 .createLanguageStringWithLabelElement(formElement, "Locality",
98 entity.getLocality(), style);
99 element_point = formFactory.createPointElement(formElement,
100 entity.getExactLocation(), style);
101 element_elevation = formFactory.createGatheringEventUnitElement(
102 formElement, "Elevation : ", entity, MinMaxTextSection.UnitType.ELEVATION, style);
103
104 element_date = formFactory.createTimePeriodElement(formElement, "Date",
105 entity.getGatheringPeriod(), style);
106 selection_collector = formFactory
107 .createSelectionElement(AgentBase.class,
108 getConversationHolder(), formElement, "Collector",
109 entity.getCollector(), EntitySelectionElement.ALL,
110 style);
111 text_collectingNumber = formFactory.createTextWithLabelElement(formElement,
112 "Collecting number", entity.getFieldNumber(), style);
113 }
114 selection_collection = formFactory
115 .createSelectionElement(Collection.class,
116 getConversationHolder(), formElement, "Collection",
117 entity.getCollection(),
118 EntitySelectionElement.ALL, style);
119 text_accessionNumber = formFactory.createTextWithLabelElement(
120 formElement, "Accession Number", entity.getAccessionNumber(),
121 style);
122 uriPreferredStableUri = formFactory.createUriWithLabelElement(formElement, "Pref. Stable URI", entity.getPreferredStableUri(), style);
123 checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.isPublish(), style);
124
125 }
126
127 @Override
128 public void handleEvent(Object eventSource) {
129 if (eventSource == toggleableText_titleCache) {
130 getEntity().setTitleCache(toggleableText_titleCache.getText(),
131 toggleableText_titleCache.getState());
132 } else if (eventSource == selection_country) {
133 getEntity().setCountry(selection_country.getSelection());
134 } else if (eventSource == languageText_locality) {
135 LanguageString locality = languageText_locality.getLanguageString();
136 getEntity().setLocality(locality);
137 } else if (eventSource == element_point) {
138 getEntity().setExactLocation(element_point.getPoint());
139 } else if (eventSource == number_elevation) {
140 getEntity().setAbsoluteElevation(number_elevation.getInteger());
141 } else if (eventSource == element_date) {
142 getEntity().setGatheringPeriod(element_date.getTimePeriod());
143 } else if (eventSource == selection_collector) {
144 getEntity().setCollector(selection_collector.getSelection());
145 } else if (eventSource == text_collectingNumber) {
146 getEntity().setFieldNumber(text_collectingNumber.getText());
147 }
148 else if (eventSource == selection_collection) {
149 getEntity().setCollection(selection_collection.getSelection());
150 } else if (eventSource == text_accessionNumber) {
151 getEntity().setAccessionNumber(text_accessionNumber.getText());
152 } else if (eventSource == combo_specorobstype) {
153 getEntity().setType(combo_specorobstype.getSelection());
154 } else if (eventSource == uriPreferredStableUri) {
155 getEntity().setPreferredStableUri(uriPreferredStableUri.parseText());
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 }