Merge branch 'patch/JAL-4196_structure_viewer_synchronising' into develop patch/JAL-4196_structure_viewer_synchronising
authorJames Procter <j.procter@dundee.ac.uk>
Wed, 21 Jun 2023 11:24:27 +0000 (13:24 +0200)
committerJames Procter <j.procter@dundee.ac.uk>
Wed, 21 Jun 2023 11:24:27 +0000 (13:24 +0200)
src/jalview/bin/Commands.java
src/jalview/gui/Desktop.java
src/jalview/workers/AlignCalcManager.java
test/jalview/bin/CommandsTest2.java

index bcf231e..7f493e0 100644 (file)
@@ -569,9 +569,20 @@ public class Commands
                           structureFilepath, tft, paeFilepath, false,
                           ssFromStructure, false, viewerType);
 
-          if (headless)
+          if (sv==null)
+          {
+            Console.error("Failed to import and open structure view.");
+            continue;
+          }
+          while (sv.isBusy())
           {
-            sv.setAsync(false);
+            try {
+              Thread.sleep(25);
+            }
+            catch (Exception x)
+            {
+              
+            }
           }
 
           String structureImageFilename = ArgParser.getValueFromSubValOrArg(
index 99c394b..b901ae4 100644 (file)
@@ -3627,4 +3627,24 @@ public class Desktop extends jalview.jbgui.GDesktop
       Desktop.instance = null;
     }
   }
+
+  /**
+   * checks if any progress bars are being displayed in any of the windows managed by the desktop
+   * @return
+   */
+  public boolean operationsAreInProgress()
+  {
+    JInternalFrame[] frames = getAllFrames();
+    for (JInternalFrame frame:frames)
+    {
+      if (frame instanceof IProgressIndicator)
+      {
+        if (((IProgressIndicator)frame).operationInProgress())
+        {
+          return true;
+        }
+      }
+    }
+    return operationInProgress();
+  }
 }
index d81db8c..fc28e53 100644 (file)
@@ -25,6 +25,7 @@ import jalview.api.AlignCalcWorkerI;
 import jalview.datamodel.AlignmentAnnotation;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Hashtable;
@@ -208,9 +209,18 @@ public class AlignCalcManager implements AlignCalcManagerI
     }
     synchronized (updating)
     {
-      for (List<AlignCalcWorkerI> workers : updating.values())
+      Collection<List<AlignCalcWorkerI>> workersLists = updating.values();
+      synchronized (workersLists)
       {
-        working |= workers.size() > 0;
+        for (List<AlignCalcWorkerI> workers : workersLists)
+        {
+          if (workers!=null)
+          {
+            synchronized (workers) {
+              working |= workers.size() > 0;
+            }
+          }
+        }
       }
     }
     return working;
index 0c2071a..d6b6f3c 100644 (file)
@@ -65,14 +65,18 @@ public class CommandsTest2
     String[] args = cmdLine.split("\\s+");
 
     CommandsTest.callJalviewMain(args);
-    try
+    while (Desktop.instance!=null && Desktop.instance.operationsAreInProgress())
     {
-      // sleep for slow build server to open annotations and viewer windows
-      Thread.sleep(seqNum * 50 + annNum * 50 + viewerNum * 500);
-    } catch (InterruptedException e)
-    {
-      e.printStackTrace();
+      try
+      {
+        // sleep for slow build server to open annotations and viewer windows
+        Thread.sleep(viewerNum * 50);
+      } catch (InterruptedException e)
+      {
+        e.printStackTrace();
+      }
     }
+    ;
 
     AlignFrame[] afs = Desktop.getAlignFrames();
     Assert.assertNotNull(afs);