commit 27a07b9c1e7cf113214a020191f0629e15b38cd3
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Sun Jun 3 16:48:58 2018 +0200

    fix #6321 Implement parallel loading + progress bar for bulk editor

diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorQuery.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorQuery.java
index 92ee39fe4..ac49eb4ef 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorQuery.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorQuery.java
@@ -37,11 +37,7 @@ public class BulkEditorQuery {
 		searchConfigurator.setTitleSearchString(searchString);
 		searchConfigurator.setMatchMode(null);
 		searchConfigurator.setPropertyPaths(propertyPath);
-
-		if(searchString != null && searchString.trim().equals("*")){
-			searchConfigurator.setPageSize(1000);
-		}
-
+		searchConfigurator.setPageSize(20);
 	}
 
 	public Comparator getComparator() {
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 005dbf7ca..548520355 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
@@ -19,6 +19,10 @@ import java.util.Map.Entry;
 import java.util.Set;
 import java.util.UUID;
 
+import org.eclipse.core.runtime.ICoreRunnable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.Job;
+
 import ca.odell.glazedlists.BasicEventList;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
@@ -137,24 +141,36 @@ public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEnti
 
 	public void performSearch(final BulkEditorQuery bulkEditorQuery) {
 	    model.clear();
-	    BasicEventList<T> entityList = new BasicEventList<>();
 
 		if(getEntityUuid() != null){
 
 			T entity = loadEntity(getEntityUuid());
-			entityList.add(entity);
-			model.addAll(entityList);
+			model.add(entity);
 		}
 		else if(bulkEditorQuery != null){
 
 			IIdentifiableEntityServiceConfigurator configurator = bulkEditorQuery.getSearchConfigurator();
 			Comparator queryComparator = (bulkEditorQuery.getComparator() != null) ? bulkEditorQuery.getComparator() : new TitleCacheComparator();
 
-			entityList.addAll(listEntities(configurator));
-
-			Collections.sort(entityList, queryComparator);
+			String jobLabel = "Load data";
+	        Job job = Job.create(jobLabel, (ICoreRunnable) monitor -> {
+	            monitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
+	            int pageNumber = 0;
+	            List<T> entities = listEntities(configurator);
+	            while(!entities.isEmpty()){
+	                if(monitor.isCanceled()){
+	                    break;
+	                }
+	                configurator.setPageNumber(pageNumber);
+	                entities = listEntities(configurator);
+	                model.addAll(entities);
+	                pageNumber++;
+	                Collections.sort(model, queryComparator);
+	            }
+	            monitor.done();
+	        });
+	        job.schedule();
 		}
-		model.addAll(entityList);
 	}
 
 	public boolean isMergingEnabled() {
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java
index 75dd95006..1bd710703 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java
@@ -14,9 +14,6 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.UUID;
 
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.swt.widgets.Display;
-
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.service.IAgentService;
 import eu.etaxonomy.cdm.api.service.IGroupService;
@@ -43,7 +40,6 @@ import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
-import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 
@@ -59,18 +55,10 @@ public class SearchManager {
 
 	public static int NO_COUNT = -1;
 
-
-	// TODO make this configurable via preferences
-	private static final int MAX_RESULTS_BEFORE_WARNING = 500;
-
 	public List<TaxonName> findNames(IIdentifiableEntityServiceConfigurator configurator, ConversationHolder conversation){
-
-		if(checkLargeResult(CdmStore.getService(INameService.class).countByTitle(configurator))){
-			List<TaxonName> records = CdmStore.getService(INameService.class).findByTitle(configurator).getRecords();
-			addUuidSearchResults(records, configurator, INameService.class);
-            return records;
-		}
-		return NO_RESULTS;
+	    List<TaxonName> records = CdmStore.getService(INameService.class).findByTitle(configurator).getRecords();
+	    addUuidSearchResults(records, configurator, INameService.class);
+	    return records;
 	}
 
 	public List<NameRelationship> findNameRelationships(
@@ -96,22 +84,15 @@ public class SearchManager {
 	}
 
 	public List<Reference> findReferences(IIdentifiableEntityServiceConfigurator configurator){
-		if(checkLargeResult(CdmStore.getService(IReferenceService.class).countByTitle(configurator))){
-			List<Reference> records = CdmStore.getService(IReferenceService.class).findByTitle(configurator).getRecords();
-			addUuidSearchResults(records, configurator, IReferenceService.class);
-            return records;
-		}
-		return NO_RESULTS;
+	    List<Reference> records = CdmStore.getService(IReferenceService.class).findByTitle(configurator).getRecords();
+	    addUuidSearchResults(records, configurator, IReferenceService.class);
+	    return records;
 	}
 
 	public List<AgentBase> findAgents(IIdentifiableEntityServiceConfigurator configurator){
-
-		if(checkLargeResult(CdmStore.getService(IAgentService.class).countByTitle(configurator))){
-			List<AgentBase> records = CdmStore.getService(IAgentService.class).findByTitle(configurator).getRecords();
-			addUuidSearchResults(records, configurator, IAgentService.class);
-            return records;
-		}
-		return NO_RESULTS;
+	    List<AgentBase> records = CdmStore.getService(IAgentService.class).findByTitle(configurator).getRecords();
+	    addUuidSearchResults(records, configurator, IAgentService.class);
+	    return records;
 	}
 
     /**
@@ -188,9 +169,7 @@ public class SearchManager {
 		}
 		configurator.setPropertyPaths(occurrencePropertyPaths);
 
-		if(checkLargeResult(CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator))){
-			records = CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords();
-		}
+		records = CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords();
 		addUuidSearchResults(records, configurator, IOccurrenceService.class);
 		return records;
 	}
@@ -213,39 +192,20 @@ public class SearchManager {
 	}
 
 
-	private boolean checkLargeResult(int count) {
-	    return checkLargeResult(count, MAX_RESULTS_BEFORE_WARNING);
-	}
-
-	private boolean checkLargeResult(int count, int maxBeforWarning) {
-		if(count > maxBeforWarning){
-			return MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.SearchManager_LARGE_RESULT_EXPECTED,
-					String.format(Messages.SearchManager_LONG_SEARCH_WARNING, count));
-		}else{
-			return true;
-		}
-	}
-
 	private String sqlizeTitleSearchString(IIdentifiableEntityServiceConfigurator configurator){
 		return configurator.getTitleSearchString().replace(WILDCARD, "%"); //$NON-NLS-1$
 	}
 
 	public List findTaxa(IIdentifiableEntityServiceConfigurator configurator) {
-		if(checkLargeResult(CdmStore.getService(ITaxonService.class).countByTitle(configurator))){
-			List<TaxonBase> records = CdmStore.getService(ITaxonService.class).findByTitle(configurator).getRecords();
-			addUuidSearchResults(records, configurator, ITaxonService.class);
-            return records;
-		}
-		return NO_RESULTS;
+	    List<TaxonBase> records = CdmStore.getService(ITaxonService.class).findByTitle(configurator).getRecords();
+	    addUuidSearchResults(records, configurator, ITaxonService.class);
+	    return records;
 	}
 
 	public List findMedia(IIdentifiableEntityServiceConfigurator configurator) {
-        if(checkLargeResult(CdmStore.getService(IMediaService.class).countByTitle(configurator))){
-            List<Media> records = CdmStore.getService(IMediaService.class).findByTitle(configurator).getRecords();
-            addUuidSearchResults(records, configurator, IMediaService.class);
-            return records;
-        }
-        return NO_RESULTS;
+	    List<Media> records = CdmStore.getService(IMediaService.class).findByTitle(configurator).getRecords();
+	    addUuidSearchResults(records, configurator, IMediaService.class);
+	    return records;
     }
 
 
