Project

General

Profile

Download (4.21 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10

    
11
package eu.etaxonomy.taxeditor.ui.section.occurrence.association;
12

    
13
import java.util.List;
14
import java.util.Set;
15

    
16
import org.eclipse.swt.events.SelectionListener;
17

    
18
import eu.etaxonomy.cdm.model.common.TermType;
19
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
20
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
21
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
22
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
23
import eu.etaxonomy.taxeditor.ui.combo.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.section.name.AbstractTypeDesignationElement;
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 DerivedUnitTypeDesignationElement extends AbstractTypeDesignationElement<SpecimenTypeDesignation> {
36

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

    
40
    private List<EntitySelectionElement<TaxonNameBase>> selectionTaxonNames;
41
    private ICdmFormElement parentFormElement;
42
    private int style;
43

    
44
    public DerivedUnitTypeDesignationElement(CdmFormFactory formFactory,
45
            AbstractFormSection section, SpecimenTypeDesignation entity,
46
            SelectionListener removeListener, int style) {
47
        super(formFactory, section, entity, removeListener, style);
48
    }
49

    
50
    @Override
51
    public void setEntity(SpecimenTypeDesignation entity) {
52
        this.entity = entity;
53
        Set<TaxonNameBase> typifiedNames = entity.getTypifiedNames();
54
        if(typifiedNames.isEmpty()){
55
            formFactory.createSelectionElement(
56
                    TaxonNameBase.class, getConversationHolder(), parentFormElement, "Scientific Name", null,
57
                    EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE, style);
58
        }
59
        else{
60
            for (TaxonNameBase taxonNameBase : typifiedNames) {
61
                EntitySelectionElement<TaxonNameBase> selectionElement = formFactory.createSelectionElement(
62
                        TaxonNameBase.class, getConversationHolder(), parentFormElement, "Scientific Name", null,
63
                        EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE, style);
64
                selectionElement.setEntity(taxonNameBase);
65
            }
66
        }
67

    
68
        checkbox_notDesignated = formFactory.createCheckbox(parentFormElement, "Not Designated", false, style);
69

    
70
        selection_typeSpecimen = formFactory
71
                .createSelectionElement(DerivedUnit.class,
72
                        getConversationHolder(), parentFormElement, "Specimen", null,
73
                        EntitySelectionElement.ALL, style);
74
        combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.SpecimenTypeDesignationStatus,
75
                        parentFormElement, "Designation Status", null, style);
76

    
77
    }
78

    
79
    /** {@inheritDoc} */
80
    @Override
81
    public void createControls(ICdmFormElement element, int style) {
82
        this.parentFormElement = element;
83
        this.style = style;
84
        super.createControls(element, style);
85
    }
86

    
87
    /** {@inheritDoc} */
88
    @Override
89
    public void handleEvent(Object eventSource) {
90
        if (selectionTaxonNames.contains(eventSource)) {
91
            ((EntitySelectionElement<TaxonNameBase>) eventSource).getSelection().addTypeDesignation(getEntity(), false);
92
        }
93
        else if (eventSource == combo_typeStatus) {
94
            getEntity().setTypeStatus(combo_typeStatus.getSelection());
95
        } else if (eventSource == selection_typeSpecimen) {
96
            getEntity().setTypeSpecimen(selection_typeSpecimen.getSelection());
97
        }  else if (eventSource == checkbox_notDesignated) {
98
            getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
99
        }
100
    }
101

    
102
}
(1-1/4)