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.apache.commons.lang3.StringUtils;
|
15
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
16
|
import org.eclipse.swt.events.SelectionEvent;
|
17
|
import org.eclipse.swt.events.SelectionListener;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.name.IRuleConsidered;
|
20
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCodeEdition;
|
21
|
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
25
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
26
|
|
27
|
|
28
|
/**
|
29
|
* @author k.luther
|
30
|
* @since 17.09.2019
|
31
|
*/
|
32
|
public class RuleConsideredElement extends AbstractCdmFormElement implements SelectionListener{
|
33
|
|
34
|
protected TextWithLabelElement textRuleConsidered;
|
35
|
|
36
|
protected EnumComboElement<NomenclaturalCodeEdition> nomenclaturalCodeEdition = null;
|
37
|
|
38
|
Map<String, Integer> nomenclaturalCodeEditionStringMap;
|
39
|
|
40
|
private IRuleConsidered element = null;
|
41
|
|
42
|
|
43
|
/**
|
44
|
* @param cdmFormFactory
|
45
|
* @param parentElement
|
46
|
* @param labelString
|
47
|
* @param initialRule
|
48
|
* @param style
|
49
|
*/
|
50
|
public RuleConsideredElement( CdmFormFactory formFactory, ICdmFormElement formElement, String labelString, boolean isShowCodeEdition, int style) {
|
51
|
super(formFactory, formElement);
|
52
|
this.textRuleConsidered = formFactory.createTextWithLabelElement(formElement, "Rule Considered", null, style);
|
53
|
if(isShowCodeEdition){
|
54
|
this.nomenclaturalCodeEdition = formFactory.createEnumComboElement(NomenclaturalCodeEdition.class, formElement, style);
|
55
|
nomenclaturalCodeEdition.addSelectionListener(this);
|
56
|
nomenclaturalCodeEdition.setIndent(10);
|
57
|
|
58
|
}
|
59
|
nomenclaturalCodeEditionStringMap = new HashMap<>();
|
60
|
|
61
|
formFactory.addPropertyChangeListener(this);
|
62
|
|
63
|
}
|
64
|
|
65
|
|
66
|
|
67
|
public IRuleConsidered getElement() {
|
68
|
return element;
|
69
|
}
|
70
|
|
71
|
|
72
|
public void setElement(IRuleConsidered status) {
|
73
|
this.element = status;
|
74
|
if (status.getRuleConsidered() != null){
|
75
|
this.textRuleConsidered.setText(getText());
|
76
|
if (nomenclaturalCodeEdition != null){
|
77
|
this.nomenclaturalCodeEdition.setSelection(getCodeEdition());
|
78
|
}
|
79
|
}else{
|
80
|
if (nomenclaturalCodeEdition != null){
|
81
|
this.nomenclaturalCodeEdition.setEnabled(false);
|
82
|
}
|
83
|
|
84
|
}
|
85
|
}
|
86
|
|
87
|
|
88
|
public String getText(){
|
89
|
if (element != null){
|
90
|
return this.element.getRuleConsidered();
|
91
|
}
|
92
|
return null;
|
93
|
}
|
94
|
|
95
|
public NomenclaturalCodeEdition getCodeEdition(){
|
96
|
if (element != null){
|
97
|
return this.element.getCodeEdition();
|
98
|
}
|
99
|
return null;
|
100
|
}
|
101
|
@Override
|
102
|
public void widgetSelected(SelectionEvent e) {
|
103
|
if (nomenclaturalCodeEdition != null){
|
104
|
NomenclaturalCodeEdition edition = nomenclaturalCodeEdition.getSelection();
|
105
|
if (element != null){
|
106
|
this.element.setCodeEdition(edition);
|
107
|
}
|
108
|
}
|
109
|
}
|
110
|
|
111
|
@Override
|
112
|
public void widgetDefaultSelected(SelectionEvent e) {
|
113
|
// TODO Auto-generated method stub
|
114
|
|
115
|
}
|
116
|
|
117
|
|
118
|
@Override
|
119
|
public void propertyChange(PropertyChangeEvent event) {
|
120
|
if (event == null) {
|
121
|
return;
|
122
|
}
|
123
|
if(event.getSource() == textRuleConsidered){
|
124
|
if (element != null){
|
125
|
element.setRuleConsidered(textRuleConsidered.getText());
|
126
|
}
|
127
|
if (StringUtils.isBlank(textRuleConsidered.getText())){
|
128
|
if (nomenclaturalCodeEdition != null){
|
129
|
this.nomenclaturalCodeEdition.setEnabled(false);
|
130
|
}
|
131
|
this.element.setCodeEdition(null);
|
132
|
}else{
|
133
|
if (nomenclaturalCodeEdition != null){
|
134
|
this.nomenclaturalCodeEdition.setEnabled(true);
|
135
|
}
|
136
|
}
|
137
|
}
|
138
|
|
139
|
}
|
140
|
|
141
|
|
142
|
|
143
|
|
144
|
}
|