/[svn]/jsampler/trunk/src/org/jsampler/view/InstrumentsDbTreeModel.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/view/InstrumentsDbTreeModel.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1354 by iliev, Sun Sep 16 23:24:15 2007 UTC revision 1355 by iliev, Mon Sep 17 23:55:27 2007 UTC
# Line 72  public class InstrumentsDbTreeModel impl Line 72  public class InstrumentsDbTreeModel impl
72           */           */
73          public          public
74          InstrumentsDbTreeModel(final ActionListener l) {          InstrumentsDbTreeModel(final ActionListener l) {
75                    // TODO: This shouldn't be done in the event-dispatcing thread
76                    CC.getClient().addInstrumentsDbListener(getHandler());
77                    ///////
78                                    
79                    initDb(l);
80            }
81            
82            private void
83            initDb(final ActionListener l) {
84                  final InstrumentsDb.GetDrectory gdi = new InstrumentsDb.GetDrectory("/");                  final InstrumentsDb.GetDrectory gdi = new InstrumentsDb.GetDrectory("/");
85                  final InstrumentsDb.GetDrectories gd = new InstrumentsDb.GetDrectories("/");                  final InstrumentsDb.GetDrectories gd = new InstrumentsDb.GetDrectories("/");
86                  final InstrumentsDb.GetInstruments gi = new InstrumentsDb.GetInstruments("/");                  final InstrumentsDb.GetInstruments gi = new InstrumentsDb.GetInstruments("/");
# Line 83  public class InstrumentsDbTreeModel impl Line 92  public class InstrumentsDbTreeModel impl
92                                  root = new DbDirectoryTreeNode(gdi.getResult());                                  root = new DbDirectoryTreeNode(gdi.getResult());
93                                  fireNodeStructureChanged(root);                                  fireNodeStructureChanged(root);
94                                                                    
                                 // TODO: This shouldn't be done in the event-dispatcing thread  
                                 CC.getClient().addInstrumentsDbListener(getHandler());  
                                 ///////  
95                                  CC.getTaskQueue().add(gd);                                  CC.getTaskQueue().add(gd);
96                                  CC.getTaskQueue().add(gi);                                  CC.getTaskQueue().add(gi);
97                          }                          }
# Line 407  public class InstrumentsDbTreeModel impl Line 413  public class InstrumentsDbTreeModel impl
413                  String[] dirs = getDirectoryList(path);                  String[] dirs = getDirectoryList(path);
414                  if(dirs == null) return null;                  if(dirs == null) return null;
415                  if(dirs.length == 1) return root;                  if(dirs.length == 1) return root;
416                                    if(root == null) return null;
417                  DbDirectoryTreeNode node = root;                  DbDirectoryTreeNode node = root;
418                  boolean found = false;                  boolean found = false;
419                  for(int i = 1; i < dirs.length; i++) {                  for(int i = 1; i < dirs.length; i++) {
# Line 487  public class InstrumentsDbTreeModel impl Line 493  public class InstrumentsDbTreeModel impl
493                  directoryCountChanged(final InstrumentsDbEvent e) {                  directoryCountChanged(final InstrumentsDbEvent e) {
494                          SwingUtilities.invokeLater(new Runnable() {                          SwingUtilities.invokeLater(new Runnable() {
495                                  public void                                  public void
496                                  run() {                                  run() { updateDirectoryCount(e); }
                                         DbDirectoryTreeNode node = getNodeByPath(e.getPathName());  
                                         if(node == null) {  
                                                 return;  
                                         }  
                                         if(!node.isConnected()) {  
                                                 return;  
                                         }  
                                           
                                         updateDirectoryContent(node, e.getPathName());  
                                 }  
497                          });                          });
498                  }                  }
499                                    
500                    private void
501                    updateDirectoryCount(InstrumentsDbEvent e) {
502                            if(e.getPathName().equals("/") && root == null) {
503                                    /*
504                                     * If the directory tree failed to load due to a database
505                                     * corruption it may work now if the db has been formatted
506                                     */
507                                    initDb(null);
508                            }
509                            
510                            DbDirectoryTreeNode node = getNodeByPath(e.getPathName());
511                            if(node == null) return;
512                            if(!node.isConnected()) return;
513                            
514                            updateDirectoryContent(node, e.getPathName());
515                    }
516                    
517                  /**                  /**
518                   * Invoked when the settings of an instrument directory are changed.                   * Invoked when the settings of an instrument directory are changed.
519                   */                   */

Legend:
Removed from v.1354  
changed lines
  Added in v.1355

  ViewVC Help
Powered by ViewVC