Project

General

Profile

Download (4.5 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 java.util.Comparator;
13

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

    
16
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
17
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
18
import eu.etaxonomy.cdm.model.term.TermType;
19
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
20
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
21
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
23
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
24
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
25
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
26
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
27
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractReferencedEntityElement;
28

    
29
/**
30
 * @author n.hoffmann
31
 * @created Nov 5, 2009
32
 */
33
public class NomenclaturalStatusElement extends AbstractReferencedEntityElement<NomenclaturalStatus> implements IEntityElement<NomenclaturalStatus>, ISelectableElement{
34

    
35
	private TermComboElement<NomenclaturalStatusType> nomenclaturalStatusTypeCombo;
36

    
37
	private TextWithLabelElement ruleConsideredText;
38

    
39

    
40

    
41
	private final SelectionArbitrator selectionArbitrator;
42

    
43
	public NomenclaturalStatusElement(CdmFormFactory cdmFormFactory, AbstractFormSection formElement,
44
			NomenclaturalStatus element, SelectionListener removeListener, int style) {
45
		super(cdmFormFactory, formElement, element, removeListener, style);
46
		selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
47
	}
48

    
49
	/** {@inheritDoc} */
50
	@Override
51
	public void createControls(ICdmFormElement element, int style) {
52
	    //TermVocabulary vocabulary = CdmStore.getService(IVocabularyService.class).find(VocabularyEnum.NomenclaturalStatusType.getUuid());
53

    
54
	    Comparator<NomenclaturalStatusType> termComparator= new Comparator<NomenclaturalStatusType>() {
55

    
56
            @Override
57
            public int compare(NomenclaturalStatusType t1, NomenclaturalStatusType t2) {
58
                if (t1 == t2){
59
                    return 0;
60
                }
61
                if (t1 == null){
62
                    return -1;
63
                }
64
                if (t2 == null){
65
                    return 1;
66
                }
67
                if (t1.getIdInVocabulary() == t2.getIdInVocabulary()){
68
                    return 0;
69
                }
70
                if (t1.getIdInVocabulary() == null ){
71
                    return t1.getLabel().compareTo(t2.getIdInVocabulary());
72
                }
73
                if (t2.getIdInVocabulary() == null){
74
                    return t1.getIdInVocabulary().compareTo(t2.getLabel());
75
                }
76
                return t1.getIdInVocabulary().compareTo(t2.getIdInVocabulary());
77

    
78
            }
79
        };
80

    
81
		nomenclaturalStatusTypeCombo = formFactory.createDefinedTermComboElement(TermType.NomenclaturalStatusType, this, "Status", null,true, style, true);
82
		nomenclaturalStatusTypeCombo.setTermComparator(termComparator);
83
		ruleConsideredText = formFactory.createTextWithLabelElement(this, "Rule Considered", "", style);
84

    
85
		super.createControls(element, style);
86

    
87
	}
88

    
89
	/** {@inheritDoc} */
90
	@Override
91
	public void setEntity(NomenclaturalStatus entity) {
92
		super.setEntity(entity);
93
		if (entity.getType() != null){
94
		    nomenclaturalStatusTypeCombo.setSelection(entity.getType());
95
		    nomenclaturalStatusTypeCombo.removeEmptyElement();
96
		}
97
		ruleConsideredText.setText(entity.getRuleConsidered());
98
	}
99

    
100
	/**
101
	 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
102
	 *
103
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
104
	 */
105
	@Override
106
    public SelectionArbitrator getSelectionArbitrator() {
107
		return selectionArbitrator;
108
	}
109

    
110
	/** {@inheritDoc} */
111
	@Override
112
	public void handleEvent(Object eventSource) {
113
		if(eventSource == nomenclaturalStatusTypeCombo){
114
			getEntity().setType(nomenclaturalStatusTypeCombo.getSelection());
115
		}
116
		else if(eventSource == ruleConsideredText){
117
			getEntity().setRuleConsidered(ruleConsideredText.getText());
118
		}
119
		else if(eventSource == selection_reference){
120
			getEntity().setCitation(selection_reference.getSelection());
121
		}
122
		else if(eventSource == text_referenceDetail){
123
			getEntity().setCitationMicroReference(text_referenceDetail.getText());
124
		}
125
	}
126
}
(13-13/23)