commit ea92bdaa2398648416908808ef081abb00c878bc
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Fri Nov 16 13:13:46 2018 +0100

    ref #7910 TeamOrPersonField adapting read only state handling to available teammebers setter

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 97daae63..bbf142ef 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
@@ -167,9 +167,9 @@ public class TeamOrPersonField extends CompositeCustomField<TeamOrPersonBase<?>>
         boolean userCanCreate = UserHelperAccess.userHelper().userHasPermission(Person.class, "CREATE");
 
         teamOrPersonSelect.setVisible(val == null);
-        removeButton.setVisible(val != null);
-        personButton.setEnabled(userCanCreate && val == null);
-        teamButton.setEnabled(userCanCreate && val == null);
+        removeButton.setVisible(!isReadOnly() && val != null);
+        personButton.setEnabled(!isReadOnly() && userCanCreate && val == null);
+        teamButton.setEnabled(!isReadOnly() && userCanCreate && val == null);
     }
 
     /**
@@ -187,7 +187,6 @@ public class TeamOrPersonField extends CompositeCustomField<TeamOrPersonBase<?>>
         compositeWrapper.addComponent(toolBar);
 
         if(newValue != null) {
-
             if(Person.class.isAssignableFrom(newValue.getClass())){
                 // value is a Person
                 compositeWrapper.addComponent(personField);
@@ -199,24 +198,20 @@ public class TeamOrPersonField extends CompositeCustomField<TeamOrPersonBase<?>>
             else if(Team.class.isAssignableFrom(newValue.getClass())){
                 // otherwise it a Team
                 compositeWrapper.addComponents(titleField, nomenclaturalTitleField, personsListEditor);
-
                 titleField.bindTo(fieldGroup, "titleCache", "protectedTitleCache");
                 nomenclaturalTitleField.bindTo(fieldGroup, "nomenclaturalTitle", "protectedNomenclaturalTitleCache");
                 fieldGroup.setItemDataSource(new BeanItem<Team>((Team)newValue));
-                boolean readonlyState = personsListEditor.isReadOnly();
-                fieldGroup.bind(personsListEditor, "teamMembers"); // here personField is set readonly since setTeamMembers does not exist
-                personsListEditor.setReadOnly(readonlyState); // fixing the readonly state
-
+                fieldGroup.bind(personsListEditor, "teamMembers");
                 personsListEditor.registerParentFieldGroup(fieldGroup);
-
             } else {
                 UserError usererror = new UserError("TeamOrPersonField Error: Unsupported value type: " + newValue.getClass().getName());
                 setComponentError(usererror);
                 logger.error(usererror.getMessage());
             }
         } else {
+            // new value is null
             if(oldValue != null){
-                // value is null --> clean up all nested fields
+                // value is null --> clean up all nested fields from old value
                 // allow replacing old content in the editor by null
                 setReadOnlyComponents(false);
                 if(Person.class.isAssignableFrom(oldValue.getClass())){
@@ -250,6 +245,7 @@ public class TeamOrPersonField extends CompositeCustomField<TeamOrPersonBase<?>>
         boolean canEdit = teamOrPerson == null || !teamOrPerson.isPersited() || userHelper.userHasPermission(teamOrPerson, CRUD.UPDATE);
         if(!canEdit){
             setReadOnlyComponents(true);
+            fieldGroup.setReadOnly(true); // really needed?
         }
     }
 
@@ -307,7 +303,8 @@ public class TeamOrPersonField extends CompositeCustomField<TeamOrPersonBase<?>>
         }
 
         TeamOrPersonBase<?> bean = getValue();
-        if(bean != null && bean instanceof Team){
+        boolean isTeam = bean != null && bean instanceof Team;
+        if(isTeam){
             boolean isUnsaved = bean.getId() == 0;
             if(isUnsaved){
                 UserHelperAccess.userHelper().createAuthorityForCurrentUser(bean, EnumSet.of(CRUD.UPDATE, CRUD.DELETE), null);
@@ -428,7 +425,12 @@ public class TeamOrPersonField extends CompositeCustomField<TeamOrPersonBase<?>>
      * @param readOnly
      */
     protected void setReadOnlyComponents(boolean readOnly) {
-        setDeepReadOnly(readOnly, getContent(), editorComponents);
+
+        // setDeepReadOnly(readOnly, getContent(), editorComponents);
+        // editorComponents.forEach(c -> c.setEnabled(!readOnly));
+//        personField.setReadOnly(readOnly);
+//        personsListEditor.setReadOnly(readOnly);
+
         updateCaptionReadonlyNotice(readOnly);
     }
 
