JAL-4265 JAL-4267 added a ‘restoreSession’ StructureViewer.getBinding() method that...
[jalview.git] / src / jalview / structures / models / AAStructureBindingModel.java
index 8436b48..4b11494 100644 (file)
@@ -780,7 +780,7 @@ public abstract class AAStructureBindingModel
 
     if (waiting)
     {
-      System.err.println(
+      jalview.bin.Console.errPrintln(
               "Timed out waiting for structure viewer to load file "
                       + notLoaded);
       return false;
@@ -973,7 +973,10 @@ public abstract class AAStructureBindingModel
       }
       List<StructureCommandI> finalView = commandGenerator
               .centerViewOn(models);
-      executeCommands(finalView, false, "Centered on Superposition");
+      if (finalView != null && finalView.size() > 0)
+      {
+        executeCommands(finalView, false, "Centered on Superposition");
+      }
     }
     return error;
   }
@@ -1095,7 +1098,7 @@ public abstract class AAStructureBindingModel
    * @param getReply
    * @param msg
    */
-  protected List<String> executeCommands(List<StructureCommandI> commands,
+  public List<String> executeCommands(List<StructureCommandI> commands,
           boolean getReply, String msg)
   {
     return executeCommand(getReply, msg,
@@ -1543,6 +1546,31 @@ public abstract class AAStructureBindingModel
     return f;
   }
 
+
+  /**
+   * Use restoreSession when you want to restore a previously saved sesssion to
+   * the running viewer instance.
+   * 
+   * @param absolutePath
+   */
+  public void restoreSession(String absolutePath)
+  {
+    String prefix = getViewerType().toString();
+    try {
+
+      StructureCommandI cmd = commandGenerator.restoreSession(absolutePath);
+      if (cmd != null)
+      {
+        executeCommand(cmd, false);
+      }
+    } catch (Throwable e)
+    {
+      Console.error(String.format("Error restoring %s session: %s", prefix,
+              e.toString()));
+    }
+
+  }
+
   /**
    * Saves the structure viewer session to the given file
    *