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
|
private final SelectionArbitrator selectionArbitrator;
|
40
|
|
41
|
public NomenclaturalStatusElement(CdmFormFactory cdmFormFactory, AbstractFormSection formElement,
|
42
|
NomenclaturalStatus element, SelectionListener removeListener, int style) {
|
43
|
super(cdmFormFactory, formElement, element, removeListener, style);
|
44
|
selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
|
45
|
}
|
46
|
|
47
|
/** {@inheritDoc} */
|
48
|
@Override
|
49
|
public void createControls(ICdmFormElement element, int style) {
|
50
|
//TermVocabulary vocabulary = CdmStore.getService(IVocabularyService.class).find(VocabularyEnum.NomenclaturalStatusType.getUuid());
|
51
|
|
52
|
Comparator<NomenclaturalStatusType> termComparator= new Comparator<NomenclaturalStatusType>() {
|
53
|
|
54
|
@Override
|
55
|
public int compare(NomenclaturalStatusType t1, NomenclaturalStatusType t2) {
|
56
|
if (t1 == t2){
|
57
|
return 0;
|
58
|
}
|
59
|
if (t1 == null){
|
60
|
return -1;
|
61
|
}
|
62
|
if (t2 == null){
|
63
|
return 1;
|
64
|
}
|
65
|
if (t1.getIdInVocabulary() == t2.getIdInVocabulary()){
|
66
|
return 0;
|
67
|
}
|
68
|
if (t1.getIdInVocabulary() == null ){
|
69
|
return t1.getLabel().compareTo(t2.getIdInVocabulary());
|
70
|
}
|
71
|
if (t2.getIdInVocabulary() == null){
|
72
|
return t1.getIdInVocabulary().compareTo(t2.getLabel());
|
73
|
}
|
74
|
return t1.getIdInVocabulary().compareTo(t2.getIdInVocabulary());
|
75
|
|
76
|
}
|
77
|
};
|
78
|
|
79
|
nomenclaturalStatusTypeCombo = formFactory.createDefinedTermComboElement(TermType.NomenclaturalStatusType, this, "Status", null,true, style, true);
|
80
|
nomenclaturalStatusTypeCombo.setTermComparator(termComparator);
|
81
|
ruleConsideredText = formFactory.createTextWithLabelElement(this, "Rule Considered", "", style);
|
82
|
|
83
|
super.createControls(element, style);
|
84
|
|
85
|
}
|
86
|
|
87
|
/** {@inheritDoc} */
|
88
|
@Override
|
89
|
public void setEntity(NomenclaturalStatus entity) {
|
90
|
super.setEntity(entity);
|
91
|
if (entity.getType() != null){
|
92
|
nomenclaturalStatusTypeCombo.setSelection(entity.getType());
|
93
|
nomenclaturalStatusTypeCombo.removeEmptyElement();
|
94
|
}
|
95
|
ruleConsideredText.setText(entity.getRuleConsidered());
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* <p>Getter for the field <code>selectionArbitrator</code>.</p>
|
100
|
*
|
101
|
* @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
|
102
|
*/
|
103
|
@Override
|
104
|
public SelectionArbitrator getSelectionArbitrator() {
|
105
|
return selectionArbitrator;
|
106
|
}
|
107
|
|
108
|
/** {@inheritDoc} */
|
109
|
@Override
|
110
|
public void handleEvent(Object eventSource) {
|
111
|
if(eventSource == nomenclaturalStatusTypeCombo){
|
112
|
getEntity().setType(nomenclaturalStatusTypeCombo.getSelection());
|
113
|
}
|
114
|
else if(eventSource == ruleConsideredText){
|
115
|
getEntity().setRuleConsidered(ruleConsideredText.getText());
|
116
|
}
|
117
|
else if(eventSource == selection_reference){
|
118
|
getEntity().setCitation(selection_reference.getSelection());
|
119
|
}
|
120
|
else if(eventSource == text_referenceDetail){
|
121
|
getEntity().setCitationMicroReference(text_referenceDetail.getText());
|
122
|
}
|
123
|
}
|
124
|
}
|