JAL-3725 restrict mapped virtual feature location to mapped region
[jalview.git] / src / jalview / gui / StructureViewerBase.java
index f5d350c..ae2128b 100644 (file)
@@ -221,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)
@@ -1152,12 +1156,14 @@ public abstract class StructureViewerBase extends GStructureViewer
     {
       if (afclient.isValidReference(pdbid))
       {
-        pdbseq = afclient.getSequenceRecords(pdbid);
+        pdbseq = afclient.getSequenceRecords(pdbid,processingEntry.getRetrievalUrl());
       } else {
           if (processingEntry.hasRetrievalUrl())
           {
+            String safePDBId = java.net.URLEncoder.encode(pdbid,"UTF-8");
+                     
             // retrieve from URL to new local tmpfile
-            File tmpFile = File.createTempFile(pdbid,
+            File tmpFile = File.createTempFile(safePDBId,
                     "." + (PDBEntry.Type.MMCIF.toString().equals(
                             processingEntry.getType().toString()) ? "cif"
                                     : "pdb"));
@@ -1206,8 +1212,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;
   }
 
   /**
@@ -1279,6 +1300,8 @@ public abstract class StructureViewerBase extends GStructureViewer
   @Override
   public boolean hasViewerActionsMenu()
   {
-    return viewerActionMenu!=null && viewerActionMenu.isEnabled() && viewerActionMenu.getItemCount()>0 && viewerActionMenu.isVisible();
+    return viewerActionMenu != null && viewerActionMenu.isEnabled()
+            && viewerActionMenu.getItemCount() > 0
+            && viewerActionMenu.isVisible();
   }
 }