1
|
/**
|
2
|
* Copyright (C) 2019 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.name;
|
10
|
|
11
|
import java.util.HashMap;
|
12
|
import java.util.Map;
|
13
|
|
14
|
import org.eclipse.swt.events.SelectionEvent;
|
15
|
import org.eclipse.swt.events.SelectionListener;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
18
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCodeEdition;
|
19
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
20
|
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
25
|
|
26
|
|
27
|
/**
|
28
|
* @author k.luther
|
29
|
* @since 17.09.2019
|
30
|
*/
|
31
|
public class RuleConsideredElement extends AbstractCdmFormElement implements SelectionListener {
|
32
|
|
33
|
protected TextWithLabelElement textRuleConsidered;
|
34
|
|
35
|
protected EnumComboElement<NomenclaturalCodeEdition> nomenclaturalCodeEdition;
|
36
|
|
37
|
Map<String, Integer> nomenclaturalCodeEditionStringMap;
|
38
|
|
39
|
private NomenclaturalStatus status = null;
|
40
|
|
41
|
|
42
|
private NameRelationship nameRelation = null;
|
43
|
|
44
|
/**
|
45
|
* @param cdmFormFactory
|
46
|
* @param parentElement
|
47
|
* @param labelString
|
48
|
* @param initialRule
|
49
|
* @param style
|
50
|
*/
|
51
|
public RuleConsideredElement( CdmFormFactory formFactory, ICdmFormElement formElement, String labelString, int style) {
|
52
|
super(formFactory, formElement);
|
53
|
this.textRuleConsidered = formFactory.createTextWithLabelElement(formElement, "Rule considered", null, style);
|
54
|
this.nomenclaturalCodeEdition = formFactory.createEnumComboElement(NomenclaturalCodeEdition.class, formElement, null, style);
|
55
|
nomenclaturalCodeEditionStringMap = new HashMap<>();
|
56
|
nomenclaturalCodeEdition.addSelectionListener(this);
|
57
|
|
58
|
}
|
59
|
|
60
|
|
61
|
/**
|
62
|
* @param cdmFormFactory
|
63
|
* @param parentElement
|
64
|
* @param labelString
|
65
|
* @param initialRule
|
66
|
* @param style
|
67
|
*/
|
68
|
public RuleConsideredElement( CdmFormFactory formFactory, ICdmFormElement formElement, String labelString, NomenclaturalStatus status, int style) {
|
69
|
super(formFactory, formElement);
|
70
|
this.textRuleConsidered = formFactory.createTextWithLabelElement(formElement, "Rule considered", null, style);
|
71
|
this.nomenclaturalCodeEdition = formFactory.createEnumComboElement(NomenclaturalCodeEdition.class, formElement, null, style);
|
72
|
|
73
|
nomenclaturalCodeEditionStringMap = new HashMap<>();
|
74
|
|
75
|
|
76
|
this.status = status;
|
77
|
textRuleConsidered.setText(status.getRuleConsidered());
|
78
|
|
79
|
nomenclaturalCodeEdition.addSelectionListener(this);
|
80
|
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* @param cdmFormFactory
|
85
|
* @param parentElement
|
86
|
* @param labelString
|
87
|
* @param initialRule
|
88
|
* @param style
|
89
|
*/
|
90
|
public RuleConsideredElement( CdmFormFactory formFactory, ICdmFormElement formElement, String labelString, NameRelationship relation, int style) {
|
91
|
super(formFactory, formElement);
|
92
|
this.textRuleConsidered = formFactory.createTextWithLabelElement(formElement, "Rule considered", null, style);
|
93
|
|
94
|
this.nomenclaturalCodeEdition = formFactory.createEnumComboElement(NomenclaturalCodeEdition.class, formElement, null, style);
|
95
|
|
96
|
nomenclaturalCodeEditionStringMap = new HashMap<>();
|
97
|
|
98
|
this.nameRelation = relation;
|
99
|
textRuleConsidered.setText(nameRelation.getRuleConsidered());
|
100
|
|
101
|
nomenclaturalCodeEdition.addSelectionListener(this);
|
102
|
|
103
|
}
|
104
|
|
105
|
|
106
|
public NomenclaturalStatus getStatus() {
|
107
|
return status;
|
108
|
}
|
109
|
|
110
|
|
111
|
public void setStatus(NomenclaturalStatus status) {
|
112
|
this.status = status;
|
113
|
}
|
114
|
|
115
|
|
116
|
public NameRelationship getNameRelation() {
|
117
|
return nameRelation;
|
118
|
}
|
119
|
|
120
|
|
121
|
public void setNameRelation(NameRelationship nameRelation) {
|
122
|
this.nameRelation = nameRelation;
|
123
|
this.textRuleConsidered.setText(getText());
|
124
|
this.nomenclaturalCodeEdition.setSelection(getCodeEdition());
|
125
|
}
|
126
|
|
127
|
public String getText(){
|
128
|
return this.nameRelation.getRuleConsidered();
|
129
|
}
|
130
|
|
131
|
public NomenclaturalCodeEdition getCodeEdition(){
|
132
|
return this.nameRelation.getCodeEdition();
|
133
|
}
|
134
|
@Override
|
135
|
public void widgetSelected(SelectionEvent e) {
|
136
|
//if (e.getSource().equals(nomenclaturalCodeEdition)){
|
137
|
NomenclaturalCodeEdition edition = nomenclaturalCodeEdition.getSelection();
|
138
|
if (status != null){
|
139
|
this.status.setCodeEdition(edition);
|
140
|
}else if (nameRelation != null){
|
141
|
this.nameRelation.setCodeEdition(edition);
|
142
|
}
|
143
|
// }
|
144
|
|
145
|
}
|
146
|
|
147
|
@Override
|
148
|
public void widgetDefaultSelected(SelectionEvent e) {
|
149
|
// TODO Auto-generated method stub
|
150
|
|
151
|
}
|
152
|
|
153
|
|
154
|
public void handleEvent(Object eventSource) {
|
155
|
if(eventSource == textRuleConsidered){
|
156
|
if (status != null){
|
157
|
status.setRuleConsidered(textRuleConsidered.getText());
|
158
|
}else if (nameRelation != null){
|
159
|
nameRelation.setRuleConsidered(textRuleConsidered.getText());
|
160
|
}
|
161
|
}
|
162
|
|
163
|
}
|
164
|
|
165
|
|
166
|
}
|