Project

General

Profile

Download (3.57 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.association;
10

    
11
import java.util.Set;
12

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

    
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.name.TaxonName;
19
import eu.etaxonomy.cdm.model.term.TermType;
20
import eu.etaxonomy.taxeditor.ui.combo.term.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.section.name.AbstractTypeDesignationElement;
25
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
26

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

    
34
    private TermComboElement<SpecimenTypeDesignationStatus> combo_typeStatus;
35

    
36
    private ICdmFormElement parentFormElement;
37
    private int style;
38

    
39
    private EntitySelectionElement<TaxonName> selectionTaxonName;
40

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

    
47
    @Override
48
    public void setEntity(SpecimenTypeDesignation entity) {
49
        super.setEntity(entity);
50
        if (combo_typeStatus != null){
51
	        Set<TaxonName> typifiedNames = entity.getTypifiedNames();
52
	        if(typifiedNames.size()==1){
53
	            selectionTaxonName.setEntity(typifiedNames.iterator().next());
54
	        }
55
	        else if(typifiedNames.size()>1){
56
	            formFactory.createLabel(getLayoutComposite(), "!!!!!!!!");
57
	        }
58

    
59
	        SpecimenTypeDesignationStatus typeStatus = HibernateProxyHelper
60
	        		.deproxy(entity.getTypeStatus());
61
	        combo_typeStatus.setSelection(typeStatus);
62
	        checkbox_notDesignated.setSelection(entity.isNotDesignated());
63
        }
64
    }
65

    
66
    @Override
67
    public void createControls(ICdmFormElement element, int style) {
68
        this.parentFormElement = element;
69
        this.style = style;
70

    
71
        selectionTaxonName = formFactory.createSelectionElement(
72
                TaxonName.class,
73
                parentFormElement, "Scientific Name", null,
74
                EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE, style);
75

    
76
        combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.SpecimenTypeDesignationStatus,
77
                parentFormElement, "Designation Status", null, style);
78

    
79
        super.createControls(element, style);
80
        if (entity != null){
81
        	setEntity(entity);
82
        }
83
    }
84

    
85
    @Override
86
    public void handleEvent(Object eventSource) {
87
        if (eventSource == selectionTaxonName) {
88
            selectionTaxonName.getSelection().addTypeDesignation(getEntity(), false);
89
        } else if (eventSource == combo_typeStatus) {
90
            getEntity().setTypeStatus(combo_typeStatus.getSelection());
91
        } else if (eventSource == checkbox_notDesignated) {
92
            getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
93
        }
94
    }
95
}
(1-1/4)