added some error checking and instruction dialogs
authorjprocter <Jim Procter>
Thu, 8 Dec 2005 16:10:39 +0000 (16:10 +0000)
committerjprocter <Jim Procter>
Thu, 8 Dec 2005 16:10:39 +0000 (16:10 +0000)
src/jalview/gui/SequenceFetcher.java

index ca2e375..e7d03fe 100755 (executable)
@@ -36,10 +36,11 @@ public class SequenceFetcher
   JInternalFrame frame;\r
   AlignFrame alignFrame;\r
   StringBuffer result;\r
+  final String noDbSelected = "-- Select Database --";\r
   public SequenceFetcher(AlignFrame af)\r
   {\r
     alignFrame = af;\r
-    database.addItem("-- Select Database --");\r
+    database.addItem(noDbSelected);\r
     database.addItem("Uniprot");\r
     database.addItem("EMBL");\r
     database.addItem("EMBLCDS");\r
@@ -146,8 +147,29 @@ public class SequenceFetcher
     worker.start();\r
   }\r
 \r
+  private void resetDialog() {\r
+    database.setEnabled(true);\r
+    textfield.setEnabled(true);\r
+    ok.setEnabled(true);\r
+    cancel.setEnabled(true);\r
+    frame.setTitle("Sequence Fetcher (WSDBfetch@EBI)");\r
+  }\r
+\r
   public void run()\r
   {\r
+    String error = "";\r
+    if (database.getSelectedItem().equals(noDbSelected))\r
+      error += "Please select the source database\n";\r
+    com.stevesoft.pat.Regex empty=new com.stevesoft.pat.Regex("\\s+","");\r
+    textfield.setText(empty.replaceAll(textfield.getText()));\r
+    if (textfield.getText().length()==0)\r
+      error+="Please enter a (semi-colon separated list of) database id(s)";\r
+    if (error.length()>0) {\r
+      showErrorMessage(error);\r
+      resetDialog();\r
+      return;\r
+    }\r
+\r
    result = new StringBuffer();\r
     if (database.getSelectedItem().equals("Uniprot"))\r
     {\r
@@ -170,20 +192,17 @@ public class SequenceFetcher
     else if (database.getSelectedItem().equals("PDB"))\r
     {\r
       result = getPDBFile(textfield.getText().toUpperCase());\r
-      parseResult(result.toString());\r
+      if (result!=null)\r
+        parseResult(result.toString());\r
     }\r
 \r
 \r
     if (result == null || result.length() == 0)\r
       showErrorMessage("Error retrieving " + textfield.getText()\r
                        + " from " + database.getSelectedItem());\r
-\r
-\r
-      database.setEnabled(true);\r
-      textfield.setEnabled(true);\r
-      ok.setEnabled(true);\r
-      cancel.setEnabled(true);\r
-      frame.setTitle("Sequence Fetcher (WSDBfetch@EBI)");\r
+    else\r
+      textfield.setText("");\r
+    resetDialog();\r
   }\r
 \r
   void getUniprotFile(String id)\r
@@ -256,6 +275,8 @@ public class SequenceFetcher
 \r
       EBIFetchClient ebi = new EBIFetchClient();\r
       String[] reply = ebi.fetchData("pdb:" + id, "pdb", "raw");\r
+      if (reply==null)\r
+        return null;\r
       try\r
       {\r
         PDBfile pdbfile = new PDBfile(reply);\r
@@ -275,8 +296,8 @@ public class SequenceFetcher
       }\r
       catch (Exception ex) // Problem parsing PDB file\r
       {\r
-        showErrorMessage("Error retrieving " + textfield.getText() + " from " +\r
-            database.getSelectedItem());\r
+        jalview.bin.Cache.log.warn("Exception when retrieving " + textfield.getText() + " from " +\r
+            database.getSelectedItem(), ex);\r
         return null;\r
       }\r
 \r