Merge branch 'feature/JAL-2664' into feature/JAL-2527
[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
56         implements 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(
142               selectedSources.contains(sources.get(i).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 + MessageManager
181               .getString("label.select_das_service_from_table"));
182       return;
183     }
184
185     int dSize = sourceRegistry.getSources().size();
186     for (jalviewSourceI ds : sourceRegistry.getSources())
187     {
188       if (!ds.getTitle().equals(nickName))
189       {
190         continue;
191       }
192
193       VERSION latest = ds.getVersion();
194       text.append(
195               "<font color=\"#0000FF\">Id:</font> " + ds.getUri() + "<br>");
196       text.append("<font color=\"#0000FF\">Nickname:</font> "
197               + ds.getTitle() + "<br>");
198
199       text.append("<font color=\"#0000FF\">URL:</font> <a href=\""
200               + ds.getSourceURL() + "\">" + ds.getSourceURL() + "</a>"
201               + "<br>");
202       if (!ds.isLocal())
203       {
204         if (ds.getDocHref() != null && ds.getDocHref().length() > 0)
205         {
206           text.append("<font color=\"#0000FF\">Site:</font> <a href=\""
207                   + ds.getDocHref() + "\">" + ds.getDocHref() + "</a>"
208                   + "<br>");
209         }
210
211         text.append("<font color=\"#0000FF\">Description:</font> "
212                 + ds.getDescription() + "<br>");
213
214         text.append(
215                 "<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"
216                         + ds.getEmail() + "\">" + ds.getEmail() + "</a>"
217                         + "<br>");
218
219         text.append("<font color=\"#0000FF\">Registered at:</font> "
220                 + latest.getCreated() + "<br>");
221
222         // TODO: Identify last successful test date
223         // text.append("<font color=\"#0000FF\">Last successful test:</font> "
224         // + latest.dasSources[i].getLeaseDate() + "<br>");
225       }
226       else
227       {
228         text.append("Source was added manually.<br/>");
229       }
230       text.append("<font color=\"#0000FF\">Labels:</font> ");
231       boolean b = false;
232       for (PROP labl : latest.getPROP())
233       {
234         if (labl.getName().equalsIgnoreCase("LABEL"))
235         {
236           if (b)
237           {
238             text.append(",");
239           }
240           text.append(" ");
241
242           text.append(labl.getValue());
243           b = true;
244         }
245         ;
246       }
247       text.append("<br>");
248
249       text.append("<font color=\"#0000FF\">Capabilities:</font> ");
250       CAPABILITY[] scap = latest.getCAPABILITY().toArray(new CAPABILITY[0]);
251       for (int j = 0; j < scap.length; j++)
252       {
253         text.append(scap[j].getType());
254         if (j < scap.length - 1)
255         {
256           text.append(", ");
257         }
258       }
259       text.append("<br>");
260
261       text.append("<font color=\"#0000FF\">Coordinates:</font>");
262       int i = 1;
263       for (COORDINATES dcs : latest.getCOORDINATES())
264       {
265         text.append("<br/>" + i++ + ". ");
266         text.append(dcs.getAuthority() + " : " + dcs.getSource());
267         if (dcs.getTaxid() != null && dcs.getTaxid().trim().length() > 0)
268         {
269           text.append(" [TaxId:" + dcs.getTaxid() + "]");
270         }
271         if (dcs.getVersion() != null
272                 && dcs.getVersion().trim().length() > 0)
273         {
274           {
275             text.append(" {v. " + dcs.getVersion() + "}");
276           }
277         }
278         text.append(" (<a href=\"" + dcs.getUri() + "\">" + dcs.getUri()
279                 + "</a>)");
280       }
281       text.append("</font></html>");
282
283       break;
284     }
285
286     fullDetails.setText(text.toString());
287     javax.swing.SwingUtilities.invokeLater(new Runnable()
288     {
289       @Override
290       public void run()
291       {
292         fullDetailsScrollpane.getVerticalScrollBar().setValue(0);
293       }
294     });
295   }
296
297   @Override
298   public void run()
299   {
300     loadingDasSources = true;
301
302     addLocal.setVisible(false);
303     refresh.setVisible(false);
304     progressBar.setVisible(true);
305     progressBar.setIndeterminate(true);
306     setParentGuiEnabled(false);
307     // Refresh the source list.
308     sourceRegistry.refreshSources();
309
310     init();
311
312     setParentGuiEnabled(true);
313     loadingDasSources = false;
314
315   }
316
317   private void setParentGuiEnabled(boolean b)
318   {
319     if (fs != null)
320     {
321       fs.fetchDAS.setEnabled(b);
322       fs.saveDAS.setEnabled(b);
323     }
324   }
325
326   public Vector<jalviewSourceI> getSelectedSources()
327   {
328     // wait around if we're still loading.
329     while (sourceRegistry == null)
330     {
331       if (!loadingDasSources)
332       {
333         new Thread(this).start();
334         try
335         {
336           Thread.sleep(5);
337         } catch (Exception e)
338         {
339         }
340         ;
341         while (loadingDasSources)
342         {
343           try
344           {
345             Thread.sleep(5);
346           } catch (Exception e)
347           {
348           }
349           ;
350         }
351         ;
352       }
353     }
354
355     Vector<jalviewSourceI> selected = new Vector<jalviewSourceI>();
356     for (String source : selectedSources)
357     {
358       jalviewSourceI srce = sourceRegistry.getSource(source);
359       if (srce != null)
360       {
361         selected.addElement(srce);
362       }
363     }
364     return selected;
365   }
366
367   @Override
368   public void refresh_actionPerformed(ActionEvent e)
369   {
370     saveProperties(jalview.bin.Cache.applicationProperties);
371
372     Thread worker = new Thread(this);
373     worker.start();
374   }
375
376   private void setCapabilities(DasSourceRegistryI sourceRegistry2)
377   {
378     Vector<String> authority = new Vector<String>();
379     Vector<String> type = new Vector<String>();
380     Vector<String> label = new Vector<String>();
381     Vector<String> taxIds = new Vector<String>();
382     authority.add("Any");
383     type.add("Any");
384     label.add("Any");
385
386     for (jalviewSourceI ds : sourceRegistry2.getSources())
387     {
388       VERSION latest = ds.getVersion();
389
390       for (COORDINATES cs : latest.getCOORDINATES())
391       {
392         if (!type.contains(cs.getSource()))
393         {
394           type.add(cs.getSource()); // source==category
395         }
396
397         if (!authority.contains(cs.getAuthority()))
398         {
399           authority.add(cs.getAuthority());
400         }
401       }
402
403       for (PROP slabel : latest.getPROP())
404       {
405         if (slabel.getName().equalsIgnoreCase("LABEL")
406                 && !label.contains(slabel.getValue()))
407         {
408           label.add(slabel.getValue());
409         }
410       }
411
412     }
413
414     filter1.setListData(authority);
415     filter2.setListData(type);
416     filter3.setListData(label);
417     // filter4 taxIds
418
419     javax.swing.SwingUtilities.invokeLater(new Runnable()
420     {
421       @Override
422       public void run()
423       {
424         filter1.setSelectedIndex(0);
425         filter2.setSelectedIndex(0);
426         filter3.setSelectedIndex(0);
427       }
428     });
429   }
430
431   @Override
432   public void amendLocal(boolean newSource)
433   {
434     String url = "http://localhost:8080/", nickname = "";
435     boolean seqsrc = false;
436     if (!newSource)
437     {
438       int selectedRow = table.getSelectionModel().getMinSelectionIndex();
439       nickname = table.getValueAt(selectedRow, 0).toString();
440       jalviewSourceI source = sourceRegistry.getSource(nickname);
441       url = source.getUri();
442       seqsrc = source.isSequenceSource();
443     }
444
445     JTextField nametf = new JTextField(nickname, 40);
446     JTextField urltf = new JTextField(url, 40);
447     JCheckBox seqs = new JCheckBox(
448             MessageManager.getString("label.sequence_source"));
449     seqs.setSelected(seqsrc);
450     JPanel panel = new JPanel(new BorderLayout());
451     JPanel pane12 = new JPanel(new BorderLayout());
452     pane12.add(new JLabel(MessageManager.getString("label.name:")),
453             BorderLayout.CENTER);
454     pane12.add(nametf, BorderLayout.EAST);
455     panel.add(pane12, BorderLayout.NORTH);
456     pane12 = new JPanel(new BorderLayout());
457     pane12.add(new JLabel(MessageManager.getString("label.url:")),
458             BorderLayout.NORTH);
459     pane12.add(seqs, BorderLayout.SOUTH);
460     pane12.add(urltf, BorderLayout.EAST);
461     panel.add(pane12, BorderLayout.SOUTH);
462
463     int reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
464             panel, MessageManager.getString("label.enter_local_das_source"),
465             JvOptionPane.OK_CANCEL_OPTION);
466
467     if (reply != JvOptionPane.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(urltf.getText(),
478             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)
485             ? (DASTableModel) ((TableSorter) table.getModel())
486                     .getTableModel()
487             : null;
488     for (int i = 0; i < osize; i++)
489     {
490       String osrc = (dtm == null || i >= osize) ? null
491               : (String) dtm.getValueAt(i, 0);
492       if (!newSource && osrc != null
493               && dtm.getValueAt(i, 0).equals(nickname))
494       {
495         data[i][0] = local.getTitle();
496         data[i][1] = new Boolean(true);
497       }
498       else
499       {
500         data[i][0] = osrc;
501         data[i][1] = new Boolean(selectedSources.contains(osrc));
502       }
503     }
504     // Always add a new source at the end
505     if (newSource)
506     {
507       data[osize][0] = local.getTitle();
508       data[osize][1] = new Boolean(true);
509       selectedSources.add(local.getTitle());
510     }
511
512     refreshTableData(data);
513
514     SwingUtilities.invokeLater(new Runnable()
515     {
516       @Override
517       public void run()
518       {
519         scrollPane.getVerticalScrollBar()
520                 .setValue(scrollPane.getVerticalScrollBar().getMaximum());
521       }
522     });
523
524     displayFullDetails(local.getTitle());
525   }
526
527   public void editRemoveLocalSource(MouseEvent evt)
528   {
529     int selectedRow = table.getSelectionModel().getMinSelectionIndex();
530     if (selectedRow == -1)
531     {
532       return;
533     }
534
535     String nickname = table.getValueAt(selectedRow, 0).toString();
536
537     if (!sourceRegistry.getSource(nickname).isLocal())
538     {
539       JvOptionPane.showInternalMessageDialog(Desktop.desktop,
540               MessageManager.getString(
541                       "label.you_can_only_edit_or_remove_local_das_sources"),
542               MessageManager.getString("label.public_das_source"),
543               JvOptionPane.WARNING_MESSAGE);
544       return;
545     }
546
547     Object[] options = { "Edit", "Remove", "Cancel" };
548     int choice = JvOptionPane.showInternalOptionDialog(Desktop.desktop,
549             "Do you want to edit or remove " + nickname + "?",
550             "Edit / Remove Local DAS Source",
551             JvOptionPane.YES_NO_CANCEL_OPTION,
552             JvOptionPane.QUESTION_MESSAGE, 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, l = table.getRowCount();
564
565       for (int i = 0; i < l; i++)
566       {
567         String nm;
568         if ((nm = (String) table.getValueAt(i, 0)).equals(nickname))
569         {
570           continue;
571         }
572         else
573         {
574           data[index][0] = nm;
575           data[index][1] = new Boolean(selectedSources.contains(nm));
576           index++;
577         }
578       }
579       refreshTableData(data);
580       SwingUtilities.invokeLater(new Runnable()
581       {
582         @Override
583         public void run()
584         {
585           scrollPane.getVerticalScrollBar()
586                   .setValue(scrollPane.getVerticalScrollBar().getMaximum());
587         }
588       });
589
590       break;
591     }
592   }
593
594   @Override
595   public void valueChanged(ListSelectionEvent evt)
596   {
597     // Called when the MainTable selection changes
598     if (evt.getValueIsAdjusting())
599     {
600       return;
601     }
602
603     displayFullDetails(null);
604
605     // Filter the displayed data sources
606
607     ArrayList names = new ArrayList();
608     ArrayList selected = new ArrayList();
609
610     // The features filter is not visible, but we must still
611     // filter the das source list here.
612     // July 2006 - only 6 sources fo not serve features
613     Object[] dummyFeatureList = new Object[] { "features" };
614     List<jalviewSourceI> srcs = sourceRegistry.getSources();
615     for (jalviewSourceI ds : srcs)
616     {
617
618       VERSION v = ds.getVersion();
619       List<COORDINATES> coords = v.getCOORDINATES();
620       if (ds.isLocal() || ((coords == null || coords.size() == 0)
621               && filter1.getSelectedIndex() == 0
622               && filter2.getSelectedIndex() == 0
623               && filter3.getSelectedIndex() == 0))
624       {
625         // THIS IS A FIX FOR LOCAL SOURCES WHICH DO NOT
626         // HAVE COORDINATE SYSTEMS, INFO WHICH AT PRESENT
627         // IS ADDED FROM THE REGISTRY
628         names.add(ds.getTitle());
629         selected.add(new Boolean(selectedSources.contains(ds.getTitle())));
630         continue;
631       }
632
633       if (!selectedInList(dummyFeatureList, ds.getCapabilityList(v))
634               || !selectedInList(filter3.getSelectedValues(),
635                       ds.getLabelsFor(v)))
636       {
637         continue;
638       }
639
640       for (int j = 0; j < coords.size(); j++)
641       {
642         if (selectedInList(filter1.getSelectedValues(),
643                 new String[]
644                 { coords.get(j).getAuthority() })
645                 && selectedInList(filter2.getSelectedValues(), new String[]
646                 { coords.get(j).getSource() }))
647         {
648           names.add(ds.getTitle());
649           selected.add(
650                   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 }