From 6f9554d86c10332d0d90cdb86ccf2ec94f7b4ebe Mon Sep 17 00:00:00 2001 From: James Procter Date: Wed, 20 Sep 2023 17:59:26 +0100 Subject: [PATCH] =?utf8?q?JAL-4265=20JAL-4267=20added=20a=20=E2=80=98restore?= =?utf8?q?Session=E2=80=99=20StructureViewer.getBinding()=20method=20that=20?= =?utf8?q?allows=20a=20snapshot=20to=20be=20explicitly=20reloaded=20in=20pla?= =?utf8?q?ce.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/jalview/ext/jmol/JmolCommands.java | 6 +++++ src/jalview/structure/StructureCommandsBase.java | 6 +++++ src/jalview/structure/StructureCommandsI.java | 9 +++++++ .../structures/models/AAStructureBindingModel.java | 25 ++++++++++++++++++++ 4 files changed, 46 insertions(+) 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 * -- 1.7.10.2