Project

General

Profile

Download (5.62 KB) Statistics
| Branch: | Tag: | Revision:
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.lang.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.NameRelationship;
21
import eu.etaxonomy.cdm.model.name.NomenclaturalCodeEdition;
22
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
23
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
24
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
25
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
27
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
28

    
29

    
30
/**
31
 * @author k.luther
32
 * @since 17.09.2019
33
 */
34
public class RuleConsideredElement extends AbstractCdmFormElement implements SelectionListener{
35

    
36
    protected TextWithLabelElement textRuleConsidered;
37

    
38
    protected EnumComboElement<NomenclaturalCodeEdition> nomenclaturalCodeEdition;
39

    
40
    Map<String, Integer> nomenclaturalCodeEditionStringMap;
41

    
42
    private IRuleConsidered element = null;
43

    
44

    
45
    //private NameRelationship nameRelation = null;
46

    
47
    /**
48
     * @param cdmFormFactory
49
     * @param parentElement
50
     * @param labelString
51
     * @param initialRule
52
     * @param style
53
     */
54
    public RuleConsideredElement( CdmFormFactory formFactory, ICdmFormElement formElement, String labelString, int style) {
55
        super(formFactory, formElement);
56
        this.textRuleConsidered = formFactory.createTextWithLabelElement(formElement, "Rule considered", null, style);
57
        this.nomenclaturalCodeEdition = formFactory.createEnumComboElement(NomenclaturalCodeEdition.class, formElement, null, style);
58
        nomenclaturalCodeEditionStringMap = new HashMap<>();
59
        nomenclaturalCodeEdition.addSelectionListener(this);
60
        formFactory.addPropertyChangeListener(this);
61

    
62
    }
63

    
64

    
65
    /**
66
     * @param cdmFormFactory
67
     * @param parentElement
68
     * @param labelString
69
     * @param initialRule
70
     * @param style
71
     */
72
    public RuleConsideredElement( CdmFormFactory formFactory, ICdmFormElement formElement, String labelString, NomenclaturalStatus status, int style) {
73
        super(formFactory, formElement);
74
        this.textRuleConsidered = formFactory.createTextWithLabelElement(formElement, "Rule considered", null, style);
75
        this.nomenclaturalCodeEdition =  formFactory.createEnumComboElement(NomenclaturalCodeEdition.class, formElement, null, style);
76

    
77
        nomenclaturalCodeEditionStringMap = new HashMap<>();
78

    
79

    
80
        this.element = status;
81
        textRuleConsidered.setText(status.getRuleConsidered());
82

    
83
        nomenclaturalCodeEdition.addSelectionListener(this);
84
        formFactory.addPropertyChangeListener(this);
85
    }
86

    
87
    /**
88
     * @param cdmFormFactory
89
     * @param parentElement
90
     * @param labelString
91
     * @param initialRule
92
     * @param style
93
     */
94
    public RuleConsideredElement( CdmFormFactory formFactory, ICdmFormElement formElement, String labelString, NameRelationship relation, int style) {
95
        super(formFactory, formElement);
96
        this.textRuleConsidered = formFactory.createTextWithLabelElement(formElement, "Rule considered", null, style);
97

    
98
        this.nomenclaturalCodeEdition =  formFactory.createEnumComboElement(NomenclaturalCodeEdition.class, formElement, null, style);
99

    
100
        nomenclaturalCodeEditionStringMap = new HashMap<>();
101

    
102
        this.element = relation;
103
        textRuleConsidered.setText(element.getRuleConsidered());
104

    
105
        nomenclaturalCodeEdition.addSelectionListener(this);
106
        formFactory.addPropertyChangeListener(this);
107
    }
108

    
109

    
110
    public IRuleConsidered getElement() {
111
        return element;
112
    }
113

    
114

    
115
    public void setElement(IRuleConsidered status) {
116
        this.element = status;
117
        if (status.getRuleConsidered() != null){
118
            this.textRuleConsidered.setText(getText());
119
            this.nomenclaturalCodeEdition.setSelection(getCodeEdition());
120
        }else{
121
            this.nomenclaturalCodeEdition.setEnabled(false);
122
        }
123
    }
124

    
125

    
126
    public String getText(){
127
        if (element != null){
128
            return this.element.getRuleConsidered();
129
        }
130
        return null;
131
    }
132

    
133
    public NomenclaturalCodeEdition getCodeEdition(){
134
        if (element != null){
135
            return this.element.getCodeEdition();
136
        }
137
        return null;
138
    }
139
    @Override
140
    public void widgetSelected(SelectionEvent e) {
141
        NomenclaturalCodeEdition edition =  nomenclaturalCodeEdition.getSelection();
142
        if (element != null){
143
            this.element.setCodeEdition(edition);
144
        }
145
    }
146

    
147
    @Override
148
    public void widgetDefaultSelected(SelectionEvent e) {
149
        // TODO Auto-generated method stub
150

    
151
    }
152

    
153

    
154
    @Override
155
    public void propertyChange(PropertyChangeEvent event) {
156
        if (event == null) {
157
            return;
158
        }
159
        if(event.getSource() == textRuleConsidered){
160
            if (element != null){
161
                element.setRuleConsidered(textRuleConsidered.getText());
162
            }
163
            if (StringUtils.isBlank(textRuleConsidered.getText())){
164
                this.nomenclaturalCodeEdition.setEnabled(false);
165
                this.element.setCodeEdition(null);
166
            }else{
167
                this.nomenclaturalCodeEdition.setEnabled(true);
168
            }
169
        }
170

    
171
    }
172

    
173

    
174

    
175

    
176
}
(20-20/23)