(JAL-972) jdas source retrieval and use of jdas structures for local sources
[jalview.git] / src / jalview / gui / DasSourceBrowser.java
index e695d3d..faf4712 100755 (executable)
@@ -1,24 +1,25 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, 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
- *\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
- *\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 - 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 file is part of Jalview.\r
+ * \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
+ * 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.text.ParseException;\r
 import java.util.*;\r
+import java.util.List;\r
 \r
 import java.awt.*;\r
 import java.awt.event.*;\r
@@ -26,37 +27,55 @@ import javax.swing.*;
 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.DasCoordinateSystemCollector;\r
+import org.biodas.jdas.dassources.utils.DasTimeFormat;\r
+import org.biodas.jdas.schema.registrycoordinates.DASCOORDINATESYSTEM;\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\r
-    extends GDasSourceBrowser implements Runnable, ListSelectionListener\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
+  Hashtable<String, SOURCE> localSources = null;\r
 \r
   Vector selectedSources;\r
 \r
-  public static String DEFAULT_REGISTRY =\r
-      "http://www.dasregistry.org/das1/sources/";\r
+  public static String DEFAULT_REGISTRY = "http://www.dasregistry.org/das1/sources/";\r
 \r
   /**\r
    * true if thread is running and we are talking to DAS registry service\r
    */\r
   public boolean loadingDasSources = false;\r
 \r
-  public DasSourceBrowser()\r
+  protected static String getDasRegistryURL()\r
   {\r
     String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",\r
-        DEFAULT_REGISTRY);\r
+            DEFAULT_REGISTRY);\r
 \r
     if (registry.indexOf("/registry/das1/sources/") > -1)\r
     {\r
-      jalview.bin.Cache.setProperty("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(FeatureSettings featureSettings)\r
+  {\r
+    fs = featureSettings;\r
+    String registry = getDasRegistryURL();\r
 \r
     registryURL.setText(registry);\r
 \r
@@ -69,7 +88,7 @@ public class DasSourceBrowser
     filter2.addListSelectionListener(this);\r
     filter3.addListSelectionListener(this);\r
 \r
-    //Ask to be notified of selection changes.\r
+    // Ask to be notified of selection changes.\r
     ListSelectionModel rowSM = table.getSelectionModel();\r
     rowSM.addListSelectionListener(new ListSelectionListener()\r
     {\r
@@ -89,7 +108,7 @@ public class DasSourceBrowser
       public void mouseClicked(MouseEvent evt)\r
       {\r
         if (evt.getClickCount() == 2\r
-            || SwingUtilities.isRightMouseButton(evt))\r
+                || SwingUtilities.isRightMouseButton(evt))\r
         {\r
           editRemoveLocalSource(evt);\r
         }\r
@@ -102,6 +121,13 @@ public class DasSourceBrowser
     }\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
@@ -117,9 +143,9 @@ public class DasSourceBrowser
     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][1] = new Boolean(selectedSources.contains(dasSources[i].\r
-          getNickname()));\r
+      data[i][0] = dasSources[i].getTitle(); // what's equivalent of nickname\r
+      data[i][1] = new Boolean(selectedSources.contains(dasSources[i]\r
+              .getTitle()));\r
     }\r
 \r
     refreshTableData(data);\r
@@ -152,61 +178,65 @@ public class DasSourceBrowser
   {\r
 \r
     StringBuffer text = new StringBuffer(\r
-        "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");\r
+            "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");\r
 \r
     if (nickName == null)\r
     {\r
-      fullDetails.setText(text +\r
-                          "Select a DAS service from the table"\r
-                          + " to read a full description here.</font></html>");\r
+      fullDetails.setText(text + "Select a DAS service from the table"\r
+              + " to read a full description here.</font></html>");\r
       return;\r
     }\r
 \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
-      text.append("<font color=\"#0000FF\">Id:</font> " + dasSources[i].getId() +\r
-                  "<br>");\r
-      text.append("<font color=\"#0000FF\">Nickname:</font> " +\r
-                  dasSources[i].getNickname() + "<br>");\r
-      text.append("<font color=\"#0000FF\">URL:</font> " + dasSources[i].getUrl() +\r
-                  "<br>");\r
+      SOURCE ds = dasSources[i];\r
+      VERSION latest = getVersionFor(ds);\r
+      text.append("<font color=\"#0000FF\">Id:</font> "\r
+              + dasSources[i].getUri() + "<br>");\r
+      text.append("<font color=\"#0000FF\">Nickname:</font> "\r
+              + dasSources[i].getTitle() + "<br>");\r
+      text.append("<font color=\"#0000FF\">URL:</font> " + latest.getUri()\r
+              + "<br>");\r
 \r
-      text.append(\r
-          "<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"\r
-          + dasSources[i].getAdminemail()\r
-          + "\">" + dasSources[i].getAdminemail() + "</a>" +\r
-          "<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() +\r
-                  "<br>");\r
+      text.append("<font color=\"#0000FF\">Registered at:</font> "\r
+              + latest.getCreated() + "<br>");\r
 \r
-      text.append("<font color=\"#0000FF\">Last successful test:</font> " +\r
-                  dasSources[i].getLeaseDate() +\r
-                  "<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
+      boolean b = false;\r
+      for (PROP labl : latest.getPROP())\r
       {\r
-        text.append(dasSources[i].getLabels()[s]);\r
-        if (s < dasSources[i].getLabels().length - 1)\r
+        if (labl.getName().equalsIgnoreCase("LABEL"))\r
         {\r
-          text.append(",");\r
+          if (!b)\r
+          {\r
+            text.append(",");\r
+          }\r
+          text.append(" ");\r
+\r
+          text.append(labl.getValue());\r
+          b = true;\r
         }\r
-        text.append(" ");\r
+        ;\r
       }\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
@@ -218,39 +248,40 @@ public class DasSourceBrowser
       text.append("<br>");\r
 \r
       text.append("<font color=\"#0000FF\">Coordinates:</font> ");\r
-      DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
-      for (int j = 0; j < dcs.length; j++)\r
+      for (COORDINATES dcs : latest.getCOORDINATES())\r
       {\r
-        text.append("(" + dcs[j].getUniqueId() + ") "\r
-                    + dcs[j].getCategory() + ", " + dcs[j].getName());\r
-        if (dcs[j].getNCBITaxId() != 0)\r
+        text.append("(" + dcs.getUri() + ") "\r
+\r
+        + dcs.getSource() + ", " + dcs.getAuthority());\r
+        if (dcs.getTaxid() != null && dcs.getTaxid().trim().length() > 0)\r
         {\r
-          text.append(", " + dcs[j].getNCBITaxId());\r
+          text.append(", " + dcs.getTaxid());\r
         }\r
-        if (dcs[j].getOrganismName().length() > 0)\r
+        if (dcs.getVersion().trim().length() > 0)\r
         {\r
-          text.append(", " + dcs[j].getOrganismName());\r
-        }\r
+          {\r
+            text.append(", " + dcs.getVersion());\r
+          }\r
 \r
-        text.append("<br>");\r
-      }\r
+          text.append("<br>");\r
+        }\r
 \r
-      text.append("<font color=\"#0000FF\">Description:</font> " +\r
-                  dasSources[i].getDescription() + "<br>");\r
+        text.append("<font color=\"#0000FF\">Description:</font> "\r
+                + dasSources[i].getDescription() + "<br>");\r
 \r
-      if (dasSources[i].getHelperurl() != null\r
-          && dasSources[i].getHelperurl().length() > 0)\r
-      {\r
-        text.append("<font color=\"#0000FF\"><a href=\"" +\r
-                    dasSources[i].getHelperurl()\r
-                    + "\">Go to site</a></font<br>");\r
-      }\r
+        if (dasSources[i].getDocHref() != null\r
+                && dasSources[i].getDocHref().length() > 0)\r
+        {\r
+          text.append("<font color=\"#0000FF\"><a href=\""\r
+                  + dasSources[i].getDocHref()\r
+                  + "\">Go to site</a></font<br>");\r
+        }\r
 \r
-      text.append("</font></html>");\r
+        text.append("</font></html>");\r
 \r
-      break;\r
+        break;\r
+      }\r
     }\r
-\r
     fullDetails.setText(text.toString());\r
     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
     {\r
@@ -269,25 +300,62 @@ public class DasSourceBrowser
     refresh.setVisible(false);\r
     progressBar.setVisible(true);\r
     progressBar.setIndeterminate(true);\r
+    setParentGuiEnabled(false);\r
     // Refresh the source list.\r
-    dasSources=null;\r
+    dasSources = null;\r
     getDASSource();\r
-    \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
+    {\r
+      if (!loadingDasSources)\r
+      {\r
+        new Thread(this).start();\r
+        try\r
+        {\r
+          Thread.sleep(5);\r
+        } catch (Exception e)\r
+        {\r
+        }\r
+        ;\r
+        while (loadingDasSources)\r
+        {\r
+          try\r
+          {\r
+            Thread.sleep(5);\r
+          } catch (Exception e)\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().equals(\r
-            selectedSources.elementAt(r)))\r
+        if (dasSources[i].getTitle().equals(selectedSources.elementAt(r)))\r
         {\r
           selected.addElement(dasSources[i]);\r
           break;\r
@@ -297,11 +365,13 @@ public class DasSourceBrowser
 \r
     return selected;\r
   }\r
+\r
   /**\r
    * retrieve das sources from registry and add local source list\r
+   * \r
    * @return\r
    */\r
-  public DasSource[] getDASSource()\r
+  public SOURCE[] getDASSource()\r
   {\r
     if (dasSources == null)\r
     {\r
@@ -320,41 +390,92 @@ public class DasSourceBrowser
     worker.start();\r
   }\r
 \r
-  private void setCapabilities(DasSource[] sources)\r
+  private boolean isLaterThan(String ref, String newer)\r
+  {\r
+    Date refdate = null, newdate = null;\r
+    try\r
+    {\r
+      refdate = DasTimeFormat.fromDASString(ref);\r
+\r
+    } catch (ParseException x)\r
+    {\r
+      return false;\r
+    }\r
+    try\r
+    {\r
+      newdate = DasTimeFormat.fromDASString(newer);\r
+    } catch (ParseException e)\r
+    {\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\r
+    // natural ordering of source versions is newest first or oldest first\r
+    return false;\r
+  }\r
+\r
+  private VERSION getVersionFor(SOURCE ds)\r
   {\r
-    Vector authority = new Vector();\r
-    Vector type = new Vector();\r
-    Vector label = new Vector();\r
+    VERSION latest = null;\r
+    for (VERSION v : ds.getVERSION())\r
+    {\r
+      if (latest == null\r
+              || isLaterThan(latest.getCreated(), v.getCreated()))\r
+      {\r
+        // TODO: das 1.6 - should just get the first version - ignore other\r
+        // versions since not specified how to construct URL from version's URI\r
+        // + source URI\r
+        latest = v;\r
+      }\r
+    }\r
+    return latest;\r
+  }\r
 \r
-    authority.addElement("Any");\r
-    type.addElement("Any");\r
-    label.addElement("Any");\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
     for (int i = 0; i < sources.length; i++)\r
     {\r
-      DasSource ds = sources[i];\r
-\r
-      DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
+      SOURCE ds = sources[i];\r
+      VERSION latest = getVersionFor(ds);\r
 \r
-      for (int j = 0; j < dcs.length; j++)\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")\r
+                && !label.contains(slabel.getValue()))\r
         {\r
-          label.addElement(slabels[s]);\r
+          label.add(slabel.getValue());\r
         }\r
       }\r
 \r
@@ -363,6 +484,7 @@ public class DasSourceBrowser
     filter1.setListData(authority);\r
     filter2.setListData(type);\r
     filter3.setListData(label);\r
+    // filter4 taxIds\r
 \r
     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
     {\r
@@ -378,30 +500,34 @@ public class DasSourceBrowser
   public void amendLocal(boolean newSource)\r
   {\r
     String url = "http://localhost:8080/", nickname = "";\r
-\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
+      url = ((SOURCE) localSources.get(nickname)).getUri();\r
+      seqsrc = ((SOURCE) localSources.get(nickname)).getVERSION().get(0)\r
+              .getCAPABILITY().contains(Capabilities.SEQUENCE);\r
     }\r
 \r
     JTextField nametf = new JTextField(nickname, 40);\r
     JTextField urltf = new JTextField(url, 40);\r
-\r
+    JCheckBox seqs = new JCheckBox("Sequence Source");\r
+    seqs.setSelected(seqsrc);\r
     JPanel panel = new JPanel(new BorderLayout());\r
     JPanel pane12 = new JPanel(new BorderLayout());\r
     pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER);\r
     pane12.add(nametf, BorderLayout.EAST);\r
     panel.add(pane12, BorderLayout.NORTH);\r
     pane12 = new JPanel(new BorderLayout());\r
-    pane12.add(new JLabel("URL: "), BorderLayout.CENTER);\r
+    pane12.add(new JLabel("URL: "), BorderLayout.NORTH);\r
+    pane12.add(seqs, BorderLayout.SOUTH);\r
     pane12.add(urltf, BorderLayout.EAST);\r
     panel.add(pane12, BorderLayout.SOUTH);\r
 \r
     int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,\r
-        panel, "Enter Nickname & URL of Local DAS Source",\r
-        JOptionPane.OK_CANCEL_OPTION);\r
+            panel, "Enter Nickname & URL of Local DAS Source",\r
+            JOptionPane.OK_CANCEL_OPTION);\r
 \r
     if (reply != JOptionPane.OK_OPTION)\r
     {\r
@@ -413,17 +539,14 @@ public class DasSourceBrowser
       urltf.setText(urltf.getText() + "/");\r
     }\r
 \r
-    Das1Source local = new Das1Source();\r
-\r
-    local.setUrl(urltf.getText());\r
-    local.setNickname(nametf.getText());\r
-\r
+    SOURCE local = createLocalSource(urltf.getText(), nametf.getText(), seqs.isSelected(), true);\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
@@ -436,29 +559,28 @@ public class DasSourceBrowser
     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]).setUrl(local.getUrl());\r
-        data[i][0] = local.getNickname();\r
+        dasSources[i] = local;\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][1] = new Boolean(selectedSources.contains(dasSources[i].\r
-            getNickname()));\r
+        data[i][0] = dasSources[i].getTitle();\r
+        data[i][1] = new Boolean(selectedSources.contains(dasSources[i]\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
+    SOURCE[] tmp = new SOURCE[size + adjust];\r
 \r
     System.arraycopy(dasSources, 0, tmp, 0, size);\r
 \r
@@ -476,12 +598,47 @@ public class DasSourceBrowser
       public void run()\r
       {\r
         scrollPane.getVerticalScrollBar().setValue(\r
-            scrollPane.getVerticalScrollBar().getMaximum()\r
-            );\r
+                scrollPane.getVerticalScrollBar().getMaximum());\r
       }\r
     });\r
 \r
-    displayFullDetails(local.getNickname());\r
+    displayFullDetails(local.getTitle());\r
+  }\r
+\r
+  private SOURCE createLocalSource(String url, String name,\r
+          boolean sequence, boolean features)\r
+  {\r
+    SOURCE local = new SOURCE();\r
+\r
+    local.setUri(url);\r
+    local.setTitle(name);\r
+    local.setVERSION(new ArrayList<VERSION>());\r
+    VERSION v = new VERSION();\r
+    List<CAPABILITY> cp = new ArrayList<CAPABILITY>();\r
+    if (sequence)\r
+    {\r
+/* Could try and synthesize a coordinate system for the source if needbe\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.setType("das1:"+Capabilities.SEQUENCE.getName());\r
+      cp.add(cap);\r
+    }\r
+    if (features)\r
+    {\r
+    CAPABILITY cap = new CAPABILITY();\r
+    cap.setType("das1:"+Capabilities.FEATURES.getName());\r
+    cp.add(cap);\r
+    }\r
+    \r
+    v.getCAPABILITY().addAll(cp);\r
+    local.getVERSION().add(v);\r
+\r
+    return local;\r
   }\r
 \r
   public void editRemoveLocalSource(MouseEvent evt)\r
@@ -497,63 +654,58 @@ public class DasSourceBrowser
     if (!localSources.containsKey(nickname))\r
     {\r
       JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
-                                            "You can only edit or remove local DAS Sources!",\r
-                                            "Public DAS source - not editable",\r
-                                            JOptionPane.WARNING_MESSAGE);\r
+              "You can only edit or remove local DAS Sources!",\r
+              "Public DAS source - not editable",\r
+              JOptionPane.WARNING_MESSAGE);\r
       return;\r
     }\r
 \r
     Object[] options =\r
-        {\r
-        "Edit", "Remove", "Cancel"};\r
+    { "Edit", "Remove", "Cancel" };\r
     int choice = JOptionPane.showInternalOptionDialog(Desktop.desktop,\r
-        "Do you want to edit or remove " + nickname + "?",\r
-        "Edit / Remove Local DAS Source",\r
-        JOptionPane.YES_NO_CANCEL_OPTION,\r
-        JOptionPane.QUESTION_MESSAGE,\r
-        null,\r
-        options,\r
-        options[2]);\r
+            "Do you want to edit or remove " + nickname + "?",\r
+            "Edit / Remove Local DAS Source",\r
+            JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,\r
+            null, options, options[2]);\r
 \r
     switch (choice)\r
     {\r
-      case 0:\r
-        amendLocal(false);\r
-        break;\r
-      case 1:\r
-        localSources.remove(nickname);\r
-        selectedSources.remove(nickname);\r
-        Object[][] data = new Object[dasSources.length - 1][2];\r
-        DasSource[] tmp = new DasSource[dasSources.length - 1];\r
-        int index = 0;\r
-        for (int i = 0; i < dasSources.length; i++)\r
+    case 0:\r
+      amendLocal(false);\r
+      break;\r
+    case 1:\r
+      localSources.remove(nickname);\r
+      selectedSources.remove(nickname);\r
+      Object[][] data = new Object[dasSources.length - 1][2];\r
+      SOURCE[] tmp = new SOURCE[dasSources.length - 1];\r
+      int index = 0;\r
+      for (int i = 0; i < dasSources.length; i++)\r
+      {\r
+        if (dasSources[i].getTitle().equals(nickname))\r
         {\r
-          if (dasSources[i].getNickname().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.contains(dasSources[i].\r
-                getNickname()));\r
-            index++;\r
-          }\r
+          continue;\r
         }\r
-        dasSources = tmp;\r
-        refreshTableData(data);\r
-        SwingUtilities.invokeLater(new Runnable()\r
+        else\r
         {\r
-          public void run()\r
-          {\r
-            scrollPane.getVerticalScrollBar().setValue(\r
-                scrollPane.getVerticalScrollBar().getMaximum()\r
-                );\r
-          }\r
-        });\r
+          tmp[index] = dasSources[i];\r
+          data[index][0] = dasSources[i].getTitle();\r
+          data[index][1] = new Boolean(\r
+                  selectedSources.contains(dasSources[i].getTitle()));\r
+          index++;\r
+        }\r
+      }\r
+      dasSources = tmp;\r
+      refreshTableData(data);\r
+      SwingUtilities.invokeLater(new Runnable()\r
+      {\r
+        public void run()\r
+        {\r
+          scrollPane.getVerticalScrollBar().setValue(\r
+                  scrollPane.getVerticalScrollBar().getMaximum());\r
+        }\r
+      });\r
 \r
-        break;\r
+      break;\r
     }\r
   }\r
 \r
@@ -563,19 +715,20 @@ public class DasSourceBrowser
     {\r
       return;\r
     }\r
-\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][1] = new Boolean(selectedSources.contains(dasSources[i].\r
-          getNickname()));\r
+      data[i][0] = dasSources[i].getTitle();\r
+      data[i][1] = new Boolean(selectedSources.contains(dasSources[i]\r
+              .getTitle()));\r
     }\r
 \r
-    DasSource[] tmp = new DasSource[size + lsize];\r
+    SOURCE[] tmp = new SOURCE[size + lsize];\r
     if (dasSources != null)\r
     {\r
       System.arraycopy(dasSources, 0, tmp, 0, size);\r
@@ -588,9 +741,7 @@ public class DasSourceBrowser
       String key = en.nextElement().toString();\r
       data[index][0] = key;\r
       data[index][1] = new Boolean(false);\r
-      tmp[index] = new Das1Source();\r
-      tmp[index].setNickname(key);\r
-      tmp[index].setUrl( ( (DasSource) localSources.get(key)).getUrl());\r
+      tmp[index] = createLocalSource(localSources.get(key).getUri(), key, false, true);\r
 \r
       index++;\r
     }\r
@@ -602,7 +753,7 @@ public class DasSourceBrowser
 \r
   public void valueChanged(ListSelectionEvent evt)\r
   {\r
-    //Called when the MainTable selection changes\r
+    // Called when the MainTable selection changes\r
     if (evt.getValueIsAdjusting())\r
     {\r
       return;\r
@@ -615,53 +766,48 @@ public class DasSourceBrowser
 \r
     ArrayList names = new ArrayList();\r
     ArrayList selected = new ArrayList();\r
-    DasSource ds;\r
+    SOURCE ds;\r
 \r
-    //The features filter is not visible, but we must still\r
-    //filter the das source list here.\r
-    //July 2006 - only 6 sources fo not serve features\r
+    // The features filter is not visible, but we must still\r
+    // filter the das source list here.\r
+    // July 2006 - only 6 sources fo not serve features\r
     Object[] dummyFeatureList = new Object[]\r
-        {\r
-        "features"};\r
+    { "features" };\r
 \r
     for (int i = 0; i < dSize; i++)\r
     {\r
       ds = dasSources[i];\r
-      DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
-\r
-      if (dcs.length == 0 && ds.getCapabilities().length == 0\r
-          && filter1.getSelectedIndex() == 0\r
-          && filter2.getSelectedIndex() == 0\r
-          && filter3.getSelectedIndex() == 0)\r
-      {\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.add(new Boolean(\r
-            selectedSources.contains(ds.getNickname())));\r
+      VERSION v=getVersionFor(ds);\r
+      List<COORDINATES> coords = v.getCOORDINATES();\r
+      if ((coords==null || coords.size()==0)\r
+              && filter1.getSelectedIndex() == 0\r
+              && filter2.getSelectedIndex() == 0\r
+              && filter3.getSelectedIndex() == 0)\r
+      {\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.getTitle());\r
+        selected.add(new Boolean(selectedSources.contains(ds.getTitle())));\r
         continue;\r
       }\r
 \r
-      if (!selectedInList(dummyFeatureList, ds.getCapabilities())\r
-          || !selectedInList(filter3.getSelectedValues(),\r
-                             ds.getLabels()))\r
+      if (!selectedInList(dummyFeatureList, getCapabilityKeys(v))\r
+              || !selectedInList(filter3.getSelectedValues(),\r
+                      getLabelsFor(v)))\r
       {\r
         continue;\r
       }\r
 \r
-      for (int j = 0; j < dcs.length; j++)\r
+      for (int j = 0; j <coords.size(); j++)\r
       {\r
-        if (selectedInList(filter1.getSelectedValues(),\r
-                           new String[]\r
-                           {dcs[j].getName()})\r
-            && selectedInList(filter2.getSelectedValues(),\r
-                              new String[]\r
-                              {dcs[j].getCategory()}))\r
+        if (selectedInList(filter1.getSelectedValues(), new String[]\r
+        { coords.get(j).getAuthority() })\r
+                && selectedInList(filter2.getSelectedValues(), new String[]\r
+                { coords.get(j).getSource()}))\r
         {\r
-          names.add(ds.getNickname());\r
-          selected.add(new Boolean(\r
-              selectedSources.contains(ds.getNickname())));\r
+          names.add(ds.getTitle());\r
+          selected.add(new Boolean(selectedSources.contains(ds.getTitle())));\r
           break;\r
         }\r
       }\r
@@ -678,6 +824,36 @@ public class DasSourceBrowser
     refreshTableData(data);\r
   }\r
 \r
+  private String[] getLabelsFor(VERSION v)\r
+  {\r
+    ArrayList<String> labels=new ArrayList<String>();\r
+    for (PROP p: v.getPROP())\r
+    {\r
+      if (p.getName().equalsIgnoreCase("LABEL"))\r
+      {\r
+        labels.add(p.getValue());\r
+      }\r
+    }\r
+    return labels.toArray(new String[0]);\r
+  }\r
+\r
+  private String[] getCapabilityKeys(VERSION v)\r
+  {\r
+\r
+    ArrayList<String> labels=new ArrayList<String>();\r
+    for (CAPABILITY p: v.getCAPABILITY())\r
+    {\r
+      // TODO: work out what to do with namespace prefix \r
+      // does SEQUENCE == das1:SEQUENCE and das2:SEQUENCE ?\r
+      // for moment, just show all capabilities...\r
+      if (p.getType().startsWith("das1:"))\r
+      {\r
+        labels.add(p.getType());\r
+      }\r
+    }\r
+    return labels.toArray(new String[0]);\r
+  }\r
+\r
   boolean selectedInList(Object[] selection, String[] items)\r
   {\r
     for (int i = 0; i < selection.length; i++)\r
@@ -701,7 +877,8 @@ public class DasSourceBrowser
 \r
   void setSelectedFromProperties()\r
   {\r
-    String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot");\r
+    String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",\r
+            "uniprot");\r
     StringTokenizer st = new StringTokenizer(active, "\t");\r
     selectedSources = new Vector();\r
     while (st.hasMoreTokens())\r
@@ -709,25 +886,18 @@ public class DasSourceBrowser
       selectedSources.addElement(st.nextToken());\r
     }\r
 \r
-    String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");\r
-    if (local != null)\r
+    Vector _localSources = jalview.bin.Cache.getLocalDasSources();\r
+    if (_localSources != null)\r
     {\r
       if (localSources == null)\r
       {\r
-        localSources = new Hashtable();\r
+        localSources = new Hashtable<String, SOURCE>();\r
       }\r
-\r
-      st = new StringTokenizer(local, "\t");\r
-      while (st.hasMoreTokens())\r
+      Enumeration sources = _localSources.elements();\r
+      while (sources.hasMoreElements())\r
       {\r
-        String token = st.nextToken();\r
-        int bar = token.indexOf("|");\r
-        Das1Source source = new Das1Source();\r
-\r
-        source.setUrl(token.substring(bar + 1));\r
-        source.setNickname(token.substring(0, bar));\r
-\r
-        localSources.put(source.getNickname(), source);\r
+        SOURCE source = (SOURCE) sources.nextElement();\r
+        localSources.put(source.getTitle(), source);\r
       }\r
     }\r
   }\r
@@ -737,27 +907,34 @@ public class DasSourceBrowser
     registryURL.setText(DEFAULT_REGISTRY);\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
     if (registryURL.getText() == null || registryURL.getText().length() < 1)\r
     {\r
-      properties.remove("DAS_REGISTRY_URL");\r
+      properties.remove(jalview.bin.Cache.DAS_REGISTRY_URL);\r
     }\r
     else\r
     {\r
-      properties.setProperty("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
     for (int r = 0; r < table.getModel().getRowCount(); r++)\r
     {\r
-      if ( ( (Boolean) table.getValueAt(r, 1)).booleanValue())\r
+      if (((Boolean) table.getValueAt(r, 1)).booleanValue())\r
       {\r
         sb.append(table.getValueAt(r, 0) + "\t");\r
       }\r
     }\r
 \r
-    properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString());\r
+    properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE,\r
+            sb.toString());\r
 \r
     if (localSources != null)\r
     {\r
@@ -766,18 +943,20 @@ public class DasSourceBrowser
       while (en.hasMoreElements())\r
       {\r
         String token = en.nextElement().toString();\r
-        sb.append(token + "|"\r
-                  + ( (DasSource) localSources.get(token)).getUrl()\r
-                  + "\t");\r
+        sb.append(token\r
+                + "|"\r
+                + (selectedInList(getCapabilityKeys(getVersionFor(localSources.get(token))),\r
+                        new String[] { "das1:"+Capabilities.SEQUENCE.getName()}) ? "sequence:" : "")\r
+                + getVersionFor(localSources.get(token)).getUri() + "\t");\r
       }\r
 \r
-      properties.setProperty("DAS_LOCAL_SOURCE", sb.toString());\r
+      properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE,\r
+              sb.toString());\r
     }\r
 \r
   }\r
 \r
-  class DASTableModel\r
-      extends AbstractTableModel\r
+  class DASTableModel extends AbstractTableModel\r
   {\r
 \r
     public DASTableModel(Object[][] data)\r
@@ -786,8 +965,7 @@ public class DasSourceBrowser
     }\r
 \r
     private String[] columnNames = new String[]\r
-        {\r
-        "Nickname", "Use Source"};\r
+    { "Nickname", "Use Source" };\r
 \r
     private Object[][] data;\r
 \r
@@ -812,10 +990,9 @@ public class DasSourceBrowser
     }\r
 \r
     /*\r
-     * JTable uses this method to determine the default renderer/\r
-     * editor for each cell.  If we didn't implement this method,\r
-     * then the last column would contain text ("true"/"false"),\r
-     * rather than a check box.\r
+     * JTable uses this method to determine the default renderer/ editor for\r
+     * each cell. If we didn't implement this method, then the last column would\r
+     * contain text ("true"/"false"), rather than a check box.\r
      */\r
     public Class getColumnClass(int c)\r
     {\r
@@ -823,20 +1000,18 @@ public class DasSourceBrowser
     }\r
 \r
     /*\r
-     * Don't need to implement this method unless your table's\r
-     * editable.\r
+     * Don't need to implement this method unless your table's editable.\r
      */\r
     public boolean isCellEditable(int row, int col)\r
     {\r
-      //Note that the data/cell address is constant,\r
-      //no matter where the cell appears onscreen.\r
+      // Note that the data/cell address is constant,\r
+      // no matter where the cell appears onscreen.\r
       return col == 1;\r
 \r
     }\r
 \r
     /*\r
-     * Don't need to implement this method unless your table's\r
-     * data can change.\r
+     * Don't need to implement this method unless your table's data can change.\r
      */\r
     public void setValueAt(Object value, int row, int col)\r
     {\r
@@ -844,7 +1019,7 @@ public class DasSourceBrowser
       fireTableCellUpdated(row, col);\r
 \r
       String name = getValueAt(row, 0).toString();\r
-      boolean selected = ( (Boolean) value).booleanValue();\r
+      boolean selected = ((Boolean) value).booleanValue();\r
 \r
       if (selectedSources.contains(name) && !selected)\r
       {\r
@@ -857,4 +1032,59 @@ public class DasSourceBrowser
       }\r
     }\r
   }\r
+\r
+  public void initDasSources()\r
+  {\r
+\r
+    Thread thr = new Thread(new Runnable()\r
+    {\r
+      public void run()\r
+      {\r
+        // this actually initialises the das source list\r
+        paintComponent(null); // yuk\r
+      }\r
+    });\r
+    thr.start();\r
+    while (loadingDasSources || dasSources == null)\r
+    {\r
+      try\r
+      {\r
+        Thread.sleep(10);\r
+      } catch (Exception e)\r
+      {\r
+      }\r
+      ;\r
+    }\r
+  }\r
+\r
+  public Vector resolveSourceNicknames(Vector sources)\r
+  {\r
+\r
+    Vector resolved = new Vector();\r
+    if (sources != null)\r
+    {\r
+      for (int i = 0; i < dasSources.length; i++)\r
+      {\r
+        if (sources.contains(dasSources[i].getTitle()))\r
+        {\r
+          if (!resolved.contains(dasSources[i]))\r
+          {\r
+            resolved.addElement(dasSources[i]);\r
+          }\r
+        }\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