Avoid duplication of edited team member (#4997)
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 24 Jun 2015 18:58:19 +0000 (20:58 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 29 Jun 2015 11:45:15 +0000 (13:45 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/agent/TeamMemberElement.java

index 0600c843f900b8b4e478098f602c891908a4132d..8e8e1e64489eff3f9b82ab21e0e48c068161b667 100644 (file)
@@ -13,6 +13,7 @@ package eu.etaxonomy.taxeditor.ui.section.agent;
 import org.eclipse.swt.events.SelectionListener;
 
 import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.agent.Team;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
@@ -58,7 +59,19 @@ public class TeamMemberElement extends AbstractEntityCollectionElement<Person> {
         if (eventSource == selection_person) {
             if (getParentElement() instanceof TeamMemberSection) {
                 TeamMemberSection teamMemberSection = (TeamMemberSection) getParentElement();
-                teamMemberSection.getEntity().addTeamMember(selection_person.getEntity());
+                Team team = teamMemberSection.getEntity();
+
+                int index = team.getTeamMembers().indexOf(getEntity());
+
+                if(index==-1){
+                    team.addTeamMember(selection_person.getEntity());
+                }
+                else{
+                    //first remove the edited team member and then add it again
+                    //because the model allows the same person multiple time in on team
+                    team.removeTeamMember(getEntity());
+                    team.addTeamMember(selection_person.getEntity(), index);
+                }
                 firePropertyChangeEvent(new CdmPropertyChangeEvent(teamMemberSection, eventSource));
             }
             entity = selection_person.getEntity();