-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 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
- */\r
-package jalview.gui;\r
-\r
-import jalview.jbgui.*;\r
-import javax.swing.table.AbstractTableModel;\r
-import javax.swing.event.*;\r
-import jalview.util.TableSorter;\r
-import java.awt.event.*;\r
-import javax.swing.*;\r
-import java.util.*;\r
-import java.net.*;\r
-\r
-import org.biojava.services.das.registry.DasCoordinateSystem;\r
-import org.biojava.services.das.registry.DasSource;\r
-import java.awt.BorderLayout;\r
-\r
-public class DasSourceBrowser extends GDasSourceBrowser\r
- implements Runnable, ListSelectionListener\r
-{\r
- static DasSource[] dasSources = null;\r
-\r
- Hashtable localSources = null;\r
-\r
- Vector selectedSources;\r
-\r
- public DasSourceBrowser()\r
- {\r
- registryURL.setText(jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",\r
- "http://servlet.sanger.ac.uk/dasregistry/services/das_registry") );\r
-\r
- setSelectedFromProperties();\r
-\r
- displayFullDetails(null);\r
- table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
-\r
- capabilities.addListSelectionListener(this);\r
- coords1.addListSelectionListener(this);\r
- coords2.addListSelectionListener(this);\r
-\r
- //Ask to be notified of selection changes.\r
- ListSelectionModel rowSM = table.getSelectionModel();\r
- rowSM.addListSelectionListener(new ListSelectionListener()\r
- {\r
- public void valueChanged(ListSelectionEvent e)\r
- {\r
- //Ignore extra messages.\r
- if (e.getValueIsAdjusting())\r
- return;\r
-\r
- ListSelectionModel lsm = (ListSelectionModel) e.getSource();\r
- if (!lsm.isSelectionEmpty())\r
- {\r
- int selectedRow = lsm.getMinSelectionIndex();\r
- displayFullDetails(table.getValueAt(selectedRow, 0).toString());\r
- }\r
- }\r
- });\r
-\r
- table.addMouseListener(new MouseAdapter()\r
- {\r
- public void mouseClicked(MouseEvent evt)\r
- {\r
- if(evt.getClickCount()==2\r
- || SwingUtilities.isRightMouseButton(evt))\r
- editRemoveLocalSource(evt);\r
- }\r
- });\r
-\r
- if(dasSources==null)\r
- {\r
- Thread worker = new Thread(this);\r
- worker.start();\r
- }\r
- else\r
- {\r
- init();\r
- }\r
- }\r
-\r
- void init()\r
- {\r
- int dSize = dasSources.length;\r
- Object[][] data = new Object[dSize][2];\r
- for (int i = 0; i < dSize; i++)\r
- {\r
- data[i][0] = dasSources[i].getNickname();\r
- data[i][1] = new Boolean(selectedSources.contains(dasSources[i].\r
- getNickname()));\r
- }\r
-\r
- refreshTableData(data);\r
- setCapabilities(dasSources);\r
-\r
- javax.swing.SwingUtilities.invokeLater(new Runnable()\r
- {\r
- public void run()\r
- {\r
- TableSorter sorter = (TableSorter)table.getModel();\r
- sorter.setSortingStatus(1, TableSorter.DESCENDING);\r
- sorter.setSortingStatus(1, TableSorter.NOT_SORTED);\r
- }\r
- });\r
-\r
- progressBar.setIndeterminate(false);\r
- progressBar.setVisible(false);\r
- addLocal.setVisible(true);\r
- refresh.setVisible(true);\r
- }\r
-\r
-\r
- public void refreshTableData(Object[][] data)\r
- {\r
- TableSorter sorter = new TableSorter(new DASTableModel(data));\r
- sorter.setTableHeader(table.getTableHeader());\r
- table.setModel(sorter);\r
- }\r
-\r
- void displayFullDetails(String nickName)\r
- {\r
-\r
- StringBuffer text = new StringBuffer(\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
- 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
- continue;\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
-\r
- text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"\r
- +dasSources[i].getAdminemail()\r
- +"\">"+dasSources[i].getAdminemail()+"</a>" +\r
- "<br>");\r
-\r
-\r
- text.append("<font color=\"#0000FF\">Registered at:</font> " + dasSources[i].getRegisterDate() +\r
- "<br>");\r
-\r
- text.append("<font color=\"#0000FF\">Last successful test:</font> " + dasSources[i].getLeaseDate() +\r
- "<br>");\r
-\r
- text.append("<font color=\"#0000FF\">Labels:</font> ");\r
- for(int s=0; s<dasSources[i].getLabels().length; s++)\r
- {\r
- text.append( dasSources[i].getLabels()[s]);\r
- if(s<dasSources[i].getLabels().length-1)\r
- text.append(",");\r
- text.append(" ");\r
- }\r
- text.append("<br>");\r
-\r
-\r
-\r
- text.append("<font color=\"#0000FF\">Capabilities:</font> ");\r
- String[] scap = dasSources[i].getCapabilities();\r
- for (int j = 0; j < scap.length; j++)\r
- {\r
- text.append(scap[j]);\r
- if (j < scap.length - 1)\r
- text.append(", ");\r
- }\r
- 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
- {\r
- text.append("(" + dcs[j].getUniqueId() + ") "\r
- + dcs[j].getCategory() + ", " + dcs[j].getName());\r
- if (dcs[j].getNCBITaxId() != 0)\r
- text.append(", " + dcs[j].getNCBITaxId());\r
- if (dcs[j].getOrganismName().length() > 0)\r
- text.append(", " + dcs[j].getOrganismName());\r
-\r
- text.append("<br>");\r
- }\r
-\r
- text.append("<font color=\"#0000FF\">Description:</font> " +\r
- dasSources[i].getDescription() + "<br>");\r
-\r
- if (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
-\r
- text.append("</font></html>");\r
-\r
- break;\r
- }\r
-\r
- fullDetails.setText(text.toString());\r
- javax.swing.SwingUtilities.invokeLater(new Runnable()\r
- {\r
- public void run()\r
- {\r
- fullDetailsScrollpane.getVerticalScrollBar().setValue(0);\r
- }\r
- });\r
- }\r
-\r
-\r
- public void run()\r
- {\r
- addLocal.setVisible(false);\r
- refresh.setVisible(false);\r
- progressBar.setVisible(true);\r
- progressBar.setIndeterminate(true);\r
-\r
- dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();\r
-\r
- appendLocalSources();\r
-\r
- init();\r
- }\r
-\r
- public DasSource[] getDASSource()\r
- {\r
- if(dasSources==null)\r
- {\r
- dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();\r
- appendLocalSources();\r
- }\r
-\r
- return dasSources;\r
- }\r
-\r
- public void refresh_actionPerformed(ActionEvent e)\r
- {\r
- saveProperties(jalview.bin.Cache.applicationProperties);\r
-\r
- Thread worker = new Thread(this);\r
- worker.start();\r
- }\r
-\r
- private void setCapabilities(DasSource[] sources)\r
- {\r
- Vector vcapabilities = new Vector();\r
- Vector vcoords = new Vector();\r
- Vector vcoords2 = new Vector();\r
-\r
- vcapabilities.addElement("All");\r
- vcoords.addElement("All");\r
- vcoords2.addElement("All");\r
-\r
- for (int i = 0; i < sources.length; i++)\r
- {\r
- DasSource ds = sources[i];\r
- String[] scap = ds.getCapabilities();\r
- for (int s = 0; s < scap.length; s++)\r
- {\r
- if (!vcapabilities.contains(scap[s]))\r
- {\r
- vcapabilities.addElement(scap[s]);\r
- }\r
- }\r
-\r
- DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
-\r
- for (int j = 0; j < dcs.length; j++)\r
- {\r
- if (!vcoords.contains(dcs[j].getCategory()))\r
- vcoords.addElement(dcs[j].getCategory());\r
-\r
- if (!vcoords2.contains(dcs[j].getName()))\r
- vcoords2.addElement(dcs[j].getName());\r
- }\r
- }\r
-\r
- capabilities.setListData(vcapabilities);\r
- coords1.setListData(vcoords);\r
- coords2.setListData(vcoords2);\r
-\r
- javax.swing.SwingUtilities.invokeLater(new Runnable()\r
- {\r
- public void run()\r
- {\r
- capabilities.setSelectedIndex(0);\r
- coords1.setSelectedIndex(0);\r
- coords2.setSelectedIndex(0);\r
- }\r
- });\r
- }\r
-\r
- public void amendLocal(boolean newSource)\r
- {\r
- String url = "http://localhost:8080/", nickname = "";\r
-\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
- }\r
-\r
- JTextField nametf = new JTextField(nickname, 40);\r
- JTextField urltf = new JTextField(url, 40);\r
-\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(urltf, BorderLayout.EAST);\r
- panel.add(pane12, BorderLayout.SOUTH);\r
-\r
-\r
- int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,\r
- panel, "Enter Nickname & URL of Local DAS Source",\r
- JOptionPane.OK_CANCEL_OPTION);\r
-\r
- if (reply != JOptionPane.OK_OPTION )\r
- {\r
- return;\r
- }\r
-\r
- if(!urltf.getText().endsWith("/"))\r
- urltf.setText(urltf.getText()+"/");\r
-\r
- DasSource local = new DasSource();\r
-\r
- local.setUrl(urltf.getText());\r
- local.setNickname(nametf.getText());\r
-\r
-\r
- if(localSources==null)\r
- localSources = new Hashtable();\r
-\r
- localSources.put(local.getNickname(), local);\r
-\r
- if(!newSource && !nickname.equals(nametf.getText()))\r
- {\r
- localSources.remove(nickname);\r
- }\r
-\r
- int size = dasSources.length;\r
- int adjust = newSource ? 1 : 0;\r
-\r
- Object[][] data = new Object[size+adjust][2];\r
- for (int i = 0; i < size; i++)\r
- {\r
- if(!newSource && dasSources[i].getNickname().equals(nickname))\r
- {\r
- ((DasSource)dasSources[i]).setNickname(local.getNickname());\r
- ((DasSource)dasSources[i]).setUrl(local.getUrl());\r
- data[i][0] = local.getNickname();\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
- }\r
- }\r
-\r
- if(newSource)\r
- {\r
- data[size][0] = local.getNickname();\r
- data[size][1] = new Boolean(true);\r
- selectedSources.add(local.getNickname());\r
- }\r
-\r
- DasSource [] tmp = new DasSource[size+adjust];\r
-\r
- System.arraycopy(dasSources, 0, tmp, 0, size);\r
-\r
- if(newSource)\r
- tmp[size] = local;\r
-\r
- dasSources = tmp;\r
-\r
- refreshTableData(data);\r
-\r
- SwingUtilities.invokeLater(new Runnable()\r
- {\r
- public void run()\r
- {\r
- scrollPane.getVerticalScrollBar().setValue(\r
- scrollPane.getVerticalScrollBar().getMaximum()\r
- );\r
- }\r
- });\r
-\r
- displayFullDetails(local.getNickname());\r
- }\r
-\r
- public void editRemoveLocalSource(MouseEvent evt)\r
- {\r
- int selectedRow = table.getSelectionModel().getMinSelectionIndex();\r
- if(selectedRow==-1)\r
- return;\r
-\r
- String nickname = table.getValueAt(selectedRow, 0).toString();\r
-\r
- 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
- return;\r
- }\r
-\r
-\r
- Object[] options = {"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
-\r
- switch(choice)\r
- {\r
- case 0: amendLocal(false); 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
- {\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
- }\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
-\r
- break;\r
- }\r
- }\r
-\r
- void appendLocalSources()\r
- {\r
- if(localSources==null)\r
- return;\r
-\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
- }\r
-\r
- DasSource [] tmp = new DasSource[size+lsize];\r
- if(dasSources!=null)\r
- System.arraycopy(dasSources, 0, tmp, 0, size);\r
-\r
- Enumeration en = localSources.keys();\r
- int index = size;\r
- while(en.hasMoreElements())\r
- {\r
- String key = en.nextElement().toString();\r
- data[index][0] = key;\r
- data[index][1] = new Boolean(false);\r
- tmp[index] = new DasSource();\r
- tmp[index].setNickname(key);\r
- tmp[index].setUrl( ((DasSource)localSources.get(key)).getUrl() );\r
-\r
- index++;\r
- }\r
-\r
- dasSources = tmp;\r
-\r
- refreshTableData(data);\r
- }\r
-\r
- public void valueChanged(ListSelectionEvent evt)\r
- {\r
- //Called when the MainTable selection changes\r
- if (evt.getValueIsAdjusting())\r
- {\r
- return;\r
- }\r
-\r
- displayFullDetails(null);\r
-\r
- // Filter the displayed data sources\r
- int dSize = dasSources.length;\r
- ArrayList names = new ArrayList();\r
- ArrayList selected = new ArrayList();\r
- DasSource ds;\r
-\r
- // capabilities.get\r
- for (int i = 0; i < dSize; i++)\r
- {\r
- ds = dasSources[i];\r
-\r
- if (!selectedInList(capabilities, ds.getCapabilities()))\r
- {\r
- continue;\r
- }\r
-\r
- DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
- for (int j = 0; j < dcs.length; j++)\r
- {\r
- if (selectedInList(coords1, new String[]\r
- {dcs[j].getCategory()})\r
- && selectedInList(coords2, new String[]\r
- {dcs[j].getName()}))\r
- {\r
- names.add(ds.getNickname());\r
- selected.add(new Boolean(\r
- selectedSources.contains(ds.getNickname())));\r
- break;\r
- }\r
- }\r
- }\r
-\r
- dSize = names.size();\r
- Object[][] data = new Object[dSize][2];\r
- for (int d = 0; d < dSize; d++)\r
- {\r
- data[d][0] = names.get(d);\r
- data[d][1] = selected.get(d);\r
- }\r
-\r
- refreshTableData(data);\r
- }\r
-\r
- boolean selectedInList(JList list, String[] items)\r
- {\r
- Object[] selection = list.getSelectedValues();\r
- for (int i = 0; i < selection.length; i++)\r
- {\r
- if (selection[i].equals("All"))\r
- return true;\r
-\r
- for (int j = 0; j < items.length; j++)\r
- {\r
- if (selection[i].equals(items[j]))\r
- return true;\r
- }\r
- }\r
-\r
- return false;\r
- }\r
-\r
- void setSelectedFromProperties()\r
- {\r
- String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot");\r
- StringTokenizer st = new StringTokenizer(active, "\t");\r
- selectedSources = new Vector();\r
- while(st.hasMoreTokens())\r
- {\r
- selectedSources.addElement(st.nextToken());\r
- }\r
-\r
- String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");\r
- if(local!=null)\r
- {\r
- if(localSources == null)\r
- localSources = new Hashtable();\r
-\r
- st = new StringTokenizer(local, "\t");\r
- while(st.hasMoreTokens())\r
- {\r
- String token = st.nextToken();\r
- int bar = token.indexOf("|");\r
- DasSource source = new DasSource();\r
-\r
- source.setUrl(token.substring(bar + 1));\r
- source.setNickname(token.substring(0, bar));\r
-\r
- localSources.put(source.getNickname(), source);\r
- }\r
- }\r
- }\r
-\r
- void saveProperties(Properties properties)\r
- {\r
- properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());\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
- {\r
- sb.append(table.getValueAt(r,0)+"\t");\r
- }\r
- }\r
-\r
- properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString() );\r
-\r
- if(localSources!=null)\r
- {\r
- sb = new StringBuffer();\r
- Enumeration en = localSources.keys();\r
- while(en.hasMoreElements())\r
- {\r
- String token = en.nextElement().toString();\r
- sb.append(token+"|"\r
- + ((DasSource)localSources.get(token)).getUrl()\r
- +"\t");\r
- }\r
-\r
- properties.setProperty("DAS_LOCAL_SOURCE", sb.toString());\r
- }\r
-\r
- }\r
-\r
- class DASTableModel\r
- extends AbstractTableModel\r
- {\r
-\r
- public DASTableModel(Object[][] data)\r
- {\r
- this.data = data;\r
- }\r
-\r
- private String[] columnNames = new String[] {"Nickname", "Use Source"};\r
-\r
- private Object[][] data;\r
-\r
- public int getColumnCount()\r
- {\r
- return columnNames.length;\r
- }\r
-\r
- public int getRowCount()\r
- {\r
- return data.length;\r
- }\r
-\r
- public String getColumnName(int col)\r
- {\r
- return columnNames[col];\r
- }\r
-\r
- public Object getValueAt(int row, int col)\r
- {\r
- return data[row][col];\r
- }\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
- */\r
- public Class getColumnClass(int c)\r
- {\r
- return getValueAt(0, c).getClass();\r
- }\r
-\r
- /*\r
- * Don't need to implement this method unless your table's\r
- * 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
- return col == 1;\r
-\r
- }\r
-\r
- /*\r
- * Don't need to implement this method unless your table's\r
- * data can change.\r
- */\r
- public void setValueAt(Object value, int row, int col)\r
- {\r
- data[row][col] = value;\r
- fireTableCellUpdated(row, col);\r
-\r
- String name = getValueAt(row,0).toString();\r
- boolean selected = ((Boolean)value).booleanValue();\r
-\r
- if(selectedSources.contains(name) && !selected)\r
- selectedSources.remove(name);\r
-\r
- if(!selectedSources.contains(name) && selected)\r
- selectedSources.add(name);\r
- }\r
- }\r
-}\r
-\r
-\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.gui;
+
+import jalview.jbgui.GDasSourceBrowser;
+import jalview.util.MessageManager;
+import jalview.util.TableSorter;
+import jalview.ws.dbsources.das.api.DasSourceRegistryI;
+import jalview.ws.dbsources.das.api.jalviewSourceI;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingUtilities;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.table.AbstractTableModel;
+
+import org.biodas.jdas.schema.sources.CAPABILITY;
+import org.biodas.jdas.schema.sources.COORDINATES;
+import org.biodas.jdas.schema.sources.PROP;
+import org.biodas.jdas.schema.sources.VERSION;
+
+public class DasSourceBrowser extends GDasSourceBrowser implements
+ Runnable, ListSelectionListener
+{
+ DasSourceRegistryI sourceRegistry = null;
+
+ Vector<String> selectedSources;
+
+ public DasSourceBrowser(FeatureSettings featureSettings)
+ {
+ fs = featureSettings;
+ // TODO DasSourceRegistryProvider API
+ sourceRegistry = jalview.bin.Cache.getDasSourceRegistry();
+ String registry = sourceRegistry.getDasRegistryURL();
+
+ registryURL.setText(registry);
+
+ setSelectedFromProperties();
+
+ displayFullDetails(null);
+ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+
+ filter1.addListSelectionListener(this);
+ filter2.addListSelectionListener(this);
+ filter3.addListSelectionListener(this);
+
+ // Ask to be notified of selection changes.
+ ListSelectionModel rowSM = table.getSelectionModel();
+ rowSM.addListSelectionListener(new ListSelectionListener()
+ {
+ public void valueChanged(ListSelectionEvent e)
+ {
+ ListSelectionModel lsm = (ListSelectionModel) e.getSource();
+ if (!lsm.isSelectionEmpty())
+ {
+ int selectedRow = lsm.getMinSelectionIndex();
+ displayFullDetails(table.getValueAt(selectedRow, 0).toString());
+ }
+ }
+ });
+
+ table.addMouseListener(new MouseAdapter()
+ {
+ public void mouseClicked(MouseEvent evt)
+ {
+ if (evt.getClickCount() == 2
+ || SwingUtilities.isRightMouseButton(evt))
+ {
+ editRemoveLocalSource(evt);
+ }
+ }
+ });
+
+ if (sourceRegistry.getSources() != null)
+ {
+ init();
+ }
+ }
+
+ FeatureSettings fs = null;
+
+ private boolean loadingDasSources;
+
+ public DasSourceBrowser()
+ {
+ this(null);
+ }
+
+ public void paintComponent(java.awt.Graphics g)
+ {
+ if (sourceRegistry == null)
+ {
+ Thread worker = new Thread(this);
+ worker.start();
+ }
+ }
+
+ void init()
+ {
+ List<jalviewSourceI> sources = sourceRegistry.getSources();
+ int dSize = sources.size();
+ Object[][] data = new Object[dSize][2];
+ for (int i = 0; i < dSize; i++)
+ {
+ data[i][0] = sources.get(i).getTitle(); // what's equivalent of nickname
+ data[i][1] = new Boolean(selectedSources.contains(sources.get(i)
+ .getTitle()));
+ }
+
+ refreshTableData(data);
+ setCapabilities(sourceRegistry);
+
+ 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);
+ }
+ });
+
+ progressBar.setIndeterminate(false);
+ progressBar.setVisible(false);
+ addLocal.setVisible(true);
+ refresh.setVisible(true);
+ }
+
+ public void refreshTableData(Object[][] data)
+ {
+ TableSorter sorter = new TableSorter(new DASTableModel(data));
+ sorter.setTableHeader(table.getTableHeader());
+ table.setModel(sorter);
+ }
+
+ void displayFullDetails(String nickName)
+ {
+
+ StringBuffer text = new StringBuffer(
+ "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
+
+ if (nickName == null)
+ {
+ fullDetails.setText(text
+ + MessageManager
+ .getString("label.select_das_service_from_table"));
+ return;
+ }
+
+ int dSize = sourceRegistry.getSources().size();
+ for (jalviewSourceI ds : sourceRegistry.getSources())
+ {
+ if (!ds.getTitle().equals(nickName))
+ {
+ continue;
+ }
+
+ VERSION latest = ds.getVersion();
+ text.append("<font color=\"#0000FF\">Id:</font> " + ds.getUri()
+ + "<br>");
+ text.append("<font color=\"#0000FF\">Nickname:</font> "
+ + ds.getTitle() + "<br>");
+
+ text.append("<font color=\"#0000FF\">URL:</font> <a href=\""
+ + ds.getSourceURL() + "\">" + ds.getSourceURL() + "</a>"
+ + "<br>");
+ if (!ds.isLocal())
+ {
+ if (ds.getDocHref() != null && ds.getDocHref().length() > 0)
+ {
+ text.append("<font color=\"#0000FF\">Site:</font> <a href=\""
+ + ds.getDocHref() + "\">" + ds.getDocHref() + "</a>"
+ + "<br>");
+ }
+
+ text.append("<font color=\"#0000FF\">Description:</font> "
+ + ds.getDescription() + "<br>");
+
+ text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
+ + ds.getEmail() + "\">" + ds.getEmail() + "</a>" + "<br>");
+
+ text.append("<font color=\"#0000FF\">Registered at:</font> "
+ + latest.getCreated() + "<br>");
+
+ // TODO: Identify last successful test date
+ // text.append("<font color=\"#0000FF\">Last successful test:</font> "
+ // + latest.dasSources[i].getLeaseDate() + "<br>");
+ }
+ else
+ {
+ text.append("Source was added manually.<br/>");
+ }
+ text.append("<font color=\"#0000FF\">Labels:</font> ");
+ boolean b = false;
+ for (PROP labl : latest.getPROP())
+ {
+ if (labl.getName().equalsIgnoreCase("LABEL"))
+ {
+ if (b)
+ {
+ text.append(",");
+ }
+ text.append(" ");
+
+ text.append(labl.getValue());
+ b = true;
+ }
+ ;
+ }
+ text.append("<br>");
+
+ text.append("<font color=\"#0000FF\">Capabilities:</font> ");
+ CAPABILITY[] scap = latest.getCAPABILITY().toArray(new CAPABILITY[0]);
+ for (int j = 0; j < scap.length; j++)
+ {
+ text.append(scap[j].getType());
+ if (j < scap.length - 1)
+ {
+ text.append(", ");
+ }
+ }
+ text.append("<br>");
+
+ text.append("<font color=\"#0000FF\">Coordinates:</font>");
+ int i = 1;
+ for (COORDINATES dcs : latest.getCOORDINATES())
+ {
+ text.append("<br/>" + i++ + ". ");
+ text.append(dcs.getAuthority() + " : " + dcs.getSource());
+ if (dcs.getTaxid() != null && dcs.getTaxid().trim().length() > 0)
+ {
+ text.append(" [TaxId:" + dcs.getTaxid() + "]");
+ }
+ if (dcs.getVersion() != null
+ && dcs.getVersion().trim().length() > 0)
+ {
+ {
+ text.append(" {v. " + dcs.getVersion() + "}");
+ }
+ }
+ text.append(" (<a href=\"" + dcs.getUri() + "\">" + dcs.getUri()
+ + "</a>)");
+ }
+ text.append("</font></html>");
+
+ break;
+ }
+
+ fullDetails.setText(text.toString());
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ fullDetailsScrollpane.getVerticalScrollBar().setValue(0);
+ }
+ });
+ }
+
+ public void run()
+ {
+ loadingDasSources = true;
+
+ addLocal.setVisible(false);
+ refresh.setVisible(false);
+ progressBar.setVisible(true);
+ progressBar.setIndeterminate(true);
+ setParentGuiEnabled(false);
+ // Refresh the source list.
+ sourceRegistry.refreshSources();
+
+ init();
+
+ setParentGuiEnabled(true);
+ loadingDasSources = false;
+
+ }
+
+ private void setParentGuiEnabled(boolean b)
+ {
+ if (fs != null)
+ {
+ fs.fetchDAS.setEnabled(b);
+ fs.saveDAS.setEnabled(b);
+ }
+ }
+
+ public Vector<jalviewSourceI> getSelectedSources()
+ {
+ // wait around if we're still loading.
+ while (sourceRegistry == null)
+ {
+ if (!loadingDasSources)
+ {
+ new Thread(this).start();
+ try
+ {
+ Thread.sleep(5);
+ } catch (Exception e)
+ {
+ }
+ ;
+ while (loadingDasSources)
+ {
+ try
+ {
+ Thread.sleep(5);
+ } catch (Exception e)
+ {
+ }
+ ;
+ }
+ ;
+ }
+ }
+
+ Vector<jalviewSourceI> selected = new Vector<jalviewSourceI>();
+ for (String source : selectedSources)
+ {
+ jalviewSourceI srce = sourceRegistry.getSource(source);
+ if (srce != null)
+ {
+ selected.addElement(srce);
+ }
+ }
+ return selected;
+ }
+
+ public void refresh_actionPerformed(ActionEvent e)
+ {
+ saveProperties(jalview.bin.Cache.applicationProperties);
+
+ Thread worker = new Thread(this);
+ worker.start();
+ }
+
+ private void setCapabilities(DasSourceRegistryI sourceRegistry2)
+ {
+ Vector<String> authority = new Vector<String>();
+ Vector<String> type = new Vector<String>();
+ Vector<String> label = new Vector<String>();
+ Vector<String> taxIds = new Vector<String>();
+ authority.add("Any");
+ type.add("Any");
+ label.add("Any");
+
+ for (jalviewSourceI ds : sourceRegistry2.getSources())
+ {
+ VERSION latest = ds.getVersion();
+
+ for (COORDINATES cs : latest.getCOORDINATES())
+ {
+ if (!type.contains(cs.getSource()))
+ {
+ type.add(cs.getSource()); // source==category
+ }
+
+ if (!authority.contains(cs.getAuthority()))
+ {
+ authority.add(cs.getAuthority());
+ }
+ }
+
+ for (PROP slabel : latest.getPROP())
+ {
+ if (slabel.getName().equalsIgnoreCase("LABEL")
+ && !label.contains(slabel.getValue()))
+ {
+ label.add(slabel.getValue());
+ }
+ }
+
+ }
+
+ filter1.setListData(authority);
+ filter2.setListData(type);
+ filter3.setListData(label);
+ // filter4 taxIds
+
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ filter1.setSelectedIndex(0);
+ filter2.setSelectedIndex(0);
+ filter3.setSelectedIndex(0);
+ }
+ });
+ }
+
+ 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();
+ jalviewSourceI source = sourceRegistry.getSource(nickname);
+ url = source.getUri();
+ seqsrc = source.isSequenceSource();
+ }
+
+ JTextField nametf = new JTextField(nickname, 40);
+ JTextField urltf = new JTextField(url, 40);
+ JCheckBox seqs = new JCheckBox(
+ MessageManager.getString("label.sequence_source"));
+ seqs.setSelected(seqsrc);
+ JPanel panel = new JPanel(new BorderLayout());
+ JPanel pane12 = new JPanel(new BorderLayout());
+ pane12.add(
+ new JLabel(MessageManager.getString("label.structure_manager")),
+ BorderLayout.CENTER);
+ pane12.add(nametf, BorderLayout.EAST);
+ panel.add(pane12, BorderLayout.NORTH);
+ pane12 = new JPanel(new BorderLayout());
+ pane12.add(new JLabel(MessageManager.getString("label.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,
+ MessageManager.getString("label.enter_local_das_source"),
+ JOptionPane.OK_CANCEL_OPTION);
+
+ if (reply != JOptionPane.OK_OPTION)
+ {
+ return;
+ }
+
+ if (!urltf.getText().endsWith("/"))
+ {
+ urltf.setText(urltf.getText() + "/");
+ }
+
+ jalviewSourceI local = sourceRegistry.createLocalSource(
+ urltf.getText(), nametf.getText(), seqs.isSelected(), true);
+ List sources = sourceRegistry.getSources();
+ int osize = sources.size();
+ int size = osize + (newSource ? 1 : 0);
+
+ Object[][] data = new Object[size][2];
+ DASTableModel dtm = (table != null) ? (DASTableModel) ((TableSorter) table
+ .getModel()).getTableModel() : null;
+ for (int i = 0; i < osize; i++)
+ {
+ String osrc = (dtm == null || i >= osize) ? null : (String) dtm
+ .getValueAt(i, 0);
+ if (!newSource && osrc != null
+ && dtm.getValueAt(i, 0).equals(nickname))
+ {
+ data[i][0] = local.getTitle();
+ data[i][1] = new Boolean(true);
+ }
+ else
+ {
+ data[i][0] = osrc;
+ data[i][1] = new Boolean(selectedSources.contains(osrc));
+ }
+ }
+ // Always add a new source at the end
+ if (newSource)
+ {
+ data[osize][0] = local.getTitle();
+ data[osize][1] = new Boolean(true);
+ selectedSources.add(local.getTitle());
+ }
+
+ refreshTableData(data);
+
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ scrollPane.getVerticalScrollBar().setValue(
+ scrollPane.getVerticalScrollBar().getMaximum());
+ }
+ });
+
+ displayFullDetails(local.getTitle());
+ }
+
+ public void editRemoveLocalSource(MouseEvent evt)
+ {
+ int selectedRow = table.getSelectionModel().getMinSelectionIndex();
+ if (selectedRow == -1)
+ {
+ return;
+ }
+
+ String nickname = table.getValueAt(selectedRow, 0).toString();
+
+ if (!sourceRegistry.getSource(nickname).isLocal())
+ {
+ JOptionPane
+ .showInternalMessageDialog(
+ Desktop.desktop,
+ MessageManager
+ .getString("label.you_can_only_edit_or_remove_local_das_sources"),
+ MessageManager.getString("label.public_das_source"),
+ JOptionPane.WARNING_MESSAGE);
+ return;
+ }
+
+ 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)
+ {
+ case 0:
+ amendLocal(false);
+ break;
+ case 1:
+ sourceRegistry.removeLocalSource(sourceRegistry.getSource(nickname));
+ selectedSources.remove(nickname);
+ Object[][] data = new Object[sourceRegistry.getSources().size()][2];
+ int index = 0,
+ l = table.getRowCount();
+
+ for (int i = 0; i < l; i++)
+ {
+ String nm;
+ if ((nm = (String) table.getValueAt(i, 0)).equals(nickname))
+ {
+ continue;
+ }
+ else
+ {
+ data[index][0] = nm;
+ data[index][1] = new Boolean(selectedSources.contains(nm));
+ index++;
+ }
+ }
+ refreshTableData(data);
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ scrollPane.getVerticalScrollBar().setValue(
+ scrollPane.getVerticalScrollBar().getMaximum());
+ }
+ });
+
+ break;
+ }
+ }
+
+ public void valueChanged(ListSelectionEvent evt)
+ {
+ // Called when the MainTable selection changes
+ if (evt.getValueIsAdjusting())
+ {
+ return;
+ }
+
+ displayFullDetails(null);
+
+ // Filter the displayed data sources
+
+ ArrayList names = new ArrayList();
+ ArrayList selected = new ArrayList();
+
+ // 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" };
+ List<jalviewSourceI> srcs = sourceRegistry.getSources();
+ for (jalviewSourceI ds : srcs)
+ {
+
+ VERSION v = ds.getVersion();
+ List<COORDINATES> coords = v.getCOORDINATES();
+ if (ds.isLocal()
+ || ((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.getCapabilityList(v))
+ || !selectedInList(filter3.getSelectedValues(),
+ ds.getLabelsFor(v)))
+ {
+ continue;
+ }
+
+ for (int j = 0; j < coords.size(); j++)
+ {
+ if (selectedInList(filter1.getSelectedValues(), new String[]
+ { coords.get(j).getAuthority() })
+ && selectedInList(filter2.getSelectedValues(), new String[]
+ { coords.get(j).getSource() }))
+ {
+ names.add(ds.getTitle());
+ selected.add(new Boolean(selectedSources.contains(ds.getTitle())));
+ break;
+ }
+ }
+ }
+
+ int dSize = names.size();
+ Object[][] data = new Object[dSize][2];
+ for (int d = 0; d < dSize; d++)
+ {
+ data[d][0] = names.get(d);
+ data[d][1] = selected.get(d);
+ }
+
+ refreshTableData(data);
+ }
+
+ private boolean selectedInList(Object[] selection, String[] items)
+ {
+ for (int i = 0; i < selection.length; i++)
+ {
+ if (selection[i].equals("Any"))
+ {
+ return true;
+ }
+ if (items == null || items.length == 0)
+ {
+ return false;
+ }
+ String sel = (items[0].startsWith("das1:") ? "das1:" : "")
+ + selection[i];
+ for (int j = 0; j < items.length; j++)
+ {
+ if (sel.equals(items[j]))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ 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());
+ }
+ }
+
+ public void reset_actionPerformed(ActionEvent e)
+ {
+ registryURL.setText(sourceRegistry.getDasRegistryURL());
+ }
+
+ /**
+ * 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 < table.getModel().getRowCount(); r++)
+ {
+ if (((Boolean) table.getValueAt(r, 1)).booleanValue())
+ {
+ sb.append(table.getValueAt(r, 0) + "\t");
+ }
+ }
+
+ properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE,
+ sb.toString());
+
+ String sourceprop = sourceRegistry.getLocalSourceString();
+ properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sourceprop);
+ }
+
+ class DASTableModel extends AbstractTableModel
+ {
+
+ public DASTableModel(Object[][] data)
+ {
+ this.data = data;
+ }
+
+ private String[] columnNames = new String[]
+ { MessageManager.getString("label.nickname"), MessageManager.getString("label.use_source") };
+
+ private Object[][] data;
+
+ public int getColumnCount()
+ {
+ return columnNames.length;
+ }
+
+ public int getRowCount()
+ {
+ return data.length;
+ }
+
+ public String getColumnName(int col)
+ {
+ return columnNames[col];
+ }
+
+ public Object getValueAt(int row, int col)
+ {
+ return data[row][col];
+ }
+
+ /*
+ * 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)
+ {
+ return getValueAt(0, c).getClass();
+ }
+
+ /*
+ * 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.
+ return col == 1;
+
+ }
+
+ /*
+ * Don't need to implement this method unless your table's data can change.
+ */
+ public void setValueAt(Object value, int row, int col)
+ {
+ data[row][col] = value;
+ fireTableCellUpdated(row, col);
+
+ String name = getValueAt(row, 0).toString();
+ boolean selected = ((Boolean) value).booleanValue();
+
+ if (selectedSources.contains(name) && !selected)
+ {
+ selectedSources.remove(name);
+ }
+
+ if (!selectedSources.contains(name) && selected)
+ {
+ selectedSources.add(name);
+ }
+ }
+ }
+
+ 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 || sourceRegistry == null)
+ {
+ try
+ {
+ Thread.sleep(10);
+ } catch (Exception e)
+ {
+ }
+ ;
+ }
+ }
+
+ /**
+ * disable or enable the buttons on the source browser
+ *
+ * @param b
+ */
+ public void setGuiEnabled(boolean b)
+ {
+ refresh.setEnabled(b);
+ addLocal.setEnabled(b);
+ }
+}