commit c02fc11ae73482b118a48cfb4fca97e7302bda1f
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Tue Jul 2 18:17:45 2019 +0200

    fix #8346 flexible editing of annotations for Curator and Admin roles

diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/component/common/FilterableAnnotationsField.java b/src/main/java/eu/etaxonomy/cdm/vaadin/component/common/FilterableAnnotationsField.java
index 54c8484f..25bc5458 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/component/common/FilterableAnnotationsField.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/component/common/FilterableAnnotationsField.java
@@ -22,6 +22,7 @@ import com.vaadin.data.Item;
 import com.vaadin.data.Validator.InvalidValueException;
 import com.vaadin.data.fieldgroup.FieldGroup;
 import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.ui.Button;
 import com.vaadin.ui.Component;
 import com.vaadin.ui.CssLayout;
 import com.vaadin.ui.DefaultFieldFactory;
@@ -35,6 +36,7 @@ import eu.etaxonomy.cdm.model.common.Annotation;
 import eu.etaxonomy.cdm.model.common.AnnotationType;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.term.DefinedTermBase;
+import eu.etaxonomy.cdm.vaadin.component.ButtonFactory;
 import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
 import eu.etaxonomy.cdm.vaadin.util.filter.CdmTermFilter;
 import eu.etaxonomy.vaadin.component.CompositeCustomField;
@@ -52,14 +54,16 @@ public class FilterableAnnotationsField extends CompositeCustomField<List<Annota
 
     private Table table = new Table();
 
-    private List<AnnotationType> typesFilter = null;
+    private Button newButton = ButtonFactory.CREATE_NEW.createButton();
 
-    private Annotation emptyDefaultAnnotation = Annotation.NewInstance(null, Language.DEFAULT());
+    private List<AnnotationType> typesFilter = null;
 
     private BeanItemContainer<DefinedTermBase> typeSelectItemContainer;
 
     private FilterableListContainer<Annotation> container;
 
+    private boolean withNewButton;
+
     public FilterableAnnotationsField() {
         this(null);
     }
@@ -172,11 +176,13 @@ public class FilterableAnnotationsField extends CompositeCustomField<List<Annota
 
     @Override
     protected void setInternalValue(List<Annotation> newValue) {
+
         boolean hasIncludeFilter = typesFilter != null && !typesFilter.isEmpty();
         boolean onlyOneType = hasIncludeFilter && typesFilter.size() == 1;
 
         if(newValue.isEmpty()){
-            newValue.add(emptyDefaultAnnotation);
+            Annotation emptyDefaultAnnotation = newInstance();
+            newValue.add(emptyDefaultAnnotation );
             if(onlyOneType){
                 emptyDefaultAnnotation.setAnnotationType(typesFilter.get(0));
             }
@@ -192,6 +198,9 @@ public class FilterableAnnotationsField extends CompositeCustomField<List<Annota
             table.setVisibleColumns("text", "annotationType");
         }
         table.setEditable(true);
+        if(newValue.size() > 1){
+            table.setPageLength(2);
+        }
     }
 
     /**
@@ -199,11 +208,31 @@ public class FilterableAnnotationsField extends CompositeCustomField<List<Annota
      */
     @Override
     protected Component initContent() {
-        root.addComponent(table);
+        root.addComponentAsFirst(table);
+
+        newButton.addClickListener(e -> addAnnotation());
+        withNewButton(true);
         return root;
     }
 
 
+    /**
+     * @return
+     */
+    private void addAnnotation() {
+        container.addItem(newInstance());
+        if(container.size() > 1){
+            table.setPageLength(2);
+        }
+    }
+
+    /**
+     * @return
+     */
+    private Annotation newInstance() {
+        return Annotation.NewInstance(null, Language.DEFAULT());
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -228,6 +257,20 @@ public class FilterableAnnotationsField extends CompositeCustomField<List<Annota
         setDeepReadOnly(readOnly, table, null);
     }
 
+    public void withNewButton(boolean withNewButton) {
+        if(this.withNewButton != withNewButton){
+            if(!this.withNewButton){
+                root.addComponent(newButton);
+            } else {
+                root.removeComponent(newButton);
+            }
+            this.withNewButton = withNewButton;
+        }
+    }
+
+
+
+
 
 
 }
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPopupEditor.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPopupEditor.java
index 2e7214d5..6217d764 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPopupEditor.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPopupEditor.java
@@ -17,13 +17,16 @@ import com.vaadin.ui.GridLayout;
 import com.vaadin.ui.NativeSelect;
 import com.vaadin.ui.TextField;
 
+import eu.etaxonomy.cdm.api.utility.RoleProber;
 import eu.etaxonomy.cdm.model.common.AnnotationType;
 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
 import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.service.UserHelperAccess;
 import eu.etaxonomy.cdm.vaadin.component.common.FilterableAnnotationsField;
 import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
 import eu.etaxonomy.cdm.vaadin.permission.CdmEditDeletePermissionTester;
+import eu.etaxonomy.cdm.vaadin.permission.RolesAndPermissions;
 import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
 import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
 import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
@@ -180,7 +183,13 @@ public class NameTypeDesignationPopupEditor extends AbstractCdmPopupEditor<NameT
         row++;
         annotationsListField = new FilterableAnnotationsField("Editorial notes");
         annotationsListField.setWidth(100, Unit.PERCENTAGE);
-        annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
+        boolean isCurator = UserHelperAccess.userHelper().userIs(new RoleProber(RolesAndPermissions.ROLE_CURATION));
+        boolean isAdmin = UserHelperAccess.userHelper().userIsAdmin();
+        if(isCurator || isAdmin){
+            annotationsListField.withNewButton(true);
+        } else {
+            annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
+        }
         addField(annotationsListField, "annotations", 0, row, 3, row);
     }
 
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPresenter.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPresenter.java
index cb0b1bfd..bfcadf98 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPresenter.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/NameTypeDesignationPresenter.java
@@ -29,6 +29,7 @@ import eu.etaxonomy.cdm.api.service.registration.IRegistrationWorkingSetService;
 import eu.etaxonomy.cdm.format.ReferenceEllypsisFormatter;
 import eu.etaxonomy.cdm.format.ReferenceEllypsisFormatter.LabelType;
 import eu.etaxonomy.cdm.model.common.Annotation;
+import eu.etaxonomy.cdm.model.common.AnnotationType;
 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
 import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
 import eu.etaxonomy.cdm.model.name.TaxonName;
@@ -165,6 +166,9 @@ public class NameTypeDesignationPresenter
 
         getView().getTypifiedNamesComboboxSelect().setPagingProviders(namePagingProvider, namePagingProvider, namePagingProvider.getPageSize(), this);
 
+        getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory.buildBeanItemContainer(
+                AnnotationType.EDITORIAL().getVocabulary().getUuid()));
+
     }
 
 
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetEditorPresenter.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetEditorPresenter.java
index e97c067c..17329436 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetEditorPresenter.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetEditorPresenter.java
@@ -30,6 +30,7 @@ import eu.etaxonomy.cdm.model.ICdmEntityUuidCacher;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.agent.Person;
 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
+import eu.etaxonomy.cdm.model.common.AnnotationType;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.location.Country;
 import eu.etaxonomy.cdm.model.name.Registration;
@@ -191,12 +192,16 @@ public class SpecimenTypeDesignationWorkingsetEditorPresenter
         getView().getTypeDesignationsCollectionField().addElementRemovedListener(e -> deleteTypeDesignation(e.getElement()));
         getView().getTypeDesignationsCollectionField().addElementAddedListener(e -> addTypeDesignation(e.getElement()));
 
+        getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory.buildBeanItemContainer(
+                AnnotationType.EDITORIAL().getVocabulary().getUuid()));
+
         popuEditorTypeDesignationSourceRows.clear();
         CdmFilterablePagingProvider<Collection, Collection> collectionPagingProvider = new CdmFilterablePagingProvider<Collection, Collection>(getRepo().getCollectionService());
         collectionPagingProvider.getRestrictions().add(new Restriction<>("institute.titleCache", Operator.OR, MatchMode.ANYWHERE, CdmFilterablePagingProvider.QUERY_STRING_PLACEHOLDER));
 
         CdmFilterablePagingProvider<Reference, Reference> referencePagingProvider = pagingProviderFactory.referencePagingProvider();
 
+
         getView().getTypeDesignationsCollectionField().setEditorInstantiator(new AbstractElementCollection.Instantiator<SpecimenTypeDesignationDTORow>() {
 
             @Override
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetPopupEditor.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetPopupEditor.java
index 1affac3f..8b226239 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetPopupEditor.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetPopupEditor.java
@@ -27,8 +27,10 @@ import com.vaadin.ui.NativeSelect;
 import com.vaadin.ui.Panel;
 import com.vaadin.ui.TextArea;
 
+import eu.etaxonomy.cdm.api.utility.RoleProber;
 import eu.etaxonomy.cdm.model.common.AnnotationType;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
+import eu.etaxonomy.cdm.service.UserHelperAccess;
 import eu.etaxonomy.cdm.vaadin.component.CollectionRowRepresentative;
 import eu.etaxonomy.cdm.vaadin.component.common.FilterableAnnotationsField;
 import eu.etaxonomy.cdm.vaadin.component.common.GeoLocationField;
@@ -38,6 +40,7 @@ import eu.etaxonomy.cdm.vaadin.component.common.TimePeriodField;
 import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationDTO;
 import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
 import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
+import eu.etaxonomy.cdm.vaadin.permission.RolesAndPermissions;
 import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
 import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
 import eu.etaxonomy.cdm.vaadin.util.converter.DoubleConverter;
@@ -242,7 +245,13 @@ public class SpecimenTypeDesignationWorkingsetPopupEditor
         row++;
         annotationsListField = new FilterableAnnotationsField("Editorial notes");
         annotationsListField.setWidth(100, Unit.PERCENTAGE);
-        annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
+        boolean isCurator = UserHelperAccess.userHelper().userIs(new RoleProber(RolesAndPermissions.ROLE_CURATION));
+        boolean isAdmin = UserHelperAccess.userHelper().userIsAdmin();
+        if(isCurator || isAdmin){
+            annotationsListField.withNewButton(true);
+        } else {
+            annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
+        }
         addField(annotationsListField, "annotations", 0, row, 2, row);
 
      }
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 f8720bb0..6c6bffb3 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
@@ -234,9 +234,8 @@ public class TaxonNameEditorPresenter extends AbstractCdmDTOEditorPresenter<Taxo
         getView().getOrthographicVariantField().getCitatonComboBox().loadFrom(icbnCodesPagingProvider, icbnCodesPagingProvider, icbnCodesPagingProvider.getPageSize());
         getView().getOrthographicVariantField().getCitatonComboBox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getOrthographicVariantField().getCitatonComboBox(), this));
 
-
-        getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory.buildTermItemContainer(
-                AnnotationType.EDITORIAL().getUuid(), AnnotationType.TECHNICAL().getUuid()));
+        getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory.buildBeanItemContainer(
+                AnnotationType.EDITORIAL().getVocabulary().getUuid()));
     }
 
     /**
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 982e2f5f..08f5176a 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
@@ -35,6 +35,7 @@ import com.vaadin.ui.NativeSelect;
 import com.vaadin.ui.Panel;
 import com.vaadin.ui.TextField;
 
+import eu.etaxonomy.cdm.api.utility.RoleProber;
 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
 import eu.etaxonomy.cdm.model.common.AnnotationType;
 import eu.etaxonomy.cdm.model.common.CdmBase;
@@ -45,6 +46,7 @@ import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.name.RankClass;
 import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.service.UserHelperAccess;
 import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix;
 import eu.etaxonomy.cdm.vaadin.component.common.FilterableAnnotationsField;
 import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
@@ -55,6 +57,7 @@ import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorActionStrRep;
 import eu.etaxonomy.cdm.vaadin.model.name.NameRelationshipDTO;
 import eu.etaxonomy.cdm.vaadin.model.name.TaxonNameDTO;
 import eu.etaxonomy.cdm.vaadin.permission.CdmEditDeletePermissionTester;
+import eu.etaxonomy.cdm.vaadin.permission.RolesAndPermissions;
 import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
 import eu.etaxonomy.cdm.vaadin.ui.UIMessages;
 import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
@@ -563,7 +566,14 @@ public class TaxonNamePopupEditor extends AbstractCdmDTOPopupEditor<TaxonNameDTO
         row++;
         annotationsListField = new FilterableAnnotationsField("Editorial notes");
         annotationsListField.setWidth(100, Unit.PERCENTAGE);
-        annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
+        boolean isCurator = UserHelperAccess.userHelper().userIs(new RoleProber(RolesAndPermissions.ROLE_CURATION));
+        boolean isAdmin = UserHelperAccess.userHelper().userIsAdmin();
+        if(isCurator || isAdmin){
+            annotationsListField.withNewButton(true);
+        } else {
+            annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
+        }
+
         addField(annotationsListField, "annotations", 0, row, GRID_COLS-1, row);
 
         // -----------------------------------------------------------------------------
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferencePopupEditor.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferencePopupEditor.java
index fb30bc6a..4be57b57 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferencePopupEditor.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferencePopupEditor.java
@@ -280,7 +280,13 @@ public class ReferencePopupEditor extends AbstractCdmPopupEditor<Reference, Refe
         row++;
         annotationsListField = new FilterableAnnotationsField("Editorial notes");
         annotationsListField.setWidth(100, Unit.PERCENTAGE);
-        annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
+        boolean isCurator = UserHelperAccess.userHelper().userIs(new RoleProber(RolesAndPermissions.ROLE_CURATION));
+        boolean isAdmin = UserHelperAccess.userHelper().userIsAdmin();
+        if(isCurator || isAdmin){
+            annotationsListField.withNewButton(true);
+        } else {
+            annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
+        }
         addField(annotationsListField, "annotations", 0, row, GRID_COLS-1, row);
 
 
