X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDasSourceBrowser.java;h=2f257afd52875e85fb3263a51d8b61a6e8cbfe5e;hb=90d7e508abaf1010078fce1fec804b70179caad5;hp=90741056628fb623232c2fd6f841a1f11184d626;hpb=c2d22d00716c6865d4d090ba1db5f7c063166e77;p=jalview.git
diff --git a/src/jalview/gui/DasSourceBrowser.java b/src/jalview/gui/DasSourceBrowser.java
index 9074105..2f257af 100755
--- a/src/jalview/gui/DasSourceBrowser.java
+++ b/src/jalview/gui/DasSourceBrowser.java
@@ -1,24 +1,26 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
*/
package jalview.gui;
+import java.security.interfaces.DSAKey;
+import java.text.ParseException;
import java.util.*;
+import java.util.List;
import java.awt.*;
import java.awt.event.*;
@@ -26,14 +28,23 @@ import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
-import org.biojava.dasobert.dasregistry.*;
+import org.biodas.jdas.dassources.Capabilities;
+import org.biodas.jdas.dassources.utils.DasTimeFormat;
+import org.biodas.jdas.schema.sources.CAPABILITY;
+import org.biodas.jdas.schema.sources.COORDINATES;
+import org.biodas.jdas.schema.sources.MAINTAINER;
+import org.biodas.jdas.schema.sources.PROP;
+import org.biodas.jdas.schema.sources.SOURCE;
+import org.biodas.jdas.schema.sources.SOURCES;
+import org.biodas.jdas.schema.sources.VERSION;
+
import jalview.jbgui.*;
import jalview.util.*;
public class DasSourceBrowser extends GDasSourceBrowser implements
Runnable, ListSelectionListener
{
- static DasSource[] dasSources = null;
+ static org.biodas.jdas.schema.sources.SOURCE[] dasSources = null;
Hashtable localSources = null;
@@ -53,14 +64,16 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
if (registry.indexOf("/registry/das1/sources/") > -1)
{
- jalview.bin.Cache.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, DEFAULT_REGISTRY);
+ jalview.bin.Cache.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL,
+ DEFAULT_REGISTRY);
registry = DEFAULT_REGISTRY;
}
return registry;
}
- public DasSourceBrowser()
+ public DasSourceBrowser(FeatureSettings featureSettings)
{
+ fs = featureSettings;
String registry = getDasRegistryURL();
registryURL.setText(registry);
@@ -107,6 +120,13 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
}
}
+ FeatureSettings fs = null;
+
+ public DasSourceBrowser()
+ {
+ this(null);
+ }
+
public void paintComponent(java.awt.Graphics g)
{
if (dasSources == null && !loadingDasSources)
@@ -122,9 +142,9 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
Object[][] data = new Object[dSize][2];
for (int i = 0; i < dSize; i++)
{
- data[i][0] = dasSources[i].getNickname();
+ data[i][0] = dasSources[i].getTitle(); // what's equivalent of nickname
data[i][1] = new Boolean(selectedSources.contains(dasSources[i]
- .getNickname()));
+ .getTitle()));
}
refreshTableData(data);
@@ -169,34 +189,34 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
int dSize = dasSources.length;
for (int i = 0; i < dSize; i++)
{
- if (!dasSources[i].getNickname().equals(nickName))
+ if (!dasSources[i].getTitle().equals(nickName))
{
continue;
}
- DasSource ds = dasSources[i];
-
+ SOURCE ds = dasSources[i];
+ VERSION latest = getVersionFor(ds);
text.append("Id: "
- + dasSources[i].getId() + "
");
+ + dasSources[i].getUri() + "
");
text.append("Nickname: "
- + dasSources[i].getNickname() + "
");
+ + dasSources[i].getTitle() + "
");
text.append("URL: "
- + dasSources[i].getUrl() + "
");
+ + latest.getUri() + "
");
- text
- .append("Admin Email: "
- + dasSources[i].getAdminemail() + "" + "
");
+ text.append("Admin Email: "
+ + ds.getMAINTAINER().getEmail() + "" + "
");
text.append("Registered at: "
- + dasSources[i].getRegisterDate() + "
");
+ + latest.getCreated() + "
");
- text.append("Last successful test: "
- + dasSources[i].getLeaseDate() + "
");
+ // TODO: Identify last successful test date
+// text.append("Last successful test: "
+// + latest.dasSources[i].getLeaseDate() + "
");
text.append("Labels: ");
- for (int s = 0; s < dasSources[i].getLabels().length; s++)
+ for (int s = 0; s < latest.getPROP().length; s++)
{
text.append(dasSources[i].getLabels()[s]);
if (s < dasSources[i].getLabels().length - 1)
@@ -208,7 +228,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
text.append("
");
text.append("Capabilities: ");
- String[] scap = dasSources[i].getCapabilities();
+ CAPABILITY[] scap = latest.getCAPABILITY().toArray(new CAPABILITY[0]);
for (int j = 0; j < scap.length; j++)
{
text.append(scap[j]);
@@ -271,37 +291,62 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
refresh.setVisible(false);
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
+ setParentGuiEnabled(false);
// Refresh the source list.
dasSources = null;
getDASSource();
init();
+ setParentGuiEnabled(true);
loadingDasSources = false;
}
+ private void setParentGuiEnabled(boolean b)
+ {
+ if (fs != null)
+ {
+ fs.fetchDAS.setEnabled(b);
+ fs.saveDAS.setEnabled(b);
+ }
+ }
+
public Vector getSelectedSources()
{
// wait around if we're still loading.
- while (dasSources ==null) {
+ while (dasSources == null)
+ {
if (!loadingDasSources)
{
new Thread(this).start();
- try { Thread.sleep(5); } catch (Exception e) {};
+ try
+ {
+ Thread.sleep(5);
+ } catch (Exception e)
+ {
+ }
+ ;
while (loadingDasSources)
{
- try { Thread.sleep(5); } catch (Exception e) {};
- };
+ try
+ {
+ Thread.sleep(5);
+ } catch (Exception e)
+ {
+ }
+ ;
+ }
+ ;
}
}
-
+
Vector selected = new Vector();
for (int r = 0; r < selectedSources.size(); r++)
{
for (int i = 0; i < dasSources.length; i++)
{
- if (dasSources[i].getNickname()
+ if (dasSources[i].getTitle()
.equals(selectedSources.elementAt(r)))
{
selected.addElement(dasSources[i]);
@@ -318,7 +363,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
*
* @return
*/
- public DasSource[] getDASSource()
+ public SOURCE[] getDASSource()
{
if (dasSources == null)
{
@@ -337,41 +382,84 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
worker.start();
}
- private void setCapabilities(DasSource[] sources)
+ private boolean isLaterThan(String ref, String newer)
{
- Vector authority = new Vector();
- Vector type = new Vector();
- Vector label = new Vector();
-
- authority.addElement("Any");
- type.addElement("Any");
- label.addElement("Any");
+ Date refdate=null,newdate=null;
+ try {
+ refdate=DasTimeFormat.fromDASString(ref);
+
+ }
+ catch (ParseException x)
+ {
+ return false;
+ }
+ try {
+ newdate = DasTimeFormat.fromDASString(newer);
+ }
+ catch (ParseException e) {
+ // TODO: handle exception
+ }
+ if (refdate!=null)
+ {
+ if (newdate!=null)
+ {
+ return refdate.before(newdate);
+ }
+ return false;
+ }
+ if (newdate!=null)
+ {
+ return true;
+ }
+ // assume first instance of source is newest in list. - TODO: check if natural ordering of source versions is newest first or oldest first
+ return false;
+ }
+ private VERSION getVersionFor(SOURCE ds)
+ {
+ VERSION latest=null;
+ for (VERSION v:ds.getVERSION()) {
+ if (latest==null || isLaterThan(latest.getCreated(),v.getCreated()))
+ {
+ // TODO: das 1.6 - should just get the first version - ignore other versions since not specified how to construct URL from version's URI + source URI
+ latest=v;
+ }
+ }
+ return latest;
+ }
+ private void setCapabilities(SOURCE[] sources)
+ {
+ Vector authority = new Vector();
+ Vector type = new Vector();
+ Vector label = new Vector();
+ Vector taxIds=new Vector();
+ authority.add("Any");
+ type.add("Any");
+ label.add("Any");
+
for (int i = 0; i < sources.length; i++)
{
- DasSource ds = sources[i];
-
- DasCoordinateSystem[] dcs = ds.getCoordinateSystem();
-
- for (int j = 0; j < dcs.length; j++)
+ SOURCE ds = sources[i];
+ VERSION latest=getVersionFor(ds);
+
+ for (COORDINATES cs: latest.getCOORDINATES())
{
- if (!type.contains(dcs[j].getCategory()))
+ if (!type.contains(cs.getSource()))
{
- type.addElement(dcs[j].getCategory());
+ type.add(cs.getSource()); // source==category
}
- if (!authority.contains(dcs[j].getName()))
+ if (!authority.contains(cs.getAuthority()))
{
- authority.addElement(dcs[j].getName());
+ authority.add(cs.getAuthority());
}
}
- String[] slabels = ds.getLabels();
- for (int s = 0; s < slabels.length; s++)
+ for (PROP slabel:latest.getPROP())
{
- if (!label.contains(slabels[s]))
+ if (slabel.getName().equalsIgnoreCase("LABEL") && !label.contains(slabel.getValue()))
{
- label.addElement(slabels[s]);
+ label.add(slabel.getValue());
}
}
@@ -380,6 +468,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
filter1.setListData(authority);
filter2.setListData(type);
filter3.setListData(label);
+ // filter4 taxIds
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
@@ -395,13 +484,13 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
public void amendLocal(boolean newSource)
{
String url = "http://localhost:8080/", nickname = "";
- boolean seqsrc=false;
+ boolean seqsrc = false;
if (!newSource)
{
int selectedRow = table.getSelectionModel().getMinSelectionIndex();
nickname = table.getValueAt(selectedRow, 0).toString();
- url = ((DasSource) localSources.get(nickname)).getUrl();
- seqsrc = ((DasSource)localSources.get(nickname)).hasCapability("sequence");
+ url = ((SOURCE) localSources.get(nickname)).getUri();
+ seqsrc = ((SOURCE) localSources.get(nickname)).getVERSION().get(0).getCAPABILITY().contains(Capabilities.SEQUENCE);
}
JTextField nametf = new JTextField(nickname, 40);
@@ -418,7 +507,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
pane12.add(seqs, BorderLayout.SOUTH);
pane12.add(urltf, BorderLayout.EAST);
panel.add(pane12, BorderLayout.SOUTH);
-
+
int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
panel, "Enter Nickname & URL of Local DAS Source",
JOptionPane.OK_CANCEL_OPTION);
@@ -433,20 +522,46 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
urltf.setText(urltf.getText() + "/");
}
- Das1Source local = new Das1Source();
+ // build using pattern from test: sourcesclientImplTest
+ {
+ SOURCE source = new SOURCE();
+ String uri = "http://das.sanger.ac.uk/das/dummysource";
+ source.setUri("http://das.sanger.ac.uk/das/dummysource");
+ source.setDescription("Dummy Test Source, should not be in a working registry sources doc");
+ VERSION version = new VERSION();
+ version.setUri(uri);
+ COORDINATES coord = new COORDINATES();
+ coord.setAuthority("NCBI");
+ coord.setSource("Chromosome");
+ coord.setTaxid("9606");
+ coord.setVersion("35");
+ version.getCOORDINATES().add(coord);
+ CAPABILITY cap = new CAPABILITY();
+ cap.setQueryUri(uri + "features");
+ cap.setType("das1:" + Capabilities.FEATURES.getName());
+ version.getCAPABILITY().add(cap);
+ source.getVERSION().add(version);
+ MAINTAINER m = new MAINTAINER();
+ m.setEmail("jw12@sanger.ac.uk");
+ source.setMAINTAINER(m);
+ source.setTitle("dummy title");
+
+ }
+ SOURCE local = new Das1Source();
local.setUrl(urltf.getText());
local.setNickname(nametf.getText());
if (seqs.isSelected())
{
- local.setCapabilities(new String[] {"features","sequence"});
+ local.setCapabilities(new String[]
+ { "features", "sequence" });
}
if (localSources == null)
{
localSources = new Hashtable();
}
- localSources.put(local.getNickname(), local);
+ localSources.put(local.getTitle(), local);
if (!newSource && !nickname.equals(nametf.getText()))
{
@@ -459,26 +574,26 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
Object[][] data = new Object[size + adjust][2];
for (int i = 0; i < size; i++)
{
- if (!newSource && dasSources[i].getNickname().equals(nickname))
+ if (!newSource && dasSources[i].getTitle().equals(nickname))
{
- ((DasSource) dasSources[i]).setNickname(local.getNickname());
+ ((DasSource) dasSources[i]).setNickname(local.getTitle());
((DasSource) dasSources[i]).setUrl(local.getUrl());
- data[i][0] = local.getNickname();
+ data[i][0] = local.getTitle();
data[i][1] = new Boolean(true);
}
else
{
- data[i][0] = dasSources[i].getNickname();
+ data[i][0] = dasSources[i].getTitle();
data[i][1] = new Boolean(selectedSources.contains(dasSources[i]
- .getNickname()));
+ .getTitle()));
}
}
if (newSource)
{
- data[size][0] = local.getNickname();
+ data[size][0] = local.getTitle();
data[size][1] = new Boolean(true);
- selectedSources.add(local.getNickname());
+ selectedSources.add(local.getTitle());
}
DasSource[] tmp = new DasSource[size + adjust];
@@ -503,7 +618,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
}
});
- displayFullDetails(local.getNickname());
+ displayFullDetails(local.getTitle());
}
public void editRemoveLocalSource(MouseEvent evt)
@@ -546,16 +661,16 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
int index = 0;
for (int i = 0; i < dasSources.length; i++)
{
- if (dasSources[i].getNickname().equals(nickname))
+ if (dasSources[i].getTitle().equals(nickname))
{
continue;
}
else
{
tmp[index] = dasSources[i];
- data[index][0] = dasSources[i].getNickname();
- data[index][1] = new Boolean(selectedSources
- .contains(dasSources[i].getNickname()));
+ data[index][0] = dasSources[i].getTitle();
+ data[index][1] = new Boolean(
+ selectedSources.contains(dasSources[i].getTitle()));
index++;
}
}
@@ -580,16 +695,17 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
{
return;
}
- // note - we add all das sources to list so they can be filtered for the standard fetchDbRefs function
+ // note - we add all das sources to list so they can be filtered for the
+ // standard fetchDbRefs function
int size = dasSources != null ? dasSources.length : 0;
int lsize = localSources.size();
Object[][] data = new Object[size + lsize][2];
for (int i = 0; i < size; i++)
{
- data[i][0] = dasSources[i].getNickname();
+ data[i][0] = dasSources[i].getTitle();
data[i][1] = new Boolean(selectedSources.contains(dasSources[i]
- .getNickname()));
+ .getTitle()));
}
DasSource[] tmp = new DasSource[size + lsize];
@@ -653,15 +769,14 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
// THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT
// HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT
// IS ADDED FROM THE REGISTRY
- names.add(ds.getNickname());
- selected
- .add(new Boolean(selectedSources.contains(ds.getNickname())));
+ names.add(ds.getTitle());
+ selected.add(new Boolean(selectedSources.contains(ds.getTitle())));
continue;
}
if (!selectedInList(dummyFeatureList, ds.getCapabilities())
- || !selectedInList(filter3.getSelectedValues(), ds
- .getLabels()))
+ || !selectedInList(filter3.getSelectedValues(),
+ ds.getLabels()))
{
continue;
}
@@ -673,9 +788,9 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
&& selectedInList(filter2.getSelectedValues(), new String[]
{ dcs[j].getCategory() }))
{
- names.add(ds.getNickname());
+ names.add(ds.getTitle());
selected.add(new Boolean(selectedSources.contains(ds
- .getNickname())));
+ .getTitle())));
break;
}
}
@@ -723,11 +838,11 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
{
selectedSources.addElement(st.nextToken());
}
-
+
Vector _localSources = jalview.bin.Cache.getLocalDasSources();
- if (_localSources!=null)
+ if (_localSources != null)
{
- if (localSources==null)
+ if (localSources == null)
{
localSources = new Hashtable();
}
@@ -735,7 +850,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
while (sources.hasMoreElements())
{
Das1Source source = (Das1Source) sources.nextElement();
- localSources.put(source.getNickname(), source);
+ localSources.put(source.getTitle(), source);
}
}
}
@@ -747,6 +862,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
/**
* set the DAS source settings in the given jalview properties.
+ *
* @param properties
*/
public void saveProperties(Properties properties)
@@ -757,7 +873,8 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
}
else
{
- properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, registryURL.getText());
+ properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL,
+ registryURL.getText());
}
StringBuffer sb = new StringBuffer();
@@ -769,7 +886,8 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
}
}
- properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE, sb.toString());
+ properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE,
+ sb.toString());
if (localSources != null)
{
@@ -778,12 +896,15 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
while (en.hasMoreElements())
{
String token = en.nextElement().toString();
- sb.append(token + "|"
- +(((DasSource) localSources.get(token)).hasCapability("sequence") ? "sequence:" : "")
+ sb.append(token
+ + "|"
+ + (((DasSource) localSources.get(token))
+ .hasCapability("sequence") ? "sequence:" : "")
+ ((DasSource) localSources.get(token)).getUrl() + "\t");
}
- properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sb.toString());
+ properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE,
+ sb.toString());
}
}
@@ -877,8 +998,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
}
});
thr.start();
- while (loadingDasSources
- || dasSources == null)
+ while (loadingDasSources || dasSources == null)
{
try
{
@@ -898,7 +1018,7 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
{
for (int i = 0; i < dasSources.length; i++)
{
- if (sources.contains(dasSources[i].getNickname()))
+ if (sources.contains(dasSources[i].getTitle()))
{
if (!resolved.contains(dasSources[i]))
{
@@ -909,4 +1029,15 @@ public class DasSourceBrowser extends GDasSourceBrowser implements
}
return resolved;
}
+
+ /**
+ * disable or enable the buttons on the source browser
+ *
+ * @param b
+ */
+ public void setGuiEnabled(boolean b)
+ {
+ refresh.setEnabled(b);
+ addLocal.setEnabled(b);
+ }
}