JAL-2089 patch broken merge to master for Release 2.10.0b1
[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.JOptionPane;
42 import javax.swing.JPanel;
43 import javax.swing.JTextField;
44 import javax.swing.ListSelectionModel;
45 import javax.swing.SwingUtilities;
46 import javax.swing.event.ListSelectionEvent;
47 import javax.swing.event.ListSelectionListener;
48 import javax.swing.table.AbstractTableModel;
49
50 import org.biodas.jdas.schema.sources.CAPABILITY;
51 import org.biodas.jdas.schema.sources.COORDINATES;
52 import org.biodas.jdas.schema.sources.PROP;
53 import org.biodas.jdas.schema.sources.VERSION;
54
55 public class DasSourceBrowser extends GDasSourceBrowser implements
56         Runnable, ListSelectionListener
57 {
58   DasSourceRegistryI sourceRegistry = null;
59
60   Vector<String> selectedSources;
61
62   public DasSourceBrowser(FeatureSettings featureSettings)
63   {
64     fs = featureSettings;
65     // TODO DasSourceRegistryProvider API
66     sourceRegistry = jalview.bin.Cache.getDasSourceRegistry();
67     String registry = sourceRegistry.getDasRegistryURL();
68
69     registryURL.setText(registry);
70
71     setSelectedFromProperties();
72
73     displayFullDetails(null);
74     table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
75
76     filter1.addListSelectionListener(this);
77     filter2.addListSelectionListener(this);
78     filter3.addListSelectionListener(this);
79
80     // Ask to be notified of selection changes.
81     ListSelectionModel rowSM = table.getSelectionModel();
82     rowSM.addListSelectionListener(new ListSelectionListener()
83     {
84       @Override
85       public void valueChanged(ListSelectionEvent e)
86       {
87         ListSelectionModel lsm = (ListSelectionModel) e.getSource();
88         if (!lsm.isSelectionEmpty())
89         {
90           int selectedRow = lsm.getMinSelectionIndex();
91           displayFullDetails(table.getValueAt(selectedRow, 0).toString());
92         }
93       }
94     });
95
96     table.addMouseListener(new MouseAdapter()
97     {
98       @Override
99       public void mouseClicked(MouseEvent evt)
100       {
101         if (evt.getClickCount() == 2 || evt.isPopupTrigger())
102         {
103           editRemoveLocalSource(evt);
104         }
105       }
106     });
107
108     if (sourceRegistry.getSources() != null)
109     {
110       init();
111     }
112   }
113
114   FeatureSettings fs = null;
115
116   private boolean loadingDasSources;
117
118   public DasSourceBrowser()
119   {
120     this(null);
121   }
122
123   @Override
124   public void paintComponent(java.awt.Graphics g)
125   {
126     if (sourceRegistry == null)
127     {
128       Thread worker = new Thread(this);
129       worker.start();
130     }
131   }
132
133   void init()
134   {
135     List<jalviewSourceI> sources = sourceRegistry.getSources();
136     int dSize = sources.size();
137     Object[][] data = new Object[dSize][2];
138     for (int i = 0; i < dSize; i++)
139     {
140       data[i][0] = sources.get(i).getTitle(); // what's equivalent of nickname
141       data[i][1] = new Boolean(selectedSources.contains(sources.get(i)
142               .getTitle()));
143     }
144
145     refreshTableData(data);
146     setCapabilities(sourceRegistry);
147
148     javax.swing.SwingUtilities.invokeLater(new Runnable()
149     {
150       @Override
151       public void run()
152       {
153         TableSorter sorter = (TableSorter) table.getModel();
154         sorter.setSortingStatus(1, TableSorter.DESCENDING);
155         sorter.setSortingStatus(1, TableSorter.NOT_SORTED);
156       }
157     });
158
159     progressBar.setIndeterminate(false);
160     progressBar.setVisible(false);
161     addLocal.setVisible(true);
162     refresh.setVisible(true);
163   }
164
165   public void refreshTableData(Object[][] data)
166   {
167     TableSorter sorter = new TableSorter(new DASTableModel(data));
168     sorter.setTableHeader(table.getTableHeader());
169     table.setModel(sorter);
170   }
171
172   void displayFullDetails(String nickName)
173   {
174
175     StringBuffer text = new StringBuffer(
176             "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");
177
178     if (nickName == null)
179     {
180       fullDetails.setText(text
181               + MessageManager
182                       .getString("label.select_das_service_from_table"));
183       return;
184     }
185
186     int dSize = sourceRegistry.getSources().size();
187     for (jalviewSourceI ds : sourceRegistry.getSources())
188     {
189       if (!ds.getTitle().equals(nickName))
190       {
191         continue;
192       }
193
194       VERSION latest = ds.getVersion();
195       text.append("<font color=\"#0000FF\">Id:</font> " + ds.getUri()
196               + "<br>");
197       text.append("<font color=\"#0000FF\">Nickname:</font> "
198               + ds.getTitle() + "<br>");
199
200       text.append("<font color=\"#0000FF\">URL:</font> <a href=\""
201               + ds.getSourceURL() + "\">" + ds.getSourceURL() + "</a>"
202               + "<br>");
203       if (!ds.isLocal())
204       {
205         if (ds.getDocHref() != null && ds.getDocHref().length() > 0)
206         {
207           text.append("<font color=\"#0000FF\">Site:</font> <a href=\""
208                   + ds.getDocHref() + "\">" + ds.getDocHref() + "</a>"
209                   + "<br>");
210         }
211
212         text.append("<font color=\"#0000FF\">Description:</font> "
213                 + ds.getDescription() + "<br>");
214
215         text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
216                 + ds.getEmail() + "\">" + ds.getEmail() + "</a>" + "<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<jalviewSourceI>();
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);
372     worker.start();
373   }
374
375   private void setCapabilities(DasSourceRegistryI sourceRegistry2)
376   {
377     Vector<String> authority = new Vector<String>();
378     Vector<String> type = new Vector<String>();
379     Vector<String> label = new Vector<String>();
380     Vector<String> taxIds = new Vector<String>();
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 = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
463             panel,
464             MessageManager.getString("label.enter_local_das_source"),
465             JOptionPane.OK_CANCEL_OPTION);
466
467     if (reply != JOptionPane.OK_OPTION)
468     {
469       return;
470     }
471
472     if (!urltf.getText().endsWith("/"))
473     {
474       urltf.setText(urltf.getText() + "/");
475     }
476
477     jalviewSourceI local = sourceRegistry.createLocalSource(
478             urltf.getText(), nametf.getText(), seqs.isSelected(), true);
479     List sources = sourceRegistry.getSources();
480     int osize = sources.size();
481     int size = osize + (newSource ? 1 : 0);
482
483     Object[][] data = new Object[size][2];
484     DASTableModel dtm = (table != null) ? (DASTableModel) ((TableSorter) table
485             .getModel()).getTableModel() : null;
486     for (int i = 0; i < osize; i++)
487     {
488       String osrc = (dtm == null || i >= osize) ? null : (String) dtm
489               .getValueAt(i, 0);
490       if (!newSource && osrc != null
491               && dtm.getValueAt(i, 0).equals(nickname))
492       {
493         data[i][0] = local.getTitle();
494         data[i][1] = new Boolean(true);
495       }
496       else
497       {
498         data[i][0] = osrc;
499         data[i][1] = new Boolean(selectedSources.contains(osrc));
500       }
501     }
502     // Always add a new source at the end
503     if (newSource)
504     {
505       data[osize][0] = local.getTitle();
506       data[osize][1] = new Boolean(true);
507       selectedSources.add(local.getTitle());
508     }
509
510     refreshTableData(data);
511
512     SwingUtilities.invokeLater(new Runnable()
513     {
514       @Override
515       public void run()
516       {
517         scrollPane.getVerticalScrollBar().setValue(
518                 scrollPane.getVerticalScrollBar().getMaximum());
519       }
520     });
521
522     displayFullDetails(local.getTitle());
523   }
524
525   public void editRemoveLocalSource(MouseEvent evt)
526   {
527     int selectedRow = table.getSelectionModel().getMinSelectionIndex();
528     if (selectedRow == -1)
529     {
530       return;
531     }
532
533     String nickname = table.getValueAt(selectedRow, 0).toString();
534
535     if (!sourceRegistry.getSource(nickname).isLocal())
536     {
537       JOptionPane
538               .showInternalMessageDialog(
539                       Desktop.desktop,
540                       MessageManager
541                               .getString("label.you_can_only_edit_or_remove_local_das_sources"),
542                       MessageManager.getString("label.public_das_source"),
543                       JOptionPane.WARNING_MESSAGE);
544       return;
545     }
546
547     Object[] options = { "Edit", "Remove", "Cancel" };
548     int choice = JOptionPane.showInternalOptionDialog(Desktop.desktop,
549             "Do you want to edit or remove " + nickname + "?",
550             "Edit / Remove Local DAS Source",
551             JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
552             null, options, options[2]);
553
554     switch (choice)
555     {
556     case 0:
557       amendLocal(false);
558       break;
559     case 1:
560       sourceRegistry.removeLocalSource(sourceRegistry.getSource(nickname));
561       selectedSources.remove(nickname);
562       Object[][] data = new Object[sourceRegistry.getSources().size()][2];
563       int index = 0,
564       l = table.getRowCount();
565
566       for (int i = 0; i < l; i++)
567       {
568         String nm;
569         if ((nm = (String) table.getValueAt(i, 0)).equals(nickname))
570         {
571           continue;
572         }
573         else
574         {
575           data[index][0] = nm;
576           data[index][1] = new Boolean(selectedSources.contains(nm));
577           index++;
578         }
579       }
580       refreshTableData(data);
581       SwingUtilities.invokeLater(new Runnable()
582       {
583         @Override
584         public void run()
585         {
586           scrollPane.getVerticalScrollBar().setValue(
587                   scrollPane.getVerticalScrollBar().getMaximum());
588         }
589       });
590
591       break;
592     }
593   }
594
595   @Override
596   public void valueChanged(ListSelectionEvent evt)
597   {
598     // Called when the MainTable selection changes
599     if (evt.getValueIsAdjusting())
600     {
601       return;
602     }
603
604     displayFullDetails(null);
605
606     // Filter the displayed data sources
607
608     ArrayList names = new ArrayList();
609     ArrayList selected = new ArrayList();
610
611     // The features filter is not visible, but we must still
612     // filter the das source list here.
613     // July 2006 - only 6 sources fo not serve features
614     Object[] dummyFeatureList = new Object[] { "features" };
615     List<jalviewSourceI> srcs = sourceRegistry.getSources();
616     for (jalviewSourceI ds : srcs)
617     {
618
619       VERSION v = ds.getVersion();
620       List<COORDINATES> coords = v.getCOORDINATES();
621       if (ds.isLocal()
622               || ((coords == null || coords.size() == 0)
623                       && filter1.getSelectedIndex() == 0
624                       && filter2.getSelectedIndex() == 0 && filter3
625                       .getSelectedIndex() == 0))
626       {
627         // THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT
628         // HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT
629         // IS ADDED FROM THE REGISTRY
630         names.add(ds.getTitle());
631         selected.add(new Boolean(selectedSources.contains(ds.getTitle())));
632         continue;
633       }
634
635       if (!selectedInList(dummyFeatureList, ds.getCapabilityList(v))
636               || !selectedInList(filter3.getSelectedValues(),
637                       ds.getLabelsFor(v)))
638       {
639         continue;
640       }
641
642       for (int j = 0; j < coords.size(); j++)
643       {
644         if (selectedInList(filter1.getSelectedValues(),
645                 new String[] { coords.get(j).getAuthority() })
646                 && selectedInList(filter2.getSelectedValues(), new String[]
647                 { coords.get(j).getSource() }))
648         {
649           names.add(ds.getTitle());
650           selected.add(new Boolean(selectedSources.contains(ds.getTitle())));
651           break;
652         }
653       }
654     }
655
656     int dSize = names.size();
657     Object[][] data = new Object[dSize][2];
658     for (int d = 0; d < dSize; d++)
659     {
660       data[d][0] = names.get(d);
661       data[d][1] = selected.get(d);
662     }
663
664     refreshTableData(data);
665   }
666
667   private boolean selectedInList(Object[] selection, String[] items)
668   {
669     for (int i = 0; i < selection.length; i++)
670     {
671       if (selection[i].equals("Any"))
672       {
673         return true;
674       }
675       if (items == null || items.length == 0)
676       {
677         return false;
678       }
679       String sel = (items[0].startsWith("das1:") ? "das1:" : "")
680               + selection[i];
681       for (int j = 0; j < items.length; j++)
682       {
683         if (sel.equals(items[j]))
684         {
685           return true;
686         }
687       }
688     }
689
690     return false;
691   }
692
693   void setSelectedFromProperties()
694   {
695     String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",
696             "uniprot");
697     StringTokenizer st = new StringTokenizer(active, "\t");
698     selectedSources = new Vector();
699     while (st.hasMoreTokens())
700     {
701       selectedSources.addElement(st.nextToken());
702     }
703   }
704
705   @Override
706   public void reset_actionPerformed(ActionEvent e)
707   {
708     registryURL.setText(sourceRegistry.getDasRegistryURL());
709   }
710
711   /**
712    * set the DAS source settings in the given jalview properties.
713    * 
714    * @param properties
715    */
716   public void saveProperties(Properties properties)
717   {
718     if (registryURL.getText() == null || registryURL.getText().length() < 1)
719     {
720       properties.remove(jalview.bin.Cache.DAS_REGISTRY_URL);
721     }
722     else
723     {
724       properties.setProperty(jalview.bin.Cache.DAS_REGISTRY_URL,
725               registryURL.getText());
726     }
727
728     StringBuffer sb = new StringBuffer();
729     for (int r = 0; r < table.getModel().getRowCount(); r++)
730     {
731       if (((Boolean) table.getValueAt(r, 1)).booleanValue())
732       {
733         sb.append(table.getValueAt(r, 0) + "\t");
734       }
735     }
736
737     properties.setProperty(jalview.bin.Cache.DAS_ACTIVE_SOURCE,
738             sb.toString());
739
740     String sourceprop = sourceRegistry.getLocalSourceString();
741     properties.setProperty(jalview.bin.Cache.DAS_LOCAL_SOURCE, sourceprop);
742   }
743
744   class DASTableModel extends AbstractTableModel
745   {
746
747     public DASTableModel(Object[][] data)
748     {
749       this.data = data;
750     }
751
752     private String[] columnNames = new String[] {
753         MessageManager.getString("label.nickname"),
754         MessageManager.getString("label.use_source") };
755
756     private Object[][] data;
757
758     @Override
759     public int getColumnCount()
760     {
761       return columnNames.length;
762     }
763
764     @Override
765     public int getRowCount()
766     {
767       return data.length;
768     }
769
770     @Override
771     public String getColumnName(int col)
772     {
773       return columnNames[col];
774     }
775
776     @Override
777     public Object getValueAt(int row, int col)
778     {
779       return data[row][col];
780     }
781
782     /*
783      * JTable uses this method to determine the default renderer/ editor for
784      * each cell. If we didn't implement this method, then the last column would
785      * contain text ("true"/"false"), rather than a check box.
786      */
787     @Override
788     public Class getColumnClass(int c)
789     {
790       return getValueAt(0, c).getClass();
791     }
792
793     /*
794      * Don't need to implement this method unless your table's editable.
795      */
796     @Override
797     public boolean isCellEditable(int row, int col)
798     {
799       // Note that the data/cell address is constant,
800       // no matter where the cell appears onscreen.
801       return col == 1;
802
803     }
804
805     /*
806      * Don't need to implement this method unless your table's data can change.
807      */
808     @Override
809     public void setValueAt(Object value, int row, int col)
810     {
811       data[row][col] = value;
812       fireTableCellUpdated(row, col);
813
814       String name = getValueAt(row, 0).toString();
815       boolean selected = ((Boolean) value).booleanValue();
816
817       if (selectedSources.contains(name) && !selected)
818       {
819         selectedSources.remove(name);
820       }
821
822       if (!selectedSources.contains(name) && selected)
823       {
824         selectedSources.add(name);
825       }
826     }
827   }
828
829   public void initDasSources()
830   {
831
832     Thread thr = new Thread(new Runnable()
833     {
834       @Override
835       public void run()
836       {
837         // this actually initialises the das source list
838         paintComponent(null); // yuk
839       }
840     });
841     thr.start();
842     while (loadingDasSources || sourceRegistry == null)
843     {
844       try
845       {
846         Thread.sleep(10);
847       } catch (Exception e)
848       {
849       }
850       ;
851     }
852   }
853
854   /**
855    * disable or enable the buttons on the source browser
856    * 
857    * @param b
858    */
859   public void setGuiEnabled(boolean b)
860   {
861     refresh.setEnabled(b);
862     addLocal.setEnabled(b);
863   }
864 }