From: jprocter Date: Thu, 8 Dec 2005 16:10:39 +0000 (+0000) Subject: added some error checking and instruction dialogs X-Git-Tag: Release_2_07~25 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=36269160d91eccc05eb4def98d2a6362f462eda2;p=jalview.git added some error checking and instruction dialogs --- diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index ca2e375..e7d03fe 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -36,10 +36,11 @@ public class SequenceFetcher JInternalFrame frame; AlignFrame alignFrame; StringBuffer result; + final String noDbSelected = "-- Select Database --"; public SequenceFetcher(AlignFrame af) { alignFrame = af; - database.addItem("-- Select Database --"); + database.addItem(noDbSelected); database.addItem("Uniprot"); database.addItem("EMBL"); database.addItem("EMBLCDS"); @@ -146,8 +147,29 @@ public class SequenceFetcher worker.start(); } + private void resetDialog() { + database.setEnabled(true); + textfield.setEnabled(true); + ok.setEnabled(true); + cancel.setEnabled(true); + frame.setTitle("Sequence Fetcher (WSDBfetch@EBI)"); + } + public void run() { + String error = ""; + if (database.getSelectedItem().equals(noDbSelected)) + error += "Please select the source database\n"; + com.stevesoft.pat.Regex empty=new com.stevesoft.pat.Regex("\\s+",""); + textfield.setText(empty.replaceAll(textfield.getText())); + if (textfield.getText().length()==0) + error+="Please enter a (semi-colon separated list of) database id(s)"; + if (error.length()>0) { + showErrorMessage(error); + resetDialog(); + return; + } + result = new StringBuffer(); if (database.getSelectedItem().equals("Uniprot")) { @@ -170,20 +192,17 @@ public class SequenceFetcher else if (database.getSelectedItem().equals("PDB")) { result = getPDBFile(textfield.getText().toUpperCase()); - parseResult(result.toString()); + if (result!=null) + parseResult(result.toString()); } if (result == null || result.length() == 0) showErrorMessage("Error retrieving " + textfield.getText() + " from " + database.getSelectedItem()); - - - database.setEnabled(true); - textfield.setEnabled(true); - ok.setEnabled(true); - cancel.setEnabled(true); - frame.setTitle("Sequence Fetcher (WSDBfetch@EBI)"); + else + textfield.setText(""); + resetDialog(); } void getUniprotFile(String id) @@ -256,6 +275,8 @@ public class SequenceFetcher EBIFetchClient ebi = new EBIFetchClient(); String[] reply = ebi.fetchData("pdb:" + id, "pdb", "raw"); + if (reply==null) + return null; try { PDBfile pdbfile = new PDBfile(reply); @@ -275,8 +296,8 @@ public class SequenceFetcher } catch (Exception ex) // Problem parsing PDB file { - showErrorMessage("Error retrieving " + textfield.getText() + " from " + - database.getSelectedItem()); + jalview.bin.Cache.log.warn("Exception when retrieving " + textfield.getText() + " from " + + database.getSelectedItem(), ex); return null; }