From: James Procter Date: Wed, 20 Sep 2023 16:59:26 +0000 (+0100) Subject: JAL-4265 JAL-4267 added a ‘restoreSession’ StructureViewer.getBinding() method that... X-Git-Tag: Release_2_11_4_0~177 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6f9554d86c10332d0d90cdb86ccf2ec94f7b4ebe;p=jalview.git JAL-4265 JAL-4267 added a ‘restoreSession’ StructureViewer.getBinding() method that allows a snapshot to be explicitly reloaded in place. --- diff --git a/src/jalview/ext/jmol/JmolCommands.java b/src/jalview/ext/jmol/JmolCommands.java index 19d64f0..f9ba1e4 100644 --- a/src/jalview/ext/jmol/JmolCommands.java +++ b/src/jalview/ext/jmol/JmolCommands.java @@ -316,6 +316,12 @@ public class JmolCommands extends StructureCommandsBase return new StructureCommand( "load FILES \"" + Platform.escapeBackslashes(file) + "\""); } + @Override + public StructureCommandI restoreSession(String filePath) + { + return new StructureCommand( + "restore STATE \"" + Platform.escapeBackslashes(filePath) + "\""); + } /** * Obsolete method, only referenced from diff --git a/src/jalview/structure/StructureCommandsBase.java b/src/jalview/structure/StructureCommandsBase.java index 7f919ce..9c2bc6b 100644 --- a/src/jalview/structure/StructureCommandsBase.java +++ b/src/jalview/structure/StructureCommandsBase.java @@ -277,4 +277,10 @@ public abstract class StructureCommandsBase implements StructureCommandsI { return null; } + + @Override + public StructureCommandI restoreSession(String filePath) + { + return loadFile(filePath); + } } diff --git a/src/jalview/structure/StructureCommandsI.java b/src/jalview/structure/StructureCommandsI.java index 575f256..b1e1486 100644 --- a/src/jalview/structure/StructureCommandsI.java +++ b/src/jalview/structure/StructureCommandsI.java @@ -193,6 +193,15 @@ public interface StructureCommandsI * @return */ StructureCommandI openSession(String filepath); + + /** + * Returns command to restore a previously saved version of an existing structure viewer session file. + * Default implementation calls 'openSession' + * @param filePath + * @return + */ + StructureCommandI restoreSession(String filePath); + /** * Returns a command to ask the viewer to close down diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index 6385551..4b11494 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -1546,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 *