JAL-1443 data validation for empty content before loading alignment from file or...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 2 Jul 2015 15:37:56 +0000 (16:37 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 2 Jul 2015 15:37:56 +0000 (16:37 +0100)
src/jalview/bin/Jalview.java
src/jalview/gui/CutAndPasteTransfer.java
src/jalview/io/FileLoader.java
src/jalview/io/IdentifyFile.java

index 00a042d..f4b38d4 100755 (executable)
@@ -963,6 +963,16 @@ public class Jalview
     }
     return ff;
   }
+
+  public static boolean isHeadlessMode()
+  {
+    String isheadless = System.getProperty("java.awt.headless");
+    if (isheadless != null && isheadless.equalsIgnoreCase("true"))
+    {
+      return true;
+    }
+    return false;
+  }
 }
 
 /**
@@ -1131,4 +1141,4 @@ class FeatureFetcher
     return queued == 0 && running == 0;
   }
 
-};
+}
index e663cf8..979d1aa 100644 (file)
@@ -195,7 +195,13 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer
    */
   public void ok_actionPerformed(ActionEvent e)
   {
-    String format = new IdentifyFile().Identify(getText(), "Paste");
+    String text = getText();
+    if (text.trim().length() < 1)
+    {
+      return;
+    }
+
+    String format = new IdentifyFile().Identify(text, "Paste");
     // TODO: identify feature, annotation or tree file and parse appropriately.
     AlignmentI al = null;
 
index 18ab642..3aded05 100755 (executable)
@@ -22,6 +22,7 @@ package jalview.io;
 
 import jalview.api.ComplexAlignFile;
 import jalview.api.FeaturesDisplayedI;
+import jalview.bin.Jalview;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
@@ -257,6 +258,21 @@ public class FileLoader implements Runnable
         {
           format = new IdentifyFile().Identify(file, protocol);
         }
+
+      }
+
+      if (format == null || format.equalsIgnoreCase("EMPTY DATA FILE"))
+      {
+        Desktop.instance.stopLoading();
+        System.err.println("The input file \"" + file
+                + "\" has no data content!");
+        if (!Jalview.isHeadlessMode())
+        {
+          JOptionPane.showMessageDialog(null, "The input file \""
+                  + file + "\" has no data content!", "Empty data file",
+                  JOptionPane.ERROR_MESSAGE);
+        }
+        return;
       }
       // TODO: cache any stream datasources as a temporary file (eg. PDBs
       // retrieved via URL)
index 27f08ae..4c83ac1 100755 (executable)
@@ -98,7 +98,7 @@ public class IdentifyFile
       }
       while ((data = source.nextLine()) != null)
       {
-        length += data.length();
+        length += data.trim().length();
         if (!lineswereskipped)
         {
           for (int i = 0; !isBinary && i < data.length(); i++)