ref #9894: add field primary collector and handle as described in ticket
authorKatja Luther <k.luther@bgbm.org>
Wed, 5 Jan 2022 12:01:32 +0000 (13:01 +0100)
committerKatja Luther <k.luther@bgbm.org>
Wed, 5 Jan 2022 12:01:32 +0000 (13:01 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/CollectorSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/DerivedUnitGeneralDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/FieldUnitFacadeGeneralDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/CollectorSelectionElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/NomenclaturalAuthorTeamSelectionElement.java [deleted file]

index 23b001e4594d01ff0f46fddcbe8b4f5bf10cd6be..360de4da3acb38c32e9ca98ccbd93c892689af6e 100755 (executable)
@@ -8,8 +8,17 @@
 */
 package eu.etaxonomy.taxeditor.ui.dialog.selection;
 
+import java.lang.reflect.Member;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.internal.win32.TCHITTESTINFO;
 import org.eclipse.swt.widgets.Shell;
 
 import eu.etaxonomy.cdm.api.service.IAgentService;
@@ -17,6 +26,7 @@ import eu.etaxonomy.cdm.api.service.dto.EntityDTOBase;
 import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.agent.Team;
 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
 import eu.etaxonomy.cdm.persistence.dto.TeamOrPersonUuidAndTitleCache;
@@ -29,6 +39,7 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @since Jul 1, 2021
  */
 public class CollectorSelectionDialog extends AgentSelectionDialog<AgentBase<?>> {
+       Team collectorTeam = null;
 
     /**
      * @param shell
@@ -41,10 +52,15 @@ public class CollectorSelectionDialog extends AgentSelectionDialog<AgentBase<?>>
     protected CollectorSelectionDialog(Shell shell, String title, boolean multi, String settings,
             AgentBase<?> agent, boolean selectTeamMember) {
         super(shell, title, multi, settings, agent, selectTeamMember);
+        if (selectTeamMember && agent instanceof Team){
+               this.collectorTeam = (Team)agent;
+               
+       }
 
     }
     public static <S extends AgentBase> S select(Shell shell,
             S entity, boolean selectTeamMember) {
+       
         CollectorSelectionDialog dialog = new CollectorSelectionDialog(shell,
                 "Choose Collector", false, CollectorSelectionDialog.class.getCanonicalName(), entity, selectTeamMember);
         return  (S) getSelectionFromDialog(dialog);
@@ -93,8 +109,28 @@ public class CollectorSelectionDialog extends AgentSelectionDialog<AgentBase<?>>
         if (selectTeamMember){
             clazz = Person.class;
         }
-
+        Set<UUID> memberUuids = new HashSet<>();
+        if (collectorTeam != null && selectTeamMember){
+               List<Person> teamMembers = this.collectorTeam.getTeamMembers();
+               
+            teamMembers.forEach(member -> memberUuids.add(member.getUuid()));
+        }
+        
         model = CdmStore.getService(IAgentService.class).getUuidAndTitleCacheWithCollectorTitleCache(clazz, limitOfInitialElements, pattern);
+        if (collectorTeam == null){
+               return;
+        }
+        //filter
+        Iterator<UuidAndTitleCache<AgentBase<?>>> modelIterator = model.iterator();
+        List<UuidAndTitleCache<AgentBase<?>>> tempModel = new ArrayList<>();
+        while(modelIterator.hasNext()){
+               UuidAndTitleCache<AgentBase<?>> person = modelIterator.next();
+               if (memberUuids.contains(person.getUuid())){
+                       tempModel.add(person);
+               }
+        }
+        model.clear();
+        model.addAll(tempModel);
     }
 
     @Override
index d276f5f83ff5ba2daaaf4c3abd9572c72fc24789..c642891542d3a8023dd8a6ed7dbd7ddd8d489edf 100644 (file)
@@ -61,6 +61,7 @@ import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalSourceDetailElem
 import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;\r
 import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement;\r
 import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection;\r
+import eu.etaxonomy.taxeditor.ui.selection.CollectorSelectionElement;\r
 \r
 /**\r
  * @author n.hoffmann\r
@@ -122,6 +123,9 @@ public class SelectionDialogFactory {
         }else if(clazz.equals(AgentBase.class) && (parentElement instanceof FieldUnitFacadeGeneralDetailElement || parentElement instanceof DerivedUnitGeneralDetailElement)){\r
                    return (T) CollectorSelectionDialog.select(shell,\r
                            (TeamOrPersonBase) currentSelection, false);\r
+               }else if (clazz.equals(AgentBase.class) && parentElement instanceof CollectorSelectionElement){\r
+                       return (T) CollectorSelectionDialog.select(shell,\r
+                           (TeamOrPersonBase) ((CollectorSelectionElement)parentElement).getCollectorTeam(), true);\r
                }else if(clazz.equals(TeamOrPersonBase.class)){\r
             //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)\r
             return (T) TeamOrPersonBaseSelectionDialog.select(shell,\r
index e83696d8e87dab498be6a625deb22f4843fe77d6..b1ed7d73ae6374fb61f21019a89ed712a8404ff8 100644 (file)
@@ -415,7 +415,6 @@ import eu.etaxonomy.taxeditor.ui.selection.CommonNameReferenceSelectionElement;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementWithAbbreviatedTitle;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementWithIdInVocabulary;
-import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
 import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
 import eu.etaxonomy.taxeditor.view.detail.CdmSectionPart;
 
@@ -3300,7 +3299,16 @@ public class CdmFormFactory extends FormToolkit {
       adapt(element);
       parentElement.addElement(element);
       return element;
-  }
+    }
+    
+    public CollectorSelectionElement createCollectorSelectionElement(ICdmFormElement parentElement, String labelString, AgentBase team, Person member, int mode,
+            int style) {
+       CollectorSelectionElement element = new CollectorSelectionElement(this, parentElement, 
+                labelString, team, member, mode, style);
+        adapt(element);
+        parentElement.addElement(element);
+        return element;
+      }
 
     public CommonNameReferenceSelectionElement createCommonNameReferenceSelectionElement(ICdmFormElement parentElement, String labelString, Reference selection, int mode,
           int style) {
index 387a37eee97b7bbafb2b8a9e9d7d593c8b91febb..caec7352978e993caf296cfe98fa957995c56928 100644 (file)
@@ -11,6 +11,8 @@ package eu.etaxonomy.taxeditor.ui.section.occurrence;
 
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
+import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.agent.Team;
 import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.occurrence.Collection;
@@ -32,6 +34,7 @@ import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
 import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
 import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
+import eu.etaxonomy.taxeditor.ui.selection.CollectorSelectionElement;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
 
 /**
@@ -54,7 +57,8 @@ public class DerivedUnitGeneralDetailElement extends
        private PointElement element_point;
        private NumberWithLabelElement number_elevation;
        private TimePeriodElement element_date;
-       private EntitySelectionElement<AgentBase> selection_collector;
+       private CollectorSelectionElement selection_collector;
+       private CollectorSelectionElement selection_primary_collector;
        private TextWithLabelElement text_collectingNumber;
        private EntitySelectionElement<Collection> selection_collection;
        private TextWithLabelElement text_accessionNumber;
@@ -103,6 +107,14 @@ public class DerivedUnitGeneralDetailElement extends
                                    formElement, "Collector",
                                    entity.getCollector(), EntitySelectionElement.ALL,
                                    style);
+                   selection_primary_collector = formFactory
+                           .createCollectorSelectionElement(
+                                   formElement, "Primary collector",
+                                   entity.getCollector(), entity.getPrimaryCollector(), EntitySelectionElement.ALL,
+                                   style);
+               if (!(entity.getCollector() instanceof Team)){
+                       selection_primary_collector.setEnabled(false);
+                   }
                    text_collectingNumber = formFactory.createTextWithLabelElement(formElement,
                            "Collecting number", entity.getFieldNumber(), style);
                }
@@ -138,7 +150,14 @@ public class DerivedUnitGeneralDetailElement extends
                        getEntity().setGatheringPeriod(element_date.getTimePeriod());
                } else if (eventSource == selection_collector) {
                        getEntity().setCollector(selection_collector.getSelection());
-               } else if (eventSource == text_collectingNumber) {
+                        getEntity().setCollector(selection_collector.getSelection());
+                if (getEntity().getCollector() instanceof Team){
+                        selection_primary_collector.setCollectorTeam((Team)getEntity().getCollector());
+                }
+                       selection_primary_collector.setEnabled(getEntity().getCollector() instanceof Team);
+               } else if (eventSource == selection_primary_collector) {
+                       getEntity().setPrimaryCollector((Person)selection_primary_collector.getSelection());
+               }else if (eventSource == text_collectingNumber) {
                        getEntity().setFieldNumber(text_collectingNumber.getText());
                }
                  else if (eventSource == selection_collection) {
index c58b0e262091d12b75e09d2796c475d740185750..77a5ee61cf08f72e535d188f001a8e9f9de688ba 100644 (file)
@@ -8,12 +8,19 @@
  */
 package eu.etaxonomy.taxeditor.ui.section.occurrence;
 
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
+import eu.etaxonomy.cdm.model.agent.Team;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
@@ -47,6 +54,7 @@ public class FieldUnitFacadeGeneralDetailElement extends AbstractCdmDetailElemen
     private NumberWithLabelElement number_elevation;
     private TimePeriodElement element_date;
     private CollectorSelectionElement selection_collector;
+    private CollectorSelectionElement selection_primary_collector;
     private TextWithLabelElement text_collectingNumber;
     private GatheringEventUnitElement element_elevation;
     private CheckboxElement checkIsPublish;
@@ -81,6 +89,14 @@ public class FieldUnitFacadeGeneralDetailElement extends AbstractCdmDetailElemen
 
         element_date = formFactory.createTimePeriodElement(formElement, "Date", entity.getGatheringPeriod(), style);
         selection_collector = formFactory.createCollectorSelectionElement(formElement, "Collector", entity.getCollector(), EntitySelectionElement.ALL, style);
+        selection_primary_collector = formFactory
+                   .createCollectorSelectionElement(
+                           formElement, "Primary collector",
+                           entity.getCollector(), entity.getPrimaryCollector(), EntitySelectionElement.ALL,
+                           style);
+        if (!(entity.getCollector() instanceof Team)){
+               selection_primary_collector.setEnabled(false);
+           }
         text_collectingNumber = formFactory.createTextWithLabelElement(formElement, "Collecting number",
                 entity.getFieldNumber(), style);
         checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.innerFieldUnit().isPublish(), style);
@@ -104,6 +120,16 @@ public class FieldUnitFacadeGeneralDetailElement extends AbstractCdmDetailElemen
             getEntity().setGatheringPeriod(element_date.getTimePeriod());
         } else if (eventSource == selection_collector) {
             getEntity().setCollector(selection_collector.getSelection());
+            
+            if (getEntity().getCollector() instanceof Team){
+               selection_primary_collector.setCollectorTeam((Team)getEntity().getCollector());
+            }else{
+               selection_primary_collector.setEntity(null);
+            }
+            selection_primary_collector.setEnabled((getEntity().getCollector() instanceof Team));
+            
+        } else if (eventSource == selection_primary_collector) {
+            getEntity().setCollector(selection_primary_collector.getSelection());
         } else if (eventSource == text_collectingNumber) {
             getEntity().setFieldNumber(text_collectingNumber.getText());
         } else if (eventSource == combo_specorobstype) {
@@ -115,4 +141,18 @@ public class FieldUnitFacadeGeneralDetailElement extends AbstractCdmDetailElemen
         toggleableText_titleCache.setText(getEntity().getTitleCache());
 
     }
+    protected void updateControlStates(){
+        if (getEntity() != null ){
+            enabled = enabled && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), requiredCrud);
+        }else{
+            enabled = true;
+        }
+        Set<Object> except = new HashSet<>(); 
+        if (!selection_primary_collector.isEnabled() && enabled){
+               except.add(selection_primary_collector);
+        }
+        setEnabled(enabled, except);
+        
+    }
+
 }
\ No newline at end of file
index 7c0edde3393085e118a406766b980d20ca914504..95cb2b600bce3074191560eef7253a5d8e4ae852 100644 (file)
@@ -1,13 +1,21 @@
 package eu.etaxonomy.taxeditor.ui.selection;
 
+import org.eclipse.swt.events.SelectionEvent;
+
 import eu.etaxonomy.cdm.model.agent.AgentBase;
+import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.agent.Team;
 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 
 public class CollectorSelectionElement extends EntitySelectionElement<AgentBase> {
+       
+       Team collectorTeam;
        /**
      * @param formFactory
      * @param conversation
@@ -24,6 +32,15 @@ public class CollectorSelectionElement extends EntitySelectionElement<AgentBase>
         parentElement, AgentBase.class,
         labelString, entity, mode, style);
     }
+    public CollectorSelectionElement(CdmFormFactory formFactory,// ConversationHolder conversation,
+            ICdmFormElement parentElement, String labelString, AgentBase entity, Person primaryCollector, int mode, int style) {
+       super(formFactory, //conversation,
+        parentElement, AgentBase.class,
+        labelString, primaryCollector, mode, style);
+       if (entity instanceof Team){
+               collectorTeam = (Team)entity;
+       }
+    }
 
     @Override
     protected String getTitle() {
@@ -36,4 +53,27 @@ public class CollectorSelectionElement extends EntitySelectionElement<AgentBase>
                }
                return "";
        }
+       public Team getCollectorTeam() {
+               return collectorTeam;
+       }
+       public void setCollectorTeam(Team collectorTeam) {
+               this.collectorTeam = collectorTeam;
+       }
+       
+       public void widgetSelected(SelectionEvent e) {
+           if (e.getSource().equals(button_selection) ){
+               AgentBase selection = null;
+               if (this.collectorTeam != null){
+                       selection = SelectionDialogFactory.getSelectionFromDialog(AgentBase.class, getShell(),
+                               collectorTeam, this);
+               }else{          
+                       selection = SelectionDialogFactory.getSelectionFromDialog(AgentBase.class, getShell(),
+                       getEntity(), getParentElement());
+               }
+            setSelectionInternal(selection);
+            if(!getLayoutComposite().isDisposed()){
+                StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
+            }
+           }
+       }
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/NomenclaturalAuthorTeamSelectionElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/NomenclaturalAuthorTeamSelectionElement.java
deleted file mode 100644 (file)
index 4602c05..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * Copyright (C) 2007 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.selection;
-
-import org.eclipse.swt.events.SelectionEvent;
-
-import eu.etaxonomy.cdm.model.agent.Team;
-import eu.etaxonomy.taxeditor.ui.dialog.selection.NomenclaturalAuthorTeamSelectionDialog;
-import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-
-/**
- * <p>
- * NomenclaturalAuthorTeamSelectionElement class.
- * </p>
- *
- * @author n.hoffmann
- * @created Jun 22, 2010
- * @version 1.0
- */
-public class NomenclaturalAuthorTeamSelectionElement extends
-               EntitySelectionElement<Team> {
-
-       public static final int DEFAULT = EDITABLE | SELECTABLE | DELETABLE;
-
-       /**
-        * <p>
-        * Constructor for NomenclaturalAuthorTeamSelectionElement.
-        * </p>
-        *
-        * @param formFactory
-        *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
-        *            object.
-        * @param conversation
-        *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
-        *            object.
-        * @param parentElement
-        *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
-        *            object.
-        * @param labelString
-        *            a {@link java.lang.String} object.
-        * @param entity
-        *            a {@link eu.etaxonomy.cdm.model.agent.Team} object.
-        * @param style
-        *            a int.
-        */
-       public NomenclaturalAuthorTeamSelectionElement(CdmFormFactory formFactory,//ConversationHolder conversation,
-               ICdmFormElement parentElement,
-                       String labelString, Team entity, int mode, int style) {
-               super(formFactory,// conversation,
-                       parentElement, Team.class, labelString, entity,
-                               mode, style);
-       }
-
-       /** {@inheritDoc} */
-       @Override
-       protected String getTitle() {
-               return (entity != null) ? entity.getNomenclaturalTitleCache() : "";
-       }
-
-       /** {@inheritDoc} */
-       @Override
-       public void widgetSelected(SelectionEvent e) {
-               Team newSelection = NomenclaturalAuthorTeamSelectionDialog.select(
-                               getShell(), //getConversationHolder(),
-                               entity);
-               setSelectionInternal(newSelection);
-       }
-}