(no commit message)
[jalview.git] / forester / java / src / org / forester / archaeopteryx / tools / TaxonomyDataObtainer.java
index 17d871b..a6d814b 100644 (file)
@@ -33,21 +33,34 @@ import java.util.SortedSet;
 import javax.swing.JOptionPane;
 
 import org.forester.analysis.AncestralTaxonomyInference;
+import org.forester.analysis.AncestralTaxonomyInferenceException;
 import org.forester.archaeopteryx.MainFrameApplication;
 import org.forester.archaeopteryx.TreePanel;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.ws.uniprot.UniProtWsTools;
 
-public class TaxonomyDataObtainer implements Runnable {
+public class TaxonomyDataObtainer extends RunnableProcess {
 
     private final Phylogeny            _phy;
     private final MainFrameApplication _mf;
     private final TreePanel            _treepanel;
+    private final boolean              _delete;
+
+    public TaxonomyDataObtainer( final MainFrameApplication mf,
+                                 final TreePanel treepanel,
+                                 final Phylogeny phy,
+                                 final boolean delete ) {
+        _phy = phy;
+        _mf = mf;
+        _treepanel = treepanel;
+        _delete = delete;
+    }
 
     public TaxonomyDataObtainer( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) {
         _phy = phy;
         _mf = mf;
         _treepanel = treepanel;
+        _delete = false;
     }
 
     private String getBaseUrl() {
@@ -55,13 +68,12 @@ public class TaxonomyDataObtainer implements Runnable {
     }
 
     private void execute() {
-        _mf.getMainPanel().getCurrentTreePanel().setWaitCursor();
+        start( _mf, "taxonomy data" );
         SortedSet<String> not_found = null;
         try {
-            not_found = AncestralTaxonomyInference.obtainDetailedTaxonomicInformation( _phy );
+            not_found = AncestralTaxonomyInference.obtainDetailedTaxonomicInformation( _phy, _delete );
         }
         catch ( final UnknownHostException e ) {
-            _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
             JOptionPane.showMessageDialog( _mf,
                                            "Could not connect to \"" + getBaseUrl() + "\"",
                                            "Network error during taxonomic information gathering",
@@ -69,7 +81,14 @@ public class TaxonomyDataObtainer implements Runnable {
             return;
         }
         catch ( final IOException e ) {
-            _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
+            e.printStackTrace();
+            JOptionPane.showMessageDialog( _mf,
+                                           e.toString(),
+                                           "Failed to obtain taxonomic information",
+                                           JOptionPane.ERROR_MESSAGE );
+            return;
+        }
+        catch ( final AncestralTaxonomyInferenceException e ) {
             e.printStackTrace();
             JOptionPane.showMessageDialog( _mf,
                                            e.toString(),
@@ -78,7 +97,19 @@ public class TaxonomyDataObtainer implements Runnable {
             return;
         }
         finally {
-            _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
+            end( _mf );
+        }
+        if ( _phy == null || _phy.isEmpty() ) {
+            try {
+                JOptionPane.showMessageDialog( _mf,
+                                               "None of the external node taxonomies could be resolved",
+                                               "Taxonomy Tool Failed",
+                                               JOptionPane.WARNING_MESSAGE );
+            }
+            catch ( final Exception e ) {
+                // Not important if this fails, do nothing. 
+            }
+            return;
         }
         _treepanel.setTree( _phy );
         _mf.showWhole();
@@ -93,10 +124,21 @@ public class TaxonomyDataObtainer implements Runnable {
             final StringBuffer sb = new StringBuffer();
             sb.append( "Not all taxonomies could be resolved.\n" );
             if ( not_found.size() == 1 ) {
-                sb.append( "The following taxonomy was not found:\n" );
+                if ( _delete ) {
+                    sb.append( "The following taxonomy was not found and deleted (if external):\n" );
+                }
+                else {
+                    sb.append( "The following taxonomy was not found:\n" );
+                }
             }
             else {
-                sb.append( "The following taxonomies were not found (total: " + not_found.size() + "):\n" );
+                if ( _delete ) {
+                    sb.append( "The following taxonomies were not found and deleted (if external) (total: "
+                            + not_found.size() + "):\n" );
+                }
+                else {
+                    sb.append( "The following taxonomies were not found (total: " + not_found.size() + "):\n" );
+                }
             }
             int i = 0;
             for( final String string : not_found ) {