JAL-2902 - isBusy and hasMapping methods so client can wait until a newly opened...
authorJim Procter <jprocter@issues.jalview.org>
Wed, 7 Feb 2018 13:04:07 +0000 (13:04 +0000)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 7 Feb 2018 13:04:07 +0000 (13:04 +0000)
[ needed for JAL-2780 JAL-2781 tests]

src/jalview/api/structures/JalviewStructureDisplayI.java
src/jalview/gui/StructureViewer.java
src/jalview/gui/StructureViewerBase.java

index fd66388..b4612cf 100644 (file)
@@ -62,4 +62,11 @@ public interface JalviewStructureDisplayI
    */
   void setJalviewColourScheme(ColourSchemeI colourScheme);
 
+  /**
+   * 
+   * @return true if all background sequence/structure binding threads have
+   *         completed for this viewer instance
+   */
+  boolean hasMapping();
+
 }
index fb37b77..f37df71 100644 (file)
@@ -104,7 +104,7 @@ public class StructureViewer
             new PDBEntry[seqsForPdbs.size()]);
     SequenceI[][] theSeqs = seqsForPdbs.values().toArray(
             new SequenceI[seqsForPdbs.size()][]);
-    JalviewStructureDisplayI sview = null;
+
     if (viewerType.equals(ViewerType.JMOL))
     {
       sview = new AppJmol(ap, pdbsForFile, theSeqs);
@@ -203,7 +203,7 @@ public class StructureViewer
   private JalviewStructureDisplayI onlyOnePdb(PDBEntry[] pdbs,
           SequenceI[] seqsForPdbs, AlignmentPanel ap)
   {
-    List<SequenceI> seqs = new ArrayList<SequenceI>();
+    List<SequenceI> seqs = new ArrayList<>();
     if (pdbs == null || pdbs.length == 0)
     {
       return null;
@@ -227,11 +227,12 @@ public class StructureViewer
             ap);
   }
 
+  JalviewStructureDisplayI sview = null;
+
   public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
           SequenceI[] seqsForPdb, AlignmentPanel ap)
   {
     ViewerType viewerType = getViewerType();
-    JalviewStructureDisplayI sview = null;
     if (viewerType.equals(ViewerType.JMOL))
     {
       sview = new AppJmol(pdb, seqsForPdb, null, ap);
@@ -270,7 +271,6 @@ public class StructureViewer
     final boolean usetoColourbyseq = viewerData.isColourWithAlignPanel();
     final boolean viewerColouring = viewerData.isColourByViewer();
 
-    JalviewStructureDisplayI sview = null;
     switch (type)
     {
     case JMOL:
@@ -287,4 +287,16 @@ public class StructureViewer
     return sview;
   }
 
+  public boolean isBusy()
+  {
+    if (sview != null)
+    {
+      if (!sview.hasMapping())
+      {
+        return true;
+      }
+    }
+    return false;
+  }
+
 }
index 31c20ed..891e771 100644 (file)
@@ -34,6 +34,7 @@ import jalview.io.JalviewFileView;
 import jalview.jbgui.GStructureViewer;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemes;
+import jalview.structure.StructureMapping;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MessageManager;
 
@@ -113,6 +114,13 @@ public abstract class StructureViewerBase extends GStructureViewer
   protected JMenu viewSelectionMenu;
 
   /**
+   * set after sequence colouring has been applied for this structure viewer.
+   * used to determine if the final sequence/structure mapping has been
+   * determined
+   */
+  protected boolean seqColoursApplied = false;
+
+  /**
    * Default constructor
    */
   public StructureViewerBase()
@@ -909,6 +917,7 @@ public abstract class StructureViewerBase extends GStructureViewer
       {
         binding.colourBySequence(ap);
       }
+      seqColoursApplied = true;
     }
   }
 
@@ -1028,4 +1037,37 @@ public abstract class StructureViewerBase extends GStructureViewer
       seqColour_actionPerformed(null);
     }
   }
+
+  @Override
+  public boolean hasMapping()
+  {
+    if (worker != null && (addingStructures || _started))
+    {
+      return false;
+    }
+    if (getBinding() == null)
+    {
+      return false;
+    }
+    String[] pdbids = getBinding().getStructureFiles();
+    if (pdbids == null)
+    {
+      return false;
+    }
+    int p=0;
+    for (String pdbid:pdbids) {
+      StructureMapping sm[] = getBinding().getSsm().getMapping(pdbid);
+      if (sm!=null && sm.length>0 && sm[0]!=null) {
+        p++;
+      }
+    }
+    // only return true if there is a mapping for every structure file we have loaded
+    if (p == 0 || p != pdbids.length)
+    {
+      return false;
+    }
+    // and that coloring has been applied
+    return seqColoursApplied;
+  }
+
 }