progress bar and OOM/Exception traps for project marshalling
authorjprocter <Jim Procter>
Sun, 19 Sep 2010 22:35:29 +0000 (22:35 +0000)
committerjprocter <Jim Procter>
Sun, 19 Sep 2010 22:35:29 +0000 (22:35 +0000)
src/jalview/gui/Desktop.java

index cf89494..7726179 100755 (executable)
@@ -1185,13 +1185,23 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     if (value == JalviewFileChooser.APPROVE_OPTION)
     {
       java.io.File choice = chooser.getSelectedFile();
-      JProgressBar progpanel = addProgressPanel("Saving jalview project "
-              + choice.getName());
+      setProgressBar("Saving jalview project "
+              + choice.getName(), choice.hashCode());
       jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
       // TODO catch and handle errors for savestate
-      new Jalview2XML().SaveState(choice);
-      removeProgressPanel(progpanel);
-
+      try {
+        new Jalview2XML().SaveState(choice);
+      } catch (OutOfMemoryError oom)
+      {
+        new OOMWarning("Whilst saving current state to "+choice.getName(), oom);
+      }
+      catch (Exception ex)
+      {
+        Cache.log.error("Problems whilst trying to save to "+choice.getName(),ex);
+        JOptionPane.showMessageDialog(this, "Error whilst saving current state to "+choice.getName(), "Couldn't save project", JOptionPane.WARNING_MESSAGE);
+      }
+      setProgressBar(null, choice.hashCode());
+      
     }
   }
 
@@ -1214,13 +1224,27 @@ public class Desktop extends jalview.jbgui.GDesktop implements
 
     if (value == JalviewFileChooser.APPROVE_OPTION)
     {
-      String choice = chooser.getSelectedFile().getAbsolutePath();
-      setProgressBar("loading jalview project "
-              + chooser.getSelectedFile().getName(), choice.hashCode());
+      final String choice = chooser.getSelectedFile().getAbsolutePath();
       jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
               .getSelectedFile().getParent());
-      new Jalview2XML().LoadJalviewAlign(choice);
+      new Thread(new Runnable() {
+        public void run() {
+          setProgressBar("loading jalview project "
+              + choice, choice.hashCode());
+          try {
+      new Jalview2XML().LoadJalviewAlign(choice); } 
+      catch (OutOfMemoryError oom)
+      {
+        new OOMWarning("Whilst loading project from "+choice, oom);
+      }
+      catch (Exception ex)
+      {
+        Cache.log.error("Problems whilst loading project from "+choice,ex);
+        JOptionPane.showMessageDialog(Desktop.desktop, "Error whilst loading project from "+choice, "Couldn't load project", JOptionPane.WARNING_MESSAGE);
+      }
       setProgressBar(null, choice.hashCode());
+        }
+      }).start();
     }
   }