JAL-4279 move on if the file doesn't exist, or Identify fails for the file.
[jalview.git] / src / jalview / bin / Commands.java
index e409c77..8164182 100644 (file)
@@ -6,7 +6,6 @@ import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -166,13 +165,9 @@ public class Commands
     if (avm == null)
       return true;
 
-    /*
-     * // script to execute after all loading is completed one way or another String
-     * groovyscript = m.get(Arg.GROOVY) == null ? null :
-     * m.get(Arg.GROOVY).getValue(); String file = m.get(Arg.OPEN) == null ? null :
-     * m.get(Arg.OPEN).getValue(); String data = null; FileFormatI format = null;
-     * DataSourceType protocol = null;
-     */
+    // set wrap scope here so it can be applied after structures are opened
+    boolean wrap = false;
+
     if (avm.containsArg(Arg.APPEND) || avm.containsArg(Arg.OPEN))
     {
       commandArgsProvided = true;
@@ -222,6 +217,7 @@ public class Commands
             if (!(new File(openFile)).exists())
             {
               Console.warn("Can't find file '" + openFile + "'");
+              continue;
             }
           }
         }
@@ -236,6 +232,7 @@ public class Commands
         } catch (FileFormatException e1)
         {
           Console.error("Unknown file format for '" + openFile + "'");
+          continue;
         }
 
         af = afMap.get(id);
@@ -252,14 +249,24 @@ public class Commands
           Console.debug(
                   "Opening '" + openFile + "' in new alignment frame");
           FileLoader fileLoader = new FileLoader(!headless);
-
-          af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol,
-                  format);
-
-          // wrap alignment?
-          boolean wrap = ArgParser.getFromSubValArgOrPref(avm, Arg.WRAP, sv,
-                  null, "WRAP_ALIGNMENT", false);
-          af.getCurrentView().setWrapAlignment(wrap);
+          boolean xception=false;
+          try {
+            af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol,
+                    format);
+          } catch (Throwable thr)
+          {
+            xception=true;
+            Console.error("Couldn't open '"+openFile+"' as "+format+" "+thr.getLocalizedMessage()+ " (Enable debug for full stack trace)");
+            Console.debug("Exception when opening '"+openFile+"'",thr);
+          }
+          finally
+          {
+            if (af==null && !xception)
+            {
+              Console.info("Ignoring '"+openFile+"' - no alignment data found.");
+              continue;
+            }
+          }
 
           // colour alignment?
           String colour = ArgParser.getFromSubValArgOrPref(avm, av,
@@ -365,6 +372,12 @@ public class Commands
                     false, false);
           }
 
+          // wrap alignment? do this last for formatting reasons
+          wrap = ArgParser.getFromSubValArgOrPref(avm, Arg.WRAP, sv, null,
+                  "WRAP_ALIGNMENT", false);
+          // af.setWrapFormat(wrap) is applied after structures are opened for
+          // annotation reasons
+
           // store the AlignFrame for this id
           afMap.put(id, af);
 
@@ -556,20 +569,7 @@ public class Commands
           String sViewer = ArgParser.getFromSubValArgOrPref(avm,
                   Arg.STRUCTUREVIEWER, Position.AFTER, av, subVals, null,
                   null, "jmol");
-          ViewerType viewerType = null;
-          if (!"none".equals(sViewer))
-          {
-            for (ViewerType v : EnumSet.allOf(ViewerType.class))
-            {
-              String name = v.name().toLowerCase(Locale.ROOT)
-                      .replaceAll(" ", "");
-              if (sViewer.equals(name))
-              {
-                viewerType = v;
-                break;
-              }
-            }
-          }
+          ViewerType viewerType = ViewerType.getFromString(sViewer);
 
           // TODO use ssFromStructure
           StructureViewer sv = StructureChooser
@@ -693,6 +693,15 @@ public class Commands
       }
     }
 
+    if (wrap)
+    {
+      AlignFrame af = afMap.get(id);
+      if (af != null)
+      {
+        af.setWrapFormat(wrap, true);
+      }
+    }
+
     /*
     boolean doShading = avm.getBoolean(Arg.TEMPFAC_SHADING);
     if (doShading)
@@ -811,7 +820,7 @@ public class Commands
 
           case "biojs":
             Console.debug(
-                    "Creating BioJS MSA Viwer HTML file: " + fileName);
+                    "Outputting BioJS MSA Viwer HTML file: " + fileName);
             try
             {
               BioJsHTMLOutput.refreshVersionInfo(
@@ -825,12 +834,12 @@ public class Commands
             break;
 
           case "eps":
-            Console.debug("Creating EPS file: " + fileName);
-            af.createEPS(file, name);
+            Console.debug("Outputting EPS file: " + fileName);
+            af.createEPS(file, renderer);
             break;
 
           case "imagemap":
-            Console.debug("Creating ImageMap file: " + fileName);
+            Console.debug("Outputting ImageMap file: " + fileName);
             af.createImageMap(file, name);
             break;
 
@@ -1001,7 +1010,7 @@ public class Commands
         seq = al.getSequenceAt(subVals.getIndex());
       }
     }
-    else if (idAv != null)
+    if (seq == null && idAv != null)
     {
       seq = al.findName(idAv.getValue());
     }