Project

General

Profile

Download (9.45 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
package eu.etaxonomy.taxeditor.ui.section.occurrence;
10

    
11
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
12
import eu.etaxonomy.cdm.model.agent.Person;
13
import eu.etaxonomy.cdm.model.agent.Team;
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.CollectorSelectionElement;
36
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
37

    
38
/**
39
 * @author n.hoffmann
40
 * @created Dec 16, 2010
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 CollectorSelectionElement selection_collector;
58
	private CollectorSelectionElement selection_primary_collector;
59
	private TextWithLabelElement text_collectingNumber;
60
	private EntitySelectionElement<Collection> selection_collection;
61
	private TextWithLabelElement text_accessionNumber;
62
    private TextWithLabelElement text_barcode;
63
	private GatheringEventUnitElement element_elevation;
64
	private UriWithLabelElement uriPreferredStableUri;
65
	private CheckboxElement checkIsPublish;
66
	private StatusCollectionDetailSection section_status;
67

    
68

    
69
	public DerivedUnitGeneralDetailElement(CdmFormFactory formFactory,
70
			ICdmFormElement formElement) {
71
	    super(formFactory, formElement);
72
	}
73

    
74
	@Override
75
	protected void createControls(ICdmFormElement formElement,
76
			DerivedUnitFacade entity, int style) {
77
		toggleableText_titleCache = formFactory.createToggleableTextField(
78
				formElement, "Title Cache", entity.getTitleCache(),
79
				entity.isProtectedTitleCache(), style);
80
        //TODO for DerivateEditor do not use facade anymore to avoid this special case handling #4539
81
		if(!showOnlyDerivedUnitData){
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,
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
		            .createCollectorSelectionElement(
106
		                    formElement, "Collector",
107
		                    entity.getCollector(), EntitySelectionElement.ALL,
108
		                    style);
109
		    selection_primary_collector = formFactory
110
		            .createCollectorSelectionElement(
111
		                    formElement, "Primary collector",
112
		                    entity.getCollector(), entity.getPrimaryCollector(), EntitySelectionElement.ALL,
113
		                    style);
114
	        if (!(entity.getCollector() instanceof Team)){
115
		    	selection_primary_collector.setEnabled(false);
116
		    }
117
		    text_collectingNumber = formFactory.createTextWithLabelElement(formElement,
118
		            "Collecting number", entity.getFieldNumber(), style);
119
		}
120
		selection_collection = formFactory
121
				.createSelectionElement(Collection.class,//getConversationHolder(),
122
				        formElement, "Collection",
123
						entity.getCollection(),
124
						EntitySelectionElement.ALL, style);
125
		text_accessionNumber = formFactory.createTextWithLabelElement(
126
				formElement, "Accession Number", entity.getAccessionNumber(),
127
				style);
128
		text_barcode = formFactory.createTextWithLabelElement(formElement, "Barcode", entity.getBarcode(), style);
129

    
130
		uriPreferredStableUri = formFactory.createUriWithLabelElement(formElement, "Pref. Stable URI", entity.getPreferredStableUri(), style);
131
		section_status = formFactory.createStatusCollectionDetailSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(SourceCollectionDetailSection.class, entity.getClass().getCanonicalName()));
132
		section_status.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
133
		section_status.setEntity(entity);
134

    
135
		checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.innerDerivedUnit().isPublish(), style);
136

    
137
	}
138

    
139
	@Override
140
	public void handleEvent(Object eventSource) {
141
		if (eventSource == toggleableText_titleCache) {
142
			
143
			getEntity().setTitleCache(toggleableText_titleCache.getText(),
144
					toggleableText_titleCache.getState());
145
			if (toggleableText_titleCache.getState()) {
146
				return;
147
			}			
148
		} else if (eventSource == selection_country) {
149
			getEntity().setCountry(selection_country.getSelection());
150
		} else if (eventSource == languageText_locality) {
151
			LanguageString locality = languageText_locality.getLanguageString();
152
			getEntity().setLocality(locality);
153
		} else if (eventSource == element_point) {
154
			getEntity().setExactLocation(element_point.getPoint());
155
		} else if (eventSource == number_elevation) {
156
			getEntity().setAbsoluteElevation(number_elevation.getInteger());
157
		} else if (eventSource == element_date) {
158
			getEntity().setGatheringPeriod(element_date.getTimePeriod());
159
		} else if (eventSource == selection_collector) {
160
			getEntity().setCollector(selection_collector.getSelection());
161
			 getEntity().setCollector(selection_collector.getSelection());
162
	         if (getEntity().getCollector() instanceof Team){
163
	        	 selection_primary_collector.setCollectorTeam((Team)getEntity().getCollector());
164
	         }
165
			selection_primary_collector.setEnabled(getEntity().getCollector() instanceof Team);
166
		} else if (eventSource == selection_primary_collector) {
167
			getEntity().setPrimaryCollector((Person)selection_primary_collector.getSelection());
168
		}else if (eventSource == text_collectingNumber) {
169
			getEntity().setFieldNumber(text_collectingNumber.getText());
170
		}
171
		  else if (eventSource == selection_collection) {
172
			getEntity().setCollection(selection_collection.getSelection());
173
		} else if (eventSource == text_accessionNumber) {
174
			getEntity().setAccessionNumber(text_accessionNumber.getText());
175
        } else if (eventSource == text_barcode) {
176
            getEntity().setBarcode(text_barcode.getText());
177
		} else if (eventSource == combo_specorobstype) {
178
			getEntity().setType(combo_specorobstype.getSelection());
179
		} else if (eventSource == uriPreferredStableUri) {
180
		    getEntity().setPreferredStableUri(uriPreferredStableUri.parseText());
181
		} else if (eventSource == checkIsPublish) {
182
            getEntity().innerDerivedUnit().setPublish(checkIsPublish.getSelection());
183
        }
184

    
185
		toggleableText_titleCache.setText(getEntity().getTitleCache());
186

    
187
	}
188

    
189
    public void setShowOnlyDerivedUnitData(boolean showOnlyDerivedUnitData) {
190
        this.showOnlyDerivedUnitData = showOnlyDerivedUnitData;
191
    }
192

    
193
    public void setShowSpecimenType(boolean showSpecimenType) {
194
        this.showSpecimenType = showSpecimenType;
195
    }
196

    
197
}
(12-12/38)