commit c8cf806c6f86514a56af30050045d28d25289f2c
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Thu Apr 26 09:52:10 2018 +0200

    ref #7366 fixing problems with readonly states while setting values

diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java b/src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java
index 0625acd5..4f681f8d 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java
@@ -80,6 +80,8 @@ public class TeamOrPersonField extends CompositeCustomField<TeamOrPersonBase<?>>
 
     private TeamOrPersonBaseCaptionGenerator.CacheType cacheType;
 
+    protected List<Component> editorComponents = Arrays.asList(removeButton, personButton, teamButton, teamOrPersonSelect);
+
     public TeamOrPersonField(String caption, TeamOrPersonBaseCaptionGenerator.CacheType cacheType){
 
         setCaption(caption);
@@ -123,25 +125,27 @@ public class TeamOrPersonField extends CompositeCustomField<TeamOrPersonBase<?>>
         selectConfirmButton.setEnabled(teamOrPersonSelect.getValue() != null);
         selectConfirmButton.addClickListener(e -> {
             // new entitiy being set, reset the readonly state
-            resetReadOnlyComponents();
-            setValue(teamOrPersonSelect.getValue());
+//            resetReadOnlyComponents();
+//            getPropertyDataSource().setReadOnly(false);
+            setValue(teamOrPersonSelect.getValue(), false, true);
             teamOrPersonSelect.clear();
             updateToolBarButtonStates();
         });
         removeButton.addClickListener(e -> {
-            resetReadOnlyComponents();
-            setValue(null);
+//            resetReadOnlyComponents();
+//            getPropertyDataSource().setReadOnly(false);
+            setValue(null, false, true);
             updateToolBarButtonStates();
         });
         removeButton.setDescription("Remove");
 
         personButton.addClickListener(e -> {
-            setValue(Person.NewInstance()); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
+            setValue(Person.NewInstance(), false, true); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
 
         });
         personButton.setDescription("Add person");
         teamButton.addClickListener(e -> {
-            setValue(Team.NewInstance()); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
+            setValue(Team.NewInstance(), false, true); // FIXME add SelectField or open select dialog, use ToOneSelect field!!
         });
         teamButton.setDescription("Add team");
 
@@ -243,14 +247,11 @@ public class TeamOrPersonField extends CompositeCustomField<TeamOrPersonBase<?>>
 
     private void adaptToUserPermissions(TeamOrPersonBase teamOrPerson) {
 
-        if(teamOrPerson == null){
-            return;
-        }
-
         UserHelper userHelper = UserHelper.fromSession();
-        boolean canEdit = !teamOrPerson.isPersited() || userHelper.userHasPermission(teamOrPerson, CRUD.UPDATE);
+        boolean canEdit = teamOrPerson == null || !teamOrPerson.isPersited() || userHelper.userHasPermission(teamOrPerson, CRUD.UPDATE);
         if(!canEdit){
-            setReadOnlyComponents(true);
+            getPropertyDataSource().setReadOnly(true);
+            //setReadOnlyComponents(true); will be set later on automatically by vaadin
         }
     }
 
@@ -382,10 +383,18 @@ public class TeamOrPersonField extends CompositeCustomField<TeamOrPersonBase<?>>
      */
     @Override
     public void setReadOnly(boolean readOnly) {
-        super.setReadOnly(readOnly);
+//        super.setReadOnly(readOnly); // moved into setEditorReadOnly()
         setReadOnlyComponents(readOnly);
     }
 
+    public void setEditorReadOnly(boolean readOnly) {
+        super.setReadOnly(readOnly);
+        for(Component c : editorComponents){
+            c.setReadOnly(readOnly);
+        }
+
+    }
+
     /**
      * Reset the readonly state of nested components to <code>false</code>.
      */
@@ -403,9 +412,9 @@ public class TeamOrPersonField extends CompositeCustomField<TeamOrPersonBase<?>>
      *
      * @param readOnly
      */
-    public void setReadOnlyComponents(boolean readOnly) {
-        setDeepReadOnly(readOnly, getContent(), Arrays.asList(removeButton, personButton, teamButton, teamOrPersonSelect));
-        updateCaptionReadonlyNotice();
+    protected void setReadOnlyComponents(boolean readOnly) {
+        setDeepReadOnly(readOnly, getContent(), editorComponents);
+        updateCaptionReadonlyNotice(readOnly);
     }
 
 
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 c8b60cd3..518e18f3 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
@@ -668,6 +668,10 @@ public class TaxonNamePopupEditor extends AbstractCdmDTOPopupEditor<TaxonNameDTO
         boolean basionymToggleReadonly = basionymToggle.isReadOnly();
         boolean validationToggleReadonly = validationToggle.isReadOnly();
         super.setReadOnly(readOnly);
+        combinationAuthorshipField.setEditorReadOnly(readOnly);
+        exCombinationAuthorshipField.setEditorReadOnly(readOnly);
+        basionymAuthorshipField.setEditorReadOnly(readOnly);
+        exBasionymAuthorshipField.setEditorReadOnly(readOnly);
         // preserve old readonly states if they were true
         if(basionymToggleReadonly){
             basionymToggle.setReadOnly(true);
diff --git a/src/main/java/eu/etaxonomy/vaadin/component/CompositeCustomField.java b/src/main/java/eu/etaxonomy/vaadin/component/CompositeCustomField.java
index 5ac35f2d..ff4bf00b 100644
--- a/src/main/java/eu/etaxonomy/vaadin/component/CompositeCustomField.java
+++ b/src/main/java/eu/etaxonomy/vaadin/component/CompositeCustomField.java
@@ -213,15 +213,6 @@ public abstract class CompositeCustomField<T> extends CustomField<T> implements
         parent.removeCommitHandler(commitHandler);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void setReadOnly(boolean readOnly) {
-        super.setReadOnly(readOnly);
-        // setDeepReadOnly(readOnly, getContent());
-    }
-
     /**
      * @param readOnly
      */
@@ -248,8 +239,8 @@ public abstract class CompositeCustomField<T> extends CustomField<T> implements
                 ( getValue() != null ? getValue() : "null");
     }
 
-    protected void updateCaptionReadonlyNotice() {
-        if(isReadOnly()){
+    protected void updateCaptionReadonlyNotice(boolean readOnly) {
+        if(readOnly){
             setCaption(getCaption() + READ_ONLY_CAPTION_SUFFIX);
         } else {
             setCaption(getCaption().replace(READ_ONLY_CAPTION_SUFFIX, ""));
