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