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