Project

General

Profile

Download (4.58 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.model.MessagingUtils;
22
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
23
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
24
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
27
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
28

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

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

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

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

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

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

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

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

    
77
	/** {@inheritDoc} */
78
	@Override
79
	public void handleEvent(Object eventSource) {
80
	    super.handleEvent(eventSource);
81
		if (eventSource == combo_typeStatus) {
82
		    if (getEntity().getTypeStatus().isLectotype() && !combo_typeStatus.getSelection().isLectotype() && entity.getCitation() != null){
83
		        boolean ok = MessagingUtils.confirmDialog("Citation will be removed", "When changing the type from lectotype to a non lectotype the citation will be removed.Do you want to continue?");
84
		        if (!ok){
85
		            combo_typeStatus.setSelection(entity.getTypeStatus());
86
		            return;
87
		        }
88
		    }
89
			getEntity().setTypeStatus(combo_typeStatus.getSelection());
90
			setEntity(entity);
91

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