vamsas connects and updates are threaded with a progress bar.
[jalview.git] / src / jalview / gui / Desktop.java
index 36fbcf9..fb2c65f 100755 (executable)
@@ -815,21 +815,45 @@ public class Desktop
   {
     if (fileLoadingCount == 0)
     {
+      addProgressPanel("Loading File: " + fileName + "   ");
+      
+    }
+    fileLoadingCount++;
+  }
+  private JProgressBar addProgressPanel(String string)
+  {
+    if (progressPanel==null)
+    {
       progressPanel = new JPanel(new BorderLayout());
-      JProgressBar progressBar = new JProgressBar();
-      progressBar.setIndeterminate(true);
+      totalProgressCount=0;
+    }
+    JProgressBar progressBar = new JProgressBar();
+    progressBar.setIndeterminate(true);
 
-      progressPanel.add(new JLabel("Loading File: " + fileName + "   "),
-                        BorderLayout.WEST);
+    progressPanel.add(new JLabel(string),
+                      BorderLayout.WEST);
 
-      progressPanel.add(progressBar, BorderLayout.CENTER);
+    progressPanel.add(progressBar, BorderLayout.CENTER);
 
-      instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
+    instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
+    totalProgressCount++;
+    validate();
+    return progressBar;
+  }
+  int totalProgressCount=0;
+  private void removeProgressPanel(JProgressBar progbar)
+  {
+    if (progressPanel!=null)
+    {
+      progressPanel.remove(progbar);
+      if (--totalProgressCount<1)
+      {
+        this.getContentPane().remove(progressPanel);
+        progressPanel = null;
+      }
     }
-    fileLoadingCount++;
     validate();
   }
-
   public void stopLoading()
   {
     fileLoadingCount--;
@@ -844,7 +868,6 @@ public class Desktop
     }
     validate();
   }
-
   public static int getViewCount(String viewId)
   {
     int count = 0;
@@ -1058,15 +1081,25 @@ public class Desktop
             {
               if (dsktp.v_client == null)
               {
-                dsktp.v_client = new VamsasApplication(dsktp, mysesid);
-                dsktp.setupVamsasConnectedGui();
-                dsktp.v_client.initial_update();
+                Thread rthr = new Thread(new Runnable() {
+
+                  public void run()
+                  {
+                    dsktp.v_client = new VamsasApplication(dsktp, mysesid);
+                    dsktp.setupVamsasConnectedGui();
+                    dsktp.v_client.initial_update();
+                  }
+                  
+                });
+                rthr.start();
               }
             };
           });
           VamsasStMenu.add(sessit);
         }
-        VamsasStMenu.setVisible(true);
+        // don't show an empty menu.
+        VamsasStMenu.setVisible(sess.length>0);
+        
       }
       else
       {
@@ -1128,6 +1161,7 @@ public class Desktop
         }
     }
   }
+  JProgressBar vamUpdate = null;
   /**
    * hide vamsas user gui bits when a vamsas document event is being handled.
    * @param b true to hide gui, false to reveal gui
@@ -1136,6 +1170,15 @@ public class Desktop
   {
     jalview.bin.Cache.log.debug("Setting gui for Vamsas update " +
                                 (b ? "in progress" : "finished"));
+    
+    if (vamUpdate!=null)
+    {
+      this.removeProgressPanel(vamUpdate);
+    }
+    if (b)
+    {
+      vamUpdate = this.addProgressPanel("Updating vamsas session");
+    }
     vamsasStart.setVisible(!b);
     vamsasStop.setVisible(!b);
     vamsasSave.setVisible(!b);