commit fd28a17f87da19fee489fa588ec82f6c3218d37d
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Mon Jun 18 17:10:05 2018 +0200

    ref #6321 Show search progress in progress bar

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 65190bb37..4cbda9aeb 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
@@ -9,7 +9,6 @@
 package eu.etaxonomy.taxeditor.bulkeditor.input;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -20,7 +19,6 @@ 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;
@@ -102,6 +100,8 @@ public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEnti
 
 	protected abstract List<T> listEntities(IIdentifiableEntityServiceConfigurator configurator);
 
+	protected abstract long countEntities(IIdentifiableEntityServiceConfigurator configurator);
+
 	protected abstract T loadEntity(UUID entityUuid);
 
 	public void setMergeTarget(T t){
@@ -160,9 +160,11 @@ public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEnti
 			IIdentifiableEntityServiceConfigurator configurator = bulkEditorQuery.getSearchConfigurator();
 			Comparator queryComparator = (bulkEditorQuery.getComparator() != null) ? bulkEditorQuery.getComparator() : new TitleCacheComparator();
 
+			long count = countEntities(configurator);
+			int totalWork = count>Integer.MAX_VALUE?Integer.MAX_VALUE:(int)count;
 			String jobLabel = String.format(Messages.AbstractBulkEditorInput_LOADING, getName(), bulkEditorQuery.getSearchString());
 	        searchJob = Job.create(jobLabel, (ICoreRunnable) monitor -> {
-	            monitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
+	            monitor.beginTask(jobLabel, totalWork);
 	            int pageNumber = 0;
 	            List<T> entities;
                 do {
@@ -173,7 +175,10 @@ public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEnti
                     entities = listEntities(configurator);
                     model.addAll(entities);
                     pageNumber++;
-                    Collections.sort(model, queryComparator);
+                    monitor.worked(configurator.getPageSize());
+                    long workedLong = configurator.getPageSize()*pageNumber;
+                    int loadedCount =  workedLong>Integer.MAX_VALUE?Integer.MAX_VALUE:(int)workedLong;
+                    monitor.setTaskName(String.format("%s/%s %s loaded", loadedCount, totalWork, getName()));
                 } while (!entities.isEmpty());
 	            monitor.done();
 	        });
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java
index 7bdcf41cd..0e7677988 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java
@@ -102,6 +102,11 @@ public class AgentEditorInput extends AbstractBulkEditorInput<TeamOrPersonBase>
 		return true;
 	}
 
+    @Override
+    protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
+        return CdmStore.getService(IAgentService.class).countByTitle(configurator);
+    }
+
 	/** {@inheritDoc} */
 	@Override
 	public List<TeamOrPersonBase> listEntities(IIdentifiableEntityServiceConfigurator configurator) {
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/GroupEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/GroupEditorInput.java
index b12f1153f..350a50c89 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/GroupEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/GroupEditorInput.java
@@ -67,6 +67,12 @@ public class GroupEditorInput extends AbstractBulkEditorInput<Group> {
 		return CdmStore.getService(IGroupService.class).delete(entity.getUuid()) != null;
 	}
 
+	@Override
+	protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
+	    //TODO there is no count method for groups
+	    return CdmStore.getService(IGroupService.class).count(Group.class);
+	}
+
 	/* (non-Javadoc)
 	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#listEntities(eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator)
 	 */
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/MediaEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/MediaEditorInput.java
index 94d1e030a..8062df834 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/MediaEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/MediaEditorInput.java
@@ -67,6 +67,11 @@ public class MediaEditorInput extends AbstractBulkEditorInput<Media> {
         return CdmStore.getService(IMediaService.class).delete(entity.getUuid(), mediaConfig) != null;
     }
 
+    @Override
+    protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
+        return CdmStore.getService(IMediaService.class).countByTitle(configurator);
+    }
+
     @Override
     protected List<Media> listEntities(IIdentifiableEntityServiceConfigurator configurator) {
         return CdmStore.getSearchManager().findMedia(configurator);
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameEditorInput.java
index 207923f31..996b19c8a 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameEditorInput.java
@@ -74,10 +74,14 @@ public class NameEditorInput extends AbstractBulkEditorInput<TaxonName> {
 		return false;
 	}
 
+	@Override
+	protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
+	    return CdmStore.getService(INameService.class).countByTitle(configurator);
+	}
+
 	/** {@inheritDoc} */
 	@Override
 	public List listEntities(IIdentifiableEntityServiceConfigurator configurator) {
-
 		configurator.setPropertyPaths(getPropertyPaths());
 		return CdmStore.getSearchManager().findNames(configurator, this.getConversation());
 	}
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameRelationshipEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameRelationshipEditorInput.java
index 258568831..1ca54b5c6 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameRelationshipEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/NameRelationshipEditorInput.java
@@ -76,6 +76,13 @@ public class NameRelationshipEditorInput extends AbstractBulkEditorInput<NameRel
 		return false;
 	}
 
+	@Override
+	protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
+	    //TODO there is neither a service for name relationships nor any concrete
+	    //method for counting them
+	    return CdmStore.getCommonService().count(NameRelationship.class);
+	}
+
 	/* (non-Javadoc)
 	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#listEntities(eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator)
 	 */
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/OccurrenceEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/OccurrenceEditorInput.java
index ef09e931b..b67fd8b5b 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/OccurrenceEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/OccurrenceEditorInput.java
@@ -58,6 +58,11 @@ public class OccurrenceEditorInput extends AbstractBulkEditorInput<SpecimenOrObs
 		return instance;
 	}
 
+	@Override
+	protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
+	    return CdmStore.getService(IOccurrenceService.class).countByTitle(configurator);
+	}
+
 	/** {@inheritDoc} */
 	@Override
 	protected List<SpecimenOrObservationBase> listEntities(
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/ReferenceEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/ReferenceEditorInput.java
index 560685966..737dbcdbf 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/ReferenceEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/ReferenceEditorInput.java
@@ -91,6 +91,10 @@ public class ReferenceEditorInput extends AbstractBulkEditorInput<Reference> {
 		return super.isMarkerTypeEditingEnabled(markerType);
 	}
 
+    @Override
+    protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
+        return CdmStore.getService(IReferenceService.class).countByTitle(configurator);
+    }
 
 	/** {@inheritDoc} */
 	@Override
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/TaxonEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/TaxonEditorInput.java
index b7ce2fa4b..9e13a199a 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/TaxonEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/TaxonEditorInput.java
@@ -82,7 +82,10 @@ public class TaxonEditorInput extends AbstractBulkEditorInput<TaxonBase>{
 	    return CdmStore.getService(ITaxonService.class).merge(entity, true).getMergedEntity();
 	}
 
-
+    @Override
+    protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
+        return CdmStore.getService(ITaxonService.class).countByTitle(configurator);
+    }
 
 	/** {@inheritDoc} */
 	@Override
diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/UserEditorInput.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/UserEditorInput.java
index fa45be18e..05bab91f9 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/UserEditorInput.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/UserEditorInput.java
@@ -64,6 +64,12 @@ public class UserEditorInput extends AbstractBulkEditorInput<User> {
 		return CdmStore.getService(IUserService.class).delete(entity) != null;
 	}
 
+	@Override
+	protected long countEntities(IIdentifiableEntityServiceConfigurator configurator) {
+	    //TODO there is no count method for users
+	    return CdmStore.getService(IUserService.class).count(User.class);
+	}
+
 	/* (non-Javadoc)
 	 * @see eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput#listEntities(eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator)
 	 */
