import java.awt.event.*;
import javax.swing.*;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.MutableTreeNode;
+import javax.swing.tree.TreeModel;
import jalview.datamodel.*;
import jalview.io.*;
final String noDbSelected = "-- Select Database --";
- Hashtable sources = new Hashtable();
-
private static jalview.ws.SequenceFetcher sfetch = null;
+ private static long lastDasSourceRegistry = -3;
+
private static DasSourceRegistryI dasRegistry = null;
private static boolean _initingFetcher = false;
}
}
if (sfetch == null
- || dasRegistry != jalview.bin.Cache.getDasSourceRegistry())
+ || dasRegistry != jalview.bin.Cache.getDasSourceRegistry()
+ || lastDasSourceRegistry != (jalview.bin.Cache
+ .getDasSourceRegistry().getDasRegistryURL() + jalview.bin.Cache
+ .getDasSourceRegistry().getLocalSourceString())
+ .hashCode())
{
_initingFetcher = true;
initingThread = Thread.currentThread();
}
dasRegistry = jalview.bin.Cache.getDasSourceRegistry();
dasRegistry.refreshSources();
-
+
jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
if (guiWindow != null)
{
guiWindow.setProgressBar("Initialising Sequence Database Fetchers",
Thread.currentThread().hashCode());
}
+ lastDasSourceRegistry = (dasRegistry.getDasRegistryURL() + dasRegistry
+ .getLocalSourceString()).hashCode();
sfetch = sf;
_initingFetcher = false;
initingThread = null;
sf.start();
}
+ private class DatabaseAuthority extends DefaultMutableTreeNode
+ {
+
+ };
+
+ private class DatabaseSource extends DefaultMutableTreeNode
+ {
+
+ };
+
/**
* called by thread spawned by constructor
*
{
alignFrame = (AlignFrame) guiWindow;
}
-
- database.addItem(noDbSelected);
- /*
- * Dynamically generated database list will need a translation function from
- * internal source to externally distinct names. UNIPROT and UP_NAME are
- * identical DB sources, and should be collapsed.
- */
-
- String dbs[] = sfetch.getOrderedSupportedSources();
- for (int i = 0; i < dbs.length; i++)
- {
- if (!sources.containsValue(dbs[i]))
- {
- String name = sfetch.getSourceProxy(dbs[i]).getDbName();
- // duplicate source names are thrown away, here.
- if (!sources.containsKey(name))
- {
- database.addItem(name);
- }
- // overwrite with latest version of the retriever for this source
- sources.put(name, dbs[i]);
- }
- }
+ database = new JDatabaseTree(sfetch);
try
{
jbInit();
jPanel1.add(close);
jPanel3.add(jPanel2, java.awt.BorderLayout.CENTER);
jPanel2.setLayout(borderLayout3);
-
+ databaseButt = database.getDatabaseSelectorButton();
+ databaseButt.setFont(JvSwingUtils.getLabelFont());
database.addActionListener(new ActionListener()
{
DbSourceProxy db = null;
try
{
- db = sfetch.getSourceProxy((String) sources.get(database
- .getSelectedItem()));
- String eq = db.getTestQuery();
+ databaseButt.setText(database.getSelectedItem()
+ + (database.getSelectedSources().size() > 1 ? " (and "
+ + database.getSelectedSources().size()
+ + " others)" : ""));
+ String eq = database.getExampleQueries();
dbeg.setText("Example query: " + eq);
replacePunctuation.setEnabled(!(eq != null && eq.indexOf(",") > -1));
} catch (Exception ex)
}
});
dbeg.setText("");
- jPanel2.add(database, java.awt.BorderLayout.NORTH);
+ jPanel2.add(databaseButt, java.awt.BorderLayout.NORTH);
jPanel2.add(dbeg, java.awt.BorderLayout.CENTER);
JPanel jPanel2a = new JPanel(new BorderLayout());
jPanel2a.add(jLabel1, java.awt.BorderLayout.NORTH);
DbSourceProxy db = null;
try
{
- db = sfetch.getSourceProxy((String) sources.get(database
- .getSelectedItem()));
- textArea.setText(db.getTestQuery());
+ textArea.setText(database.getExampleQueries());
} catch (Exception ex)
{
}
JLabel dbeg = new JLabel();
- JComboBox database = new JComboBox();
+ JDatabaseTree database;
+
+ JButton databaseButt;
JLabel jLabel1 = new JLabel();
public void run()
{
String error = "";
- if (database.getSelectedItem().equals(noDbSelected))
+ if (!database.hasSelection())
{
error += "Please select the source database\n";
}
resetDialog();
return;
}
- ArrayList<String> aresultq=new ArrayList<String>();
+ ArrayList<String> aresultq = new ArrayList<String>();
ArrayList<AlignmentI> aresult = new ArrayList<AlignmentI>();
- Object source = database.getSelectedItem();
+ DbSourceProxy proxy = database.getSelectedSources().get(0);
Enumeration en = new StringTokenizer(textArea.getText(), ";");
- boolean isAliSource=false;
+ boolean isAliSource = false;
try
{
guiWindow.setProgressBar(
- "Fetching Sequences from " + database.getSelectedItem(),
- Thread.currentThread().hashCode());
- DbSourceProxy proxy = sfetch.getSourceProxy((String) sources
- .get(source));
+ "Fetching Sequences from " + proxy.getDbName(), Thread
+ .currentThread().hashCode());
isAliSource = proxy.isA(DBRefSource.ALIGNMENTDB);
if (proxy.getAccessionSeparator() == null)
{
} catch (OutOfMemoryError oome)
{
new OOMWarning("fetching " + item + " from "
- + database.getSelectedItem(), oome, this);
+ + proxy.getDbName(), oome, this);
}
if (indres != null)
{
} catch (Exception e)
{
jalview.bin.Cache.log.info("Error retrieving " + item
- + " from " + source, e);
+ + " from " + proxy.getDbName(), e);
}
}
}
+ " from " + database.getSelectedItem());
e.printStackTrace();
}
- if (aresult != null && aresult.size()>0)
+ if (aresult != null && aresult.size() > 0)
{
- AlignmentI ar=null;
- if (isAliSource) {
+ AlignmentI ar = null;
+ if (isAliSource)
+ {
// new window for each result
- while (aresult.size()>0)
+ while (aresult.size() > 0)
{
- parseResult(aresult.remove(0), aresultq.remove(0)+" "+getDefaultRetrievalTitle(), null);
+ parseResult(aresult.remove(0), aresultq.remove(0) + " "
+ + getDefaultRetrievalTitle(), null);
}
- } else {
+ }
+ else
+ {
// concatenate all results in one window
- while (aresult.size()>0)
+ while (aresult.size() > 0)
{
- if (ar==null) { ar = aresult.remove(0);}
- else { ar.append(aresult.remove(0)); };
+ if (ar == null)
+ {
+ ar = aresult.remove(0);
+ }
+ else
+ {
+ ar.append(aresult.remove(0));
+ }
+ ;
}
parseResult(ar, null, null);
- }
+ }
}
// only remove visual delay after we finished parsing.
guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
/**
*
- * @return a standard title for any results retrieved using the currently selected source and settings
+ * @return a standard title for any results retrieved using the currently
+ * selected source and settings
*/
- public String getDefaultRetrievalTitle() {
+ public String getDefaultRetrievalTitle()
+ {
return "Retrieved from " + database.getSelectedItem();
}
+
AlignmentI parseResult(AlignmentI al, String title,
String currentFileFormat)
{
{
for (int i = 0; i < al.getHeight(); i++)
{
- alignFrame.viewport.getAlignment().addSequence(al.getSequenceAt(i)); // this
+ alignFrame.viewport.getAlignment().addSequence(
+ al.getSequenceAt(i)); // this
// also
// creates
// dataset