JAL-3851 some changes. HighlightSequenceEndpoint and SelectSequenceEndpoint
[jalview.git] / src / jalview / gui / SequenceFetcher.java
index b57fa46..1fc56d8 100755 (executable)
@@ -128,10 +128,18 @@ public class SequenceFetcher extends JPanel implements Runnable
    * @param guiIndic
    * @param selectedDb
    * @param queryString
+   * @param interactive
    */
   public SequenceFetcher(IProgressIndicator guiIndic,
           final String selectedDb, final String queryString)
   {
+    this(guiIndic, selectedDb, queryString, true);
+  }
+
+  public SequenceFetcher(IProgressIndicator guiIndic,
+          final String selectedDb, final String queryString,
+          boolean interactive)
+  {
     this.progressIndicator = guiIndic;
     getSequenceFetcherSingleton();
     this.guiWindow = progressIndicator;
@@ -141,7 +149,7 @@ public class SequenceFetcher extends JPanel implements Runnable
       alignFrame = (AlignFrame) progressIndicator;
     }
 
-    jbInit(selectedDb);
+    jbInit(selectedDb, interactive);
     textArea.setText(queryString);
 
     frame = new JInternalFrame();
@@ -158,7 +166,7 @@ public class SequenceFetcher extends JPanel implements Runnable
                     .getString("label.additional_sequence_fetcher"));
   }
 
-  private void jbInit(String selectedDb)
+  private void jbInit(String selectedDb, boolean interactive)
   {
     this.setLayout(new BorderLayout());
 
@@ -300,9 +308,22 @@ public class SequenceFetcher extends JPanel implements Runnable
     jScrollPane1.getViewport().add(textArea);
     idsPanel.add(jScrollPane1, BorderLayout.CENTER);
 
+    // En/disable or show/hide interactive elements
+    database.setEnabled(interactive);
+    exampleAccession.setVisible(interactive);
+    replacePunctuation.setVisible(interactive);
+    okBtn.setVisible(interactive);
+    exampleBtn.setVisible(interactive);
+    closeBtn.setVisible(interactive);
+    backBtn.setVisible(interactive);
+    jLabel1.setVisible(interactive);
+    clear.setVisible(interactive);
+    textArea.setEnabled(interactive);
+
     this.add(actionPanel, BorderLayout.SOUTH);
     this.add(idsPanel, BorderLayout.CENTER);
     this.add(databasePanel, BorderLayout.NORTH);
+
   }
 
   /**
@@ -415,10 +436,11 @@ public class SequenceFetcher extends JPanel implements Runnable
    */
   public void ok_actionPerformed()
   {
-    ok_actionPerformed(false);
+    ok_actionPerformed(false, null);
   }
 
-  public CompletableFuture ok_actionPerformed(boolean returnFuture)
+  public CompletableFuture<Void> ok_actionPerformed(boolean returnFuture,
+          String id)
   {
     /*
      * tidy inputs and check there is something to search for
@@ -457,11 +479,18 @@ public class SequenceFetcher extends JPanel implements Runnable
     backBtn.setEnabled(false);
 
     CompletableFuture<Void> worker = CompletableFuture
-            .runAsync(new Thread(this));
+            .runAsync(() -> runAndCacheAlignFrame(returnFuture, id));
 
     return returnFuture ? worker : null;
   }
 
+  private void runAndCacheAlignFrame(boolean cacheAlignFrame, String id)
+  {
+    AlignFrame af = this.run(cacheAlignFrame);
+    if (cacheAlignFrame && id != null && af != null)
+      af.cacheAlignFrameFromRestId(id);
+  }
+
   private void resetDialog()
   {
     exampleBtn.setEnabled(true);
@@ -474,6 +503,11 @@ public class SequenceFetcher extends JPanel implements Runnable
   @Override
   public void run()
   {
+    run(false);
+  }
+
+  public AlignFrame run(boolean returnAlignFrame)
+  {
     boolean addToLast = false;
     List<String> aresultq = new ArrayList<>();
     List<String> presultTitle = new ArrayList<>();
@@ -611,9 +645,10 @@ public class SequenceFetcher extends JPanel implements Runnable
                             : MessageManager.getString("status.processing"),
                     Thread.currentThread().hashCode());
     // process results
+    AlignFrame af = null;
     while (presult.size() > 0)
     {
-      parseResult(presult.remove(0), presultTitle.remove(0), null,
+      af = parseResult(presult.remove(0), presultTitle.remove(0), null,
               preferredFeatureColours);
     }
     // only remove visual delay after we finished parsing.
@@ -641,6 +676,7 @@ public class SequenceFetcher extends JPanel implements Runnable
       showErrorMessage(sb.toString());
     }
     resetDialog();
+    return returnAlignFrame ? af : null;
   }
 
   /**
@@ -806,20 +842,21 @@ public class SequenceFetcher extends JPanel implements Runnable
     return "Retrieved from " + database.getSelectedItem();
   }
 
-  AlignmentI parseResult(AlignmentI al, String title,
+  AlignFrame parseResult(AlignmentI al, String title,
           FileFormatI currentFileFormat,
           FeatureSettingsModelI preferredFeatureColours)
   {
 
+    AlignFrame af = alignFrame;
     if (al != null && al.getHeight() > 0)
     {
       if (title == null)
       {
         title = getDefaultRetrievalTitle();
       }
-      if (alignFrame == null)
+      if (af == null)
       {
-        AlignFrame af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
+        af = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
                 AlignFrame.DEFAULT_HEIGHT);
         if (currentFileFormat != null)
         {
@@ -862,10 +899,10 @@ public class SequenceFetcher extends JPanel implements Runnable
       }
       else
       {
-        alignFrame.viewport.addAlignment(al, title);
+        af.viewport.addAlignment(al, title);
       }
     }
-    return al;
+    return af;
   }
 
   void showErrorMessage(final String error)