2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
\r
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
\r
11 * Jalview is distributed in the hope that it will be useful, but
\r
12 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
14 * PURPOSE. See the GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
18 package jalview.gui;
\r
20 import jalview.jbgui.GDasSourceBrowser;
\r
21 import jalview.util.TableSorter;
\r
22 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
\r
23 import jalview.ws.dbsources.das.api.jalviewSourceI;
\r
25 import java.awt.BorderLayout;
\r
26 import java.awt.event.ActionEvent;
\r
27 import java.awt.event.MouseAdapter;
\r
28 import java.awt.event.MouseEvent;
\r
29 import java.util.ArrayList;
\r
30 import java.util.List;
\r
31 import java.util.Properties;
\r
32 import java.util.StringTokenizer;
\r
33 import java.util.Vector;
\r
35 import javax.swing.JCheckBox;
\r
36 import javax.swing.JLabel;
\r
37 import javax.swing.JOptionPane;
\r
38 import javax.swing.JPanel;
\r
39 import javax.swing.JTextField;
\r
40 import javax.swing.ListSelectionModel;
\r
41 import javax.swing.SwingUtilities;
\r
42 import javax.swing.event.ListSelectionEvent;
\r
43 import javax.swing.event.ListSelectionListener;
\r
44 import javax.swing.table.AbstractTableModel;
\r
46 import org.biodas.jdas.schema.sources.CAPABILITY;
\r
47 import org.biodas.jdas.schema.sources.COORDINATES;
\r
48 import org.biodas.jdas.schema.sources.PROP;
\r
49 import org.biodas.jdas.schema.sources.VERSION;
\r
51 public class DasSourceBrowser extends GDasSourceBrowser implements
\r
52 Runnable, ListSelectionListener
\r
54 DasSourceRegistryI sourceRegistry = null;
\r
56 Vector<String> selectedSources;
\r
58 public DasSourceBrowser(FeatureSettings featureSettings)
\r
60 fs = featureSettings;
\r
61 // TODO DasSourceRegistryProvider API
\r
62 sourceRegistry = jalview.bin.Cache.getDasSourceRegistry();
\r
63 String registry = sourceRegistry.getDasRegistryURL();
\r
65 registryURL.setText(registry);
\r
67 setSelectedFromProperties();
\r
69 displayFullDetails(null);
\r
70 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
\r
72 filter1.addListSelectionListener(this);
\r
73 filter2.addListSelectionListener(this);
\r
74 filter3.addListSelectionListener(this);
\r
76 // Ask to be notified of selection changes.
\r
77 ListSelectionModel rowSM = table.getSelectionModel();
\r
78 rowSM.addListSelectionListener(new ListSelectionListener()
\r
80 public void valueChanged(ListSelectionEvent e)
\r
82 ListSelectionModel lsm = (ListSelectionModel) e.getSource();
\r
83 if (!lsm.isSelectionEmpty())
\r
85 int selectedRow = lsm.getMinSelectionIndex();
\r
86 displayFullDetails(table.getValueAt(selectedRow, 0).toString());
\r
91 table.addMouseListener(new MouseAdapter()
\r
93 public void mouseClicked(MouseEvent evt)
\r
95 if (evt.getClickCount() == 2
\r
96 || SwingUtilities.isRightMouseButton(evt))
\r
98 editRemoveLocalSource(evt);
\r
103 if (sourceRegistry.getSources() != null)
\r
109 FeatureSettings fs = null;
\r
111 private boolean loadingDasSources;
\r
113 public DasSourceBrowser()
\r
118 public void paintComponent(java.awt.Graphics g)
\r
120 if (sourceRegistry == null)
\r
122 Thread worker = new Thread(this);
\r
129 List<jalviewSourceI> sources = sourceRegistry.getSources();
\r
130 int dSize = sources.size();
\r
131 Object[][] data = new Object[dSize][2];
\r
132 for (int i = 0; i < dSize; i++)
\r
134 data[i][0] = sources.get(i).getTitle(); // what's equivalent of nickname
\r
135 data[i][1] = new Boolean(selectedSources.contains(sources.get(i)
\r
139 refreshTableData(data);
\r
140 setCapabilities(sourceRegistry);
\r
142 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
146 TableSorter sorter = (TableSorter) table.getModel();
\r
147 sorter.setSortingStatus(1, TableSorter.DESCENDING);
\r
148 sorter.setSortingStatus(1, TableSorter.NOT_SORTED);
\r
152 progressBar.setIndeterminate(false);
\r
153 progressBar.setVisible(false);
\r
154 addLocal.setVisible(true);
\r
155 refresh.setVisible(true);
\r
158 public void refreshTableData(Object[][] data)
\r
160 TableSorter sorter = new TableSorter(new DASTableModel(data));
\r
161 sorter.setTableHeader(table.getTableHeader());
\r
162 table.setModel(sorter);
\r
165 void displayFullDetails(String nickName)
\r
168 StringBuffer text = new StringBuffer(
\r
169 "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
\r
171 if (nickName == null)
\r
173 fullDetails.setText(text + "Select a DAS service from the table"
\r
174 + " to read a full description here.</font></html>");
\r
178 int dSize = sourceRegistry.getSources().size();
\r
179 for (jalviewSourceI ds : sourceRegistry.getSources())
\r
181 if (!ds.getTitle().equals(nickName))
\r
186 VERSION latest = ds.getVersion();
\r
187 text.append("<font color=\"#0000FF\">Id:</font> " + ds.getUri()
\r
189 text.append("<font color=\"#0000FF\">Nickname:</font> "
\r
190 + ds.getTitle() + "<br>");
\r
192 text.append("<font color=\"#0000FF\">URL:</font> <a href=\""
\r
193 + ds.getSourceURL() + "\">" + ds.getSourceURL() + "</a>"
\r
197 if (ds.getDocHref() != null && ds.getDocHref().length() > 0)
\r
199 text.append("<font color=\"#0000FF\">Site:</font> <a href=\""
\r
200 + ds.getDocHref() + "\">" + ds.getDocHref() + "</a>"
\r
204 text.append("<font color=\"#0000FF\">Description:</font> "
\r
205 + ds.getDescription() + "<br>");
\r
207 text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
\r
208 + ds.getEmail() + "\">" + ds.getEmail() + "</a>" + "<br>");
\r
210 text.append("<font color=\"#0000FF\">Registered at:</font> "
\r
211 + latest.getCreated() + "<br>");
\r
213 // TODO: Identify last successful test date
\r
214 // text.append("<font color=\"#0000FF\">Last successful test:</font> "
\r
215 // + latest.dasSources[i].getLeaseDate() + "<br>");
\r
219 text.append("Source was added manually.<br/>");
\r
221 text.append("<font color=\"#0000FF\">Labels:</font> ");
\r
223 for (PROP labl : latest.getPROP())
\r
225 if (labl.getName().equalsIgnoreCase("LABEL"))
\r
233 text.append(labl.getValue());
\r
238 text.append("<br>");
\r
240 text.append("<font color=\"#0000FF\">Capabilities:</font> ");
\r
241 CAPABILITY[] scap = latest.getCAPABILITY().toArray(new CAPABILITY[0]);
\r
242 for (int j = 0; j < scap.length; j++)
\r
244 text.append(scap[j].getType());
\r
245 if (j < scap.length - 1)
\r
250 text.append("<br>");
\r
252 text.append("<font color=\"#0000FF\">Coordinates:</font>");
\r
254 for (COORDINATES dcs : latest.getCOORDINATES())
\r
256 text.append("<br/>"+i+++". ");
\r
257 text.append(dcs.getAuthority()+" : "+dcs.getSource());
\r
258 if (dcs.getTaxid() != null && dcs.getTaxid().trim().length() > 0)
\r
260 text.append(" [TaxId:" + dcs.getTaxid()+"]");
\r
262 if (dcs.getVersion() != null
\r
263 && dcs.getVersion().trim().length() > 0)
\r
266 text.append(" {v. " + dcs.getVersion()+"}");
\r
269 text.append(" (<a href=\""+dcs.getUri() +"\">"+dcs.getUri() + "</a>)");
\r
271 text.append("</font></html>");
\r
276 fullDetails.setText(text.toString());
\r
277 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
281 fullDetailsScrollpane.getVerticalScrollBar().setValue(0);
\r
288 loadingDasSources = true;
\r
290 addLocal.setVisible(false);
\r
291 refresh.setVisible(false);
\r
292 progressBar.setVisible(true);
\r
293 progressBar.setIndeterminate(true);
\r
294 setParentGuiEnabled(false);
\r
295 // Refresh the source list.
\r
296 sourceRegistry.refreshSources();
\r
300 setParentGuiEnabled(true);
\r
301 loadingDasSources = false;
\r
305 private void setParentGuiEnabled(boolean b)
\r
309 fs.fetchDAS.setEnabled(b);
\r
310 fs.saveDAS.setEnabled(b);
\r
314 public Vector<jalviewSourceI> getSelectedSources()
\r
316 // wait around if we're still loading.
\r
317 while (sourceRegistry == null)
\r
319 if (!loadingDasSources)
\r
321 new Thread(this).start();
\r
325 } catch (Exception e)
\r
329 while (loadingDasSources)
\r
334 } catch (Exception e)
\r
343 Vector<jalviewSourceI> selected = new Vector<jalviewSourceI>();
\r
344 for (String source : selectedSources)
\r
346 jalviewSourceI srce = sourceRegistry.getSource(source);
\r
349 selected.addElement(srce);
\r
355 public void refresh_actionPerformed(ActionEvent e)
\r
357 saveProperties(jalview.bin.Cache.applicationProperties);
\r
359 Thread worker = new Thread(this);
\r
363 private void setCapabilities(DasSourceRegistryI sourceRegistry2)
\r
365 Vector<String> authority = new Vector<String>();
\r
366 Vector<String> type = new Vector<String>();
\r
367 Vector<String> label = new Vector<String>();
\r
368 Vector<String> taxIds = new Vector<String>();
\r
369 authority.add("Any");
\r
373 for (jalviewSourceI ds : sourceRegistry2.getSources())
\r
375 VERSION latest = ds.getVersion();
\r
377 for (COORDINATES cs : latest.getCOORDINATES())
\r
379 if (!type.contains(cs.getSource()))
\r
381 type.add(cs.getSource()); // source==category
\r
384 if (!authority.contains(cs.getAuthority()))
\r
386 authority.add(cs.getAuthority());
\r
390 for (PROP slabel : latest.getPROP())
\r
392 if (slabel.getName().equalsIgnoreCase("LABEL")
\r
393 && !label.contains(slabel.getValue()))
\r
395 label.add(slabel.getValue());
\r
401 filter1.setListData(authority);
\r
402 filter2.setListData(type);
\r
403 filter3.setListData(label);
\r
406 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
410 filter1.setSelectedIndex(0);
\r
411 filter2.setSelectedIndex(0);
\r
412 filter3.setSelectedIndex(0);
\r
417 public void amendLocal(boolean newSource)
\r
419 String url = "http://localhost:8080/", nickname = "";
\r
420 boolean seqsrc = false;
\r
423 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
424 nickname = table.getValueAt(selectedRow, 0).toString();
\r
425 jalviewSourceI source = sourceRegistry.getSource(nickname);
\r
426 url = source.getUri();
\r
427 seqsrc = source.isSequenceSource();
\r
430 JTextField nametf = new JTextField(nickname, 40);
\r
431 JTextField urltf = new JTextField(url, 40);
\r
432 JCheckBox seqs = new JCheckBox("Sequence Source");
\r
433 seqs.setSelected(seqsrc);
\r
434 JPanel panel = new JPanel(new BorderLayout());
\r
435 JPanel pane12 = new JPanel(new BorderLayout());
\r
436 pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER);
\r
437 pane12.add(nametf, BorderLayout.EAST);
\r
438 panel.add(pane12, BorderLayout.NORTH);
\r
439 pane12 = new JPanel(new BorderLayout());
\r
440 pane12.add(new JLabel("URL: "), BorderLayout.NORTH);
\r
441 pane12.add(seqs, BorderLayout.SOUTH);
\r
442 pane12.add(urltf, BorderLayout.EAST);
\r
443 panel.add(pane12, BorderLayout.SOUTH);
\r
445 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
446 panel, "Enter Nickname & URL of Local DAS Source",
\r
447 JOptionPane.OK_CANCEL_OPTION);
\r
449 if (reply != JOptionPane.OK_OPTION)
\r
454 if (!urltf.getText().endsWith("/"))
\r
456 urltf.setText(urltf.getText() + "/");
\r
459 jalviewSourceI local = sourceRegistry.createLocalSource(
\r
460 urltf.getText(), nametf.getText(), seqs.isSelected(), true);
\r
461 List sources = sourceRegistry.getSources();
\r
462 int osize = sources.size();
\r
463 int size = osize + (newSource ? 1 : 0);
\r
465 Object[][] data = new Object[size][2];
\r
466 DASTableModel dtm = (table != null) ? (DASTableModel) ((TableSorter) table
\r
467 .getModel()).getTableModel() : null;
\r
468 for (int i = 0; i < osize; i++)
\r
470 String osrc = (dtm == null || i >= osize) ? null : (String) dtm
\r
472 if (!newSource && osrc != null
\r
473 && dtm.getValueAt(i, 0).equals(nickname))
\r
475 data[i][0] = local.getTitle();
\r
476 data[i][1] = new Boolean(true);
\r
481 data[i][1] = new Boolean(selectedSources.contains(osrc));
\r
484 // Always add a new source at the end
\r
487 data[osize][0] = local.getTitle();
\r
488 data[osize][1] = new Boolean(true);
\r
489 selectedSources.add(local.getTitle());
\r
492 refreshTableData(data);
\r
494 SwingUtilities.invokeLater(new Runnable()
\r
498 scrollPane.getVerticalScrollBar().setValue(
\r
499 scrollPane.getVerticalScrollBar().getMaximum());
\r
503 displayFullDetails(local.getTitle());
\r
506 public void editRemoveLocalSource(MouseEvent evt)
\r
508 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
509 if (selectedRow == -1)
\r
514 String nickname = table.getValueAt(selectedRow, 0).toString();
\r
516 if (!sourceRegistry.getSource(nickname).isLocal())
\r
518 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
519 "You can only edit or remove local DAS Sources!",
\r
520 "Public DAS source - not editable",
\r
521 JOptionPane.WARNING_MESSAGE);
\r
526 { "Edit", "Remove", "Cancel" };
\r
527 int choice = JOptionPane.showInternalOptionDialog(Desktop.desktop,
\r
528 "Do you want to edit or remove " + nickname + "?",
\r
529 "Edit / Remove Local DAS Source",
\r
530 JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
\r
531 null, options, options[2]);
\r
539 sourceRegistry.removeLocalSource(sourceRegistry.getSource(nickname));
\r
540 selectedSources.remove(nickname);
\r
541 Object[][] data = new Object[sourceRegistry.getSources().size()][2];
\r
543 l = table.getRowCount();
\r
545 for (int i = 0; i < l; i++)
\r
548 if ((nm = (String) table.getValueAt(i, 0)).equals(nickname))
\r
554 data[index][0] = nm;
\r
555 data[index][1] = new Boolean(selectedSources.contains(nm));
\r
559 refreshTableData(data);
\r
560 SwingUtilities.invokeLater(new Runnable()
\r
564 scrollPane.getVerticalScrollBar().setValue(
\r
565 scrollPane.getVerticalScrollBar().getMaximum());
\r
573 public void valueChanged(ListSelectionEvent evt)
\r
575 // Called when the MainTable selection changes
\r
576 if (evt.getValueIsAdjusting())
\r
581 displayFullDetails(null);
\r
583 // Filter the displayed data sources
\r
585 ArrayList names = new ArrayList();
\r
586 ArrayList selected = new ArrayList();
\r
588 // The features filter is not visible, but we must still
\r
589 // filter the das source list here.
\r
590 // July 2006 - only 6 sources fo not serve features
\r
591 Object[] dummyFeatureList = new Object[]
\r
593 List<jalviewSourceI> srcs = sourceRegistry.getSources();
\r
594 for (jalviewSourceI ds : srcs)
\r
597 VERSION v = ds.getVersion();
\r
598 List<COORDINATES> coords = v.getCOORDINATES();
\r
600 || ((coords == null || coords.size() == 0)
\r
601 && filter1.getSelectedIndex() == 0
\r
602 && filter2.getSelectedIndex() == 0 && filter3
\r
603 .getSelectedIndex() == 0))
\r
605 // THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT
\r
606 // HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT
\r
607 // IS ADDED FROM THE REGISTRY
\r
608 names.add(ds.getTitle());
\r
609 selected.add(new Boolean(selectedSources.contains(ds.getTitle())));
\r
613 if (!selectedInList(dummyFeatureList, ds.getCapabilityList(v))
\r
614 || !selectedInList(filter3.getSelectedValues(),
\r
615 ds.getLabelsFor(v)))
\r
620 for (int j = 0; j < coords.size(); j++)
\r
622 if (selectedInList(filter1.getSelectedValues(), new String[]
\r
623 { coords.get(j).getAuthority() })
\r
624 && selectedInList(filter2.getSelectedValues(), new String[]
\r
625 { coords.get(j).getSource() }))
\r
627 names.add(ds.getTitle());
\r
628 selected.add(new Boolean(selectedSources.contains(ds.getTitle())));
\r
634 int dSize = names.size();
\r
635 Object[][] data = new Object[dSize][2];
\r
636 for (int d = 0; d < dSize; d++)
\r
638 data[d][0] = names.get(d);
\r
639 data[d][1] = selected.get(d);
\r
642 refreshTableData(data);
\r
645 private boolean selectedInList(Object[] selection, String[] items)
\r
647 for (int i = 0; i < selection.length; i++)
\r
649 if (selection[i].equals("Any"))
\r
653 if (items == null || items.length == 0)
\r
657 String sel = (items[0].startsWith("das1:") ? "das1:" : "")
\r
659 for (int j = 0; j < items.length; j++)
\r
661 if (sel.equals(items[j]))
\r
671 void setSelectedFromProperties()
\r
673 String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",
\r
675 StringTokenizer st = new StringTokenizer(active, "\t");
\r
676 selectedSources = new Vector();
\r
677 while (st.hasMoreTokens())
\r
679 selectedSources.addElement(st.nextToken());
\r
683 public void reset_actionPerformed(ActionEvent e)
\r
685 registryURL.setText(sourceRegistry.getDasRegistryURL());
\r
689 * set the DAS source settings in the given jalview properties.
\r
691 * @param properties
\r
693 public void saveProperties(Properties properties)
\r
695 if (registryURL.getText() == null || registryURL.getText().length() < 1)
\r
697 properties.remove(jalview.bin.Cache.DAS_REGISTRY_URL);
\r
701 properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL,
\r
702 registryURL.getText());
\r
705 StringBuffer sb = new StringBuffer();
\r
706 for (int r = 0; r < table.getModel().getRowCount(); r++)
\r
708 if (((Boolean) table.getValueAt(r, 1)).booleanValue())
\r
710 sb.append(table.getValueAt(r, 0) + "\t");
\r
714 properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE,
\r
717 String sourceprop = sourceRegistry.getLocalSourceString();
\r
718 properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sourceprop);
\r
721 class DASTableModel extends AbstractTableModel
\r
724 public DASTableModel(Object[][] data)
\r
729 private String[] columnNames = new String[]
\r
730 { "Nickname", "Use Source" };
\r
732 private Object[][] data;
\r
734 public int getColumnCount()
\r
736 return columnNames.length;
\r
739 public int getRowCount()
\r
741 return data.length;
\r
744 public String getColumnName(int col)
\r
746 return columnNames[col];
\r
749 public Object getValueAt(int row, int col)
\r
751 return data[row][col];
\r
755 * JTable uses this method to determine the default renderer/ editor for
\r
756 * each cell. If we didn't implement this method, then the last column would
\r
757 * contain text ("true"/"false"), rather than a check box.
\r
759 public Class getColumnClass(int c)
\r
761 return getValueAt(0, c).getClass();
\r
765 * Don't need to implement this method unless your table's editable.
\r
767 public boolean isCellEditable(int row, int col)
\r
769 // Note that the data/cell address is constant,
\r
770 // no matter where the cell appears onscreen.
\r
776 * Don't need to implement this method unless your table's data can change.
\r
778 public void setValueAt(Object value, int row, int col)
\r
780 data[row][col] = value;
\r
781 fireTableCellUpdated(row, col);
\r
783 String name = getValueAt(row, 0).toString();
\r
784 boolean selected = ((Boolean) value).booleanValue();
\r
786 if (selectedSources.contains(name) && !selected)
\r
788 selectedSources.remove(name);
\r
791 if (!selectedSources.contains(name) && selected)
\r
793 selectedSources.add(name);
\r
798 public void initDasSources()
\r
801 Thread thr = new Thread(new Runnable()
\r
805 // this actually initialises the das source list
\r
806 paintComponent(null); // yuk
\r
810 while (loadingDasSources || sourceRegistry == null)
\r
815 } catch (Exception e)
\r
823 * disable or enable the buttons on the source browser
\r
827 public void setGuiEnabled(boolean b)
\r
829 refresh.setEnabled(b);
\r
830 addLocal.setEnabled(b);
\r