Merge branch 'bug/JAL-3718_Getdown_does_not_autoupdate_correctly' into releases/Relea...
[jalview.git] / src / jalview / gui / SequenceFetcher.java
index b4619d9..7451646 100755 (executable)
@@ -26,6 +26,7 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.fts.core.GFTSPanel;
 import jalview.fts.service.pdb.PDBFTSPanel;
 import jalview.fts.service.uniprot.UniprotFTSPanel;
 import jalview.io.FileFormatI;
@@ -33,7 +34,6 @@ import jalview.io.gff.SequenceOntologyI;
 import jalview.util.DBRefUtils;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
-import jalview.ws.dbsources.das.api.DasSourceRegistryI;
 import jalview.ws.seqfetcher.DbSourceProxy;
 
 import java.awt.BorderLayout;
@@ -78,6 +78,8 @@ public class SequenceFetcher extends JPanel implements Runnable
 
   JButton close = new JButton();
 
+  JButton back = new JButton();
+
   JPanel jPanel1 = new JPanel();
 
   JTextArea textArea = new JTextArea();
@@ -108,10 +110,6 @@ public class SequenceFetcher extends JPanel implements Runnable
 
   private static jalview.ws.SequenceFetcher sfetch = null;
 
-  private static long lastDasSourceRegistry = -3;
-
-  private static DasSourceRegistryI dasRegistry = null;
-
   private static boolean _initingFetcher = false;
 
   private static Thread initingThread = null;
@@ -162,11 +160,7 @@ public class SequenceFetcher extends JPanel implements Runnable
                 Thread.currentThread().hashCode());
       }
     }
-    if (sfetch == null || dasRegistry != Cache.getDasSourceRegistry()
-            || lastDasSourceRegistry != (Cache.getDasSourceRegistry()
-                    .getDasRegistryURL()
-                    + Cache.getDasSourceRegistry().getLocalSourceString())
-                            .hashCode())
+    if (sfetch == null)
     {
       _initingFetcher = true;
       initingThread = Thread.currentThread();
@@ -180,16 +174,12 @@ public class SequenceFetcher extends JPanel implements Runnable
                         "status.init_sequence_database_fetchers"),
                 Thread.currentThread().hashCode());
       }
-      dasRegistry = Cache.getDasSourceRegistry();
-      dasRegistry.refreshSources();
 
       jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
       if (guiWindow != null)
       {
         guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
       }
-      lastDasSourceRegistry = (dasRegistry.getDasRegistryURL()
-              + dasRegistry.getLocalSourceString()).hashCode();
       sfetch = sf;
       _initingFetcher = false;
       initingThread = null;
@@ -270,7 +260,7 @@ public class SequenceFetcher extends JPanel implements Runnable
         return Collections.emptyList();
       }
     }
-    sf.newAlframes = new ArrayList<AlignFrame>();
+    sf.newAlframes = new ArrayList<>();
     sf.run();
     return sf.newAlframes;
   }
@@ -383,6 +373,15 @@ public class SequenceFetcher extends JPanel implements Runnable
                     .getString("label.additional_sequence_fetcher"));
   }
 
+  GFTSPanel parentFTSframe = null;
+  /**
+   * change the buttons so they fit with the FTS panel.
+   */
+  public void embedWithFTSPanel(GFTSPanel toClose)
+  {
+    back.setVisible(true);
+    parentFTSframe = toClose;
+  }
   private void jbInit() throws Exception
   {
     this.setLayout(borderLayout2);
@@ -427,7 +426,7 @@ public class SequenceFetcher extends JPanel implements Runnable
         example_actionPerformed();
       }
     });
-    close.setText(MessageManager.getString("action.close"));
+    close.setText(MessageManager.getString("action.cancel"));
     close.addActionListener(new ActionListener()
     {
       @Override
@@ -436,6 +435,17 @@ public class SequenceFetcher extends JPanel implements Runnable
         close_actionPerformed(e);
       }
     });
+    back.setText(MessageManager.getString("action.back"));
+    back.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        parentFTSframe.btn_back_ActionPerformed();
+      }
+    });
+    // back not visible unless embedded
+    back.setVisible(false);
     textArea.setFont(JvSwingUtils.getLabelFont());
     textArea.setLineWrap(true);
     textArea.addKeyListener(new KeyAdapter()
@@ -451,9 +461,10 @@ public class SequenceFetcher extends JPanel implements Runnable
     });
     jPanel3.setLayout(borderLayout1);
     borderLayout1.setVgap(5);
-    jPanel1.add(ok);
+    jPanel1.add(back);
     jPanel1.add(example);
     jPanel1.add(clear);
+    jPanel1.add(ok);
     jPanel1.add(close);
     jPanel2.setLayout(borderLayout3);
     databaseButt = /*database.getDatabaseSelectorButton();
@@ -540,15 +551,10 @@ public class SequenceFetcher extends JPanel implements Runnable
       dbeg.setText(MessageManager.formatMessage("label.example_query_param",
               new String[]
               { eq }));
+      // TODO this should be a property of the SequenceFetcher whether commas are and
+      // colons are allowed in the IDs...
+
       boolean enablePunct = !(eq != null && eq.indexOf(",") > -1);
-      for (DbSourceProxy dbs : database.getSelectedSources())
-      {
-        if (dbs instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)
-        {
-          enablePunct = false;
-          break;
-        }
-      }
       replacePunctuation.setEnabled(enablePunct);
 
     } catch (Exception ex)
@@ -582,6 +588,10 @@ public class SequenceFetcher extends JPanel implements Runnable
     try
     {
       frame.setClosed(true);
+      if (parentFTSframe!=null)
+      {
+        parentFTSframe.btn_cancel_ActionPerformed();
+      }
     } catch (Exception ex)
     {
     }
@@ -594,7 +604,7 @@ public class SequenceFetcher extends JPanel implements Runnable
     textArea.setEnabled(false);
     ok.setEnabled(false);
     close.setEnabled(false);
-
+    back.setEnabled(false);
     Thread worker = new Thread(this);
     worker.start();
   }
@@ -606,6 +616,7 @@ public class SequenceFetcher extends JPanel implements Runnable
     textArea.setEnabled(true);
     ok.setEnabled(true);
     close.setEnabled(true);
+    back.setEnabled(parentFTSframe != null);
   }
 
   @Override
@@ -645,10 +656,10 @@ public class SequenceFetcher extends JPanel implements Runnable
     // TODO: Refactor to GUI independent code and write tests.
     // indicate if successive sources should be merged into one alignment.
     boolean addToLast = false;
-    List<String> aresultq = new ArrayList<String>();
-    List<String> presultTitle = new ArrayList<String>();
-    List<AlignmentI> presult = new ArrayList<AlignmentI>();
-    List<AlignmentI> aresult = new ArrayList<AlignmentI>();
+    List<String> aresultq = new ArrayList<>();
+    List<String> presultTitle = new ArrayList<>();
+    List<AlignmentI> presult = new ArrayList<>();
+    List<AlignmentI> aresult = new ArrayList<>();
     Iterator<DbSourceProxy> proxies = database.getSelectedSources()
             .iterator();
     String[] qries;
@@ -666,7 +677,7 @@ public class SequenceFetcher extends JPanel implements Runnable
         nqueries = nextFetch.size();
         // save the remaining queries in the original array
         qries = nextFetch.toArray(new String[nqueries]);
-        nextFetch = new ArrayList<String>();
+        nextFetch = new ArrayList<>();
       }
 
       DbSourceProxy proxy = proxies.next();
@@ -832,7 +843,7 @@ public class SequenceFetcher extends JPanel implements Runnable
           List<AlignmentI> aresult, List<String> nextFetch) throws Exception
   {
     StringBuilder multiacc = new StringBuilder();
-    List<String> tosend = new ArrayList<String>();
+    List<String> tosend = new ArrayList<>();
     while (accessions.hasNext())
     {
       String nel = accessions.next();
@@ -1012,10 +1023,7 @@ public class SequenceFetcher extends JPanel implements Runnable
           }
         }
 
-        if (preferredFeatureColours != null)
-        {
-          af.getViewport().applyFeaturesStyle(preferredFeatureColours);
-        }
+        af.getViewport().applyFeaturesStyle(preferredFeatureColours);
         if (Cache.getDefault("HIDE_INTRONS", true))
         {
           af.hideFeatureColumns(SequenceOntologyI.EXON, false);
@@ -1027,7 +1035,7 @@ public class SequenceFetcher extends JPanel implements Runnable
         Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
                 AlignFrame.DEFAULT_HEIGHT);
 
-        af.statusBar.setText(MessageManager
+        af.setStatus(MessageManager
                 .getString("label.successfully_pasted_alignment_file"));
 
         try