JAL-629 Fix Exceptions when running with CLI not headless
authorBen Soares <b.soares@dundee.ac.uk>
Mon, 27 Feb 2023 15:05:09 +0000 (15:05 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Mon, 27 Feb 2023 15:05:09 +0000 (15:05 +0000)
src/jalview/bin/Commands.java
src/jalview/bin/Jalview.java
src/jalview/gui/JvOptionPane.java

index f8481f5..429c692 100644 (file)
@@ -19,12 +19,16 @@ import jalview.bin.ArgParser.ArgValuesMap;
 import jalview.bin.ArgParser.SubVals;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.annotations.AlphaFoldAnnotationRowBuilder;
 import jalview.gui.AlignFrame;
 import jalview.gui.AlignmentPanel;
+import jalview.gui.AssociatePdbFileWithSeq;
 import jalview.gui.Desktop;
+import jalview.gui.Preferences;
 import jalview.gui.StructureChooser;
+import jalview.gui.StructureViewer;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.DataSourceType;
 import jalview.io.FileFormatException;
@@ -144,7 +148,7 @@ public class Commands
         if (first)
         {
           first = false;
-          if (!headless)
+          if (!headless && desktop != null)
           {
             desktop.setProgressBar(
                     MessageManager.getString(
@@ -424,8 +428,17 @@ public class Commands
           Console.debug("Using structure file "
                   + structureFile.getAbsolutePath());
 
+          PDBEntry fileEntry = new AssociatePdbFileWithSeq()
+                  .associatePdbWithSeq(structureFile.getAbsolutePath(),
+                          DataSourceType.FILE, seq, true, Desktop.instance);
+
           // open structure view
           AlignmentPanel ap = af.alignPanel;
+          if (headless)
+          {
+            Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
+                    StructureViewer.ViewerType.JMOL.toString());
+          }
           StructureChooser.openStructureFileForSequence(ap, seq,
                   structureFile);
         }
index 99ae815..3cc71af 100755 (executable)
@@ -378,19 +378,6 @@ public class Jalview
 
     if (argparser.isSet(Arg.HEADLESS))
       headless = argparser.getBool(Arg.HEADLESS);
-    boolean commandsSuccess = Commands.processArgs(argparser, headless);
-    if (commandsSuccess)
-    {
-      Console.info("Successfully completed commands");
-      if (headless)
-        System.exit(0);
-    }
-    else
-    {
-      Console.warn("Error when running commands");
-      if (headless)
-        System.exit(1);
-    }
 
     if (!Platform.isJS())
     /**
@@ -613,6 +600,20 @@ public class Jalview
         }
       }
     }
+    // Run Commands from cli
+    boolean commandsSuccess = Commands.processArgs(argparser, headless);
+    if (commandsSuccess)
+    {
+      Console.info("Successfully completed commands");
+      if (headless)
+        System.exit(0);
+    }
+    else
+    {
+      Console.warn("Error when running commands");
+      if (headless)
+        System.exit(1);
+    }
 
     // Check if JVM and compile version might cause problems and log if it
     // might.
index 3c942ce..020890b 100644 (file)
@@ -1066,9 +1066,12 @@ public class JvOptionPane extends JOptionPane
 
     ourOptions = Arrays.asList(options);
     int response;
-    if (parentComponent != this)
+    if (parentComponent != this
+            && !(parentComponent == null && Desktop.instance == null))
     {
-      JInternalFrame jif = this.createInternalFrame(parentComponent, title);
+      JInternalFrame jif = this.createInternalFrame(
+              parentComponent != null ? parentComponent : Desktop.instance,
+              title);
       jif.setFrameIcon(null);
       jif.addInternalFrameListener(new InternalFrameListener()
       {