vamsas connects and updates are threaded with a progress bar.
authorjprocter <Jim Procter>
Mon, 5 Nov 2007 16:20:29 +0000 (16:20 +0000)
committerjprocter <Jim Procter>
Mon, 5 Nov 2007 16:20:29 +0000 (16:20 +0000)
src/jalview/gui/Desktop.java
src/jalview/gui/VamsasApplication.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);
index d0dbf16..bfe5487 100644 (file)
@@ -218,6 +218,7 @@ public class VamsasApplication
               "Impementation error! Vamsas Operations when client not initialised and connected.");
     }
     addDocumentUpdateHandler();
+    addStoreDocumentHandler();
     startSession();
     Cache.log
             .debug("Jalview loading the Vamsas Session for the first time.");
@@ -262,17 +263,27 @@ public class VamsasApplication
 
   public void push_update()
   {
-    Cache.log.info("Jalview updating to the Vamsas Session.");
-    dealWithDocumentUpdate(true);
-    /*
-     * IClientDocument cdoc=null; try { cdoc = vclient.getClientDocument(); }
-     * catch (Exception e) { Cache.log.error("Failed to get client document for
-     * update."); // RAISE A WARNING DIALOG disableGui(false); return; }
-     * updateVamsasDocument(cdoc); updateJalviewGui();
-     * cdoc.setVamsasRoots(cdoc.getVamsasRoots()); // propagate update flags
-     * back vclient.updateDocument(cdoc);
-     */
-    Cache.log.info("Jalview finished updating to the Vamsas Session.");
+    Thread udthread = new Thread(new Runnable() {
+
+      public void run()
+      {
+        Cache.log.info("Jalview updating to the Vamsas Session.");
+    
+        dealWithDocumentUpdate(true);
+        /*
+         * IClientDocument cdoc=null; try { cdoc = vclient.getClientDocument(); }
+         * catch (Exception e) { Cache.log.error("Failed to get client document for
+         * update."); // RAISE A WARNING DIALOG disableGui(false); return; }
+         * updateVamsasDocument(cdoc); updateJalviewGui();
+         * cdoc.setVamsasRoots(cdoc.getVamsasRoots()); // propagate update flags
+         * back vclient.updateDocument(cdoc);
+         */
+        Cache.log.info("Jalview finished updating to the Vamsas Session.");
+        // TODO Auto-generated method stub
+      }
+      
+    });
+    udthread.start();
   }
 
   public void end_session()
@@ -468,6 +479,30 @@ public class VamsasApplication
     Cache.log.debug("Added Jalview handler for vamsas document updates.");
   }
 
+  private void addStoreDocumentHandler()
+  {
+    final VamsasApplication client = this;
+    vclient.addVorbaEventHandler(uk.ac.vamsas.client.Events.DOCUMENT_REQUESTTOCLOSE, new PropertyChangeListener()
+    {
+      public void propertyChange(PropertyChangeEvent evt)
+      {
+        Cache.log.debug("Asking user if the vamsas session should be stored.");
+        int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
+                "The current VAMSAS session has unsaved data - do you want to save it ?",
+            "VAMSAS Session Shutdown",
+            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
+        
+            if(reply==JOptionPane.YES_OPTION)
+            {
+              Cache.log.debug("Prompting for vamsas store filename.");
+              Desktop.instance.vamsasSave_actionPerformed(null);
+              Cache.log.debug("Finished attempt at storing document.");
+            } 
+            Cache.log.debug("finished dealing with REQUESTTOCLOSE event.");
+      }
+    });
+    Cache.log.debug("Added Jalview handler for vamsas document updates.");
+  }
   public void disableGui(boolean b)
   {
     Desktop.instance.setVamsasUpdate(b);