debug local source management buttons and formatting
[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, 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).getTitle()));\r
136     }\r
137 \r
138     refreshTableData(data);\r
139     setCapabilities(sourceRegistry);\r
140 \r
141     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
142     {\r
143       public void run()\r
144       {\r
145         TableSorter sorter = (TableSorter) table.getModel();\r
146         sorter.setSortingStatus(1, TableSorter.DESCENDING);\r
147         sorter.setSortingStatus(1, TableSorter.NOT_SORTED);\r
148       }\r
149     });\r
150 \r
151     progressBar.setIndeterminate(false);\r
152     progressBar.setVisible(false);\r
153     addLocal.setVisible(true);\r
154     refresh.setVisible(true);\r
155   }\r
156 \r
157   public void refreshTableData(Object[][] data)\r
158   {\r
159     TableSorter sorter = new TableSorter(new DASTableModel(data));\r
160     sorter.setTableHeader(table.getTableHeader());\r
161     table.setModel(sorter);\r
162   }\r
163 \r
164   void displayFullDetails(String nickName)\r
165   {\r
166 \r
167     StringBuffer text = new StringBuffer(\r
168             "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");\r
169 \r
170     if (nickName == null)\r
171     {\r
172       fullDetails.setText(text + "Select a DAS service from the table"\r
173               + " to read a full description here.</font></html>");\r
174       return;\r
175     }\r
176 \r
177     int dSize = sourceRegistry.getSources().size();\r
178     for (jalviewSourceI ds : sourceRegistry.getSources())\r
179     {\r
180       if (!ds.getTitle().equals(nickName))\r
181       {\r
182         continue;\r
183       }\r
184 \r
185       VERSION latest = ds.getVersion();\r
186       text.append("<font color=\"#0000FF\">Id:</font> " + ds.getUri()\r
187               + "<br>");\r
188       text.append("<font color=\"#0000FF\">Nickname:</font> "\r
189               + ds.getTitle() + "<br>");\r
190       \r
191       if (!ds.isLocal())\r
192       {\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
196               + "<br>");\r
197       }\r
198       \r
199       text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"\r
200               + ds.getEmail() + "\">" + ds.getEmail() + "</a>" + "<br>");\r
201 \r
202       text.append("<font color=\"#0000FF\">Registered at:</font> "\r
203               + latest.getCreated() + "<br>");\r
204 \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
208       } else {\r
209         text.append("Source was added manually.<br/>");\r
210       }\r
211       text.append("<font color=\"#0000FF\">Labels:</font> ");\r
212       boolean b = false;\r
213       for (PROP labl : latest.getPROP())\r
214       {\r
215         if (labl.getName().equalsIgnoreCase("LABEL"))\r
216         {\r
217           if (!b)\r
218           {\r
219             text.append(",");\r
220           }\r
221           text.append(" ");\r
222 \r
223           text.append(labl.getValue());\r
224           b = true;\r
225         }\r
226         ;\r
227       }\r
228       text.append("<br>");\r
229 \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
233       {\r
234         text.append(scap[j].getType());\r
235         if (j < scap.length - 1)\r
236         {\r
237           text.append(", ");\r
238         }\r
239       }\r
240       text.append("<br>");\r
241 \r
242       text.append("<font color=\"#0000FF\">Coordinates:</font> ");\r
243       for (COORDINATES dcs : latest.getCOORDINATES())\r
244       {\r
245         text.append("(" + dcs.getUri() + ") "\r
246 \r
247         + dcs.getSource() + ", " + dcs.getAuthority());\r
248         if (dcs.getTaxid() != null && dcs.getTaxid().trim().length() > 0)\r
249         {\r
250           text.append(", " + dcs.getTaxid());\r
251         }\r
252         if (dcs.getVersion()!=null && dcs.getVersion().trim().length() > 0)\r
253         {\r
254           {\r
255             text.append(", " + dcs.getVersion());\r
256           }\r
257 \r
258           text.append("<br>");\r
259         }\r
260 \r
261         text.append("<font color=\"#0000FF\">Description:</font> "\r
262                 + ds.getDescription() + "<br>");\r
263 \r
264         if (ds.getDocHref() != null && ds.getDocHref().length() > 0)\r
265         {\r
266           text.append("<font color=\"#0000FF\"><a href=\""\r
267                   + ds.getDocHref() + "\">Go to site</a></font<br>");\r
268         }\r
269 \r
270         text.append("</font></html>");\r
271 \r
272         break;\r
273       }\r
274     }\r
275     fullDetails.setText(text.toString());\r
276     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
277     {\r
278       public void run()\r
279       {\r
280         fullDetailsScrollpane.getVerticalScrollBar().setValue(0);\r
281       }\r
282     });\r
283   }\r
284 \r
285   public void run()\r
286   {\r
287     loadingDasSources = true;\r
288 \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
296 \r
297     init();\r
298 \r
299     setParentGuiEnabled(true);\r
300     loadingDasSources = false;\r
301 \r
302   }\r
303 \r
304   private void setParentGuiEnabled(boolean b)\r
305   {\r
306     if (fs != null)\r
307     {\r
308       fs.fetchDAS.setEnabled(b);\r
309       fs.saveDAS.setEnabled(b);\r
310     }\r
311   }\r
312 \r
313   public Vector<jalviewSourceI> getSelectedSources()\r
314   {\r
315     // wait around if we're still loading.\r
316     while (sourceRegistry == null)\r
317     {\r
318       if (!loadingDasSources)\r
319       {\r
320         new Thread(this).start();\r
321         try\r
322         {\r
323           Thread.sleep(5);\r
324         } catch (Exception e)\r
325         {\r
326         }\r
327         ;\r
328         while (loadingDasSources)\r
329         {\r
330           try\r
331           {\r
332             Thread.sleep(5);\r
333           } catch (Exception e)\r
334           {\r
335           }\r
336           ;\r
337         }\r
338         ;\r
339       }\r
340     }\r
341 \r
342     Vector<jalviewSourceI> selected = new Vector<jalviewSourceI>();\r
343     for (String source : selectedSources)\r
344     {\r
345       jalviewSourceI srce = sourceRegistry.getSource(source);\r
346       if (srce != null)\r
347       {\r
348         selected.addElement(srce);\r
349       }\r
350     }\r
351     return selected;\r
352   }\r
353 \r
354   public void refresh_actionPerformed(ActionEvent e)\r
355   {\r
356     saveProperties(jalview.bin.Cache.applicationProperties);\r
357 \r
358     Thread worker = new Thread(this);\r
359     worker.start();\r
360   }\r
361 \r
362   private void setCapabilities(DasSourceRegistryI sourceRegistry2)\r
363   {\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
369     type.add("Any");\r
370     label.add("Any");\r
371 \r
372     for (jalviewSourceI ds : sourceRegistry2.getSources())\r
373     {\r
374       VERSION latest = ds.getVersion();\r
375 \r
376       for (COORDINATES cs : latest.getCOORDINATES())\r
377       {\r
378         if (!type.contains(cs.getSource()))\r
379         {\r
380           type.add(cs.getSource()); // source==category\r
381         }\r
382 \r
383         if (!authority.contains(cs.getAuthority()))\r
384         {\r
385           authority.add(cs.getAuthority());\r
386         }\r
387       }\r
388 \r
389       for (PROP slabel : latest.getPROP())\r
390       {\r
391         if (slabel.getName().equalsIgnoreCase("LABEL")\r
392                 && !label.contains(slabel.getValue()))\r
393         {\r
394           label.add(slabel.getValue());\r
395         }\r
396       }\r
397 \r
398     }\r
399 \r
400     filter1.setListData(authority);\r
401     filter2.setListData(type);\r
402     filter3.setListData(label);\r
403     // filter4 taxIds\r
404 \r
405     javax.swing.SwingUtilities.invokeLater(new Runnable()\r
406     {\r
407       public void run()\r
408       {\r
409         filter1.setSelectedIndex(0);\r
410         filter2.setSelectedIndex(0);\r
411         filter3.setSelectedIndex(0);\r
412       }\r
413     });\r
414   }\r
415 \r
416   public void amendLocal(boolean newSource)\r
417   {\r
418     String url = "http://localhost:8080/", nickname = "";\r
419     boolean seqsrc = false;\r
420     if (!newSource)\r
421     {\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
427     }\r
428 \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
443 \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
447 \r
448     if (reply != JOptionPane.OK_OPTION)\r
449     {\r
450       return;\r
451     }\r
452 \r
453     if (!urltf.getText().endsWith("/"))\r
454     {\r
455       urltf.setText(urltf.getText() + "/");\r
456     }\r
457 \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
463 \r
464     Object[][] data = new Object[size][2];\r
465     DASTableModel dtm = (table != null) ? (DASTableModel)((TableSorter) table.getModel()).getTableModel()\r
466             : null;\r
467     for (int i = 0; i < osize; i++)\r
468     {\r
469       String osrc = (dtm == null || i >= osize) ? null : (String) dtm\r
470               .getValueAt(i, 0);\r
471       if (!newSource && osrc != null\r
472               && dtm.getValueAt(i, 0).equals(nickname))\r
473       {\r
474         data[i][0] = local.getTitle();\r
475         data[i][1] = new Boolean(true);\r
476       }\r
477       else\r
478       {\r
479         data[i][0] = osrc;\r
480         data[i][1] = new Boolean(selectedSources.contains(osrc));\r
481       }\r
482     }\r
483     // Always add a new source at the end\r
484     if (newSource)\r
485     {\r
486       data[osize][0] = local.getTitle();\r
487       data[osize][1] = new Boolean(true);\r
488       selectedSources.add(local.getTitle());\r
489     }\r
490 \r
491     refreshTableData(data);\r
492 \r
493     SwingUtilities.invokeLater(new Runnable()\r
494     {\r
495       public void run()\r
496       {\r
497         scrollPane.getVerticalScrollBar().setValue(\r
498                 scrollPane.getVerticalScrollBar().getMaximum());\r
499       }\r
500     });\r
501 \r
502     displayFullDetails(local.getTitle());\r
503   }\r
504 \r
505   public void editRemoveLocalSource(MouseEvent evt)\r
506   {\r
507     int selectedRow = table.getSelectionModel().getMinSelectionIndex();\r
508     if (selectedRow == -1)\r
509     {\r
510       return;\r
511     }\r
512 \r
513     String nickname = table.getValueAt(selectedRow, 0).toString();\r
514 \r
515     if (!sourceRegistry.getSource(nickname).isLocal())\r
516     {\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
521       return;\r
522     }\r
523 \r
524     Object[] options =\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
531 \r
532     switch (choice)\r
533     {\r
534     case 0:\r
535       amendLocal(false);\r
536       break;\r
537     case 1:\r
538       sourceRegistry.removeLocalSource(sourceRegistry.getSource(nickname));\r
539       selectedSources.remove(nickname);\r
540       Object[][] data = new Object[sourceRegistry.getSources().size()][2];\r
541       int index = 0,\r
542       l = table.getRowCount();\r
543 \r
544       for (int i = 0; i < l; i++)\r
545       {\r
546         String nm;\r
547         if ((nm = (String) table.getValueAt(i, 0)).equals(nickname))\r
548         {\r
549           continue;\r
550         }\r
551         else\r
552         {\r
553           data[index][0] = nm;\r
554           data[index][1] = new Boolean(selectedSources.contains(nm));\r
555           index++;\r
556         }\r
557       }\r
558       refreshTableData(data);\r
559       SwingUtilities.invokeLater(new Runnable()\r
560       {\r
561         public void run()\r
562         {\r
563           scrollPane.getVerticalScrollBar().setValue(\r
564                   scrollPane.getVerticalScrollBar().getMaximum());\r
565         }\r
566       });\r
567 \r
568       break;\r
569     }\r
570   }\r
571 \r
572   public void valueChanged(ListSelectionEvent evt)\r
573   {\r
574     // Called when the MainTable selection changes\r
575     if (evt.getValueIsAdjusting())\r
576     {\r
577       return;\r
578     }\r
579 \r
580     displayFullDetails(null);\r
581 \r
582     // Filter the displayed data sources\r
583 \r
584     ArrayList names = new ArrayList();\r
585     ArrayList selected = new ArrayList();\r
586 \r
587     // The features filter is not visible, but we must still\r
588     // filter the das source list here.\r
589     // July 2006 - only 6 sources fo not serve features\r
590     Object[] dummyFeatureList = new Object[]\r
591     { "features" };\r
592     List<jalviewSourceI> srcs=sourceRegistry.getSources();\r
593     for (jalviewSourceI ds : srcs)\r
594     {\r
595 \r
596       VERSION v = ds.getVersion();\r
597       List<COORDINATES> coords = v.getCOORDINATES();\r
598       if (ds.isLocal() || ((coords == null || coords.size() == 0)\r
599               && filter1.getSelectedIndex() == 0\r
600               && filter2.getSelectedIndex() == 0\r
601               && filter3.getSelectedIndex() == 0))\r
602       {\r
603         // THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT\r
604         // HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT\r
605         // IS ADDED FROM THE REGISTRY\r
606         names.add(ds.getTitle());\r
607         selected.add(new Boolean(selectedSources.contains(ds.getTitle())));\r
608         continue;\r
609       }\r
610 \r
611       if (!selectedInList(dummyFeatureList, ds.getCapabilityList(v))\r
612               || !selectedInList(filter3.getSelectedValues(),\r
613                       ds.getLabelsFor(v)))\r
614       {\r
615         continue;\r
616       }\r
617 \r
618       for (int j = 0; j < coords.size(); j++)\r
619       {\r
620         if (selectedInList(filter1.getSelectedValues(), new String[]\r
621         { coords.get(j).getAuthority() })\r
622                 && selectedInList(filter2.getSelectedValues(), new String[]\r
623                 { coords.get(j).getSource() }))\r
624         {\r
625           names.add(ds.getTitle());\r
626           selected.add(new Boolean(selectedSources.contains(ds.getTitle())));\r
627           break;\r
628         }\r
629       }\r
630     }\r
631 \r
632     int dSize = names.size();\r
633     Object[][] data = new Object[dSize][2];\r
634     for (int d = 0; d < dSize; d++)\r
635     {\r
636       data[d][0] = names.get(d);\r
637       data[d][1] = selected.get(d);\r
638     }\r
639 \r
640     refreshTableData(data);\r
641   }\r
642 \r
643   private boolean selectedInList(Object[] selection, String[] items)\r
644   {\r
645     for (int i = 0; i < selection.length; i++)\r
646     {\r
647       if (selection[i].equals("Any"))\r
648       {\r
649         return true;\r
650       }\r
651       if (items==null || items.length==0)\r
652       {\r
653         return false;\r
654       }\r
655       String sel=(items[0].startsWith("das1:") ? "das1:":"")+selection[i];\r
656       for (int j = 0; j < items.length; j++)\r
657       {\r
658         if (sel.equals(items[j]))\r
659         {\r
660           return true;\r
661         }\r
662       }\r
663     }\r
664 \r
665     return false;\r
666   }\r
667 \r
668   void setSelectedFromProperties()\r
669   {\r
670     String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",\r
671             "uniprot");\r
672     StringTokenizer st = new StringTokenizer(active, "\t");\r
673     selectedSources = new Vector();\r
674     while (st.hasMoreTokens())\r
675     {\r
676       selectedSources.addElement(st.nextToken());\r
677     }\r
678   }\r
679 \r
680   public void reset_actionPerformed(ActionEvent e)\r
681   {\r
682     registryURL.setText(sourceRegistry.getDasRegistryURL());\r
683   }\r
684 \r
685   /**\r
686    * set the DAS source settings in the given jalview properties.\r
687    * \r
688    * @param properties\r
689    */\r
690   public void saveProperties(Properties properties)\r
691   {\r
692     if (registryURL.getText() == null || registryURL.getText().length() < 1)\r
693     {\r
694       properties.remove(jalview.bin.Cache.DAS_REGISTRY_URL);\r
695     }\r
696     else\r
697     {\r
698       properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL,\r
699               registryURL.getText());\r
700     }\r
701 \r
702     StringBuffer sb = new StringBuffer();\r
703     for (int r = 0; r < table.getModel().getRowCount(); r++)\r
704     {\r
705       if (((Boolean) table.getValueAt(r, 1)).booleanValue())\r
706       {\r
707         sb.append(table.getValueAt(r, 0) + "\t");\r
708       }\r
709     }\r
710 \r
711     properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE,\r
712             sb.toString());\r
713 \r
714     String sourceprop = sourceRegistry.getLocalSourceString();\r
715     properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sourceprop);\r
716   }\r
717 \r
718   class DASTableModel extends AbstractTableModel\r
719   {\r
720 \r
721     public DASTableModel(Object[][] data)\r
722     {\r
723       this.data = data;\r
724     }\r
725 \r
726     private String[] columnNames = new String[]\r
727     { "Nickname", "Use Source" };\r
728 \r
729     private Object[][] data;\r
730 \r
731     public int getColumnCount()\r
732     {\r
733       return columnNames.length;\r
734     }\r
735 \r
736     public int getRowCount()\r
737     {\r
738       return data.length;\r
739     }\r
740 \r
741     public String getColumnName(int col)\r
742     {\r
743       return columnNames[col];\r
744     }\r
745 \r
746     public Object getValueAt(int row, int col)\r
747     {\r
748       return data[row][col];\r
749     }\r
750 \r
751     /*\r
752      * JTable uses this method to determine the default renderer/ editor for\r
753      * each cell. If we didn't implement this method, then the last column would\r
754      * contain text ("true"/"false"), rather than a check box.\r
755      */\r
756     public Class getColumnClass(int c)\r
757     {\r
758       return getValueAt(0, c).getClass();\r
759     }\r
760 \r
761     /*\r
762      * Don't need to implement this method unless your table's editable.\r
763      */\r
764     public boolean isCellEditable(int row, int col)\r
765     {\r
766       // Note that the data/cell address is constant,\r
767       // no matter where the cell appears onscreen.\r
768       return col == 1;\r
769 \r
770     }\r
771 \r
772     /*\r
773      * Don't need to implement this method unless your table's data can change.\r
774      */\r
775     public void setValueAt(Object value, int row, int col)\r
776     {\r
777       data[row][col] = value;\r
778       fireTableCellUpdated(row, col);\r
779 \r
780       String name = getValueAt(row, 0).toString();\r
781       boolean selected = ((Boolean) value).booleanValue();\r
782 \r
783       if (selectedSources.contains(name) && !selected)\r
784       {\r
785         selectedSources.remove(name);\r
786       }\r
787 \r
788       if (!selectedSources.contains(name) && selected)\r
789       {\r
790         selectedSources.add(name);\r
791       }\r
792     }\r
793   }\r
794 \r
795   public void initDasSources()\r
796   {\r
797 \r
798     Thread thr = new Thread(new Runnable()\r
799     {\r
800       public void run()\r
801       {\r
802         // this actually initialises the das source list\r
803         paintComponent(null); // yuk\r
804       }\r
805     });\r
806     thr.start();\r
807     while (loadingDasSources || sourceRegistry == null)\r
808     {\r
809       try\r
810       {\r
811         Thread.sleep(10);\r
812       } catch (Exception e)\r
813       {\r
814       }\r
815       ;\r
816     }\r
817   }\r
818 \r
819   /**\r
820    * disable or enable the buttons on the source browser\r
821    * \r
822    * @param b\r
823    */\r
824   public void setGuiEnabled(boolean b)\r
825   {\r
826     refresh.setEnabled(b);\r
827     addLocal.setEnabled(b);\r
828   }\r
829 }\r