commit 6cf49987808795f35aae371f577c8d5fb983a2f0
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Thu Jun 21 15:45:46 2018 +0200

    ref #7439 Re-select after search has finished

diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
index 5cf0a9ce4..1ea4e7b65 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
@@ -21,9 +21,11 @@ import javax.inject.Inject;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.e4.core.di.annotations.Optional;
 import org.eclipse.e4.core.services.events.IEventBroker;
 import org.eclipse.e4.ui.di.Focus;
 import org.eclipse.e4.ui.di.Persist;
+import org.eclipse.e4.ui.di.UIEventTopic;
 import org.eclipse.e4.ui.model.application.ui.MDirtyable;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.services.EMenuService;
@@ -59,7 +61,6 @@ import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
 import org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack;
 import org.eclipse.nebula.widgets.nattable.selection.RowSelectionModel;
 import org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider;
-import org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand;
 import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
 import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
 import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
@@ -367,13 +368,17 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
         conversation.commit(true);
 
         if (lastQuery != null){
-            performSearch(lastQuery);
-            setSelection(selection);
+            performSearch(lastQuery, selection);
         }
 	}
 
-	/** {@inheritDoc} */
-    public void performSearch(BulkEditorQuery query) {
+	public void performSearch(BulkEditorQuery query) {
+	    performSearch(query, null);
+	}
+
+	/** {@inheritDoc}
+	 * @param selection */
+    public void performSearch(BulkEditorQuery query, IStructuredSelection selection) {
         if (query != null) {
             // TODO check if dirty, prompt save
             if (isDirty()) {
@@ -387,11 +392,18 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
                 }
             }
             dirty.setDirty(false);
-            input.performSearch(query);
+            input.performSearch(query, selection);
             lastQuery = query;
         }
     }
 
+    @Optional
+    @Inject
+    private void setSelectionAfterSearch(@UIEventTopic(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED)IStructuredSelection selection){
+        if(selection!=null){
+            setSelection(selection);
+        }
+    }
 
     public void refresh(){
         natTable.doCommand(new VisualRefreshCommand());
@@ -413,7 +425,7 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
         Object[] objects = selection.toArray();
         for (Object object : objects) {
             if(object instanceof CdmBase){
-                natTable.doCommand(new SelectRowsCommand(bodyLayer, 0, bodyDataProvider.indexOfRowObject((CdmBase) object), false, false));
+                bodyLayer.getSelectionLayer().selectRow(0, bodyDataProvider.indexOfRowObject((CdmBase) object), false, false);
             }
         }
     }
@@ -475,7 +487,7 @@ public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnable
             input.replaceInModel((CdmBase) element);
         }
         dirty.setDirty(true);
-        setSelection(getSelection());
+        setSelection(new StructuredSelection(element));
     }
 
     @Override
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 9ef47c5bf..76ff42b49 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,7 @@ import java.util.UUID;
 
 import org.eclipse.core.runtime.ICoreRunnable;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.IStructuredSelection;
 
 import ca.odell.glazedlists.BasicEventList;
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
@@ -38,6 +39,8 @@ import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortProvider;
 import eu.etaxonomy.taxeditor.bulkeditor.input.sortprovider.CdmBaseSortProvider;
 import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
 import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
+import eu.etaxonomy.taxeditor.event.EventUtility;
+import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
 import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -144,7 +147,7 @@ public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEnti
 		return entityUuid;
 	}
 
-	public void performSearch(final BulkEditorQuery bulkEditorQuery) {
+	public void performSearch(final BulkEditorQuery bulkEditorQuery, IStructuredSelection selection) {
 	    //cancel previous search job
 	    if(searchJob!=null && searchJob.getState()!=Job.NONE){
 	        searchJob.cancel();
@@ -183,8 +186,8 @@ public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEnti
                     monitor.setTaskName(String.format(Messages.AbstractBulkEditorInput_LOADED, loadedCount, totalWork, getName()));
                 } while (!entities.isEmpty());
 	            monitor.done();
+	            EventUtility.postAsyncEvent(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED, selection);
 	        });
-	        searchJob.setUser(true);
 	        searchJob.schedule();
 		}
 	}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/EventUtility.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/EventUtility.java
index 7836bf2c1..8588c149f 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/EventUtility.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/EventUtility.java
@@ -16,6 +16,7 @@ import org.eclipse.e4.core.commands.ECommandService;
 import org.eclipse.e4.core.di.annotations.Optional;
 import org.eclipse.e4.core.services.events.IEventBroker;
 import org.eclipse.e4.ui.di.UIEventTopic;
+import org.eclipse.e4.ui.di.UISynchronize;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.swt.widgets.Shell;
@@ -36,6 +37,9 @@ public class EventUtility {
 
     private static Shell shell;
 
+    @Inject
+    private static UISynchronize sync;
+
     @Inject
     private static IEventBroker eventBroker;
 
@@ -51,6 +55,14 @@ public class EventUtility {
         eventBroker.post(topic, data);
     }
 
+    public static void postSyncEvent(String topic, Object data){
+        sync.syncExec(()->eventBroker.post(topic, data));
+    }
+
+    public static void postAsyncEvent(String topic, Object data){
+        sync.asyncExec(()->eventBroker.post(topic, data));
+    }
+
     public static ECommandService getCommandService() {
         return commandService;
     }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/WorkbenchEventConstants.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/WorkbenchEventConstants.java
index d286dd1cb..5dfad0aa3 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/WorkbenchEventConstants.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/event/WorkbenchEventConstants.java
@@ -33,4 +33,6 @@ public interface WorkbenchEventConstants {
 
     public static final String RECONNECT = "RECONNECT";
 
+    public static final String BULK_EDITOR_SEARCH_FINISHED = "BULK_EDITOR/SEARCH_DONE";
+
 }
