Merge commit 'alpha/update_2_12_for_2_11_2_series_merge^2' into HEAD
[jalview.git] / src / jalview / gui / StructureViewerBase.java
index 11bf50f..59ca30f 100644 (file)
@@ -65,6 +65,7 @@ import jalview.util.BrowserLauncher;
 import jalview.util.MessageManager;
 import jalview.ws.dbsources.EBIAlfaFold;
 import jalview.ws.dbsources.Pdb;
+import jalview.ws.utils.UrlDownloadClient;
 
 /**
  * Base class with common functionality for JMol, Chimera or other structure
@@ -220,6 +221,10 @@ public abstract class StructureViewerBase extends GStructureViewer
       _alignwith.add(ap);
     }
     ;
+    // TODO: refactor to allow concrete classes to register buttons for adding
+    // here
+    // currently have to override to add buttons back in after they are cleared
+    // in this loop
     for (Component c : viewerActionMenu.getMenuComponents())
     {
       if (c != alignStructs)
@@ -421,7 +426,7 @@ public abstract class StructureViewerBase extends GStructureViewer
    */
   protected List<StructureViewerBase> getViewersFor(AlignmentPanel alp)
   {
-    return Desktop.instance.getStructureViewers(alp, this.getClass());
+    return Desktop.getInstance().getStructureViewers(alp, this.getClass());
   }
 
   @Override
@@ -1153,7 +1158,25 @@ public abstract class StructureViewerBase extends GStructureViewer
       {
         pdbseq = afclient.getSequenceRecords(pdbid);
       } else {
-        pdbseq = pdbclient.getSequenceRecords(pdbid);
+          if (processingEntry.hasRetrievalUrl())
+          {
+            // retrieve from URL to new local tmpfile
+            File tmpFile = File.createTempFile(pdbid,
+                    "." + (PDBEntry.Type.MMCIF.toString().equals(
+                            processingEntry.getType().toString()) ? "cif"
+                                    : "pdb"));
+            String fromUrl = processingEntry.getRetrievalUrl();
+            UrlDownloadClient.download(fromUrl, tmpFile);
+            
+            // may not need this check ?
+            String file = tmpFile.getAbsolutePath();
+            if (file != null)
+            {
+              pdbseq = EBIAlfaFold.importDownloadedStructureFromUrl(fromUrl,tmpFile,pdbid,null,null,null);
+            }
+          } else {
+            pdbseq = pdbclient.getSequenceRecords(pdbid);
+          }
       }
     } catch (Exception e)
     {
@@ -1187,8 +1210,23 @@ public abstract class StructureViewerBase extends GStructureViewer
    */
   public File saveSession()
   {
-    // TODO: a wait loop to ensure the file is written fully before returning?
-    return getBinding() == null ? null : getBinding().saveSession();
+    if (getBinding() == null) { return  null;}
+    File session = getBinding().saveSession();
+    long l = session.length();
+    int wait=50;
+    do {
+      try {
+        Thread.sleep(5);
+      } catch (InterruptedException e) {
+      } 
+      long nextl = session.length();
+      if (nextl!=l)
+      {
+        wait = 50;
+        l=nextl;
+      }
+    } while (--wait>0);
+    return session;
   }
 
   /**
@@ -1257,5 +1295,11 @@ public abstract class StructureViewerBase extends GStructureViewer
                       + ex.getMessage());
     }
   }
-
+  @Override
+  public boolean hasViewerActionsMenu()
+  {
+    return viewerActionMenu != null && viewerActionMenu.isEnabled()
+            && viewerActionMenu.getItemCount() > 0
+            && viewerActionMenu.isVisible();
+  }
 }