refining - still debugging.
authorjprocter <Jim Procter>
Thu, 17 May 2007 18:03:10 +0000 (18:03 +0000)
committerjprocter <Jim Procter>
Thu, 17 May 2007 18:03:10 +0000 (18:03 +0000)
src/jalview/gui/VamsasApplication.java

index b3f3f6c..62e2d21 100644 (file)
@@ -61,9 +61,7 @@ public class VamsasApplication
    * @return list of current sessions or null if no session exists.
    */
   public static String[] getSessionList() throws Exception {
-    uk.ac.vamsas.client.IClientFactory clientfactory = null;
-    clientfactory = getClientFactory();
-    return clientfactory.getCurrentSessions();
+    return getClientFactory().getCurrentSessions();
   }
   /**
    * initialise, possibly with e valid session url
@@ -115,33 +113,11 @@ public class VamsasApplication
     {
       throw new Error("Impementation error! Vamsas Operations when client not initialised and connected.");
     }
-    this.addDocumentUpdateHandler();
-    this.startSession();
-    Cache.log.info("Jalview loading the Vamsas Session.");
-    // load in the vamsas archive for the first time
-    IClientDocument cdoc=null;
-    try
-    {
-      cdoc = vclient.getClientDocument();
-    }
-    catch (IOException e)
-    {
-      Cache.log.error("Serious: Exception whilst getting vamsas document",e);
-      return;
-    }
-    updateJalview(cdoc);
-    updateJalviewGui();
-    cdoc.setVamsasRoots(cdoc.getVamsasRoots()); // propagate update flags back
-    
-    try{
-      vclient.updateDocument(cdoc);
-    }
-    catch (Exception e)
-    {
-      Cache.log.error("Serious: Exception whilst updating vamsas document.",e);
-      return;
-    }
-    cdoc=null;
+    addDocumentUpdateHandler();
+    startSession();
+    Cache.log.debug("Jalview loading the Vamsas Session for the first time.");
+    dealWithDocumentUpdate();
+    Cache.log.debug("... finished update for the first time.");
   }
   /**
    * Update all windows after a vamsas datamodel change.
@@ -150,7 +126,7 @@ public class VamsasApplication
    */
   protected void updateJalviewGui() 
   {
-    JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+    JInternalFrame[] frames = jdesktop.getAllFrames();
 
     if (frames == null)
     {
@@ -176,38 +152,11 @@ public class VamsasApplication
           e);
     }
   }
-  /**
-   * this will close all windows currently in Jalview.
-   *
-
-    protected void closeWindows() {
-     JInternalFrame[] frames = Desktop.desktop.getAllFrames();
-
-        if (frames == null)
-        {
-            return;
-        }
-
-        try
-        {
-            for (int i = frames.length - 1; i > -1; i--) {
-             frames[i].dispose();
-            }
-        } catch (Exception e) {
-         Cache.log.error("Whilst closing windows",e);
-        }
-
-    }
-
-    public void get_update(VamsasArchive doc) {
-     // Close windows - load update.
-     Cache.log.info("Jalview updating from Vamsas Session.");
-    }
-   */
   public void push_update()
   {
-    disableGui(true);
-    Cache.log.info("Jalview updating the Vamsas Session.");
+    Cache.log.info("Jalview updating to the Vamsas Session.");
+    dealWithDocumentUpdate();
+    /*
     IClientDocument cdoc=null;
     try
     {
@@ -224,8 +173,8 @@ public class VamsasApplication
     updateJalviewGui();
     cdoc.setVamsasRoots(cdoc.getVamsasRoots()); // propagate update flags back
     vclient.updateDocument(cdoc);
-    disableGui(false);
-    cdoc = null;
+    */
+    Cache.log.info("Jalview finished updating to the Vamsas Session.");
   }
 
   public void end_session()
@@ -241,6 +190,7 @@ public class VamsasApplication
       } else {
         Cache.log.warn("JV Client leaving a session that's its not joined yet.");
       }
+      joinedSession=false;
       vclient = null;
       app=null; user = null;
       jv2vobj = null;
@@ -254,10 +204,13 @@ public class VamsasApplication
 
   public void updateJalview(IClientDocument cdoc)
   {
+    Cache.log.debug("Jalview updating from sesion document ..");
     ensureJvVamsas();
     VamsasAppDatastore vds = new VamsasAppDatastore(cdoc, vobj2jv, jv2vobj,
                                               baseProvEntry());
     vds.updateToJalview();
+    Cache.log.debug(".. finished updating from sesion document.");
+    
   }
   private void ensureJvVamsas()
   {
@@ -315,31 +268,36 @@ public class VamsasApplication
     pentry.setAction("created");
     return pentry;
   }
-
+  protected void dealWithDocumentUpdate()
+  {
+    // called by update handler for document update.
+    Cache.log.debug("Updating jalview from changed vamsas document.");
+    disableGui(true);
+    try {
+      IClientDocument cdoc = vclient.getClientDocument();
+      updateJalview(cdoc);
+      // cdoc.setVamsasRoots(cdoc.getVamsasRoots());
+      vclient.updateDocument(cdoc);
+      cdoc=null;
+    } catch (Exception ee) {
+      System.err.println("Exception whilst updating :");
+      ee.printStackTrace(System.err);
+    }
+    Cache.log.debug("Finished updating from document change.");
+    disableGui(false);
+  }
   private void addDocumentUpdateHandler()
   {
-    final IClient vorbaclient = vclient;
     final VamsasApplication client = this;
-    vorbaclient.addDocumentUpdateHandler(new PropertyChangeListener() {
+    vclient.addDocumentUpdateHandler(new PropertyChangeListener() {
       public void propertyChange(PropertyChangeEvent evt)
       {
-        // update handler for document update.
-        Cache.log.debug("Updating jalview from changed vamsas document.");
-        client.disableGui(true);
-        try {
-          IClientDocument cdoc = vorbaclient.getClientDocument();
-          client.updateJalview(cdoc);
-          // cdoc.setVamsasRoots(cdoc.getVamsasRoots());
-          vorbaclient.updateDocument(cdoc);
-          cdoc=null;
-        } catch (Exception ee) {
-          System.err.println("Exception whilst updating :");
-          ee.printStackTrace(System.err);
-        }
-        Cache.log.debug("Finished updating from document change.");
-        client.disableGui(false);
+        Cache.log.debug("Dealing with document update event.");
+        client.dealWithDocumentUpdate();
+        Cache.log.debug("finished dealing with event.");
       }
     });
+    Cache.log.debug("Added Jalview handler for vamsas document updates.");
   }
   public void disableGui(boolean b)
   {