Project

General

Profile

Download (8.96 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 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.PreferencesUtil;
21
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
22
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
24
import eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement;
25
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
27
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
28
import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection;
29
import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
30
import eu.etaxonomy.taxeditor.ui.element.PointElement;
31
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
32
import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
33
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
34
import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
35
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
36
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
37

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

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

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

    
66

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

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

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

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

    
124
	}
125

    
126
	@Override
127
	protected void update(DerivedUnitFacade entity) {
128
	    super.update(entity);
129
	    toggleableText_titleCache.setText(entity.getTitleCache());
130
	    if(!showOnlyDerivedUnitData){
131
	        combo_specorobstype.setSelection(entity.getType());
132
	        selection_country.setEntity(entity.getCountry());
133
	        if(PreferencesUtil.isCollectingAreaInGeneralSection()){
134
	            section_collectingAreas.setEntity(entity);
135
	        }
136
	        languageText_locality.setText(entity.getLocalityText());
137
	        element_point.setEntity(entity.getExactLocation());
138
	        //	        element_elevation.set(entity);//FIXME needs setter for updating entity value
139

    
140
	        element_date.setTimePeriod(entity.getGatheringPeriod());
141
	        selection_collector.setEntity(entity.getCollector());
142
	        text_collectingNumber.setText(entity.getFieldNumber());
143
	    }
144
	    selection_collection.setEntity(entity.getCollection());
145
	    text_accessionNumber.setText(entity.getAccessionNumber());
146
	    uriPreferredStableUri.setParsedText(entity.getPreferredStableUri());
147
	    checkIsPublish.setSelection(entity.isPublish());
148
	}
149

    
150
	@Override
151
	public void handleEvent(Object eventSource) {
152
		if (eventSource == toggleableText_titleCache) {
153
			getEntity().setTitleCache(toggleableText_titleCache.getText(),
154
					toggleableText_titleCache.getState());
155
		} else if (eventSource == selection_country) {
156
			getEntity().setCountry(selection_country.getSelection());
157
		} else if (eventSource == languageText_locality) {
158
			LanguageString locality = languageText_locality.getLanguageString();
159
			getEntity().setLocality(locality);
160
		} else if (eventSource == element_point) {
161
			getEntity().setExactLocation(element_point.getPoint());
162
		} else if (eventSource == number_elevation) {
163
			getEntity().setAbsoluteElevation(number_elevation.getInteger());
164
		} else if (eventSource == element_date) {
165
			getEntity().setGatheringPeriod(element_date.getTimePeriod());
166
		} else if (eventSource == selection_collector) {
167
			getEntity().setCollector(selection_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 == combo_specorobstype) {
176
			getEntity().setType(combo_specorobstype.getSelection());
177
		} else if (eventSource == uriPreferredStableUri) {
178
		    getEntity().setPreferredStableUri(uriPreferredStableUri.parseText());
179
		} else if (eventSource == checkIsPublish) {
180
            getEntity().innerDerivedUnit().setPublish(checkIsPublish.getSelection());
181
        }
182

    
183
		if (eventSource != toggleableText_titleCache) {
184
			toggleableText_titleCache.setText(getEntity().getTitleCache());
185
		}
186
	}
187

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

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

    
196
}
(12-12/35)