Project

General

Profile

Download (3.74 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.name;
11

    
12
import org.eclipse.swt.events.SelectionListener;
13

    
14
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
15
import eu.etaxonomy.cdm.model.common.TermType;
16
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
17
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
18
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
19
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
20
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
21
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
22
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
25
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
26

    
27
/**
28
 * @author n.hoffmann
29
 * @created May 17, 2010
30
 * @version 1.0
31
 */
32
public class SpecimenTypeDesignationElement extends
33
		AbstractTypeDesignationElement<SpecimenTypeDesignation> {
34

    
35
	private TermComboElement<SpecimenTypeDesignationStatus> combo_typeStatus;
36
	private EntitySelectionElement<DerivedUnit> selection_typeSpecimen;
37
	private TextWithLabelElement text_specimenTypeText;
38

    
39
	public SpecimenTypeDesignationElement(CdmFormFactory formFactory,
40
			AbstractFormSection section, SpecimenTypeDesignation entity,
41
			SelectionListener removeListener, int style) {
42
		super(formFactory, section, entity, removeListener, style);
43
	}
44

    
45
	/** {@inheritDoc} */
46
	@Override
47
	public void createControls(ICdmFormElement formElement, int style) {
48
		selection_typeSpecimen = formFactory
49
				.createSelectionElement(DerivedUnit.class,
50
						getConversationHolder(), formElement, "Specimen", null,
51
						EntitySelectionElement.ALL, style);
52
		combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.SpecimenTypeDesignationStatus,
53
						formElement, "Designation Status", null, style);
54

    
55
		super.createControls(formElement, style);
56
	}
57

    
58
	/** {@inheritDoc} */
59
	@Override
60
	public void setEntity(SpecimenTypeDesignation entity) {
61
		super.setEntity(entity);
62
		selection_typeSpecimen.setEntity(entity.getTypeSpecimen());
63

    
64
		SpecimenTypeDesignationStatus typeStatus = HibernateProxyHelper
65
				.deproxy(entity.getTypeStatus(), SpecimenTypeDesignationStatus.class);
66
		combo_typeStatus.setSelection(typeStatus);
67
		checkbox_notDesignated.setSelection(entity.isNotDesignated());
68
	}
69

    
70
	/** {@inheritDoc} */
71
	@Override
72
	public void handleEvent(Object eventSource) {
73
		if (eventSource == combo_typeStatus) {
74
			getEntity().setTypeStatus(combo_typeStatus.getSelection());
75
		}
76
		// TODO remove this once specimens are correctly implemented
77
		else if (eventSource == text_specimenTypeText) {
78
			// TODO this is a simple workaround to enter type specimen as text
79
			// strings
80
			if (getEntity().getTypeSpecimen() == null) {
81
				DerivedUnit typeSpecimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
82
				getEntity().setTypeSpecimen(typeSpecimen);
83
			}
84
			getEntity().getTypeSpecimen().setTitleCache(
85
					text_specimenTypeText.getText());
86
		} else if (eventSource == selection_typeSpecimen) {
87
			getEntity().setTypeSpecimen(selection_typeSpecimen.getSelection());
88
		} else if (eventSource == checkbox_notDesignated) {
89
			getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
90
		} else if (eventSource == selection_reference) {
91
			getEntity().setCitation(selection_reference.getSelection());
92
		} else if (eventSource == text_referenceDetail) {
93
			getEntity().setCitationMicroReference(
94
					text_referenceDetail.getText());
95
		}
96
	}
97
}
(20-20/21)