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() {
}
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",
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(),
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();
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 ) {