JAL-1953 named various threads
[jalview.git] / src / jalview / gui / DasSourceBrowser.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.jbgui.GDasSourceBrowser;
24 import jalview.util.MessageManager;
25 import jalview.util.TableSorter;
26 import jalview.ws.dbsources.das.api.DasSourceRegistryI;
27 import jalview.ws.dbsources.das.api.jalviewSourceI;
28
29 import java.awt.BorderLayout;
30 import java.awt.event.ActionEvent;
31 import java.awt.event.MouseAdapter;
32 import java.awt.event.MouseEvent;
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.Properties;
36 import java.util.StringTokenizer;
37 import java.util.Vector;
38
39 import javax.swing.JCheckBox;
40 import javax.swing.JLabel;
41 import javax.swing.JPanel;
42 import javax.swing.JTextField;
43 import javax.swing.ListSelectionModel;
44 import javax.swing.SwingUtilities;
45 import javax.swing.event.ListSelectionEvent;
46 import javax.swing.event.ListSelectionListener;
47 import javax.swing.table.AbstractTableModel;
48
49 import org.biodas.jdas.schema.sources.CAPABILITY;
50 import org.biodas.jdas.schema.sources.COORDINATES;
51 import org.biodas.jdas.schema.sources.PROP;
52 import org.biodas.jdas.schema.sources.VERSION;
53
54 public class DasSourceBrowser extends GDasSourceBrowser
55         implements Runnable, ListSelectionListener
56 {
57   DasSourceRegistryI sourceRegistry = null;
58
59   Vector<String> selectedSources;
60
61   public DasSourceBrowser(FeatureSettings featureSettings)
62   {
63     fs = featureSettings;
64     // TODO DasSourceRegistryProvider API
65     sourceRegistry = jalview.bin.Cache.getDasSourceRegistry();
66     String registry = sourceRegistry.getDasRegistryURL();
67
68     registryURL.setText(registry);
69
70     setSelectedFromProperties();
71
72     displayFullDetails(null);
73     table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
74
75     filter1.addListSelectionListener(this);
76     filter2.addListSelectionListener(this);
77     filter3.addListSelectionListener(this);
78
79     // Ask to be notified of selection changes.
80     ListSelectionModel rowSM = table.getSelectionModel();
81     rowSM.addListSelectionListener(new ListSelectionListener()
82     {
83       @Override
84       public void valueChanged(ListSelectionEvent e)
85       {
86         ListSelectionModel lsm = (ListSelectionModel) e.getSource();
87         if (!lsm.isSelectionEmpty())
88         {
89           int selectedRow = lsm.getMinSelectionIndex();
90           displayFullDetails(table.getValueAt(selectedRow, 0).toString());
91         }
92       }
93     });
94
95     table.addMouseListener(new MouseAdapter()
96     {
97       @Override
98       public void mouseClicked(MouseEvent evt)
99       {
100         if (evt.getClickCount() == 2 || evt.isPopupTrigger())
101         {
102           editRemoveLocalSource(evt);
103         }
104       }
105     });
106
107     if (sourceRegistry.getSources() != null)
108     {
109       init();
110     }
111   }
112
113   FeatureSettings fs = null;
114
115   private boolean loadingDasSources;
116
117   public DasSourceBrowser()
118   {
119     this(null);
120   }
121
122   @Override
123   public void paintComponent(java.awt.Graphics g)
124   {
125     if (sourceRegistry == null)
126     {
127       Thread worker = new Thread(this, "PaintDas");
128       worker.start();
129     }
130   }
131
132   void init()
133   {
134     List<jalviewSourceI> sources = sourceRegistry.getSources();
135     int dSize = sources.size();
136     Object[][] data = new Object[dSize][2];
137     for (int i = 0; i < dSize; i++)
138     {
139       data[i][0] = sources.get(i).getTitle(); // what's equivalent of nickname
140       data[i][1] = new Boolean(
141               selectedSources.contains(sources.get(i).getTitle()));
142     }
143
144     refreshTableData(data);
145     setCapabilities(sourceRegistry);
146
147     javax.swing.SwingUtilities.invokeLater(new Runnable()
148     {
149       @Override
150       public void run()
151       {
152         TableSorter sorter = (TableSorter) table.getModel();
153         sorter.setSortingStatus(1, TableSorter.DESCENDING);
154         sorter.setSortingStatus(1, TableSorter.NOT_SORTED);
155       }
156     });
157
158     progressBar.setIndeterminate(false);
159     progressBar.setVisible(false);
160     addLocal.setVisible(true);
161     refresh.setVisible(true);
162   }
163
164   public void refreshTableData(Object[][] data)
165   {
166     TableSorter sorter = new TableSorter(new DASTableModel(data));
167     sorter.setTableHeader(table.getTableHeader());
168     table.setModel(sorter);
169   }
170
171   void displayFullDetails(String nickName)
172   {
173
174     StringBuffer text = new StringBuffer(
175             "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
176
177     if (nickName == null)
178     {
179       fullDetails.setText(text + MessageManager
180               .getString("label.select_das_service_from_table"));
181       return;
182     }
183
184     int dSize = sourceRegistry.getSources().size();
185     for (jalviewSourceI ds : sourceRegistry.getSources())
186     {
187       if (!ds.getTitle().equals(nickName))
188       {
189         continue;
190       }
191
192       VERSION latest = ds.getVersion();
193       text.append(
194               "<font color=\"#0000FF\">Id:</font> " + ds.getUri() + "<br>");
195       text.append("<font color=\"#0000FF\">Nickname:</font> "
196               + ds.getTitle() + "<br>");
197
198       text.append("<font color=\"#0000FF\">URL:</font> <a href=\""
199               + ds.getSourceURL() + "\">" + ds.getSourceURL() + "</a>"
200               + "<br>");
201       if (!ds.isLocal())
202       {
203         if (ds.getDocHref() != null && ds.getDocHref().length() > 0)
204         {
205           text.append("<font color=\"#0000FF\">Site:</font> <a href=\""
206                   + ds.getDocHref() + "\">" + ds.getDocHref() + "</a>"
207                   + "<br>");
208         }
209
210         text.append("<font color=\"#0000FF\">Description:</font> "
211                 + ds.getDescription() + "<br>");
212
213         text.append(
214                 "<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
215                         + ds.getEmail() + "\">" + ds.getEmail() + "</a>"
216                         + "<br>");
217
218         text.append("<font color=\"#0000FF\">Registered at:</font> "
219                 + latest.getCreated() + "<br>");
220
221         // TODO: Identify last successful test date
222         // text.append("<font color=\"#0000FF\">Last successful test:</font> "
223         // + latest.dasSources[i].getLeaseDate() + "<br>");
224       }
225       else
226       {
227         text.append("Source was added manually.<br/>");
228       }
229       text.append("<font color=\"#0000FF\">Labels:</font> ");
230       boolean b = false;
231       for (PROP labl : latest.getPROP())
232       {
233         if (labl.getName().equalsIgnoreCase("LABEL"))
234         {
235           if (b)
236           {
237             text.append(",");
238           }
239           text.append(" ");
240
241           text.append(labl.getValue());
242           b = true;
243         }
244         ;
245       }
246       text.append("<br>");
247
248       text.append("<font color=\"#0000FF\">Capabilities:</font> ");
249       CAPABILITY[] scap = latest.getCAPABILITY().toArray(new CAPABILITY[0]);
250       for (int j = 0; j < scap.length; j++)
251       {
252         text.append(scap[j].getType());
253         if (j < scap.length - 1)
254         {
255           text.append(", ");
256         }
257       }
258       text.append("<br>");
259
260       text.append("<font color=\"#0000FF\">Coordinates:</font>");
261       int i = 1;
262       for (COORDINATES dcs : latest.getCOORDINATES())
263       {
264         text.append("<br/>" + i++ + ". ");
265         text.append(dcs.getAuthority() + " : " + dcs.getSource());
266         if (dcs.getTaxid() != null && dcs.getTaxid().trim().length() > 0)
267         {
268           text.append(" [TaxId:" + dcs.getTaxid() + "]");
269         }
270         if (dcs.getVersion() != null
271                 && dcs.getVersion().trim().length() > 0)
272         {
273           {
274             text.append(" {v. " + dcs.getVersion() + "}");
275           }
276         }
277         text.append(" (<a href=\"" + dcs.getUri() + "\">" + dcs.getUri()
278                 + "</a>)");
279       }
280       text.append("</font></html>");
281
282       break;
283     }
284
285     fullDetails.setText(text.toString());
286     javax.swing.SwingUtilities.invokeLater(new Runnable()
287     {
288       @Override
289       public void run()
290       {
291         fullDetailsScrollpane.getVerticalScrollBar().setValue(0);
292       }
293     });
294   }
295
296   @Override
297   public void run()
298   {
299     loadingDasSources = true;
300
301     addLocal.setVisible(false);
302     refresh.setVisible(false);
303     progressBar.setVisible(true);
304     progressBar.setIndeterminate(true);
305     setParentGuiEnabled(false);
306     // Refresh the source list.
307     sourceRegistry.refreshSources();
308
309     init();
310
311     setParentGuiEnabled(true);
312     loadingDasSources = false;
313
314   }
315
316   private void setParentGuiEnabled(boolean b)
317   {
318     if (fs != null)
319     {
320       fs.fetchDAS.setEnabled(b);
321       fs.saveDAS.setEnabled(b);
322     }
323   }
324
325   public Vector<jalviewSourceI> getSelectedSources()
326   {
327     // wait around if we're still loading.
328     while (sourceRegistry == null)
329     {
330       if (!loadingDasSources)
331       {
332         new Thread(this).start();
333         try
334         {
335           Thread.sleep(5);
336         } catch (Exception e)
337         {
338         }
339         ;
340         while (loadingDasSources)
341         {
342           try
343           {
344             Thread.sleep(5);
345           } catch (Exception e)
346           {
347           }
348           ;
349         }
350         ;
351       }
352     }
353
354     Vector<jalviewSourceI> selected = new Vector<>();
355     for (String source : selectedSources)
356     {
357       jalviewSourceI srce = sourceRegistry.getSource(source);
358       if (srce != null)
359       {
360         selected.addElement(srce);
361       }
362     }
363     return selected;
364   }
365
366   @Override
367   public void refresh_actionPerformed(ActionEvent e)
368   {
369     saveProperties(jalview.bin.Cache.applicationProperties);
370
371     Thread worker = new Thread(this, "RepaintDas");
372     worker.start();
373   }
374
375   private void setCapabilities(DasSourceRegistryI sourceRegistry2)
376   {
377     Vector<String> authority = new Vector<>();
378     Vector<String> type = new Vector<>();
379     Vector<String> label = new Vector<>();
380     Vector<String> taxIds = new Vector<>();
381     authority.add("Any");
382     type.add("Any");
383     label.add("Any");
384
385     for (jalviewSourceI ds : sourceRegistry2.getSources())
386     {
387       VERSION latest = ds.getVersion();
388
389       for (COORDINATES cs : latest.getCOORDINATES())
390       {
391         if (!type.contains(cs.getSource()))
392         {
393           type.add(cs.getSource()); // source==category
394         }
395
396         if (!authority.contains(cs.getAuthority()))
397         {
398           authority.add(cs.getAuthority());
399         }
400       }
401
402       for (PROP slabel : latest.getPROP())
403       {
404         if (slabel.getName().equalsIgnoreCase("LABEL")
405                 && !label.contains(slabel.getValue()))
406         {
407           label.add(slabel.getValue());
408         }
409       }
410
411     }
412
413     filter1.setListData(authority);
414     filter2.setListData(type);
415     filter3.setListData(label);
416     // filter4 taxIds
417
418     javax.swing.SwingUtilities.invokeLater(new Runnable()
419     {
420       @Override
421       public void run()
422       {
423         filter1.setSelectedIndex(0);
424         filter2.setSelectedIndex(0);
425         filter3.setSelectedIndex(0);
426       }
427     });
428   }
429
430   @Override
431   public void amendLocal(boolean newSource)
432   {
433     String url = "http://localhost:8080/", nickname = "";
434     boolean seqsrc = false;
435     if (!newSource)
436     {
437       int selectedRow = table.getSelectionModel().getMinSelectionIndex();
438       nickname = table.getValueAt(selectedRow, 0).toString();
439       jalviewSourceI source = sourceRegistry.getSource(nickname);
440       url = source.getUri();
441       seqsrc = source.isSequenceSource();
442     }
443
444     JTextField nametf = new JTextField(nickname, 40);
445     JTextField urltf = new JTextField(url, 40);
446     JCheckBox seqs = new JCheckBox(
447             MessageManager.getString("label.sequence_source"));
448     seqs.setSelected(seqsrc);
449     JPanel panel = new JPanel(new BorderLayout());
450     JPanel pane12 = new JPanel(new BorderLayout());
451     pane12.add(new JLabel(MessageManager.getString("label.name:")),
452             BorderLayout.CENTER);
453     pane12.add(nametf, BorderLayout.EAST);
454     panel.add(pane12, BorderLayout.NORTH);
455     pane12 = new JPanel(new BorderLayout());
456     pane12.add(new JLabel(MessageManager.getString("label.url:")),
457             BorderLayout.NORTH);
458     pane12.add(seqs, BorderLayout.SOUTH);
459     pane12.add(urltf, BorderLayout.EAST);
460     panel.add(pane12, BorderLayout.SOUTH);
461
462     int reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
463             panel, MessageManager.getString("label.enter_local_das_source"),
464             JvOptionPane.OK_CANCEL_OPTION);
465
466     if (reply != JvOptionPane.OK_OPTION)
467     {
468       return;
469     }
470
471     if (!urltf.getText().endsWith("/"))
472     {
473       urltf.setText(urltf.getText() + "/");
474     }
475
476     jalviewSourceI local = sourceRegistry.createLocalSource(urltf.getText(),
477             nametf.getText(), seqs.isSelected(), true);
478     List sources = sourceRegistry.getSources();
479     int osize = sources.size();
480     int size = osize + (newSource ? 1 : 0);
481
482     Object[][] data = new Object[size][2];
483     DASTableModel dtm = (table != null)
484             ? (DASTableModel) ((TableSorter) table.getModel())
485                     .getTableModel()
486             : null;
487     for (int i = 0; i < osize; i++)
488     {
489       String osrc = (dtm == null || i >= osize) ? null
490               : (String) dtm.getValueAt(i, 0);
491       if (!newSource && osrc != null
492               && dtm.getValueAt(i, 0).equals(nickname))
493       {
494         data[i][0] = local.getTitle();
495         data[i][1] = new Boolean(true);
496       }
497       else
498       {
499         data[i][0] = osrc;
500         data[i][1] = new Boolean(selectedSources.contains(osrc));
501       }
502     }
503     // Always add a new source at the end
504     if (newSource)
505     {
506       data[osize][0] = local.getTitle();
507       data[osize][1] = new Boolean(true);
508       selectedSources.add(local.getTitle());
509     }
510
511     refreshTableData(data);
512
513     SwingUtilities.invokeLater(new Runnable()
514     {
515       @Override
516       public void run()
517       {
518         scrollPane.getVerticalScrollBar()
519                 .setValue(scrollPane.getVerticalScrollBar().getMaximum());
520       }
521     });
522
523     displayFullDetails(local.getTitle());
524   }
525
526   public void editRemoveLocalSource(MouseEvent evt)
527   {
528     int selectedRow = table.getSelectionModel().getMinSelectionIndex();
529     if (selectedRow == -1)
530     {
531       return;
532     }
533
534     String nickname = table.getValueAt(selectedRow, 0).toString();
535
536     if (!sourceRegistry.getSource(nickname).isLocal())
537     {
538       JvOptionPane.showInternalMessageDialog(Desktop.desktop,
539               MessageManager.getString(
540                       "label.you_can_only_edit_or_remove_local_das_sources"),
541               MessageManager.getString("label.public_das_source"),
542               JvOptionPane.WARNING_MESSAGE);
543       return;
544     }
545
546     Object[] options = { "Edit", "Remove", "Cancel" };
547     int choice = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
548             "Do you want to edit or remove " + nickname + "?",
549             "Edit / Remove Local DAS Source",
550             JvOptionPane.YES_NO_CANCEL_OPTION,
551             JvOptionPane.QUESTION_MESSAGE, null, options, options[2]);
552
553     switch (choice)
554     {
555     case 0:
556       amendLocal(false);
557       break;
558     case 1:
559       sourceRegistry.removeLocalSource(sourceRegistry.getSource(nickname));
560       selectedSources.remove(nickname);
561       Object[][] data = new Object[sourceRegistry.getSources().size()][2];
562       int index = 0, l = table.getRowCount();
563
564       for (int i = 0; i < l; i++)
565       {
566         String nm;
567         if ((nm = (String) table.getValueAt(i, 0)).equals(nickname))
568         {
569           continue;
570         }
571         else
572         {
573           data[index][0] = nm;
574           data[index][1] = new Boolean(selectedSources.contains(nm));
575           index++;
576         }
577       }
578       refreshTableData(data);
579       SwingUtilities.invokeLater(new Runnable()
580       {
581         @Override
582         public void run()
583         {
584           scrollPane.getVerticalScrollBar()
585                   .setValue(scrollPane.getVerticalScrollBar().getMaximum());
586         }
587       });
588
589       break;
590     }
591   }
592
593   @Override
594   public void valueChanged(ListSelectionEvent evt)
595   {
596     // Called when the MainTable selection changes
597     if (evt.getValueIsAdjusting())
598     {
599       return;
600     }
601
602     displayFullDetails(null);
603
604     // Filter the displayed data sources
605
606     ArrayList names = new ArrayList();
607     ArrayList selected = new ArrayList();
608
609     // The features filter is not visible, but we must still
610     // filter the das source list here.
611     // July 2006 - only 6 sources fo not serve features
612     Object[] dummyFeatureList = new Object[] { "features" };
613     List<jalviewSourceI> srcs = sourceRegistry.getSources();
614     for (jalviewSourceI ds : srcs)
615     {
616
617       VERSION v = ds.getVersion();
618       List<COORDINATES> coords = v.getCOORDINATES();
619       if (ds.isLocal() || ((coords == null || coords.size() == 0)
620               && filter1.getSelectedIndex() == 0
621               && filter2.getSelectedIndex() == 0
622               && filter3.getSelectedIndex() == 0))
623       {
624         // THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT
625         // HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT
626         // IS ADDED FROM THE REGISTRY
627         names.add(ds.getTitle());
628         selected.add(new Boolean(selectedSources.contains(ds.getTitle())));
629         continue;
630       }
631
632       if (!selectedInList(dummyFeatureList, ds.getCapabilityList(v))
633               || !selectedInList(filter3.getSelectedValues(),
634                       ds.getLabelsFor(v)))
635       {
636         continue;
637       }
638
639       for (int j = 0; j < coords.size(); j++)
640       {
641         if (selectedInList(filter1.getSelectedValues(),
642                 new String[]
643                 { coords.get(j).getAuthority() })
644                 && selectedInList(filter2.getSelectedValues(), new String[]
645                 { coords.get(j).getSource() }))
646         {
647           names.add(ds.getTitle());
648           selected.add(
649                   new Boolean(selectedSources.contains(ds.getTitle())));
650           break;
651         }
652       }
653     }
654
655     int dSize = names.size();
656     Object[][] data = new Object[dSize][2];
657     for (int d = 0; d < dSize; d++)
658     {
659       data[d][0] = names.get(d);
660       data[d][1] = selected.get(d);
661     }
662
663     refreshTableData(data);
664   }
665
666   private boolean selectedInList(Object[] selection, String[] items)
667   {
668     for (int i = 0; i < selection.length; i++)
669     {
670       if (selection[i].equals("Any"))
671       {
672         return true;
673       }
674       if (items == null || items.length == 0)
675       {
676         return false;
677       }
678       String sel = (items[0].startsWith("das1:") ? "das1:" : "")
679               + selection[i];
680       for (int j = 0; j < items.length; j++)
681       {
682         if (sel.equals(items[j]))
683         {
684           return true;
685         }
686       }
687     }
688
689     return false;
690   }
691
692   void setSelectedFromProperties()
693   {
694     String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",
695             "uniprot");
696     StringTokenizer st = new StringTokenizer(active, "\t");
697     selectedSources = new Vector();
698     while (st.hasMoreTokens())
699     {
700       selectedSources.addElement(st.nextToken());
701     }
702   }
703
704   @Override
705   public void reset_actionPerformed(ActionEvent e)
706   {
707     registryURL.setText(sourceRegistry.getDasRegistryURL());
708   }
709
710   /**
711    * set the DAS source settings in the given jalview properties.
712    * 
713    * @param properties
714    */
715   public void saveProperties(Properties properties)
716   {
717     if (registryURL.getText() == null || registryURL.getText().length() < 1)
718     {
719       properties.remove(jalview.bin.Cache.DAS_REGISTRY_URL);
720     }
721     else
722     {
723       properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL,
724               registryURL.getText());
725     }
726
727     StringBuffer sb = new StringBuffer();
728     for (int r = 0; r < table.getModel().getRowCount(); r++)
729     {
730       if (((Boolean) table.getValueAt(r, 1)).booleanValue())
731       {
732         sb.append(table.getValueAt(r, 0) + "\t");
733       }
734     }
735
736     properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE,
737             sb.toString());
738
739     String sourceprop = sourceRegistry.getLocalSourceString();
740     properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sourceprop);
741   }
742
743   class DASTableModel extends AbstractTableModel
744   {
745
746     public DASTableModel(Object[][] data)
747     {
748       this.data = data;
749     }
750
751     private String[] columnNames = new String[] {
752         MessageManager.getString("label.nickname"),
753         MessageManager.getString("label.use_source") };
754
755     private Object[][] data;
756
757     @Override
758     public int getColumnCount()
759     {
760       return columnNames.length;
761     }
762
763     @Override
764     public int getRowCount()
765     {
766       return data.length;
767     }
768
769     @Override
770     public String getColumnName(int col)
771     {
772       return columnNames[col];
773     }
774
775     @Override
776     public Object getValueAt(int row, int col)
777     {
778       return data[row][col];
779     }
780
781     /*
782      * JTable uses this method to determine the default renderer/ editor for
783      * each cell. If we didn't implement this method, then the last column would
784      * contain text ("true"/"false"), rather than a check box.
785      */
786     @Override
787     public Class getColumnClass(int c)
788     {
789       return getValueAt(0, c).getClass();
790     }
791
792     /*
793      * Don't need to implement this method unless your table's editable.
794      */
795     @Override
796     public boolean isCellEditable(int row, int col)
797     {
798       // Note that the data/cell address is constant,
799       // no matter where the cell appears onscreen.
800       return col == 1;
801
802     }
803
804     /*
805      * Don't need to implement this method unless your table's data can change.
806      */
807     @Override
808     public void setValueAt(Object value, int row, int col)
809     {
810       data[row][col] = value;
811       fireTableCellUpdated(row, col);
812
813       String name = getValueAt(row, 0).toString();
814       boolean selected = ((Boolean) value).booleanValue();
815
816       if (selectedSources.contains(name) && !selected)
817       {
818         selectedSources.remove(name);
819       }
820
821       if (!selectedSources.contains(name) && selected)
822       {
823         selectedSources.add(name);
824       }
825     }
826   }
827
828   public void initDasSources()
829   {
830
831     Thread thr = new Thread(new Runnable()
832     {
833       @Override
834       public void run()
835       {
836         // this actually initialises the das source list
837         paintComponent(null); // yuk
838       }
839     });
840     thr.start();
841     while (loadingDasSources || sourceRegistry == null)
842     {
843       try
844       {
845         Thread.sleep(10);
846       } catch (Exception e)
847       {
848       }
849       ;
850     }
851   }
852
853   /**
854    * disable or enable the buttons on the source browser
855    * 
856    * @param b
857    */
858   public void setGuiEnabled(boolean b)
859   {
860     refresh.setEnabled(b);
861     addLocal.setEnabled(b);
862   }
863 }