JAL-2757 reset textbox after a non HTTP 200 response
[jalview.git] / src / jalview / fts / service / uniprot / UniprotFTSPanel.java
index eba0f88..748088d 100644 (file)
@@ -40,10 +40,9 @@ public class UniprotFTSPanel extends GFTSPanel
   private static String defaultFTSFrameTitle = MessageManager
           .getString("label.uniprot_sequence_fetcher");
 
+  private static Map<String, Integer> tempUserPrefs = new HashMap<>();
 
-  private static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
-
-  private static final String UNIPROT_FTS_CACHE_KEY = "UNIPROT_FTS_CACHE_KEY";
+  private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_FTS";
 
   public UniprotFTSPanel(SequenceFetcher seqFetcher)
   {
@@ -51,14 +50,14 @@ public class UniprotFTSPanel extends GFTSPanel
     pageLimit = UniProtFTSRestClient.getInstance()
             .getDefaultResponsePageSize();
     this.seqFetcher = seqFetcher;
-    this.progressIndicator = (seqFetcher == null) ? null : seqFetcher
-            .getProgressIndicator();
-    fireCache();
+    this.progressIndicator = (seqFetcher == null) ? null
+            : seqFetcher.getProgressIndicator();
   }
 
   @Override
   public void searchAction(boolean isFreshSearch)
   {
+    mainFrame.requestFocusInWindow();
     if (isFreshSearch)
     {
       offSet = 0;
@@ -74,14 +73,12 @@ public class UniprotFTSPanel extends GFTSPanel
         {
           setSearchInProgress(true);
           long startTime = System.currentTimeMillis();
-
+          searchInput = getTypedText();
           String searchTarget = ((FTSDataColumnI) cmb_searchTarget
                   .getSelectedItem()).getAltCode();
-
           wantedFields = UniProtFTSRestClient.getInstance()
                   .getAllDefaultDisplayedFTSDataColumns();
-          String searchTerm = decodeSearchTerm(getTypedText(),
-                  searchTarget);
+          String searchTerm = decodeSearchTerm(searchInput, searchTarget);
 
           FTSRestRequest request = new FTSRestRequest();
           request.setFieldToSearchBy(searchTarget);
@@ -99,15 +96,15 @@ public class UniprotFTSPanel extends GFTSPanel
             e.printStackTrace();
             setErrorMessage(e.getMessage());
             checkForErrors();
+            setSearchInProgress(false);
             return;
           }
 
           if (resultList.getSearchSummary() != null
                   && resultList.getSearchSummary().size() > 0)
           {
-            getResultTable().setModel(
-                    FTSRestResponse.getTableModel(request,
-                            resultList.getSearchSummary()));
+            getResultTable().setModel(FTSRestResponse.getTableModel(request,
+                    resultList.getSearchSummary()));
             FTSRestResponse.configureTableColumn(getResultTable(),
                     wantedFields, tempUserPrefs);
             getResultTable().setVisible(true);
@@ -117,14 +114,12 @@ public class UniprotFTSPanel extends GFTSPanel
           totalResultSetCount = resultList.getNumberOfItemsFound();
           resultSetCount = resultList.getSearchSummary() == null ? 0
                   : resultList.getSearchSummary().size();
-          String result = (resultSetCount > 0) ? MessageManager
-                  .getString("label.results") : MessageManager
-                  .getString("label.result");
+          String result = (resultSetCount > 0)
+                  ? MessageManager.getString("label.results")
+                  : MessageManager.getString("label.result");
           if (isPaginationEnabled() && resultSetCount > 0)
           {
-            updateSearchFrameTitle(defaultFTSFrameTitle
-                    + " - "
-                    + result
+            updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
                     + " "
                     + totalNumberformatter.format((Number) (offSet + 1))
                     + " to "
@@ -132,8 +127,8 @@ public class UniprotFTSPanel extends GFTSPanel
                             .format((Number) (offSet + resultSetCount))
                     + " of "
                     + totalNumberformatter
-                            .format((Number) totalResultSetCount) + " "
-                    + " (" + (endTime - startTime) + " milli secs)");
+                            .format((Number) totalResultSetCount)
+                    + " " + " (" + (endTime - startTime) + " milli secs)");
           }
           else
           {
@@ -145,7 +140,7 @@ public class UniprotFTSPanel extends GFTSPanel
           refreshPaginatorState();
           updateSummaryTableSelections();
         }
-        fireCache();
+        txt_search.updateCache();
       }
     }.start();
 
@@ -189,12 +184,12 @@ public class UniprotFTSPanel extends GFTSPanel
   {
     disableActionButtons();
     StringBuilder selectedIds = new StringBuilder();
-    HashSet<String> selectedIdsSet = new HashSet<String>();
+    HashSet<String> selectedIdsSet = new HashSet<>();
     int primaryKeyColIndex = 0;
     try
     {
-      primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
-              wantedFields, false);
+      primaryKeyColIndex = getFTSRestClient()
+              .getPrimaryKeyColumIndex(wantedFields, false);
     } catch (Exception e)
     {
       e.printStackTrace();
@@ -202,8 +197,8 @@ public class UniprotFTSPanel extends GFTSPanel
     int[] selectedRows = getResultTable().getSelectedRows();
     for (int summaryRow : selectedRows)
     {
-      String idStr = getResultTable().getValueAt(summaryRow,
-              primaryKeyColIndex).toString();
+      String idStr = getResultTable()
+              .getValueAt(summaryRow, primaryKeyColIndex).toString();
       selectedIdsSet.add(idStr);
     }
     selectedIdsSet.addAll(paginatorCart);