JAL-2847 Rearranging and cleaning up of database query code
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 5 Dec 2017 16:07:05 +0000 (16:07 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 5 Dec 2017 16:07:05 +0000 (16:07 +0000)
forester
src/jalview/ext/archaeopteryx/AptxInit.java
src/jalview/gui/AlignFrame.java

index 9c3a223..5642da5 160000 (submodule)
--- a/forester
+++ b/forester
@@ -1 +1 @@
-Subproject commit 9c3a223ef0fd72affdb9f4e40845d1e3ebe52f90
+Subproject commit 5642da5f473ab9ae57fee86c0cb3b33525a2e916
index 3dc2e88..da9e348 100644 (file)
@@ -24,7 +24,6 @@ import org.forester.archaeopteryx.Configuration;
 import org.forester.archaeopteryx.MainFrame;
 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
 import org.forester.archaeopteryx.webservices.WebserviceUtil;
-import org.forester.archaeopteryx.webservices.WebservicesManager;
 import org.forester.io.parsers.PhylogenyParser;
 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
 import org.forester.io.parsers.nhx.NHXParser;
@@ -130,12 +129,11 @@ public final class AptxInit
     }
     else if (parser instanceof PhyloXmlParser)
     {
-      if ( VALIDATE_PHYLOXML_XSD ) {
-        JvOptionPane.showInternalMessageDialog( null,
-                                       ForesterUtil.wordWrap(
-                                                              "phyloXML XSD-based validation is turned off [enable with line 'validate_against_phyloxml_xsd_schem: true' in configuration file]",
-                                                              80 ),
-                                       "Warning",
+      if (VALIDATE_PHYLOXML_XSD == false)
+      {
+        JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+                MessageManager.getString("error.phyloxml_validation"),
+                MessageManager.getString("label.file_open_error"),
                                        JvOptionPane.WARNING_MESSAGE );
       }
     }
@@ -202,22 +200,13 @@ public final class AptxInit
    * @param viewport
    * @return
    */
-  public static MainFrame[] createInstancesFromDb(int databaseIndex,
-          AlignmentViewport viewport, String defaultIdentifier)
+  public static MainFrame[] createInstancesFromDb(
+          PhylogeniesWebserviceClient treeDbClient, String identifier,
+          AlignmentViewport viewport)
   {
 
     URL url = null;
     Phylogeny[] trees = null;
-    final WebservicesManager webservices_manager = WebservicesManager
-            .getInstance();
-    final PhylogeniesWebserviceClient client = webservices_manager
-            .getAvailablePhylogeniesWebserviceClient(databaseIndex);
-    String identifier = JvOptionPane.showInternalInputDialog(
-            Desktop.desktop,
-            client.getInstructions() + "\n(Reference: "
-                    + client.getReference() + ")",
-            client.getDescription(), JvOptionPane.QUESTION_MESSAGE, null,
-            null, defaultIdentifier).toString();
 
     if ((identifier != null) && (identifier.trim().length() > 0))
     {
@@ -227,7 +216,7 @@ public final class AptxInit
       }
 
       identifier = identifier.trim();
-      if (client.isQueryInteger())
+      if (treeDbClient.isQueryInteger())
       {
         identifier = identifier.replaceAll("^\\D+", "");
 
@@ -238,8 +227,11 @@ public final class AptxInit
         } catch (final NumberFormatException e)
         {
           JvOptionPane.showInternalMessageDialog(Desktop.desktop,
-                  "Identifier is expected to be a number",
-                  "Can not open URL", JvOptionPane.ERROR_MESSAGE);
+                  MessageManager.formatMessage(
+                          "error.database_id_has_letters", new String[]
+                          { identifier }),
+                  MessageManager.getString("label.invalid_url"),
+                  JvOptionPane.ERROR_MESSAGE);
           return new MainFrame[0];
         }
         identifier = id + "";
@@ -247,12 +239,12 @@ public final class AptxInit
       boolean exception = false;
       try
       {
-        String url_str = client.getUrl();
+        String url_str = treeDbClient.getUrl();
         url_str = url_str.replaceFirst(
                 PhylogeniesWebserviceClient.QUERY_PLACEHOLDER, identifier);
         url = new URL(url_str);
         PhylogenyParser parser = null;
-        switch (client.getReturnFormat())
+        switch (treeDbClient.getReturnFormat())
         {
         case TOL_XML_RESPONSE:
           parser = new TolParser();
@@ -306,7 +298,7 @@ public final class AptxInit
           break;
         default:
           throw new IllegalArgumentException(
-                  "unknown format: " + client.getReturnFormat());
+                  "unknown format: " + treeDbClient.getReturnFormat());
         }
         //
         // if (_main_frame.getMainPanel().getCurrentTreePanel() != null)
@@ -322,26 +314,32 @@ public final class AptxInit
       {
         exception = true;
         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
-                "Malformed URL: " + url + "\n" + e.getLocalizedMessage(),
-                "Malformed URL", JvOptionPane.ERROR_MESSAGE);
+                MessageManager.formatMessage(
+                        "exception.unable_to_launch_url", new String[]
+                        { url.toString() }),
+                MessageManager.getString("label.invalid_url"),
+                JvOptionPane.ERROR_MESSAGE);
+        System.err.println(e.getLocalizedMessage());
       } catch (final IOException e)
       {
         exception = true;
         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                 "Could not read from " + url + "\n"
                         + e.getLocalizedMessage(),
-                "Failed to read tree from " + client.getName() + " for "
+                "Failed to read tree from " + treeDbClient.getName() + " for "
                         + identifier,
                 JvOptionPane.ERROR_MESSAGE);
+        System.err.println(e.getLocalizedMessage());
       } catch (final NumberFormatException e)
       {
         exception = true;
         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                 "Could not read from " + url + "\n"
                         + e.getLocalizedMessage(),
-                "Failed to read tree from " + client.getName() + " for "
+                "Failed to read tree from " + treeDbClient.getName() + " for "
                         + identifier,
                 JvOptionPane.ERROR_MESSAGE);
+        System.err.println(e.getLocalizedMessage());
       } catch (final Exception e)
       {
         exception = true;
@@ -349,16 +347,7 @@ public final class AptxInit
         JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                 e.getLocalizedMessage(), "Unexpected Exception",
                 JvOptionPane.ERROR_MESSAGE);
-      } finally
-      {
-        // if (_main_frame.getCurrentTreePanel() != null)
-        // {
-        // _main_frame.getCurrentTreePanel().setArrowCursor();
-        // }
-        // else
-        // {
-        // _main_frame.getMainPanel().setArrowCursor();
-        // }
+        System.err.println(e.getLocalizedMessage());
       }
       if ((trees != null) && (trees.length > 0))
       {
@@ -366,16 +355,16 @@ public final class AptxInit
         {
           if (!phylogeny.isEmpty())
           {
-            if (client.getName().equals(WebserviceUtil.TREE_FAM_NAME))
+            if (treeDbClient.getName().equals(WebserviceUtil.TREE_FAM_NAME))
             {
               phylogeny.setRerootable(false);
               phylogeny.setRooted(true);
             }
-            if (client.getProcessingInstructions() != null)
+            if (treeDbClient.getProcessingInstructions() != null)
             {
               try
               {
-                WebserviceUtil.processInstructions(client, phylogeny);
+                WebserviceUtil.processInstructions(treeDbClient, phylogeny);
               } catch (final PhyloXmlDataFormatException e)
               {
                 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
@@ -383,12 +372,12 @@ public final class AptxInit
                         JvOptionPane.ERROR_MESSAGE);
               }
             }
-            if (client.getNodeField() != null)
+            if (treeDbClient.getNodeField() != null)
             {
               try
               {
                 PhylogenyMethods.transferNodeNameToField(phylogeny,
-                        client.getNodeField(), false);
+                        treeDbClient.getNodeField(), false);
               } catch (final PhyloXmlDataFormatException e)
               {
                 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
@@ -397,7 +386,7 @@ public final class AptxInit
               }
             }
             phylogeny.setIdentifier(
-                    new Identifier(identifier, client.getName()));
+                    new Identifier(identifier, treeDbClient.getName()));
             // _main_frame.getJMenuBar().remove(_main_frame.getHelpMenu());
             // _main_frame.getMenuBarOfMainFrame()
             // .add(_main_frame.getHelpMenu());
@@ -426,8 +415,8 @@ public final class AptxInit
               my_name_for_file = new String(
                       sb.toString().replaceAll(" ", "_"));
             }
-            // _main_frame.getMainPanel().getCurrentTreePanel()
-            // .setTreeFile(new File(my_name_for_file));
+            aptxApp.getMainPanel().getCurrentTreePanel()
+                    .setTreeFile(new File(my_name_for_file));
             AptxUtil.lookAtSomeTreePropertiesForAptxControlSettings(
                     phylogeny, aptxApp.getMainPanel().getControlPanel(),
                     APTX_CONFIG);
@@ -437,7 +426,7 @@ public final class AptxInit
           }
         }
       }
-      else if (!exception)
+      else if (!exception) // ..what?
       {
         JvOptionPane.showMessageDialog(null,
                 ForesterUtil.wordWrap(
@@ -496,12 +485,6 @@ public final class AptxInit
     return aptxApp;
   }
 
-  // private static void addPartitioningSlider(MainFrame aptxFrame)
-  // {
-  // JSlider slider = new JSlider();
-  //
-  //
-  // }
 
   public static ExternalTreeViewerBindingI<?> bindNodesToJalviewSequences(
           final MainFrame aptxApp,
index c76ce56..84e02c7 100644 (file)
@@ -157,6 +157,8 @@ import javax.swing.JScrollPane;
 import javax.swing.SwingUtilities;
 
 import org.forester.archaeopteryx.MainFrame;
+import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
+import org.forester.archaeopteryx.webservices.WebservicesManager;
 
 /**
  * DOCUMENT ME!
@@ -3962,7 +3964,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   protected void loadTreePfam_actionPerformed(ActionEvent e)
   {
 
-    // only DBRefs of first sequence are checked for matching DB for now
+    // only DBRefs of first sequence are checked for matching DB for now,
+    // iterating through them all seems excessive
     SequenceI seq = viewport.getAlignment().getSequenceAt(0);
     String dbId = null;
     for (DBRefEntry pfamRef : DBRefUtils
@@ -4099,8 +4102,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
    */
   public void chooseTreeDb(int databaseIndex, String defaultIdentifier)
   {
-    AptxInit.createInstancesFromDb(databaseIndex, viewport,
-            defaultIdentifier);
+    final WebservicesManager webservices_manager = WebservicesManager
+            .getInstance();
+    final PhylogeniesWebserviceClient client = webservices_manager
+            .getAvailablePhylogeniesWebserviceClient(databaseIndex);
+    String identifier = JvOptionPane
+            .showInternalInputDialog(Desktop.desktop,
+                    client.getInstructions() + "\n(Reference: "
+                            + client.getReference() + ")",
+                    client.getDescription(), JvOptionPane.QUESTION_MESSAGE,
+                    null, null, defaultIdentifier)
+            .toString();
+
+    AptxInit.createInstancesFromDb(client, identifier, viewport);
   }
 
   public TreePanel showNewickTree(NewickFile nf, String treeTitle)