commit f8485a00195becfc6ff2567f7fbf4735b6fb8df6
Author: Katja Luther <k.luther@bgbm.org>
Date:   Tue Mar 7 15:28:38 2017 +0100

    ref #5691: avoid invalid thread access in referencing object view by calling updateContentDescription in an extra job

diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java
index cced9c3b8..2c91071db 100644
--- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java
+++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java
@@ -20,10 +20,7 @@ import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.IJobChangeListener;
 import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.jobs.JobChangeAdapter;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.viewers.CellEditor;
 import org.eclipse.jface.viewers.ICellModifier;
@@ -191,13 +188,17 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
 	        return ;
 	    }
 	    showEmptyPage();
-	    if(currentJob!=null){
-	        boolean success = false;
-	        //wait for cancel to be done
-	        while(!success){
-	            success = currentJob.cancel();
+	    if(actualMonitor!=null && !actualMonitor.isCanceled()){
+//	        boolean success = false;
+//	        //wait for cancel to be done
+//	        while(!success){
+//	            success = currentJob.cancel();
+//	        }
+//	        currentJob = null;
+	        while(!actualMonitor.isCanceled()){
+	            actualMonitor.setCanceled(true);
 	        }
-	        currentJob = null;
+
 	    }
 		currentJob = new Job("Update Referencing Objects " + entityUUID) {
 
@@ -205,7 +206,7 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
 			protected IStatus run(IProgressMonitor monitor) {
 				monitor.beginTask("Calculating referencing objects", 100);
 				actualUuid = entityUUID;
-				System.out.println("starting job... " + entityUUID);
+
 				monitor.worked(5);
 				referencingObjects = new ArrayList<>();
 				if(monitor.isCanceled()) {
@@ -224,7 +225,7 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
 
 	                if(monitor.isCanceled()) {
 	                    actualUuid = null;
-	                    System.err.println("Job is canceled" + entityUUID);
+
 	                    return Status.CANCEL_STATUS;
 	                }
 	                monitor.worked(30);
@@ -232,7 +233,7 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
 	                if (referencingObjects == null){
 	                    if (monitor.isCanceled()){
 	                        actualUuid = null;
-	                        System.err.println("Job is canceled" + entityUUID);
+
 	                        return Status.CANCEL_STATUS;
 	                    }
 	                }
@@ -241,7 +242,7 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
 	                    if(previousCdmEntitySession != null) {
 	                        previousCdmEntitySession.bind();
 	                    }
-	                    System.err.println("Job is canceled" + entityUUID);
+
 	                    return Status.CANCEL_STATUS;
 	                }
 	                monitor.worked(80);
@@ -254,7 +255,7 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
 				}
 				monitor.done();
 
-				System.out.println("finishing job " + entityUUID);
+
 				return Status.OK_STATUS;
 
 
@@ -263,16 +264,16 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
 		currentJob.setUser(true);
 
 		currentJob.schedule();
-		final IJobChangeListener listener;
-		listener =  new JobChangeAdapter() {
-            @Override
-            public void done(IJobChangeEvent event) {
-                System.err.println("Job is done" + entityUUID);
-                //event.getJob().cancel();
-            }
-
-        };
-        currentJob.addJobChangeListener(listener);
+//		final IJobChangeListener listener;
+//		listener =  new JobChangeAdapter() {
+//            @Override
+//            public void done(IJobChangeEvent event) {
+//                System.err.println("Job is done" + entityUUID);
+//                //event.getJob().cancel();
+//            }
+//
+//        };
+//        currentJob.addJobChangeListener(listener);
 
 
 
@@ -342,7 +343,7 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
         } catch (Exception e) {
             logger.error("Error retrieving referencing objects", e);
             e.printStackTrace();
-            setContentDescription("The referencing objects view could not be loaded completely. Some Problems occured.");
+            updateDescription("The referencing objects view could not be loaded completely. Some Problems occured.");
         }
 		return null;
 	}
@@ -398,7 +399,7 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
 
         			}catch(Exception e){
         			    e.printStackTrace();
-        				setContentDescription("The referencing objects view could not be loaded completely. Some Problems occured.");
+        			    updateDescription("The referencing objects view could not be loaded completely. Some Problems occured.");
         			}
 
         		}
@@ -407,14 +408,14 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
 	}
 
 
-	private void updateDescription(){
+	private void updateDescription(final String description){
 	    Display.getDefault().asyncExec(new Runnable() {
             @Override
             public void run() {
         	    if (referencedObjectTitleCache != null){
-                    setContentDescription("'" + referencedObjectTitleCache + "' is referenced by:");
+                    setContentDescription(description);
                 } else {
-                    setContentDescription("");
+                    setContentDescription(description);
                 }
             }
 
@@ -461,13 +462,18 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
                     referencedObjectTitleCache = null;
                 }
 		    }
-		    updateDescription();
+		    if (referencedObjectTitleCache != null){
+		        updateDescription("'" + referencedObjectTitleCache + "' is referenced by:");
+		    } else{
+		        updateDescription("");
+		    }
+
 		    updateReferencingObjects(referencedCdmObject.getUuid(),firstElement.getClass() );
 
 		}
 		else if (firstElement != null){
 		    updateView();
-            setContentDescription("");
+            updateDescription("");
 		}
 	}
 
