X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDasSourceBrowser.java;h=c6235301db319ec1ba8855a8be70073796b0f0c7;hb=a45774ee31d9f35d4eff46d54d7deab719afb092;hp=e23685cf1a005aef5c77deb5e882c291ff053d9c;hpb=cdefedf239cfb9d70f5e6a1ba6ff8993bbf9d1be;p=jalview.git diff --git a/src/jalview/gui/DasSourceBrowser.java b/src/jalview/gui/DasSourceBrowser.java index e23685c..c623530 100755 --- a/src/jalview/gui/DasSourceBrowser.java +++ b/src/jalview/gui/DasSourceBrowser.java @@ -1,38 +1,36 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 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 jalview.jbgui.*; -import javax.swing.table.AbstractTableModel; -import javax.swing.event.*; -import jalview.util.TableSorter; +import java.util.*; + +import java.awt.*; import java.awt.event.*; import javax.swing.*; -import java.util.*; -import java.net.*; +import javax.swing.event.*; +import javax.swing.table.*; -import org.biojava.services.das.registry.DasCoordinateSystem; -import org.biojava.services.das.registry.DasSource; -import java.awt.BorderLayout; +import org.biojava.dasobert.dasregistry.*; +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; @@ -40,30 +38,49 @@ public class DasSourceBrowser extends GDasSourceBrowser Vector selectedSources; - public DasSourceBrowser() + 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; + + protected static String getDasRegistryURL() + { + String registry = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL", + DEFAULT_REGISTRY); + + if (registry.indexOf("/registry/das1/sources/") > -1) + { + jalview.bin.Cache.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, + DEFAULT_REGISTRY); + registry = DEFAULT_REGISTRY; + } + return registry; + } + + public DasSourceBrowser(FeatureSettings featureSettings) { - registryURL.setText(jalview.bin.Cache.getDefault("DAS_REGISTRY_URL", - "http://servlet.sanger.ac.uk/dasregistry/services/das_registry") ); + fs = featureSettings; + String registry = getDasRegistryURL(); + + registryURL.setText(registry); setSelectedFromProperties(); displayFullDetails(null); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - capabilities.addListSelectionListener(this); - coords1.addListSelectionListener(this); - coords2.addListSelectionListener(this); + filter1.addListSelectionListener(this); + 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() { public void valueChanged(ListSelectionEvent e) { - //Ignore extra messages. - if (e.getValueIsAdjusting()) - return; - ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (!lsm.isSelectionEmpty()) { @@ -74,24 +91,37 @@ public class DasSourceBrowser extends GDasSourceBrowser }); table.addMouseListener(new MouseAdapter() + { + public void mouseClicked(MouseEvent evt) + { + if (evt.getClickCount() == 2 + || SwingUtilities.isRightMouseButton(evt)) { - public void mouseClicked(MouseEvent evt) - { - if(evt.getClickCount()==2 - || SwingUtilities.isRightMouseButton(evt)) - editRemoveLocalSource(evt); - } - }); + editRemoveLocalSource(evt); + } + } + }); - if(dasSources==null) + if (dasSources != null) { - Thread worker = new Thread(this); - worker.start(); + init(); + } + } + + FeatureSettings fs = null; + + public DasSourceBrowser() + { + this(null); + } + + public void paintComponent(java.awt.Graphics g) + { + if (dasSources == null && !loadingDasSources) + { + Thread worker = new Thread(this); + worker.start(); } - else - { - init(); - } } void init() @@ -101,22 +131,22 @@ public class DasSourceBrowser extends GDasSourceBrowser 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][1] = new Boolean(selectedSources.contains(dasSources[i] + .getNickname())); } refreshTableData(data); setCapabilities(dasSources); javax.swing.SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - TableSorter sorter = (TableSorter)table.getModel(); - sorter.setSortingStatus(1, TableSorter.DESCENDING); - sorter.setSortingStatus(1, TableSorter.NOT_SORTED); - } - }); + { + public void run() + { + TableSorter sorter = (TableSorter) table.getModel(); + sorter.setSortingStatus(1, TableSorter.DESCENDING); + sorter.setSortingStatus(1, TableSorter.NOT_SORTED); + } + }); progressBar.setIndeterminate(false); progressBar.setVisible(false); @@ -124,7 +154,6 @@ public class DasSourceBrowser extends GDasSourceBrowser refresh.setVisible(true); } - public void refreshTableData(Object[][] data) { TableSorter sorter = new TableSorter(new DASTableModel(data)); @@ -136,13 +165,12 @@ public class DasSourceBrowser extends GDasSourceBrowser { 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; } @@ -150,48 +178,51 @@ public class DasSourceBrowser extends GDasSourceBrowser for (int i = 0; i < dSize; i++) { if (!dasSources[i].getNickname().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() + - "
"); + text.append("Id: " + + dasSources[i].getId() + "
"); + text.append("Nickname: " + + dasSources[i].getNickname() + "
"); + text.append("URL: " + + dasSources[i].getUrl() + "
"); text.append("Admin Email: "+dasSources[i].getAdminemail()+"" + - "
"); - + + dasSources[i].getAdminemail() + + "\">" + + dasSources[i].getAdminemail() + "" + "
"); - text.append("Registered at: " + dasSources[i].getRegisterDate() + - "
"); + text.append("Registered at: " + + dasSources[i].getRegisterDate() + "
"); - text.append("Last successful test: " + dasSources[i].getLeaseDate() + - "
"); + text.append("Last successful test: " + + dasSources[i].getLeaseDate() + "
"); text.append("Labels: "); - for(int s=0; s"); - - text.append("Capabilities: "); String[] scap = dasSources[i].getCapabilities(); for (int j = 0; j < scap.length; j++) { text.append(scap[j]); if (j < scap.length - 1) + { text.append(", "); + } } text.append("
"); @@ -200,23 +231,28 @@ public class DasSourceBrowser extends GDasSourceBrowser for (int j = 0; j < dcs.length; j++) { text.append("(" + dcs[j].getUniqueId() + ") " - + dcs[j].getCategory() + ", " + dcs[j].getName()); + + dcs[j].getCategory() + ", " + dcs[j].getName()); if (dcs[j].getNCBITaxId() != 0) + { text.append(", " + dcs[j].getNCBITaxId()); + } if (dcs[j].getOrganismName().length() > 0) + { text.append(", " + dcs[j].getOrganismName()); + } text.append("
"); } - text.append("Description: " + - dasSources[i].getDescription() + "
"); + text.append("Description: " + + dasSources[i].getDescription() + "
"); - if (dasSources[i].getHelperurl().length() > 0) + if (dasSources[i].getHelperurl() != null + && dasSources[i].getHelperurl().length() > 0) { - text.append("Go to site"); + text.append("Go to site"); } text.append(""); @@ -234,27 +270,92 @@ public class DasSourceBrowser extends GDasSourceBrowser }); } - public void run() { + loadingDasSources = true; + addLocal.setVisible(false); refresh.setVisible(false); progressBar.setVisible(true); progressBar.setIndeterminate(true); + setParentGuiEnabled(false); + // Refresh the source list. + dasSources = null; + getDASSource(); - dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources(); + init(); - appendLocalSources(); + setParentGuiEnabled(true); + loadingDasSources = false; - init(); } + 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))) + { + selected.addElement(dasSources[i]); + break; + } + } + } + + return selected; + } + + /** + * retrieve das sources from registry and add local source list + * + * @return + */ public DasSource[] getDASSource() { - if(dasSources==null) + if (dasSources == null) { - dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources(); - appendLocalSources(); + dasSources = jalview.ws.DasSequenceFeatureFetcher.getDASSources(); + appendLocalSources(); } return dasSources; @@ -270,49 +371,55 @@ public class DasSourceBrowser extends GDasSourceBrowser private void setCapabilities(DasSource[] sources) { - Vector vcapabilities = new Vector(); - Vector vcoords = new Vector(); - Vector vcoords2 = new Vector(); + Vector authority = new Vector(); + Vector type = new Vector(); + Vector label = new Vector(); - vcapabilities.addElement("All"); - vcoords.addElement("All"); - vcoords2.addElement("All"); + authority.addElement("Any"); + type.addElement("Any"); + label.addElement("Any"); for (int i = 0; i < sources.length; i++) { DasSource ds = sources[i]; - String[] scap = ds.getCapabilities(); - for (int s = 0; s < scap.length; s++) - { - if (!vcapabilities.contains(scap[s])) - { - vcapabilities.addElement(scap[s]); - } - } DasCoordinateSystem[] dcs = ds.getCoordinateSystem(); for (int j = 0; j < dcs.length; j++) { - if (!vcoords.contains(dcs[j].getCategory())) - vcoords.addElement(dcs[j].getCategory()); + if (!type.contains(dcs[j].getCategory())) + { + type.addElement(dcs[j].getCategory()); + } - if (!vcoords2.contains(dcs[j].getName())) - vcoords2.addElement(dcs[j].getName()); + if (!authority.contains(dcs[j].getName())) + { + authority.addElement(dcs[j].getName()); + } } + + String[] slabels = ds.getLabels(); + for (int s = 0; s < slabels.length; s++) + { + if (!label.contains(slabels[s])) + { + label.addElement(slabels[s]); + } + } + } - capabilities.setListData(vcapabilities); - coords1.setListData(vcoords); - coords2.setListData(vcoords2); + filter1.setListData(authority); + filter2.setListData(type); + filter3.setListData(label); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { - capabilities.setSelectedIndex(0); - coords1.setSelectedIndex(0); - coords2.setSelectedIndex(0); + filter1.setSelectedIndex(0); + filter2.setSelectedIndex(0); + filter3.setSelectedIndex(0); } }); } @@ -320,218 +427,234 @@ public class DasSourceBrowser extends GDasSourceBrowser public void amendLocal(boolean newSource) { String url = "http://localhost:8080/", nickname = ""; - - if(!newSource) + boolean seqsrc = false; + if (!newSource) { int selectedRow = table.getSelectionModel().getMinSelectionIndex(); nickname = table.getValueAt(selectedRow, 0).toString(); - url = ((DasSource)localSources.get(nickname)).getUrl(); + url = ((DasSource) localSources.get(nickname)).getUrl(); + seqsrc = ((DasSource) localSources.get(nickname)) + .hasCapability("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 ) - { - return; - } + if (reply != JOptionPane.OK_OPTION) + { + return; + } - if(!urltf.getText().endsWith("/")) - urltf.setText(urltf.getText()+"/"); + if (!urltf.getText().endsWith("/")) + { + urltf.setText(urltf.getText() + "/"); + } - DasSource local = new DasSource(); + Das1Source local = new Das1Source(); - local.setUrl(urltf.getText()); - local.setNickname(nametf.getText()); + local.setUrl(urltf.getText()); + local.setNickname(nametf.getText()); + if (seqs.isSelected()) + { + local.setCapabilities(new String[] + { "features", "sequence" }); + } + if (localSources == null) + { + localSources = new Hashtable(); + } + localSources.put(local.getNickname(), local); - if(localSources==null) - localSources = new Hashtable(); + if (!newSource && !nickname.equals(nametf.getText())) + { + localSources.remove(nickname); + } - localSources.put(local.getNickname(), local); + int size = dasSources.length; + int adjust = newSource ? 1 : 0; - if(!newSource && !nickname.equals(nametf.getText())) - { - localSources.remove(nickname); - } + Object[][] data = new Object[size + adjust][2]; + for (int i = 0; i < size; i++) + { + if (!newSource && dasSources[i].getNickname().equals(nickname)) + { + ((DasSource) dasSources[i]).setNickname(local.getNickname()); + ((DasSource) dasSources[i]).setUrl(local.getUrl()); + data[i][0] = local.getNickname(); + data[i][1] = new Boolean(true); + } + else + { + data[i][0] = dasSources[i].getNickname(); + data[i][1] = new Boolean(selectedSources.contains(dasSources[i] + .getNickname())); + } + } - int size = dasSources.length; - int adjust = newSource ? 1 : 0; + if (newSource) + { + data[size][0] = local.getNickname(); + data[size][1] = new Boolean(true); + selectedSources.add(local.getNickname()); + } - Object[][] data = new Object[size+adjust][2]; - for (int i = 0; i < size; i++) - { - if(!newSource && dasSources[i].getNickname().equals(nickname)) - { - ((DasSource)dasSources[i]).setNickname(local.getNickname()); - ((DasSource)dasSources[i]).setUrl(local.getUrl()); - data[i][0] = local.getNickname(); - data[i][1] = new Boolean(true); - } - else - { - data[i][0] = dasSources[i].getNickname(); - data[i][1] = new Boolean(selectedSources.contains(dasSources[i]. - getNickname())); - } - } + DasSource[] tmp = new DasSource[size + adjust]; - if(newSource) - { - data[size][0] = local.getNickname(); - data[size][1] = new Boolean(true); - selectedSources.add(local.getNickname()); - } + System.arraycopy(dasSources, 0, tmp, 0, size); - DasSource [] tmp = new DasSource[size+adjust]; + if (newSource) + { + tmp[size] = local; + } - System.arraycopy(dasSources, 0, tmp, 0, size); + dasSources = tmp; - if(newSource) - tmp[size] = local; + refreshTableData(data); - dasSources = tmp; + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + scrollPane.getVerticalScrollBar().setValue( + scrollPane.getVerticalScrollBar().getMaximum()); + } + }); - refreshTableData(data); + displayFullDetails(local.getNickname()); + } - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - scrollPane.getVerticalScrollBar().setValue( - scrollPane.getVerticalScrollBar().getMaximum() - ); - } - }); + public void editRemoveLocalSource(MouseEvent evt) + { + int selectedRow = table.getSelectionModel().getMinSelectionIndex(); + if (selectedRow == -1) + { + return; + } - displayFullDetails(local.getNickname()); - } + String nickname = table.getValueAt(selectedRow, 0).toString(); - public void editRemoveLocalSource(MouseEvent evt) + if (!localSources.containsKey(nickname)) { - int selectedRow = table.getSelectionModel().getMinSelectionIndex(); - if(selectedRow==-1) - return; + JOptionPane.showInternalMessageDialog(Desktop.desktop, + "You can only edit or remove local DAS Sources!", + "Public DAS source - not editable", + JOptionPane.WARNING_MESSAGE); + return; + } - String nickname = table.getValueAt(selectedRow, 0).toString(); + Object[] options = + { "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]); - if (!localSources.containsKey(nickname)) + 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++) { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - "You can only edit or remove local DAS Sources!", - "Public DAS source - not editable", - JOptionPane.WARNING_MESSAGE); - return; + 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++; + } } - - - Object[] options = {"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]); - - switch(choice) + dasSources = tmp; + refreshTableData(data); + SwingUtilities.invokeLater(new Runnable() { - 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++) - { - 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++; - } - } - dasSources = tmp; - refreshTableData(data); - SwingUtilities.invokeLater(new Runnable() - { - public void run() - { - scrollPane.getVerticalScrollBar().setValue( - scrollPane.getVerticalScrollBar().getMaximum() - ); - } - }); + public void run() + { + scrollPane.getVerticalScrollBar().setValue( + scrollPane.getVerticalScrollBar().getMaximum()); + } + }); - break; - } + break; } + } - void appendLocalSources() + void appendLocalSources() + { + if (localSources == null) { - if(localSources==null) - return; - - 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())); - } + 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(); - DasSource [] tmp = new DasSource[size+lsize]; - if(dasSources!=null) - System.arraycopy(dasSources, 0, tmp, 0, 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())); + } - Enumeration en = localSources.keys(); - int index = size; - while(en.hasMoreElements()) - { - String key = en.nextElement().toString(); - data[index][0] = key; - data[index][1] = new Boolean(false); - tmp[index] = new DasSource(); - tmp[index].setNickname(key); - tmp[index].setUrl( ((DasSource)localSources.get(key)).getUrl() ); + DasSource[] tmp = new DasSource[size + lsize]; + if (dasSources != null) + { + System.arraycopy(dasSources, 0, tmp, 0, size); + } - index++; - } + Enumeration en = localSources.keys(); + int index = size; + while (en.hasMoreElements()) + { + 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()); + + index++; + } - dasSources = tmp; + dasSources = tmp; - refreshTableData(data); + refreshTableData(data); } public void valueChanged(ListSelectionEvent evt) { - //Called when the MainTable selection changes + // Called when the MainTable selection changes if (evt.getValueIsAdjusting()) { return; @@ -541,31 +664,52 @@ public class DasSourceBrowser extends GDasSourceBrowser // Filter the displayed data sources int dSize = dasSources.length; + ArrayList names = new ArrayList(); ArrayList selected = new ArrayList(); DasSource ds; - // capabilities.get + // 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" }; + for (int i = 0; i < dSize; i++) { ds = dasSources[i]; + DasCoordinateSystem[] dcs = ds.getCoordinateSystem(); - if (!selectedInList(capabilities, ds.getCapabilities())) + 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()))); + continue; + } + + if (!selectedInList(dummyFeatureList, ds.getCapabilities()) + || !selectedInList(filter3.getSelectedValues(), + ds.getLabels())) { continue; } - DasCoordinateSystem[] dcs = ds.getCoordinateSystem(); for (int j = 0; j < dcs.length; j++) { - if (selectedInList(coords1, new String[] - {dcs[j].getCategory()}) - && selectedInList(coords2, new String[] - {dcs[j].getName()})) + if (selectedInList(filter1.getSelectedValues(), new String[] + { dcs[j].getName() }) + && selectedInList(filter2.getSelectedValues(), new String[] + { dcs[j].getCategory() })) { names.add(ds.getNickname()); - selected.add(new Boolean( - selectedSources.contains(ds.getNickname()))); + selected.add(new Boolean(selectedSources.contains(ds + .getNickname()))); break; } } @@ -582,18 +726,21 @@ public class DasSourceBrowser extends GDasSourceBrowser refreshTableData(data); } - boolean selectedInList(JList list, String[] items) + boolean selectedInList(Object[] selection, String[] items) { - Object[] selection = list.getSelectedValues(); for (int i = 0; i < selection.length; i++) { - if (selection[i].equals("All")) + if (selection[i].equals("Any")) + { return true; + } for (int j = 0; j < items.length; j++) { if (selection[i].equals(items[j])) + { return true; + } } } @@ -602,69 +749,86 @@ public class DasSourceBrowser extends GDasSourceBrowser void setSelectedFromProperties() { - String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot"); - StringTokenizer st = new StringTokenizer(active, "\t"); - selectedSources = new Vector(); - while(st.hasMoreTokens()) - { - selectedSources.addElement(st.nextToken()); - } - - String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE"); - if(local!=null) - { - if(localSources == null) - localSources = new Hashtable(); - - st = new StringTokenizer(local, "\t"); - while(st.hasMoreTokens()) - { - String token = st.nextToken(); - int bar = token.indexOf("|"); - DasSource source = new DasSource(); - - source.setUrl(token.substring(bar + 1)); - source.setNickname(token.substring(0, bar)); - - localSources.put(source.getNickname(), source); - } - } + String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", + "uniprot"); + StringTokenizer st = new StringTokenizer(active, "\t"); + selectedSources = new Vector(); + while (st.hasMoreTokens()) + { + selectedSources.addElement(st.nextToken()); + } + + Vector _localSources = jalview.bin.Cache.getLocalDasSources(); + if (_localSources != null) + { + if (localSources == null) + { + localSources = new Hashtable(); + } + Enumeration sources = _localSources.elements(); + while (sources.hasMoreElements()) + { + Das1Source source = (Das1Source) sources.nextElement(); + localSources.put(source.getNickname(), source); + } + } } - void saveProperties(Properties properties) + public void reset_actionPerformed(ActionEvent e) { - properties.setProperty("DAS_REGISTRY_URL", registryURL.getText()); + 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(jalview.bin.Cache.DAS_REGISTRY_URL); + } + else + { + properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL, + registryURL.getText()); + } StringBuffer sb = new StringBuffer(); - for(int r=0; r