JAL-629 Add a timeout to modal dialogs for command line warning
[jalview.git] / src / jalview / bin / Jalview.java
index 51e8a82..ba418fe 100755 (executable)
@@ -76,6 +76,7 @@ import jalview.bin.argparser.BootstrapArgs;
 import jalview.ext.so.SequenceOntology;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
+import jalview.gui.JvOptionPane;
 import jalview.gui.PromptUserConfig;
 import jalview.gui.QuitHandler;
 import jalview.gui.QuitHandler.QResponse;
@@ -641,14 +642,12 @@ public class Jalview
     try
     {
       Console.initLogger();
-    } catch (
-
-    NoClassDefFoundError error)
+    } catch (NoClassDefFoundError error)
     {
       error.printStackTrace();
       String message = "\nEssential logging libraries not found."
               + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview";
-      Jalview.exit(message, ExitCode.OK);
+      Jalview.exit(message, ExitCode.NO_LOGGING);
     }
     desktop = null;
 
@@ -673,6 +672,8 @@ public class Jalview
       desktop = new Desktop();
       desktop.setInBatchMode(true); // indicate we are starting up
 
+      mixedCliWarning();
+
       try
       {
         JalviewTaskbar.setTaskbar(this);
@@ -1247,6 +1248,8 @@ public class Jalview
       }
       desktop.setInBatchMode(false);
     }
+
+    cliWarning();
   }
 
   private static void setLookAndFeel()
@@ -1627,9 +1630,8 @@ public class Jalview
      */
     PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
             "USAGESTATS",
-            MessageManager.getString("prompt.plausible_analytics_title"),
-            MessageManager.getString("prompt.plausible_analytics"),
-            new Runnable()
+            MessageManager.getString("prompt.analytics_title"),
+            MessageManager.getString("prompt.analytics"), new Runnable()
             {
               @Override
               public void run()
@@ -1857,7 +1859,7 @@ public class Jalview
     // only add new ones to the end of the list (to preserve ordinal values)
     OK, FILE_NOT_FOUND, FILE_NOT_READABLE, NO_FILES, INVALID_FORMAT,
     INVALID_ARGUMENT, INVALID_VALUE, MIXED_CLI_ARGUMENTS,
-    ERROR_RUNNING_COMMANDS;
+    ERROR_RUNNING_COMMANDS, NO_LOGGING;
   }
 
   /******************************
@@ -2020,4 +2022,71 @@ public class Jalview
             || getInstance().desktop.isInBatchMode());
   }
 
+  /**
+   * Warning about old or mixed command line arguments
+   */
+  private void mixedCliWarning()
+  {
+    Jalview j = Jalview.getInstance();
+    boolean mixedStyle = j.getArgParser() != null
+            && j.getArgParser().isMixedStyle();
+    String title = MessageManager.getString("label.command_line_arguments");
+    if (mixedStyle)
+    {
+      String warning = MessageManager.formatMessage(
+              "warning.using_mixed_command_line_arguments",
+              j.getArgParser().getMixedExamples());
+      String quit = MessageManager.getString("action.quit");
+
+      Desktop.instance.nonBlockingDialog(title, warning, null, quit,
+              JvOptionPane.WARNING_MESSAGE, false, false, true, 30000);
+
+      Jalview.exit(
+              "Exiting due to mixed old and new command line arguments.",
+              ExitCode.MIXED_CLI_ARGUMENTS);
+    }
+  }
+
+  private void cliWarning()
+  {
+    Jalview j = Jalview.getInstance();
+    Commands c = j.getCommands();
+    boolean oldStyle = j.getArgParser() != null
+            && j.getArgParser().isOldStyle();
+    String title = MessageManager.getString("label.command_line_arguments");
+    if (oldStyle)
+    {
+      String warning = MessageManager
+              .getString("warning.using_old_command_line_arguments");
+      String url = "<a href=\"https://www.jalview.org/help/html/features/commandline.html\">https://www.jalview.org/help/html/features/commandline.html</a>";
+      if (Desktop.instance != null)
+      {
+        String cont = MessageManager.getString("label.continue");
+
+        Desktop.instance.nonBlockingDialog(title, warning, url, cont,
+                JvOptionPane.WARNING_MESSAGE, false, true, true, 2000);
+      }
+    }
+    if (j.getCommands() != null && j.getCommands().getErrors().size() > 0)
+    {
+      if (Desktop.instance != null)
+      {
+        String message = MessageManager
+                .getString("warning.the_following_errors");
+        String ok = MessageManager.getString("action.ok");
+        int shortest = 60;
+        List<String> errors = j.getCommands().getErrors();
+        for (int i = 0; i < errors.size(); i++)
+        {
+          shortest = Math.min(shortest, errors.get(i).length());
+        }
+        Desktop.instance.nonBlockingDialog(
+                Math.max(message.length(), Math.min(60, shortest)),
+                Math.min(errors.size(), 20), title, message,
+                j.getCommands().errorsToString(), ok,
+                JvOptionPane.WARNING_MESSAGE, true, false, true, -1);
+      }
+    }
+  }
+
 }