commit a186543e24da3e3bd7e4b57b0c993d88b93aa007
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Wed Aug 15 17:49:30 2018 +0200

    ref #7518 Pre-load and select previously selected element

diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java
index 503b8714b..61bd5a1bf 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java
@@ -17,6 +17,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 import org.eclipse.core.runtime.ICoreRunnable;
 import org.eclipse.core.runtime.jobs.Job;
@@ -173,7 +174,6 @@ public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEnti
 	    model.clear();
 
 		if(getEntityUuid() != null){
-
 			T entity = loadEntity(getEntityUuid());
 			model.add(entity);
 		}
@@ -202,30 +202,32 @@ public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEnti
 	            monitor.beginTask(jobLabel, totalWork);
 	            int pageNumber = 0;
 	            List<T> entities;
+
+	            //load previously selected element
+	            UUID selectedUuid = null;
+	            if(selection!=null && selection.getFirstElement() instanceof CdmBase){
+	                selectedUuid = ((CdmBase) selection.getFirstElement()).getUuid();
+	                T entity = loadEntity(selectedUuid);
+	                model.add(entity);
+	            }
+
                 do {
                     if (monitor.isCanceled()) {
                         break;
                     }
                     configurator.setPageNumber(pageNumber);
                     entities = listEntities(configurator);
-                    /*
-                     * IMPORTANT!
-                     * Entities have to be loaded into the main session because they are
-                     * loaded in a parallel asynchronous thread
-                     */
-                    getCdmEntitySession().load(entities, true);
-
-                    model.addAll(entities);
-
-                    //select entity when it is loaded
-                    if(selection!=null && model.containsAll(selection.toList())){
-                        EventUtility.postAsyncEvent(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED, selection);
-                    }
+
+                    addToModel(entities, selectedUuid);
+
                     pageNumber++;
                     monitor.worked(pageSize);
                     long workedLong = pageSize*pageNumber;
                     int loadedCount =  workedLong>Integer.MAX_VALUE?Integer.MAX_VALUE:(int)workedLong;
                     monitor.setTaskName(String.format(Messages.AbstractBulkEditorInput_LOADED, loadedCount, totalWork, getName()));
+
+                    //Update selection
+                    EventUtility.postAsyncEvent(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED, selection);
                 } while (!entities.isEmpty());
 	            monitor.done();
 	            EventUtility.postAsyncEvent(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED, selection);
@@ -234,6 +236,22 @@ public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEnti
 		}
 	}
 
+	private void addToModel(List<T> entities, UUID selectedUuid){
+	    //filter pre-loaded previously selected element
+	    if(selectedUuid!=null){
+	        entities = entities.stream().filter(entity->!entity.getUuid().equals(selectedUuid)).collect(Collectors.toList());
+	    }
+	    /*
+         * IMPORTANT!
+         * Entities have to be loaded into the main session because they are
+         * loaded in a parallel asynchronous thread
+         */
+        if(getCdmEntitySession()!=null){//is null when closing the bulk editor during loading
+            getCdmEntitySession().load(entities, true);
+        }
+        model.addAll(entities);
+	}
+
 	public boolean isMergingEnabled() {
 		return false;
 	}
