Project

General

Profile

Download (7.93 KB) Statistics
| Branch: | Tag: | Revision:
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 eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
13
import eu.etaxonomy.cdm.model.agent.AgentBase;
14
import eu.etaxonomy.cdm.model.common.LanguageString;
15
import eu.etaxonomy.cdm.model.location.NamedArea;
16
import eu.etaxonomy.cdm.model.occurrence.Collection;
17
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
18
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
19
import eu.etaxonomy.taxeditor.store.StoreUtil;
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.element.UriWithLabelElement;
34
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
35
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
36

    
37
/**
38
 * @author n.hoffmann
39
 * @created Dec 16, 2010
40
 * @version 1.0
41
 */
42
public class DerivedUnitGeneralDetailElement extends
43
		AbstractCdmDetailElement<DerivedUnitFacade> {
44

    
45
    boolean showOnlyDerivedUnitData = false;
46
    //TODO: flag to disable specimen type dropdown (#5244)
47
    boolean showSpecimenType = true;
48

    
49
	private ToggleableTextElement toggleableText_titleCache;
50
	private EnumComboElement<SpecimenOrObservationType> combo_specorobstype;
51
	private EntitySelectionElement<NamedArea> selection_country;
52
    private CollectingAreasDetailSection section_collectingAreas;
53
	private LanguageStringWithLabelElement languageText_locality;
54
	private PointElement element_point;
55
	private NumberWithLabelElement number_elevation;
56
	private TimePeriodElement element_date;
57
	private EntitySelectionElement<AgentBase> selection_collector;
58
	private TextWithLabelElement text_collectingNumber;
59
	private EntitySelectionElement<Collection> selection_collection;
60
	private TextWithLabelElement text_accessionNumber;
61
	private GatheringEventUnitElement element_elevation;
62
	private UriWithLabelElement uriPreferredStableUri;
63
	private CheckboxElement checkIsPublish;
64

    
65

    
66
	public DerivedUnitGeneralDetailElement(CdmFormFactory formFactory,
67
			ICdmFormElement formElement) {
68
	    super(formFactory, formElement);
69
	}
70

    
71
	@Override
72
	protected void createControls(ICdmFormElement formElement,
73
			DerivedUnitFacade entity, int style) {
74
		toggleableText_titleCache = formFactory.createToggleableTextField(
75
				formElement, "Title Cache", entity.getTitleCache(),
76
				entity.isProtectedTitleCache(), style);
77
        //TODO for DerivateEditor do not use facade anymore to avoid this special case handling #4539
78
		if(showOnlyDerivedUnitData){
79
		    toggleableText_titleCache.setEnabled(false);
80
		}
81
		else{
82
		    combo_specorobstype = formFactory.createEnumComboElement(SpecimenOrObservationType.class, formElement, style);
83
		    combo_specorobstype.setSelection(entity.getType());
84
		    combo_specorobstype.setEnabled(showSpecimenType);
85
		    selection_country = formFactory.createSelectionElement(NamedArea.class, //getConversationHolder(),
86
		            formElement, "Country",
87
		            entity.getCountry(), EntitySelectionElement.DELETABLE, style);
88

    
89
	        if(PreferencesUtil.isCollectingAreaInGeneralSection()){
90
	            section_collectingAreas = formFactory.createCollectingAreasDetailSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(CollectingAreasDetailSection.class, entity.getClass().getCanonicalName()));
91
	            section_collectingAreas.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
92
	            section_collectingAreas.setEntity(entity);
93
	        }
94
		    languageText_locality = formFactory
95
		            .createLanguageStringWithLabelElement(formElement, "Locality",
96
		                    entity.getLocality(), style);
97
		    element_point = formFactory.createPointElement(formElement,
98
		            entity.getExactLocation(), style);
99
		    element_elevation = formFactory.createGatheringEventUnitElement(
100
		            formElement, "Elevation : ", entity, MinMaxTextSection.UnitType.ELEVATION,  style);
101

    
102
		    element_date = formFactory.createTimePeriodElement(formElement, "Date",
103
		            entity.getGatheringPeriod(), style);
104
		    selection_collector = formFactory
105
		            .createSelectionElement(AgentBase.class,//getConversationHolder(),
106
		                    formElement, "Collector",
107
		                    entity.getCollector(), EntitySelectionElement.ALL,
108
		                    style);
109
		    text_collectingNumber = formFactory.createTextWithLabelElement(formElement,
110
		            "Collecting number", entity.getFieldNumber(), style);
111
		}
112
		selection_collection = formFactory
113
				.createSelectionElement(Collection.class,//getConversationHolder(),
114
				        formElement, "Collection",
115
						entity.getCollection(),
116
						EntitySelectionElement.ALL, style);
117
		text_accessionNumber = formFactory.createTextWithLabelElement(
118
				formElement, "Accession Number", entity.getAccessionNumber(),
119
				style);
120
		uriPreferredStableUri = formFactory.createUriWithLabelElement(formElement, "Pref. Stable URI", entity.getPreferredStableUri(), style);
121
        checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.isPublish(), style);
122

    
123
	}
124

    
125
	@Override
126
	public void handleEvent(Object eventSource) {
127
		if (eventSource == toggleableText_titleCache) {
128
			getEntity().setTitleCache(toggleableText_titleCache.getText(),
129
					toggleableText_titleCache.getState());
130
		} else if (eventSource == selection_country) {
131
			getEntity().setCountry(selection_country.getSelection());
132
		} else if (eventSource == languageText_locality) {
133
			LanguageString locality = languageText_locality.getLanguageString();
134
			getEntity().setLocality(locality);
135
		} else if (eventSource == element_point) {
136
			getEntity().setExactLocation(element_point.getPoint());
137
		} else if (eventSource == number_elevation) {
138
			getEntity().setAbsoluteElevation(number_elevation.getInteger());
139
		} else if (eventSource == element_date) {
140
			getEntity().setGatheringPeriod(element_date.getTimePeriod());
141
		} else if (eventSource == selection_collector) {
142
			getEntity().setCollector(selection_collector.getSelection());
143
		} else if (eventSource == text_collectingNumber) {
144
			getEntity().setFieldNumber(text_collectingNumber.getText());
145
		}
146
		  else if (eventSource == selection_collection) {
147
			getEntity().setCollection(selection_collection.getSelection());
148
		} else if (eventSource == text_accessionNumber) {
149
			getEntity().setAccessionNumber(text_accessionNumber.getText());
150
		} else if (eventSource == combo_specorobstype) {
151
			getEntity().setType(combo_specorobstype.getSelection());
152
		} else if (eventSource == uriPreferredStableUri) {
153
		    getEntity().setPreferredStableUri(uriPreferredStableUri.parseText());
154
		} else if (eventSource == checkIsPublish) {
155
            getEntity().innerDerivedUnit().setPublish(checkIsPublish.getSelection());
156
        }
157

    
158
		if (eventSource != toggleableText_titleCache) {
159
			toggleableText_titleCache.setText(getEntity().getTitleCache());
160
		}
161
	}
162

    
163
    public void setShowOnlyDerivedUnitData(boolean showOnlyDerivedUnitData) {
164
        this.showOnlyDerivedUnitData = showOnlyDerivedUnitData;
165
    }
166

    
167
    public void setShowSpecimenType(boolean showSpecimenType) {
168
        this.showSpecimenType = showSpecimenType;
169
    }
170

    
171
}
(12-12/36)