71efbd073ab55c0532b6a7fa5737416250c7e461
[jalview.git] / src / jalview / gui / DasSourceBrowser.java
1 /*\r
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
4  * \r
5  * This file is part of Jalview.\r
6  * \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
10  * \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
15  * \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
17  */\r
18 package jalview.gui;\r
19 \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
24 \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
34 \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
45 \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
50 \r
51 public class DasSourceBrowser extends GDasSourceBrowser implements\r
52         Runnable, ListSelectionListener\r
53 {\r
54   DasSourceRegistryI sourceRegistry = null;\r
55 \r
56   Vector<String> selectedSources;\r
57 \r
58   public DasSourceBrowser(FeatureSettings featureSettings)\r
59   {\r
60     fs = featureSettings;\r
61     // TODO DasSourceRegistryProvider API\r
62     sourceRegistry = jalview.bin.Cache.getDasSourceRegistry();\r
63     String registry = sourceRegistry.getDasRegistryURL();\r
64 \r
65     registryURL.setText(registry);\r
66 \r
67     setSelectedFromProperties();\r
68 \r
69     displayFullDetails(null);\r
70     table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
71 \r
72     filter1.addListSelectionListener(this);\r
73     filter2.addListSelectionListener(this);\r
74     filter3.addListSelectionListener(this);\r
75 \r
76     // Ask to be notified of selection changes.\r
77     ListSelectionModel rowSM = table.getSelectionModel();\r
78     rowSM.addListSelectionListener(new ListSelectionListener()\r
79     {\r
80       public void valueChanged(ListSelectionEvent e)\r
81       {\r
82         ListSelectionModel lsm = (ListSelectionModel) e.getSource();\r
83         if (!lsm.isSelectionEmpty())\r
84         {\r
85           int selectedRow = lsm.getMinSelectionIndex();\r
86           displayFullDetails(table.getValueAt(selectedRow, 0).toString());\r
87         }\r
88       }\r
89     });\r
90 \r
91     table.addMouseListener(new MouseAdapter()\r
92     {\r
93       public void mouseClicked(MouseEvent evt)\r
94       {\r
95         if (evt.getClickCount() == 2\r
96                 || SwingUtilities.isRightMouseButton(evt))\r
97         {\r
98           editRemoveLocalSource(evt);\r
99         }\r
100       }\r
101     });\r
102 \r
103     if (sourceRegistry.getSources() != null)\r
104     {\r
105       init();\r
106     }\r
107   }\r
108 \r
109   FeatureSettings fs = null;\r
110 \r
111   private boolean loadingDasSources;\r
112 \r
113   public DasSourceBrowser()\r
114   {\r
115     this(null);\r
116   }\r
117 \r
118   public void paintComponent(java.awt.Graphics g)\r
119   {\r
120     if (sourceRegistry == null)\r
121     {\r
122       Thread worker = new Thread(this);\r
123       worker.start();\r
124     }\r
125   }\r
126 \r
127   void init()\r
128   {\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
133     {\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
136               .getTitle()));\r
137     }\r
138 \r
139     refreshTableData(data);\r
140     setCapabilities(sourceRegistry);\r
141 \r
142     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
143     {\r
144       public void run()\r
145       {\r
146         TableSorter sorter = (TableSorter) table.getModel();\r
147         sorter.setSortingStatus(1, TableSorter.DESCENDING);\r
148         sorter.setSortingStatus(1, TableSorter.NOT_SORTED);\r
149       }\r
150     });\r
151 \r
152     progressBar.setIndeterminate(false);\r
153     progressBar.setVisible(false);\r
154     addLocal.setVisible(true);\r
155     refresh.setVisible(true);\r
156   }\r
157 \r
158   public void refreshTableData(Object[][] data)\r
159   {\r
160     TableSorter sorter = new TableSorter(new DASTableModel(data));\r
161     sorter.setTableHeader(table.getTableHeader());\r
162     table.setModel(sorter);\r
163   }\r
164 \r
165   void displayFullDetails(String nickName)\r
166   {\r
167 \r
168     StringBuffer text = new StringBuffer(\r
169             "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");\r
170 \r
171     if (nickName == null)\r
172     {\r
173       fullDetails.setText(text + "Select a DAS service from the table"\r
174               + " to read a full description here.</font></html>");\r
175       return;\r
176     }\r
177 \r
178     int dSize = sourceRegistry.getSources().size();\r
179     for (jalviewSourceI ds : sourceRegistry.getSources())\r
180     {\r
181       if (!ds.getTitle().equals(nickName))\r
182       {\r
183         continue;\r
184       }\r
185 \r
186       VERSION latest = ds.getVersion();\r
187       text.append("<font color=\"#0000FF\">Id:</font> " + ds.getUri()\r
188               + "<br>");\r
189       text.append("<font color=\"#0000FF\">Nickname:</font> "\r
190               + ds.getTitle() + "<br>");\r
191 \r
192       text.append("<font color=\"#0000FF\">URL:</font> <a href=\""\r
193               + ds.getSourceURL() + "\">" + ds.getSourceURL() + "</a>"\r
194               + "<br>");\r
195       if (!ds.isLocal())\r
196       {\r
197         if (ds.getDocHref() != null && ds.getDocHref().length() > 0)\r
198         {\r
199           text.append("<font color=\"#0000FF\">Site:</font> <a href=\""\r
200                   + ds.getDocHref() + "\">" + ds.getDocHref() + "</a>"\r
201                   + "<br>");\r
202         }\r
203 \r
204         text.append("<font color=\"#0000FF\">Description:</font> "\r
205                 + ds.getDescription() + "<br>");\r
206 \r
207         text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"\r
208                 + ds.getEmail() + "\">" + ds.getEmail() + "</a>" + "<br>");\r
209 \r
210         text.append("<font color=\"#0000FF\">Registered at:</font> "\r
211                 + latest.getCreated() + "<br>");\r
212 \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
216       }\r
217       else\r
218       {\r
219         text.append("Source was added manually.<br/>");\r
220       }\r
221       text.append("<font color=\"#0000FF\">Labels:</font> ");\r
222       boolean b = false;\r
223       for (PROP labl : latest.getPROP())\r
224       {\r
225         if (labl.getName().equalsIgnoreCase("LABEL"))\r
226         {\r
227           if (b)\r
228           {\r
229             text.append(",");\r
230           }\r
231           text.append(" ");\r
232 \r
233           text.append(labl.getValue());\r
234           b = true;\r
235         }\r
236         ;\r
237       }\r
238       text.append("<br>");\r
239 \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
243       {\r
244         text.append(scap[j].getType());\r
245         if (j < scap.length - 1)\r
246         {\r
247           text.append(", ");\r
248         }\r
249       }\r
250       text.append("<br>");\r
251 \r
252       text.append("<font color=\"#0000FF\">Coordinates:</font>");\r
253       int i=1;\r
254       for (COORDINATES dcs : latest.getCOORDINATES())\r
255       {\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
259         {\r
260           text.append(" [TaxId:" + dcs.getTaxid()+"]");\r
261         }\r
262         if (dcs.getVersion() != null\r
263                 && dcs.getVersion().trim().length() > 0)\r
264         {\r
265           {\r
266             text.append(" {v. " + dcs.getVersion()+"}");\r
267           }\r
268         }\r
269         text.append(" (<a href=\""+dcs.getUri() +"\">"+dcs.getUri() + "</a>)");\r
270       }\r
271       text.append("</font></html>");\r
272 \r
273       break;\r
274     }\r
275 \r
276     fullDetails.setText(text.toString());\r
277     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
278     {\r
279       public void run()\r
280       {\r
281         fullDetailsScrollpane.getVerticalScrollBar().setValue(0);\r
282       }\r
283     });\r
284   }\r
285 \r
286   public void run()\r
287   {\r
288     loadingDasSources = true;\r
289 \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
297 \r
298     init();\r
299 \r
300     setParentGuiEnabled(true);\r
301     loadingDasSources = false;\r
302 \r
303   }\r
304 \r
305   private void setParentGuiEnabled(boolean b)\r
306   {\r
307     if (fs != null)\r
308     {\r
309       fs.fetchDAS.setEnabled(b);\r
310       fs.saveDAS.setEnabled(b);\r
311     }\r
312   }\r
313 \r
314   public Vector<jalviewSourceI> getSelectedSources()\r
315   {\r
316     // wait around if we're still loading.\r
317     while (sourceRegistry == null)\r
318     {\r
319       if (!loadingDasSources)\r
320       {\r
321         new Thread(this).start();\r
322         try\r
323         {\r
324           Thread.sleep(5);\r
325         } catch (Exception e)\r
326         {\r
327         }\r
328         ;\r
329         while (loadingDasSources)\r
330         {\r
331           try\r
332           {\r
333             Thread.sleep(5);\r
334           } catch (Exception e)\r
335           {\r
336           }\r
337           ;\r
338         }\r
339         ;\r
340       }\r
341     }\r
342 \r
343     Vector<jalviewSourceI> selected = new Vector<jalviewSourceI>();\r
344     for (String source : selectedSources)\r
345     {\r
346       jalviewSourceI srce = sourceRegistry.getSource(source);\r
347       if (srce != null)\r
348       {\r
349         selected.addElement(srce);\r
350       }\r
351     }\r
352     return selected;\r
353   }\r
354 \r
355   public void refresh_actionPerformed(ActionEvent e)\r
356   {\r
357     saveProperties(jalview.bin.Cache.applicationProperties);\r
358 \r
359     Thread worker = new Thread(this);\r
360     worker.start();\r
361   }\r
362 \r
363   private void setCapabilities(DasSourceRegistryI sourceRegistry2)\r
364   {\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
370     type.add("Any");\r
371     label.add("Any");\r
372 \r
373     for (jalviewSourceI ds : sourceRegistry2.getSources())\r
374     {\r
375       VERSION latest = ds.getVersion();\r
376 \r
377       for (COORDINATES cs : latest.getCOORDINATES())\r
378       {\r
379         if (!type.contains(cs.getSource()))\r
380         {\r
381           type.add(cs.getSource()); // source==category\r
382         }\r
383 \r
384         if (!authority.contains(cs.getAuthority()))\r
385         {\r
386           authority.add(cs.getAuthority());\r
387         }\r
388       }\r
389 \r
390       for (PROP slabel : latest.getPROP())\r
391       {\r
392         if (slabel.getName().equalsIgnoreCase("LABEL")\r
393                 && !label.contains(slabel.getValue()))\r
394         {\r
395           label.add(slabel.getValue());\r
396         }\r
397       }\r
398 \r
399     }\r
400 \r
401     filter1.setListData(authority);\r
402     filter2.setListData(type);\r
403     filter3.setListData(label);\r
404     // filter4 taxIds\r
405 \r
406     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
407     {\r
408       public void run()\r
409       {\r
410         filter1.setSelectedIndex(0);\r
411         filter2.setSelectedIndex(0);\r
412         filter3.setSelectedIndex(0);\r
413       }\r
414     });\r
415   }\r
416 \r
417   public void amendLocal(boolean newSource)\r
418   {\r
419     String url = "http://localhost:8080/", nickname = "";\r
420     boolean seqsrc = false;\r
421     if (!newSource)\r
422     {\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
428     }\r
429 \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
444 \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
448 \r
449     if (reply != JOptionPane.OK_OPTION)\r
450     {\r
451       return;\r
452     }\r
453 \r
454     if (!urltf.getText().endsWith("/"))\r
455     {\r
456       urltf.setText(urltf.getText() + "/");\r
457     }\r
458 \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
464 \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
469     {\r
470       String osrc = (dtm == null || i >= osize) ? null : (String) dtm\r
471               .getValueAt(i, 0);\r
472       if (!newSource && osrc != null\r
473               && dtm.getValueAt(i, 0).equals(nickname))\r
474       {\r
475         data[i][0] = local.getTitle();\r
476         data[i][1] = new Boolean(true);\r
477       }\r
478       else\r
479       {\r
480         data[i][0] = osrc;\r
481         data[i][1] = new Boolean(selectedSources.contains(osrc));\r
482       }\r
483     }\r
484     // Always add a new source at the end\r
485     if (newSource)\r
486     {\r
487       data[osize][0] = local.getTitle();\r
488       data[osize][1] = new Boolean(true);\r
489       selectedSources.add(local.getTitle());\r
490     }\r
491 \r
492     refreshTableData(data);\r
493 \r
494     SwingUtilities.invokeLater(new Runnable()\r
495     {\r
496       public void run()\r
497       {\r
498         scrollPane.getVerticalScrollBar().setValue(\r
499                 scrollPane.getVerticalScrollBar().getMaximum());\r
500       }\r
501     });\r
502 \r
503     displayFullDetails(local.getTitle());\r
504   }\r
505 \r
506   public void editRemoveLocalSource(MouseEvent evt)\r
507   {\r
508     int selectedRow = table.getSelectionModel().getMinSelectionIndex();\r
509     if (selectedRow == -1)\r
510     {\r
511       return;\r
512     }\r
513 \r
514     String nickname = table.getValueAt(selectedRow, 0).toString();\r
515 \r
516     if (!sourceRegistry.getSource(nickname).isLocal())\r
517     {\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
522       return;\r
523     }\r
524 \r
525     Object[] options =\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
532 \r
533     switch (choice)\r
534     {\r
535     case 0:\r
536       amendLocal(false);\r
537       break;\r
538     case 1:\r
539       sourceRegistry.removeLocalSource(sourceRegistry.getSource(nickname));\r
540       selectedSources.remove(nickname);\r
541       Object[][] data = new Object[sourceRegistry.getSources().size()][2];\r
542       int index = 0,\r
543       l = table.getRowCount();\r
544 \r
545       for (int i = 0; i < l; i++)\r
546       {\r
547         String nm;\r
548         if ((nm = (String) table.getValueAt(i, 0)).equals(nickname))\r
549         {\r
550           continue;\r
551         }\r
552         else\r
553         {\r
554           data[index][0] = nm;\r
555           data[index][1] = new Boolean(selectedSources.contains(nm));\r
556           index++;\r
557         }\r
558       }\r
559       refreshTableData(data);\r
560       SwingUtilities.invokeLater(new Runnable()\r
561       {\r
562         public void run()\r
563         {\r
564           scrollPane.getVerticalScrollBar().setValue(\r
565                   scrollPane.getVerticalScrollBar().getMaximum());\r
566         }\r
567       });\r
568 \r
569       break;\r
570     }\r
571   }\r
572 \r
573   public void valueChanged(ListSelectionEvent evt)\r
574   {\r
575     // Called when the MainTable selection changes\r
576     if (evt.getValueIsAdjusting())\r
577     {\r
578       return;\r
579     }\r
580 \r
581     displayFullDetails(null);\r
582 \r
583     // Filter the displayed data sources\r
584 \r
585     ArrayList names = new ArrayList();\r
586     ArrayList selected = new ArrayList();\r
587 \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
592     { "features" };\r
593     List<jalviewSourceI> srcs = sourceRegistry.getSources();\r
594     for (jalviewSourceI ds : srcs)\r
595     {\r
596 \r
597       VERSION v = ds.getVersion();\r
598       List<COORDINATES> coords = v.getCOORDINATES();\r
599       if (ds.isLocal()\r
600               || ((coords == null || coords.size() == 0)\r
601                       && filter1.getSelectedIndex() == 0\r
602                       && filter2.getSelectedIndex() == 0 && filter3\r
603                       .getSelectedIndex() == 0))\r
604       {\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
610         continue;\r
611       }\r
612 \r
613       if (!selectedInList(dummyFeatureList, ds.getCapabilityList(v))\r
614               || !selectedInList(filter3.getSelectedValues(),\r
615                       ds.getLabelsFor(v)))\r
616       {\r
617         continue;\r
618       }\r
619 \r
620       for (int j = 0; j < coords.size(); j++)\r
621       {\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
626         {\r
627           names.add(ds.getTitle());\r
628           selected.add(new Boolean(selectedSources.contains(ds.getTitle())));\r
629           break;\r
630         }\r
631       }\r
632     }\r
633 \r
634     int dSize = names.size();\r
635     Object[][] data = new Object[dSize][2];\r
636     for (int d = 0; d < dSize; d++)\r
637     {\r
638       data[d][0] = names.get(d);\r
639       data[d][1] = selected.get(d);\r
640     }\r
641 \r
642     refreshTableData(data);\r
643   }\r
644 \r
645   private boolean selectedInList(Object[] selection, String[] items)\r
646   {\r
647     for (int i = 0; i < selection.length; i++)\r
648     {\r
649       if (selection[i].equals("Any"))\r
650       {\r
651         return true;\r
652       }\r
653       if (items == null || items.length == 0)\r
654       {\r
655         return false;\r
656       }\r
657       String sel = (items[0].startsWith("das1:") ? "das1:" : "")\r
658               + selection[i];\r
659       for (int j = 0; j < items.length; j++)\r
660       {\r
661         if (sel.equals(items[j]))\r
662         {\r
663           return true;\r
664         }\r
665       }\r
666     }\r
667 \r
668     return false;\r
669   }\r
670 \r
671   void setSelectedFromProperties()\r
672   {\r
673     String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",\r
674             "uniprot");\r
675     StringTokenizer st = new StringTokenizer(active, "\t");\r
676     selectedSources = new Vector();\r
677     while (st.hasMoreTokens())\r
678     {\r
679       selectedSources.addElement(st.nextToken());\r
680     }\r
681   }\r
682 \r
683   public void reset_actionPerformed(ActionEvent e)\r
684   {\r
685     registryURL.setText(sourceRegistry.getDasRegistryURL());\r
686   }\r
687 \r
688   /**\r
689    * set the DAS source settings in the given jalview properties.\r
690    * \r
691    * @param properties\r
692    */\r
693   public void saveProperties(Properties properties)\r
694   {\r
695     if (registryURL.getText() == null || registryURL.getText().length() < 1)\r
696     {\r
697       properties.remove(jalview.bin.Cache.DAS_REGISTRY_URL);\r
698     }\r
699     else\r
700     {\r
701       properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL,\r
702               registryURL.getText());\r
703     }\r
704 \r
705     StringBuffer sb = new StringBuffer();\r
706     for (int r = 0; r < table.getModel().getRowCount(); r++)\r
707     {\r
708       if (((Boolean) table.getValueAt(r, 1)).booleanValue())\r
709       {\r
710         sb.append(table.getValueAt(r, 0) + "\t");\r
711       }\r
712     }\r
713 \r
714     properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE,\r
715             sb.toString());\r
716 \r
717     String sourceprop = sourceRegistry.getLocalSourceString();\r
718     properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sourceprop);\r
719   }\r
720 \r
721   class DASTableModel extends AbstractTableModel\r
722   {\r
723 \r
724     public DASTableModel(Object[][] data)\r
725     {\r
726       this.data = data;\r
727     }\r
728 \r
729     private String[] columnNames = new String[]\r
730     { "Nickname", "Use Source" };\r
731 \r
732     private Object[][] data;\r
733 \r
734     public int getColumnCount()\r
735     {\r
736       return columnNames.length;\r
737     }\r
738 \r
739     public int getRowCount()\r
740     {\r
741       return data.length;\r
742     }\r
743 \r
744     public String getColumnName(int col)\r
745     {\r
746       return columnNames[col];\r
747     }\r
748 \r
749     public Object getValueAt(int row, int col)\r
750     {\r
751       return data[row][col];\r
752     }\r
753 \r
754     /*\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
758      */\r
759     public Class getColumnClass(int c)\r
760     {\r
761       return getValueAt(0, c).getClass();\r
762     }\r
763 \r
764     /*\r
765      * Don't need to implement this method unless your table's editable.\r
766      */\r
767     public boolean isCellEditable(int row, int col)\r
768     {\r
769       // Note that the data/cell address is constant,\r
770       // no matter where the cell appears onscreen.\r
771       return col == 1;\r
772 \r
773     }\r
774 \r
775     /*\r
776      * Don't need to implement this method unless your table's data can change.\r
777      */\r
778     public void setValueAt(Object value, int row, int col)\r
779     {\r
780       data[row][col] = value;\r
781       fireTableCellUpdated(row, col);\r
782 \r
783       String name = getValueAt(row, 0).toString();\r
784       boolean selected = ((Boolean) value).booleanValue();\r
785 \r
786       if (selectedSources.contains(name) && !selected)\r
787       {\r
788         selectedSources.remove(name);\r
789       }\r
790 \r
791       if (!selectedSources.contains(name) && selected)\r
792       {\r
793         selectedSources.add(name);\r
794       }\r
795     }\r
796   }\r
797 \r
798   public void initDasSources()\r
799   {\r
800 \r
801     Thread thr = new Thread(new Runnable()\r
802     {\r
803       public void run()\r
804       {\r
805         // this actually initialises the das source list\r
806         paintComponent(null); // yuk\r
807       }\r
808     });\r
809     thr.start();\r
810     while (loadingDasSources || sourceRegistry == null)\r
811     {\r
812       try\r
813       {\r
814         Thread.sleep(10);\r
815       } catch (Exception e)\r
816       {\r
817       }\r
818       ;\r
819     }\r
820   }\r
821 \r
822   /**\r
823    * disable or enable the buttons on the source browser\r
824    * \r
825    * @param b\r
826    */\r
827   public void setGuiEnabled(boolean b)\r
828   {\r
829     refresh.setEnabled(b);\r
830     addLocal.setEnabled(b);\r
831   }\r
832 }\r