2 * Copyright (C) 2019 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
11 import java
.util
.HashMap
;
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
;
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
;
32 public class RuleConsideredElement
extends AbstractCdmFormElement
implements SelectionListener
{
34 protected TextWithLabelElement textRuleConsidered
;
36 protected EnumComboElement
<NomenclaturalCodeEdition
> nomenclaturalCodeEdition
= null;
38 Map
<String
, Integer
> nomenclaturalCodeEditionStringMap
;
40 private IRuleConsidered element
= null;
44 * @param cdmFormFactory
45 * @param parentElement
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);
59 nomenclaturalCodeEditionStringMap
= new HashMap
<>();
61 formFactory
.addPropertyChangeListener(this);
67 public IRuleConsidered
getElement() {
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());
80 if (nomenclaturalCodeEdition
!= null){
81 this.nomenclaturalCodeEdition
.setEnabled(false);
88 public String
getText(){
90 return this.element
.getRuleConsidered();
95 public NomenclaturalCodeEdition
getCodeEdition(){
97 return this.element
.getCodeEdition();
102 public void widgetSelected(SelectionEvent e
) {
103 if (nomenclaturalCodeEdition
!= null){
104 NomenclaturalCodeEdition edition
= nomenclaturalCodeEdition
.getSelection();
105 if (element
!= null){
106 this.element
.setCodeEdition(edition
);
112 public void widgetDefaultSelected(SelectionEvent e
) {
113 // TODO Auto-generated method stub
119 public void propertyChange(PropertyChangeEvent event
) {
123 if(event
.getSource() == textRuleConsidered
){
124 if (element
!= null){
125 element
.setRuleConsidered(textRuleConsidered
.getText());
127 if (StringUtils
.isBlank(textRuleConsidered
.getText())){
128 if (nomenclaturalCodeEdition
!= null){
129 this.nomenclaturalCodeEdition
.setEnabled(false);
131 this.element
.setCodeEdition(null);
133 if (nomenclaturalCodeEdition
!= null){
134 this.nomenclaturalCodeEdition
.setEnabled(true);