2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
\r
3 * Copyright (C) 2011 J Procter, AM Waterhouse, 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).getTitle()));
\r
138 refreshTableData(data);
\r
139 setCapabilities(sourceRegistry);
\r
141 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
145 TableSorter sorter = (TableSorter) table.getModel();
\r
146 sorter.setSortingStatus(1, TableSorter.DESCENDING);
\r
147 sorter.setSortingStatus(1, TableSorter.NOT_SORTED);
\r
151 progressBar.setIndeterminate(false);
\r
152 progressBar.setVisible(false);
\r
153 addLocal.setVisible(true);
\r
154 refresh.setVisible(true);
\r
157 public void refreshTableData(Object[][] data)
\r
159 TableSorter sorter = new TableSorter(new DASTableModel(data));
\r
160 sorter.setTableHeader(table.getTableHeader());
\r
161 table.setModel(sorter);
\r
164 void displayFullDetails(String nickName)
\r
167 StringBuffer text = new StringBuffer(
\r
168 "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
\r
170 if (nickName == null)
\r
172 fullDetails.setText(text + "Select a DAS service from the table"
\r
173 + " to read a full description here.</font></html>");
\r
177 int dSize = sourceRegistry.getSources().size();
\r
178 for (jalviewSourceI ds : sourceRegistry.getSources())
\r
180 if (!ds.getTitle().equals(nickName))
\r
185 VERSION latest = ds.getVersion();
\r
186 text.append("<font color=\"#0000FF\">Id:</font> " + ds.getUri()
\r
188 text.append("<font color=\"#0000FF\">Nickname:</font> "
\r
189 + ds.getTitle() + "<br>");
\r
193 // TODO: IMMEDIATE verify that URI + ds.URI point to latest version for non-local sources.
\r
194 if (ds.getDocHref()!=null) {
\r
195 text.append("<font color=\"#0000FF\">URL:</font> " + ds.getDocHref()
\r
199 text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
\r
200 + ds.getEmail() + "\">" + ds.getEmail() + "</a>" + "<br>");
\r
202 text.append("<font color=\"#0000FF\">Registered at:</font> "
\r
203 + latest.getCreated() + "<br>");
\r
205 // TODO: Identify last successful test date
\r
206 // text.append("<font color=\"#0000FF\">Last successful test:</font> "
\r
207 // + latest.dasSources[i].getLeaseDate() + "<br>");
\r
209 text.append("Source was added manually.<br/>");
\r
211 text.append("<font color=\"#0000FF\">Labels:</font> ");
\r
213 for (PROP labl : latest.getPROP())
\r
215 if (labl.getName().equalsIgnoreCase("LABEL"))
\r
223 text.append(labl.getValue());
\r
228 text.append("<br>");
\r
230 text.append("<font color=\"#0000FF\">Capabilities:</font> ");
\r
231 CAPABILITY[] scap = latest.getCAPABILITY().toArray(new CAPABILITY[0]);
\r
232 for (int j = 0; j < scap.length; j++)
\r
234 text.append(scap[j].getType());
\r
235 if (j < scap.length - 1)
\r
240 text.append("<br>");
\r
242 text.append("<font color=\"#0000FF\">Coordinates:</font> ");
\r
243 for (COORDINATES dcs : latest.getCOORDINATES())
\r
245 text.append("(" + dcs.getUri() + ") "
\r
247 + dcs.getSource() + ", " + dcs.getAuthority());
\r
248 if (dcs.getTaxid() != null && dcs.getTaxid().trim().length() > 0)
\r
250 text.append(", " + dcs.getTaxid());
\r
252 if (dcs.getVersion()!=null && dcs.getVersion().trim().length() > 0)
\r
255 text.append(", " + dcs.getVersion());
\r
258 text.append("<br>");
\r
261 text.append("<font color=\"#0000FF\">Description:</font> "
\r
262 + ds.getDescription() + "<br>");
\r
264 if (ds.getDocHref() != null && ds.getDocHref().length() > 0)
\r
266 text.append("<font color=\"#0000FF\"><a href=\""
\r
267 + ds.getDocHref() + "\">Go to site</a></font<br>");
\r
270 text.append("</font></html>");
\r
275 fullDetails.setText(text.toString());
\r
276 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
280 fullDetailsScrollpane.getVerticalScrollBar().setValue(0);
\r
287 loadingDasSources = true;
\r
289 addLocal.setVisible(false);
\r
290 refresh.setVisible(false);
\r
291 progressBar.setVisible(true);
\r
292 progressBar.setIndeterminate(true);
\r
293 setParentGuiEnabled(false);
\r
294 // Refresh the source list.
\r
295 sourceRegistry.refreshSources();
\r
299 setParentGuiEnabled(true);
\r
300 loadingDasSources = false;
\r
304 private void setParentGuiEnabled(boolean b)
\r
308 fs.fetchDAS.setEnabled(b);
\r
309 fs.saveDAS.setEnabled(b);
\r
313 public Vector<jalviewSourceI> getSelectedSources()
\r
315 // wait around if we're still loading.
\r
316 while (sourceRegistry == null)
\r
318 if (!loadingDasSources)
\r
320 new Thread(this).start();
\r
324 } catch (Exception e)
\r
328 while (loadingDasSources)
\r
333 } catch (Exception e)
\r
342 Vector<jalviewSourceI> selected = new Vector<jalviewSourceI>();
\r
343 for (String source : selectedSources)
\r
345 jalviewSourceI srce = sourceRegistry.getSource(source);
\r
348 selected.addElement(srce);
\r
354 public void refresh_actionPerformed(ActionEvent e)
\r
356 saveProperties(jalview.bin.Cache.applicationProperties);
\r
358 Thread worker = new Thread(this);
\r
362 private void setCapabilities(DasSourceRegistryI sourceRegistry2)
\r
364 Vector<String> authority = new Vector<String>();
\r
365 Vector<String> type = new Vector<String>();
\r
366 Vector<String> label = new Vector<String>();
\r
367 Vector<String> taxIds = new Vector<String>();
\r
368 authority.add("Any");
\r
372 for (jalviewSourceI ds : sourceRegistry2.getSources())
\r
374 VERSION latest = ds.getVersion();
\r
376 for (COORDINATES cs : latest.getCOORDINATES())
\r
378 if (!type.contains(cs.getSource()))
\r
380 type.add(cs.getSource()); // source==category
\r
383 if (!authority.contains(cs.getAuthority()))
\r
385 authority.add(cs.getAuthority());
\r
389 for (PROP slabel : latest.getPROP())
\r
391 if (slabel.getName().equalsIgnoreCase("LABEL")
\r
392 && !label.contains(slabel.getValue()))
\r
394 label.add(slabel.getValue());
\r
400 filter1.setListData(authority);
\r
401 filter2.setListData(type);
\r
402 filter3.setListData(label);
\r
405 javax.swing.SwingUtilities.invokeLater(new Runnable()
\r
409 filter1.setSelectedIndex(0);
\r
410 filter2.setSelectedIndex(0);
\r
411 filter3.setSelectedIndex(0);
\r
416 public void amendLocal(boolean newSource)
\r
418 String url = "http://localhost:8080/", nickname = "";
\r
419 boolean seqsrc = false;
\r
422 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
423 nickname = table.getValueAt(selectedRow, 0).toString();
\r
424 jalviewSourceI source = sourceRegistry.getSource(nickname);
\r
425 url = source.getUri();
\r
426 seqsrc = source.isSequenceSource();
\r
429 JTextField nametf = new JTextField(nickname, 40);
\r
430 JTextField urltf = new JTextField(url, 40);
\r
431 JCheckBox seqs = new JCheckBox("Sequence Source");
\r
432 seqs.setSelected(seqsrc);
\r
433 JPanel panel = new JPanel(new BorderLayout());
\r
434 JPanel pane12 = new JPanel(new BorderLayout());
\r
435 pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER);
\r
436 pane12.add(nametf, BorderLayout.EAST);
\r
437 panel.add(pane12, BorderLayout.NORTH);
\r
438 pane12 = new JPanel(new BorderLayout());
\r
439 pane12.add(new JLabel("URL: "), BorderLayout.NORTH);
\r
440 pane12.add(seqs, BorderLayout.SOUTH);
\r
441 pane12.add(urltf, BorderLayout.EAST);
\r
442 panel.add(pane12, BorderLayout.SOUTH);
\r
444 int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
\r
445 panel, "Enter Nickname & URL of Local DAS Source",
\r
446 JOptionPane.OK_CANCEL_OPTION);
\r
448 if (reply != JOptionPane.OK_OPTION)
\r
453 if (!urltf.getText().endsWith("/"))
\r
455 urltf.setText(urltf.getText() + "/");
\r
458 jalviewSourceI local = sourceRegistry.createLocalSource(
\r
459 urltf.getText(), nametf.getText(), seqs.isSelected(), true);
\r
460 List sources = sourceRegistry.getSources();
\r
461 int osize = sources.size();
\r
462 int size = osize + (newSource ? 1 : 0);
\r
464 Object[][] data = new Object[size][2];
\r
465 DASTableModel dtm = (table != null) ? (DASTableModel)((TableSorter) table.getModel()).getTableModel()
\r
467 for (int i = 0; i < osize; i++)
\r
469 String osrc = (dtm == null || i >= osize) ? null : (String) dtm
\r
471 if (!newSource && osrc != null
\r
472 && dtm.getValueAt(i, 0).equals(nickname))
\r
474 data[i][0] = local.getTitle();
\r
475 data[i][1] = new Boolean(true);
\r
480 data[i][1] = new Boolean(selectedSources.contains(osrc));
\r
483 // Always add a new source at the end
\r
486 data[osize][0] = local.getTitle();
\r
487 data[osize][1] = new Boolean(true);
\r
488 selectedSources.add(local.getTitle());
\r
491 refreshTableData(data);
\r
493 SwingUtilities.invokeLater(new Runnable()
\r
497 scrollPane.getVerticalScrollBar().setValue(
\r
498 scrollPane.getVerticalScrollBar().getMaximum());
\r
502 displayFullDetails(local.getTitle());
\r
505 public void editRemoveLocalSource(MouseEvent evt)
\r
507 int selectedRow = table.getSelectionModel().getMinSelectionIndex();
\r
508 if (selectedRow == -1)
\r
513 String nickname = table.getValueAt(selectedRow, 0).toString();
\r
515 if (!sourceRegistry.getSource(nickname).isLocal())
\r
517 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
518 "You can only edit or remove local DAS Sources!",
\r
519 "Public DAS source - not editable",
\r
520 JOptionPane.WARNING_MESSAGE);
\r
525 { "Edit", "Remove", "Cancel" };
\r
526 int choice = JOptionPane.showInternalOptionDialog(Desktop.desktop,
\r
527 "Do you want to edit or remove " + nickname + "?",
\r
528 "Edit / Remove Local DAS Source",
\r
529 JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
\r
530 null, options, options[2]);
\r
538 sourceRegistry.removeLocalSource(sourceRegistry.getSource(nickname));
\r
539 selectedSources.remove(nickname);
\r
540 Object[][] data = new Object[sourceRegistry.getSources().size()][2];
\r
541 DASTableModel dtm = (table != null) ? (DASTableModel) table
\r
542 .getModel() : null;
\r
544 l = dtm.getRowCount();
\r
546 for (int i = 0; i < l; i++)
\r
549 if ((nm = (String) table.getValueAt(i, 0)).equals(nickname))
\r
555 data[index][0] = nm;
\r
556 data[index][1] = new Boolean(selectedSources.contains(nm));
\r
560 refreshTableData(data);
\r
561 SwingUtilities.invokeLater(new Runnable()
\r
565 scrollPane.getVerticalScrollBar().setValue(
\r
566 scrollPane.getVerticalScrollBar().getMaximum());
\r
574 public void valueChanged(ListSelectionEvent evt)
\r
576 // Called when the MainTable selection changes
\r
577 if (evt.getValueIsAdjusting())
\r
582 displayFullDetails(null);
\r
584 // Filter the displayed data sources
\r
586 ArrayList names = new ArrayList();
\r
587 ArrayList selected = new ArrayList();
\r
589 // The features filter is not visible, but we must still
\r
590 // filter the das source list here.
\r
591 // July 2006 - only 6 sources fo not serve features
\r
592 Object[] dummyFeatureList = new Object[]
\r
594 List<jalviewSourceI> srcs=sourceRegistry.getSources();
\r
595 for (jalviewSourceI ds : srcs)
\r
598 VERSION v = ds.getVersion();
\r
599 List<COORDINATES> coords = v.getCOORDINATES();
\r
600 if (ds.isLocal() || ((coords == null || coords.size() == 0)
\r
601 && filter1.getSelectedIndex() == 0
\r
602 && filter2.getSelectedIndex() == 0
\r
603 && filter3.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:":"")+selection[i];
\r
658 for (int j = 0; j < items.length; j++)
\r
660 if (sel.equals(items[j]))
\r
670 void setSelectedFromProperties()
\r
672 String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",
\r
674 StringTokenizer st = new StringTokenizer(active, "\t");
\r
675 selectedSources = new Vector();
\r
676 while (st.hasMoreTokens())
\r
678 selectedSources.addElement(st.nextToken());
\r
682 public void reset_actionPerformed(ActionEvent e)
\r
684 registryURL.setText(sourceRegistry.getDasRegistryURL());
\r
688 * set the DAS source settings in the given jalview properties.
\r
690 * @param properties
\r
692 public void saveProperties(Properties properties)
\r
694 if (registryURL.getText() == null || registryURL.getText().length() < 1)
\r
696 properties.remove(jalview.bin.Cache.DAS_REGISTRY_URL);
\r
700 properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL,
\r
701 registryURL.getText());
\r
704 StringBuffer sb = new StringBuffer();
\r
705 for (int r = 0; r < table.getModel().getRowCount(); r++)
\r
707 if (((Boolean) table.getValueAt(r, 1)).booleanValue())
\r
709 sb.append(table.getValueAt(r, 0) + "\t");
\r
713 properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE,
\r
716 String sourceprop = sourceRegistry.getLocalSourceString();
\r
717 properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sourceprop);
\r
720 class DASTableModel extends AbstractTableModel
\r
723 public DASTableModel(Object[][] data)
\r
728 private String[] columnNames = new String[]
\r
729 { "Nickname", "Use Source" };
\r
731 private Object[][] data;
\r
733 public int getColumnCount()
\r
735 return columnNames.length;
\r
738 public int getRowCount()
\r
740 return data.length;
\r
743 public String getColumnName(int col)
\r
745 return columnNames[col];
\r
748 public Object getValueAt(int row, int col)
\r
750 return data[row][col];
\r
754 * JTable uses this method to determine the default renderer/ editor for
\r
755 * each cell. If we didn't implement this method, then the last column would
\r
756 * contain text ("true"/"false"), rather than a check box.
\r
758 public Class getColumnClass(int c)
\r
760 return getValueAt(0, c).getClass();
\r
764 * Don't need to implement this method unless your table's editable.
\r
766 public boolean isCellEditable(int row, int col)
\r
768 // Note that the data/cell address is constant,
\r
769 // no matter where the cell appears onscreen.
\r
775 * Don't need to implement this method unless your table's data can change.
\r
777 public void setValueAt(Object value, int row, int col)
\r
779 data[row][col] = value;
\r
780 fireTableCellUpdated(row, col);
\r
782 String name = getValueAt(row, 0).toString();
\r
783 boolean selected = ((Boolean) value).booleanValue();
\r
785 if (selectedSources.contains(name) && !selected)
\r
787 selectedSources.remove(name);
\r
790 if (!selectedSources.contains(name) && selected)
\r
792 selectedSources.add(name);
\r
797 public void initDasSources()
\r
800 Thread thr = new Thread(new Runnable()
\r
804 // this actually initialises the das source list
\r
805 paintComponent(null); // yuk
\r
809 while (loadingDasSources || sourceRegistry == null)
\r
814 } catch (Exception e)
\r
822 * disable or enable the buttons on the source browser
\r
826 public void setGuiEnabled(boolean b)
\r
828 refresh.setEnabled(b);
\r
829 addLocal.setEnabled(b);
\r