Project

General

Profile

Download (4.68 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.api.service.name.TypeDesignationStatusComparator;
15
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
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.cdm.model.term.TermType;
21
import eu.etaxonomy.taxeditor.l10n.Messages;
22
import eu.etaxonomy.taxeditor.model.MessagingUtils;
23
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
24
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
25
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
27
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
28
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
29

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

    
38
	private TermComboElement<SpecimenTypeDesignationStatus> combo_typeStatus;
39
	private EntitySelectionElement<DerivedUnit> selection_typeSpecimen;
40
	private TextWithLabelElement text_specimenTypeText;
41

    
42
	public SpecimenTypeDesignationElement(CdmFormFactory formFactory,
43
			AbstractFormSection section, SpecimenTypeDesignation entity,
44
			SelectionListener removeListener, int style) {
45
		super(formFactory, section, entity, removeListener, style);
46
	}
47

    
48
	/** {@inheritDoc} */
49
	@Override
50
	public void createControls(ICdmFormElement formElement, int style) {
51
		selection_typeSpecimen = formFactory
52
				.createSelectionElement(DerivedUnit.class,
53
				        formElement, "Specimen", null,
54
						EntitySelectionElement.ALL, style);
55
		combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.SpecimenTypeDesignationStatus,
56
						formElement, "Designation Status", null, style, new TypeDesignationStatusComparator<SpecimenTypeDesignationStatus>());
57

    
58
		super.createControls(formElement, style);
59
	}
60

    
61
	/** {@inheritDoc} */
62
	@Override
63
	public void setEntity(SpecimenTypeDesignation entity) {
64
	    super.setEntity(entity);
65
        if (entity.getTypeSpecimen() != null){
66
            selection_typeSpecimen.setEntity(entity.getTypeSpecimen());
67
        }else{
68
            selection_typeSpecimen.setEntity(entity.getTypeSpecimen());
69
        }
70

    
71
		SpecimenTypeDesignationStatus typeStatus = HibernateProxyHelper
72
				.deproxy(entity.getTypeStatus(), SpecimenTypeDesignationStatus.class);
73
	    combo_typeStatus.setSelection(typeStatus);
74

    
75
		checkbox_notDesignated.setSelection(entity.isNotDesignated());
76
	}
77

    
78
	/** {@inheritDoc} */
79
	@Override
80
	public void handleEvent(Object eventSource) {
81
	    super.handleEvent(eventSource);
82
		if (eventSource == combo_typeStatus) {
83

    
84
		    if ((combo_typeStatus.getSelection() == null && entity.getCitation() != null) || ( entity.getTypeStatus() != null && getEntity().getTypeStatus().isLectotype() && !combo_typeStatus.getSelection().isLectotype() && entity.getCitation() != null)){
85
		        boolean ok = MessagingUtils.confirmDialog(Messages.NameTypeDesignationElement_4, Messages.NameTypeDesignationElement_5);
86
		        if (!ok){
87
		            combo_typeStatus.setSelection(entity.getTypeStatus());
88
		            return;
89
		        }
90
		    }
91
			getEntity().setTypeStatus(combo_typeStatus.getSelection());
92
			setEntity(entity);
93

    
94
		}
95
		// TODO remove this once specimens are correctly implemented
96
		else if (eventSource == text_specimenTypeText) {
97
			// TODO this is a simple workaround to enter type specimen as text
98
			// strings
99
			if (getEntity().getTypeSpecimen() == null) {
100
				DerivedUnit typeSpecimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
101
				getEntity().setTypeSpecimen(typeSpecimen);
102
			}
103
			getEntity().getTypeSpecimen().setTitleCache(
104
					text_specimenTypeText.getText());
105
		} else if (eventSource == selection_typeSpecimen) {
106
			getEntity().setTypeSpecimen(selection_typeSpecimen.getSelection());
107
		} else if (eventSource == checkbox_notDesignated) {
108
			getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
109
		}
110
		else if (eventSource == selection_reference) {
111
			getEntity().setCitation(selection_reference.getSelection());
112
		} else if (eventSource == text_referenceDetail) {
113
			getEntity().setCitationMicroReference(
114
					text_referenceDetail.getText());
115
		}
116
	}
117
}
(20-20/22)