ref #5691: avoid invalid thread access in referencing object view by calling updateCo...
authorKatja Luther <k.luther@bgbm.org>
Tue, 7 Mar 2017 14:28:38 +0000 (15:28 +0100)
committerKatja Luther <k.luther@bgbm.org>
Tue, 7 Mar 2017 14:28:38 +0000 (15:28 +0100)
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java

index cced9c3b8a40a3c3465cd25c304c6a3d16098f26..2c91071db9a47047b83697b3ae114a50ab42e026 100644 (file)
@@ -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("");
                }
        }