From 36269160d91eccc05eb4def98d2a6362f462eda2 Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 8 Dec 2005 16:10:39 +0000 Subject: [PATCH] added some error checking and instruction dialogs --- src/jalview/gui/SequenceFetcher.java | 43 +++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) 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; } -- 1.7.10.2