JAL-2847 start of cleaning up db loading code
[jalview.git] / src / jalview / ext / archaeopteryx / AptxInit.java
index 9f2817e..b9a7ae2 100644 (file)
@@ -108,20 +108,20 @@ public final class AptxInit
       Desktop.instance.startLoading(filePath);
     }
     boolean nhx_or_nexus = false;
-    final PhylogenyParser p = ParserUtils.createParserDependingOnFileType(
+    final PhylogenyParser parser = ParserUtils.createParserDependingOnFileType(
             treeFile, VALIDATE_PHYLOXML_XSD);
-    if (p instanceof NHXParser)
+    if (parser instanceof NHXParser)
     {
       nhx_or_nexus = true;
-      final NHXParser nhx = (NHXParser) p;
+      final NHXParser nhx = (NHXParser) parser;
       nhx.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
       nhx.setIgnoreQuotes(false);
       nhx.setTaxonomyExtraction(TAXONOMY_EXTRACTION);
     }
-    else if (p instanceof NexusPhylogeniesParser)
+    else if (parser instanceof NexusPhylogeniesParser)
     {
       nhx_or_nexus = true;
-      final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) p;
+      final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) parser;
       nex.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
       nex.setIgnoreQuotes(false);
     }
@@ -129,20 +129,20 @@ public final class AptxInit
 //    {
 //      MainFrameApplication.warnIfNotPhyloXmlValidation(APTX_CONFIG);
 //    }
-    Phylogeny[] phylogenies = PhylogenyMethods.readPhylogenies(p, treeFile);
-    MainFrame[] aptxFrames = new MainFrame[phylogenies.length];
+    Phylogeny[] trees = PhylogenyMethods.readPhylogenies(parser, treeFile);
+    MainFrame[] aptxFrames = new MainFrame[trees.length];
     String treeTitle = treeFile.getName();
 
-    for (int i = 0; i < phylogenies.length; i++)
+    for (int i = 0; i < trees.length; i++)
       {
-      Phylogeny tree = phylogenies[i];
+      Phylogeny tree = trees[i];
 
       if (nhx_or_nexus && INTERNAL_NUMBERS_AS_CONFIDENCE)
       {
         PhylogenyMethods.transferInternalNodeNamesToConfidence(tree, "");
       }
-
       aptxFrames[i] = createAptxFrame(tree, viewport, treeTitle);
+
     }
     if (Desktop.instance != null)
     {
@@ -184,7 +184,7 @@ public final class AptxInit
   }
 
   /**
-   * Refactored from Forester's UrlTreeReader
+   * Refactored from Forester's UrlTreeReader, this can be more efficient
    * 
    * @param databaseIndex
    * @param viewport
@@ -193,10 +193,6 @@ public final class AptxInit
   public static MainFrame[] createInstancesFromDb(int databaseIndex,
           AlignmentViewport viewport)
   {
-    if (Desktop.desktop != null)
-    {
-      // Desktop.desktop.startLoading(treeTitle);
-    }
 
     URL url = null;
     Phylogeny[] trees = null;
@@ -209,22 +205,25 @@ public final class AptxInit
             client.getInstructions() + "\n(Reference: "
                     + client.getReference() + ")",
             client.getDescription(), JvOptionPane.QUESTION_MESSAGE);
+
     if ((identifier != null) && (identifier.trim().length() > 0))
     {
+      if (Desktop.instance != null)
+      {
+        Desktop.instance.startLoading(identifier);
+      }
+
       identifier = identifier.trim();
       if (client.isQueryInteger())
       {
         identifier = identifier.replaceAll("^\\D+", "");
-        int id = -1;
+
+        int id;
         try
         {
           id = Integer.parseInt(identifier);
         } catch (final NumberFormatException e)
         {
-          id = -1;
-        }
-        if (id < 1)
-        {
           JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                   "Identifier is expected to be a number",
                   "Can not open URL", JvOptionPane.ERROR_MESSAGE);
@@ -471,17 +470,16 @@ public final class AptxInit
   {
     MainFrame aptxApp = Archaeopteryx.createApplication(aptxTree,
             APTX_CONFIG, treeTitle);
-    // addPartitioningSlider(aptxApp);
 
-
-    LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
+    LoadedTreeSequenceAssociation bindAptxNodes = new LoadedTreeSequenceAssociation(
             jalviewAlignport.getAlignment().getSequencesArray(), aptxTree);
-
     bindAptxNodes.associateLeavesToSequences();
+
     bindNodesToJalviewSequences(aptxApp, jalviewAlignport,
             bindAptxNodes.getAlignmentWithNodes(),
             bindAptxNodes.getNodesWithAlignment());
-    bindFrameToJalview(aptxApp);
+    bindTreeViewFrameToJalview(aptxApp);
+
     return aptxApp;
   }
 
@@ -503,7 +501,8 @@ public final class AptxInit
   }
 
 
-  public static MainFrame bindFrameToJalview(final MainFrame aptxApp)
+  public static MainFrame bindTreeViewFrameToJalview(
+          final MainFrame aptxApp)
   {
     int width = 400;
     int height = 550;