commit 9361ce643c9b449ce33d77973ffe7d6ff9fc80b5
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Wed Jul 4 16:42:39 2018 +0200

    fix #7524 replacing uninomial field on rank change

diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java
index 7c1420dd..6b7ab065 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java
@@ -21,6 +21,7 @@ import org.vaadin.viritin.fields.LazyComboBox;
 
 import com.vaadin.data.Property;
 import com.vaadin.spring.annotation.SpringComponent;
+import com.vaadin.ui.AbstractField;
 import com.vaadin.ui.Field;
 
 import eu.etaxonomy.cdm.api.service.INameService;
@@ -109,18 +110,6 @@ public class TaxonNameEditorPresenter extends AbstractCdmDTOEditorPresenter<Taxo
         getView().getRankSelect().setContainerDataSource(selectFieldFactory.buildBeanItemContainer(TermType.Rank));
         getView().getRankSelect().setItemCaptionPropertyId("label");
 
-        // genusOrUninomialField
-        if(getView().getGenusOrUninomialField() instanceof LazyComboBox){
-            genusOrUninomialPartPagingProvider = new TaxonNameStringFilterablePagingProvider(getRepo().getNameService());
-            genusOrUninomialPartPagingProvider.listenToFields(
-                    null,
-                    getView().getInfraGenericEpithetField(),
-                    getView().getSpecificEpithetField(),
-                    getView().getInfraSpecificEpithetField()
-                   );
-            ((LazyComboBox)getView().getGenusOrUninomialField()).loadFrom(genusOrUninomialPartPagingProvider, genusOrUninomialPartPagingProvider, genusOrUninomialPartPagingProvider.getPageSize());
-        }
-
         CdmFilterablePagingProvider<AgentBase, TeamOrPersonBase> termOrPersonPagingProvider = new CdmFilterablePagingProvider<AgentBase, TeamOrPersonBase>(getRepo().getAgentService(), TeamOrPersonBase.class);
         termOrPersonPagingProvider.setInitStrategy(AgentBaseInit.TEAM_OR_PERSON_INIT_STRATEGY);
         CdmFilterablePagingProvider<AgentBase, Person> personPagingProvider = new CdmFilterablePagingProvider<AgentBase, Person>(getRepo().getAgentService(), Person.class);
@@ -335,28 +324,51 @@ public class TaxonNameEditorPresenter extends AbstractCdmDTOEditorPresenter<Taxo
     public void onFieldReplaceEvent(FieldReplaceEvent<String> event){
 
         PropertyIdPath boundPropertyIdPath = boundPropertyIdPath(event.getNewField());
-        if(boundPropertyIdPath != null && boundPropertyIdPath.matches("specificEpithet")){
-            if(event.getNewField() instanceof LazyComboBox){
+        if(boundPropertyIdPath != null){
+            if(boundPropertyIdPath.matches("specificEpithet")){
+                AbstractField<String> genusOrUninomialField = getView().getGenusOrUninomialField();
+                if(event.getNewField() instanceof LazyComboBox){
 
-                if(specificEpithetPartPagingProvider  == null){
-                    specificEpithetPartPagingProvider = new TaxonNameStringFilterablePagingProvider(getRepo().getNameService(), Rank.SPECIES());
-                }
-                specificEpithetPartPagingProvider.listenToFields(
-                        getView().getGenusOrUninomialField(),
-                        null, null, null);
-                specificEpithetPartPagingProvider.updateFromFields();
-                LazyComboBox<String> specificEpithetField = (LazyComboBox<String>)event.getNewField();
-                refreshSpecificEpithetComboBoxListener = e -> { specificEpithetField.refresh(); specificEpithetField.setValue(null);};
-                getView().getGenusOrUninomialField().addValueChangeListener(refreshSpecificEpithetComboBoxListener);
-                specificEpithetField.loadFrom(specificEpithetPartPagingProvider, specificEpithetPartPagingProvider, specificEpithetPartPagingProvider.getPageSize());
-            } else {
-                if(specificEpithetPartPagingProvider != null){
-                    specificEpithetPartPagingProvider.unlistenAllFields();
+                    if(specificEpithetPartPagingProvider  == null){
+                        specificEpithetPartPagingProvider = new TaxonNameStringFilterablePagingProvider(getRepo().getNameService(), Rank.SPECIES());
+                    }
+                    specificEpithetPartPagingProvider.listenToFields(
+                            genusOrUninomialField,
+                            null, null, null);
+                    specificEpithetPartPagingProvider.updateFromFields();
+                    LazyComboBox<String> specificEpithetField = (LazyComboBox<String>)event.getNewField();
+                    refreshSpecificEpithetComboBoxListener = e -> { specificEpithetField.refresh(); specificEpithetField.setValue(null);};
+                    genusOrUninomialField.addValueChangeListener(refreshSpecificEpithetComboBoxListener);
+                    specificEpithetField.loadFrom(specificEpithetPartPagingProvider, specificEpithetPartPagingProvider, specificEpithetPartPagingProvider.getPageSize());
+                } else {
+                    if(specificEpithetPartPagingProvider != null){
+                        specificEpithetPartPagingProvider.unlistenAllFields();
+                    }
+                    if(refreshSpecificEpithetComboBoxListener != null){
+                        genusOrUninomialField.removeValueChangeListener(refreshSpecificEpithetComboBoxListener);
+                        refreshSpecificEpithetComboBoxListener = null;
+                    }
                 }
-                if(refreshSpecificEpithetComboBoxListener != null){
-                    getView().getGenusOrUninomialField().removeValueChangeListener(refreshSpecificEpithetComboBoxListener);
-                    refreshSpecificEpithetComboBoxListener = null;
+            } else if(boundPropertyIdPath.matches("genusOrUninomial")) {
+                if(event.getNewField() instanceof LazyComboBox){
+                    if(genusOrUninomialPartPagingProvider  == null){
+                        genusOrUninomialPartPagingProvider = new TaxonNameStringFilterablePagingProvider(getRepo().getNameService());
+                    }
+                    genusOrUninomialPartPagingProvider.listenToFields(
+                                null,
+                                getView().getInfraGenericEpithetField(),
+                                getView().getSpecificEpithetField(),
+                                getView().getInfraSpecificEpithetField()
+                               );
+                    LazyComboBox<String> genusOrUninomialField = (LazyComboBox<String>)event.getNewField();
+                    genusOrUninomialField.loadFrom(genusOrUninomialPartPagingProvider, genusOrUninomialPartPagingProvider, genusOrUninomialPartPagingProvider.getPageSize());
+
+                }else {
+                    if(genusOrUninomialPartPagingProvider != null){
+                        genusOrUninomialPartPagingProvider.unlistenAllFields();
+                    }
                 }
+
             }
         }
 
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java
index 6c41d552..d32b5e58 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java
@@ -137,6 +137,8 @@ public class TaxonNamePopupEditor extends AbstractCdmDTOPopupEditor<TaxonNameDTO
 
     private AnnotationType[] editableAnotationTypes = RegistrationUIDefaults.EDITABLE_ANOTATION_TYPES;
 
+    private int genusOrUninomialRow;
+
     /**
      * By default  AnnotationType.EDITORIAL() is enabled.
      *
@@ -301,12 +303,8 @@ public class TaxonNamePopupEditor extends AbstractCdmDTOPopupEditor<TaxonNameDTO
         protectedNameCacheField = addSwitchableTextField("Name cache", "nameCache", "protectedNameCache", 0, row, GRID_COLS-1, row);
         protectedNameCacheField.setWidth(100, Unit.PERCENTAGE);
         row++;
-        if(isModeEnabled(TaxonNamePopupEditorMode.VALIDATE_AGAINST_HIGHER_NAME_PART)){
-            genusOrUninomialField = addTextField("Genus or uninomial", "genusOrUninomial", 0, row, 1, row);
-        } else {
-            genusOrUninomialField = new LazyComboBox<String>(String.class);
-            addField(genusOrUninomialField, "genusOrUninomial", 0, row, 1, row);
-        }
+        genusOrUninomialRow = row;
+        genusOrUninomialField = addTextField("Genus or uninomial", "genusOrUninomial", 0, row, 1, row);
         genusOrUninomialField.setWidth(200, Unit.PIXELS);
         infraGenericEpithetField = addTextField("Infrageneric epithet", "infraGenericEpithet", 2, row, 3, row);
         infraGenericEpithetField.setWidth(200, Unit.PIXELS);
@@ -702,6 +700,18 @@ public class TaxonNamePopupEditor extends AbstractCdmDTOPopupEditor<TaxonNameDTO
         Boolean withBasionymSection = BooleanUtils.isTrue(basionymToggle.getValue());
         Boolean withValidationSection = isSpeciesOrBelow && BooleanUtils.isTrue(validationToggle.getValue());
 
+        if(isModeEnabled(TaxonNamePopupEditorMode.VALIDATE_AGAINST_HIGHER_NAME_PART)){
+            if(isSpeciesOrBelow) {
+                if(TextField.class.isAssignableFrom(genusOrUninomialField.getClass())){
+                    genusOrUninomialField = replaceComponent("genusOrUninomial", genusOrUninomialField, new LazyComboBox<String>(String.class), 0, genusOrUninomialRow, 1, genusOrUninomialRow);
+                }
+            } else {
+                if(LazyComboBox.class.isAssignableFrom(genusOrUninomialField.getClass())) {
+                    genusOrUninomialField = replaceComponent("genusOrUninomial", genusOrUninomialField, new TextFieldNFix(), 0, genusOrUninomialRow, 1, genusOrUninomialRow);
+                }
+            }
+        }
+
         if(isModeEnabled(TaxonNamePopupEditorMode.VALIDATE_AGAINST_HIGHER_NAME_PART)){
             if(rank.isInfraSpecific()) {
                 if(TextField.class.isAssignableFrom(specificEpithetField.getClass())) {
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
index d811740e..26b8598b 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
@@ -18,6 +18,7 @@ import java.util.Set;
 import java.util.Stack;
 import java.util.UUID;
 
+import org.apache.log4j.Logger;
 import org.hibernate.Session;
 import org.hibernate.Transaction;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -105,9 +106,8 @@ import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason;
 @ViewScope
 public class RegistrationWorkingsetPresenter extends AbstractPresenter<RegistrationWorkingsetView> {
 
-    /**
-     *
-     */
+    private static final Logger logger = Logger.getLogger(RegistrationWorkingsetPresenter.class);
+
     private static final List<String> REGISTRATION_INIT_STRATEGY = Arrays.asList(
             "$",
             "blockedBy",
@@ -341,12 +341,14 @@ public class RegistrationWorkingsetPresenter extends AbstractPresenter<Registrat
 
     private void saveRegistrationStatusChange(UUID uuid, Object value) {
         Registration reg = getRepo().getRegistrationService().load(uuid);
-        if(value != null && value instanceof RegistrationStatus && !Objects.equals(value, reg.getStatus())){
-            reg.setStatus((RegistrationStatus)value);
-            getRegistrationStore().saveBean(reg, (AbstractView)getView());
-            refreshView(true);
+        if(value != null && value instanceof RegistrationStatus){
+            if(!Objects.equals(value, reg.getStatus())){
+                reg.setStatus((RegistrationStatus)value);
+                getRegistrationStore().saveBean(reg, (AbstractView)getView());
+                refreshView(true);
+            }
         } else {
-            // only log an error here!
+            // only log here as error
             logger.error("Ivalid attempt to set RegistrationStatus to " + Objects.toString(value.toString(), "NULL"));
         }
     }
