JAL-4279 suppress error dialogs raised by file loader when working in batch mode improvement/JAL-4279_gracefully_handle_failure_to_openviaCLI
authorJames Procter <j.procter@dundee.ac.uk>
Thu, 7 Sep 2023 16:00:19 +0000 (17:00 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Thu, 7 Sep 2023 16:00:19 +0000 (17:00 +0100)
src/jalview/bin/Jalview.java
src/jalview/io/FileLoader.java

index efd2177..eabad91 100755 (executable)
@@ -1978,4 +1978,9 @@ public class Jalview
     return bootstrapArgs;
   }
 
+  public static boolean isBatchMode()
+  {
+    return getInstance()!=null && (getInstance().desktop == null || getInstance().desktop.isInBatchMode());
+  }
+
 }
index bf79fa4..dc7adac 100755 (executable)
@@ -325,7 +325,7 @@ public class FileLoader implements Runnable
         Desktop.instance.stopLoading();
         jalview.bin.Console.errPrintln("The input file \"" + file
                 + "\" has null or unidentifiable data content!");
-        if (!Jalview.isHeadlessMode())
+        if (!Jalview.isHeadlessMode() && !Jalview.isBatchMode())
         {
           JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                   MessageManager.getString("label.couldnt_read_data")
@@ -361,7 +361,7 @@ public class FileLoader implements Runnable
           // We read the data anyway - it might make sense.
         }
         // BH 2018 switch to File object here instead of filename
-        alignFrame = new Jalview2XML(raiseGUI).loadJalviewAlign(
+        alignFrame = new Jalview2XML(raiseGUI && !Jalview.isBatchMode()).loadJalviewAlign(
                 selectedFile == null ? file : selectedFile);
       }
       else
@@ -537,7 +537,7 @@ public class FileLoader implements Runnable
                   "label.couldnt_load_file") + " " + title + "\n" + error;
           // TODO: refactor FileLoader to be independent of Desktop / Applet GUI
           // bits ?
-          if (raiseGUI && Desktop.desktop != null)
+          if (raiseGUI && !Jalview.isBatchMode() && Desktop.desktop != null)
           {
             javax.swing.SwingUtilities.invokeLater(new Runnable()
             {
@@ -565,7 +565,7 @@ public class FileLoader implements Runnable
     {
       jalview.bin.Console.errPrintln("Exception whilst opening file '" + file);
       er.printStackTrace();
-      if (raiseGUI)
+      if (raiseGUI && !Jalview.isBatchMode())
       {
         javax.swing.SwingUtilities.invokeLater(new Runnable()
         {
@@ -587,7 +587,7 @@ public class FileLoader implements Runnable
 
       er.printStackTrace();
       alignFrame = null;
-      if (raiseGUI)
+      if (raiseGUI && !Jalview.isBatchMode())
       {
         javax.swing.SwingUtilities.invokeLater(new Runnable()
         {