--- /dev/null
+/**
+* Copyright (C) 2019 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.ui.section.name;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+
+import eu.etaxonomy.cdm.model.name.IRuleConsidered;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCodeEdition;
+import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
+import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
+
+
+/**
+ * @author k.luther
+ * @since 17.09.2019
+ */
+public class RuleConsideredElement extends AbstractCdmFormElement implements SelectionListener{
+
+ protected TextWithLabelElement textRuleConsidered;
+
+ protected EnumComboElement<NomenclaturalCodeEdition> nomenclaturalCodeEdition = null;
+
+ Map<String, Integer> nomenclaturalCodeEditionStringMap;
+
+ private IRuleConsidered element = null;
+
+
+ /**
+ * @param cdmFormFactory
+ * @param parentElement
+ * @param labelString
+ * @param initialRule
+ * @param style
+ */
+ public RuleConsideredElement( CdmFormFactory formFactory, ICdmFormElement formElement, String labelString, boolean isShowCodeEdition, int style) {
+ super(formFactory, formElement);
+ this.textRuleConsidered = formFactory.createTextWithLabelElement(formElement, "Rule Considered", null, style);
+ if(isShowCodeEdition){
+ this.nomenclaturalCodeEdition = formFactory.createEnumComboElement(NomenclaturalCodeEdition.class, formElement, null, style);
+ nomenclaturalCodeEdition.addSelectionListener(this);
+ nomenclaturalCodeEdition.setIndent(10);
+
+ }
+ nomenclaturalCodeEditionStringMap = new HashMap<>();
+
+ formFactory.addPropertyChangeListener(this);
+
+ }
+
+
+
+ public IRuleConsidered getElement() {
+ return element;
+ }
+
+
+ public void setElement(IRuleConsidered status) {
+ this.element = status;
+ if (status.getRuleConsidered() != null){
+ this.textRuleConsidered.setText(getText());
+ if (nomenclaturalCodeEdition != null){
+ this.nomenclaturalCodeEdition.setSelection(getCodeEdition());
+ }
+ }else{
+ if (nomenclaturalCodeEdition != null){
+ this.nomenclaturalCodeEdition.setEnabled(false);
+ }
+
+ }
+ }
+
+
+ public String getText(){
+ if (element != null){
+ return this.element.getRuleConsidered();
+ }
+ return null;
+ }
+
+ public NomenclaturalCodeEdition getCodeEdition(){
+ if (element != null){
+ return this.element.getCodeEdition();
+ }
+ return null;
+ }
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (nomenclaturalCodeEdition != null){
+ NomenclaturalCodeEdition edition = nomenclaturalCodeEdition.getSelection();
+ if (element != null){
+ this.element.setCodeEdition(edition);
+ }
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+ @Override
+ public void propertyChange(PropertyChangeEvent event) {
+ if (event == null) {
+ return;
+ }
+ if(event.getSource() == textRuleConsidered){
+ if (element != null){
+ element.setRuleConsidered(textRuleConsidered.getText());
+ }
+ if (StringUtils.isBlank(textRuleConsidered.getText())){
+ if (nomenclaturalCodeEdition != null){
+ this.nomenclaturalCodeEdition.setEnabled(false);
+ }
+ this.element.setCodeEdition(null);
+ }else{
+ if (nomenclaturalCodeEdition != null){
+ this.nomenclaturalCodeEdition.setEnabled(true);
+ }
+ }
+ }
+
+ }
+
+
+
+
+}