JAL-4285 Better checkFiles processing. Better dialog.
[jalview.git] / src / jalview / bin / Commands.java
index 8312b29..ba72831 100644 (file)
@@ -143,8 +143,9 @@ public class Commands
     }
 
     // report errors
-    Console.debug("All errors from command line argument commands:\n"
-            + errorsToString());
+    Console.warn(
+            "The following errors and warnings occurred whilst processing files:\n"
+                    + errorsToString());
     // gui errors reported in Jalview
 
     if (argParser.getBoolean(Arg.QUIT))
@@ -178,7 +179,7 @@ public class Commands
       return true;
     }
 
-    boolean isError = false;
+    Boolean isError = Boolean.valueOf(false);
 
     // set wrap scope here so it can be applied after structures are opened
     boolean wrap = false;
@@ -692,14 +693,10 @@ public class Commands
                 AppJmol jmol = (AppJmol) sview;
                 try
                 {
-                  whatNext wn = this.checksBeforeWritingToFile(avm, subVals,
-                          false, structureImageFilename, "structure image");
-                  if (wn == whatNext.ERROR)
-                  {
-                    isError = true;
-                    continue;
-                  }
-                  else if (wn == whatNext.CONTINUE)
+                  boolean success = this.checksBeforeWritingToFile(avm,
+                          subVals, false, structureImageFilename,
+                          "structure image", isError);
+                  if (!success)
                   {
                     continue;
                   }
@@ -794,7 +791,7 @@ public class Commands
       return false;
     }
 
-    boolean isError = false;
+    Boolean isError = Boolean.valueOf(false);
     if (avm.containsArg(Arg.IMAGE))
     {
       for (ArgValue av : avm.getArgValueList(Arg.IMAGE))
@@ -836,14 +833,9 @@ public class Commands
 
         Console.info("Writing " + file);
 
-        whatNext wn = this.checksBeforeWritingToFile(avm, subVal, false,
-                fileName, "image");
-        if (wn == whatNext.ERROR)
-        {
-          isError = true;
-          continue;
-        }
-        else if (wn == whatNext.CONTINUE)
+        boolean success = checksBeforeWritingToFile(avm, subVal, false,
+                fileName, "image", isError);
+        if (!success)
         {
           continue;
         }
@@ -921,7 +913,7 @@ public class Commands
       return false;
     }
 
-    boolean isError = false;
+    Boolean isError = Boolean.valueOf(false);
 
     if (avm.containsArg(Arg.OUTPUT))
     {
@@ -988,14 +980,9 @@ public class Commands
           }
         }
 
-        whatNext wn = this.checksBeforeWritingToFile(avm, subVals, true,
-                fileName, ff.getName());
-        if (wn == whatNext.ERROR)
-        {
-          isError = true;
-          continue;
-        }
-        else if (wn == whatNext.CONTINUE)
+        boolean success = checksBeforeWritingToFile(avm, subVals, true,
+                fileName, ff.getName(), isError);
+        if (!success)
         {
           continue;
         }
@@ -1113,14 +1100,9 @@ public class Commands
     errors.add(errorMessage);
   }
 
-  private enum whatNext
-  {
-    OKAY, CONTINUE, ERROR;
-  }
-
-  private whatNext checksBeforeWritingToFile(ArgValuesMap avm,
+  private boolean checksBeforeWritingToFile(ArgValuesMap avm,
           SubVals subVal, boolean includeBackups, String filename,
-          String adjective)
+          String adjective, Boolean isError)
   {
     File file = new File(filename);
 
@@ -1145,7 +1127,7 @@ public class Commands
               + Arg.OVERWRITE.argString()
               + (includeBackups ? " or " + Arg.BACKUPS.argString() : "")
               + " set");
-      return whatNext.CONTINUE;
+      return false;
     }
 
     boolean mkdirs = ArgParser.getFromSubValArgOrPref(avm, Arg.MKDIRS,
@@ -1158,10 +1140,11 @@ public class Commands
               + "' does not exist for " + adjective + " file '" + filename
               + "'."
               + (mkdirs ? "" : "  Try using " + Arg.MKDIRS.argString()));
-      return whatNext.ERROR;
+      isError = true;
+      return false;
     }
 
-    return whatNext.OKAY;
+    return true;
   }
 
   public List<String> getErrors()
@@ -1174,8 +1157,9 @@ public class Commands
     StringBuilder sb = new StringBuilder();
     for (String error : errors)
     {
+      if (sb.length() > 0)
+        sb.append("\n");
       sb.append("- " + error);
-      sb.append("\n");
     }
     return sb.toString();
   }