JAL-1700 updated error handling with suggested improvements after Jim's testing
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 31 Aug 2015 17:35:40 +0000 (18:35 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 31 Aug 2015 17:35:40 +0000 (18:35 +0100)
resources/lang/Messages.properties
src/jalview/gui/PDBSearchPanel.java
src/jalview/jbgui/GPDBSearchPanel.java
src/jalview/ws/dbsources/PDBRestClient.java

index 3ff002e..4aeeccd 100644 (file)
@@ -1254,4 +1254,9 @@ action.export_hidden_columns = Export Hidden Columns
 action.export_hidden_sequences = Export Hidden Sequences
 action.export_features = Export Features
 label.export_settings = Export Settings
-label.save_as_biojs_html = Save as BioJs HTML
\ No newline at end of file
+label.save_as_biojs_html = Save as BioJs HTML
+exception.unable_to_detect_internet_connection = Jalview is unable to detect an internet connection
+exception.pdb_rest_service_no_longer_available = PDB rest services no longer available!
+exception.resource_not_be_found = The requested resource could not be found
+exception.pdb_server_error = There seems to be an error from the PDB server
+exception.pdb_server_unreachable = Jalview is unable to reach the PDB host server at \'www.ebi.ac.uk\'. Please ensure that you are connected to the internet and try again.
index 63c3761..b31c637 100644 (file)
@@ -61,61 +61,68 @@ public class PDBSearchPanel extends GPDBSearchPanel
   @Override
   public void txt_search_ActionPerformed()
   {
-    errorWarning.setLength(0);
-    lbl_warning.setVisible(false);
-    btn_ok.setEnabled(false);
-    boolean allowEmptySequence = false;
-    mainFrame.setTitle(MessageManager
-            .getString("label.pdb_sequence_getcher"));
-    tbl_summary.setModel(new DefaultTableModel());
-    if (txt_search.getText().trim().length() > 0)
+    new Thread()
     {
-      long startTime = System.currentTimeMillis();
+      public void run()
+      {
+        lbl_loading.setVisible(false);
+        errorWarning.setLength(0);
+        lbl_warning.setVisible(false);
+        btn_ok.setEnabled(false);
+        boolean allowEmptySequence = false;
+        mainFrame.setTitle(MessageManager
+                .getString("label.pdb_sequence_getcher"));
+        tbl_summary.setModel(new DefaultTableModel());
+        if (txt_search.getText().trim().length() > 0)
+        {
+          lbl_loading.setVisible(true);
+          long startTime = System.currentTimeMillis();
 
-      String searchTarget = ((PDBDocField) cmb_searchTarget
-              .getSelectedItem()).getCode();
+          String searchTarget = ((PDBDocField) cmb_searchTarget
+                  .getSelectedItem()).getCode();
 
-      wantedFields = PDBDocFieldPreferences
-              .getSearchSummaryFields();
+          wantedFields = PDBDocFieldPreferences.getSearchSummaryFields();
 
-      String searchTerm = decodeSearchTerm(txt_search.getText(),
-              searchTarget);
+          String searchTerm = decodeSearchTerm(txt_search.getText(),
+                  searchTarget);
 
-      PDBRestRequest request = new PDBRestRequest();
-      request.setAllowEmptySeq(allowEmptySequence);
-      request.setResponseSize(100);
-      request.setFieldToSearchBy("(" + searchTarget + ":");
-      request.setSearchTerm(searchTerm + ")");
-      request.setWantedFields(wantedFields);
-      // System.out.println(">>>>>>>>>>>>>> " + request.getQuery());
-      PDBRestClient pdbRestCleint = new PDBRestClient();
-      PDBRestResponse resultList;
-      try
-      {
-        resultList = pdbRestCleint.executeRequest(request);
-      } catch (Exception e)
-      {
-        // System.out.println(">>>>>>>>>>>>>>>" + e.getMessage());
-        e.printStackTrace();
-        errorWarning.append(e.getMessage());
-        checkForErrors();
-        return;
-      }
+          PDBRestRequest request = new PDBRestRequest();
+          request.setAllowEmptySeq(allowEmptySequence);
+          request.setResponseSize(100);
+          request.setFieldToSearchBy("(" + searchTarget + ":");
+          request.setSearchTerm(searchTerm + ")");
+          request.setWantedFields(wantedFields);
+          // System.out.println(">>>>>>>>>>>>>> " + request.getQuery());
+          PDBRestClient pdbRestCleint = new PDBRestClient();
+          PDBRestResponse resultList;
+          try
+          {
+            resultList = pdbRestCleint.executeRequest(request);
+          } catch (Exception e)
+          {
+            // e.printStackTrace();
+            errorWarning.append(e.getMessage());
+            checkForErrors();
+            return;
+          }
 
-      if (resultList.getSearchSummary() != null)
-      {
-        tbl_summary.setModel(PDBRestResponse.getTableModel(request,
-                resultList.getSearchSummary()));
-      }
+          if (resultList.getSearchSummary() != null)
+          {
+            tbl_summary.setModel(PDBRestResponse.getTableModel(request,
+                    resultList.getSearchSummary()));
+          }
 
-      long endTime = System.currentTimeMillis();
-      int resultSetCount = resultList.getNumberOfItemsFound();
-      String result = (resultSetCount > 1) ? MessageManager
-              .getString("label.results") : MessageManager
-              .getString("label.result");
-      mainFrame.setTitle(frameTitle + " - " + resultSetCount + " " + result
-              + " (" + (endTime - startTime) + " milli secs)");
-    }
+          long endTime = System.currentTimeMillis();
+          int resultSetCount = resultList.getNumberOfItemsFound();
+          String result = (resultSetCount > 1) ? MessageManager
+                  .getString("label.results") : MessageManager
+                  .getString("label.result");
+          mainFrame.setTitle(frameTitle + " - " + resultSetCount + " "
+                  + result + " (" + (endTime - startTime) + " milli secs)");
+          lbl_loading.setVisible(false);
+        }
+      }
+    }.start();
   }
 
   public static String decodeSearchTerm(String enteredText,
@@ -273,6 +280,7 @@ public class PDBSearchPanel extends GPDBSearchPanel
     lbl_warning.setVisible(false);
     if (errorWarning.length() > 0)
     {
+      lbl_loading.setVisible(false);
       lbl_warning.setToolTipText(JvSwingUtils.wrapTooltip(true,
               errorWarning.toString()));
       lbl_warning.setVisible(true);
index f133a61..6f6f1aa 100644 (file)
@@ -112,8 +112,12 @@ tbl_summary);
   protected ImageIcon warningImage = new ImageIcon(getClass().getResource(
           "/images/warning.gif"));
 
+  protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
+          "/images/loading.gif"));
   protected JLabel lbl_warning = new JLabel(warningImage);
 
+  protected JLabel lbl_loading = new JLabel(loadingImage);
+
   private JTabbedPane tabbedPane = new JTabbedPane();
 
   private PDBDocFieldPreferences pdbDocFieldPrefs = new PDBDocFieldPreferences(
@@ -151,6 +155,8 @@ tbl_summary);
   {
     lbl_warning.setVisible(false);
     lbl_warning.setFont(new java.awt.Font("Verdana", 0, 12));
+    lbl_loading.setVisible(false);
+    lbl_loading.setFont(new java.awt.Font("Verdana", 0, 12));
 
     tbl_summary.setAutoCreateRowSorter(true);
     tbl_summary.getTableHeader().setReorderingAllowed(false);
@@ -323,6 +329,7 @@ tbl_summary);
     pnl_results.add(tabbedPane);
     pnl_inputs.add(cmb_searchTarget);
     pnl_inputs.add(txt_search);
+    pnl_inputs.add(lbl_loading);
     pnl_inputs.add(lbl_warning);
 
     this.setLayout(mainLayout);
index 7e80126..04c00ec 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.ws.dbsources;
 
+import jalview.util.MessageManager;
 import jalview.ws.uimodel.PDBRestRequest;
 import jalview.ws.uimodel.PDBRestResponse;
 import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary;
@@ -102,16 +103,17 @@ public class PDBRestClient
       String exceptionMsg = e.getMessage();
       if (exceptionMsg.contains("SocketException"))
       {
-        throw new Exception(
-                "Jalview is unable to detect an internet connection");
         // No internet connection
+        throw new Exception(
+                MessageManager
+                        .getString("exception.unable_to_detect_internet_connection"));
       }
       else if (exceptionMsg.contains("UnknownHostException"))
       {
-        throw new Exception(
-                "Jalview is unable to reach the host server \'www.ebi.ac.uk\'. "
-                        + "\nPlease ensure that you are connected to the internet and try again.");
         // The server 'www.ebi.ac.uk' is unreachable
+        throw new Exception(
+                MessageManager
+                        .getString("exception.pdb_server_unreachable"));
       }
       else
       {
@@ -126,11 +128,12 @@ public class PDBRestClient
     switch (code)
     {
     case 410:
-      message = "PDB Rest Service no longer exists!";
+      message = MessageManager
+              .getString("exception.pdb_rest_service_no_longer_available");
       break;
     case 403:
     case 404:
-      message = "The requested resource could not be found";
+      message = MessageManager.getString("exception.resource_not_be_found");
       break;
     case 408:
     case 409:
@@ -140,7 +143,7 @@ public class PDBRestClient
     case 503:
     case 504:
     case 505:
-      message = "There seems to be an error from the PDB Rest API server.";
+      message = MessageManager.getString("exception.pdb_server_error");
       break;
 
     default: