JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / io / cache / JvCacheableInputBox.java
index 9ec3a9f..e02a396 100644 (file)
@@ -237,65 +237,76 @@ public class JvCacheableInputBox<E>
       @Override
       public void run()
       {
-        int cacheLimit = Integer.parseInt(appCache.getCacheLimit(cacheKey));
-        String userInput = getUserInput();
-        if (userInput != null && !userInput.isEmpty())
-        {
-          LinkedHashSet<String> foundCache = appCache
-                  .getAllCachedItemsFor(cacheKey);
-          // remove old cache item so as to place current input at the top of
-          // the result
-          foundCache.remove(userInput);
-          foundCache.add(userInput);
-          appCache.putCache(cacheKey, foundCache);
-        }
+        updateCacheNow();
+      }
+    });
+  }
 
-        String lastSearch = userInput;
-        if (comboBox.getItemCount() > 0)
-        {
-          comboBox.removeAllItems();
-        }
-        Set<String> cacheItems = appCache.getAllCachedItemsFor(cacheKey);
-        List<String> reversedCacheItems = new ArrayList<>();
-        reversedCacheItems.addAll(cacheItems);
-        cacheItems = null;
-        Collections.reverse(reversedCacheItems);
-        if (lastSearch.isEmpty())
-        {
-          comboBox.addItem("");
-        }
+  /**
+   * For TestNG
+   * 
+   * @author Bob Hanson 2019.08.28
+   */
+  public void updateCacheNow()
+  {
+    int cacheLimit = Integer.parseInt(appCache.getCacheLimit(cacheKey));
+    String userInput = getUserInput();
+    if (userInput != null && !userInput.isEmpty())
+    {
+      LinkedHashSet<String> foundCache = appCache
+              .getAllCachedItemsFor(cacheKey);
+      // remove old cache item so as to place current input at the top of
+      // the result
+      foundCache.remove(userInput);
+      foundCache.add(userInput);
+      appCache.putCache(cacheKey, foundCache);
+    }
 
-        if (reversedCacheItems != null && !reversedCacheItems.isEmpty())
+    String lastSearch = userInput;
+    if (comboBox.getItemCount() > 0)
+    {
+      comboBox.removeAllItems();
+    }
+    Set<String> cacheItems = appCache.getAllCachedItemsFor(cacheKey);
+    List<String> reversedCacheItems = new ArrayList<>();
+    reversedCacheItems.addAll(cacheItems);
+    cacheItems = null;
+    Collections.reverse(reversedCacheItems);
+    if (lastSearch.isEmpty())
+    {
+      comboBox.addItem("");
+    }
+
+    if (reversedCacheItems != null && !reversedCacheItems.isEmpty())
+    {
+      LinkedHashSet<String> foundCache = appCache
+              .getAllCachedItemsFor(cacheKey);
+      boolean prune = reversedCacheItems.size() > cacheLimit;
+      int count = 1;
+      boolean limitExceeded = false;
+      for (String cacheItem : reversedCacheItems)
+      {
+        limitExceeded = (count++ > cacheLimit);
+        if (prune)
         {
-          LinkedHashSet<String> foundCache = appCache
-                  .getAllCachedItemsFor(cacheKey);
-          boolean prune = reversedCacheItems.size() > cacheLimit;
-          int count = 1;
-          boolean limitExceeded = false;
-          for (String cacheItem : reversedCacheItems)
+          if (limitExceeded)
           {
-            limitExceeded = (count++ > cacheLimit);
-            if (prune)
-            {
-              if (limitExceeded)
-              {
-                foundCache.remove(cacheItem);
-              }
-              else
-              {
-                comboBox.addItem(cacheItem);
-              }
-            }
-            else
-            {
-              comboBox.addItem(cacheItem);
-            }
+            foundCache.remove(cacheItem);
           }
-          appCache.putCache(cacheKey, foundCache);
+          else
+          {
+            comboBox.addItem(cacheItem);
+          }
+        }
+        else
+        {
+          comboBox.addItem(cacheItem);
         }
-        setSelectedItem(lastSearch.isEmpty() ? "" : lastSearch);
       }
-    });
+      appCache.putCache(cacheKey, foundCache);
+    }
+    setSelectedItem(lastSearch.isEmpty() ? "" : lastSearch);
+
   }
 
   /**