From 4ee3a368d2de9eaa050137f7d45cfac0c432ef53 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 26 Jun 2020 10:39:08 +0100 Subject: [PATCH] JAL-3518 tidy up asynchronous structure command execution --- .../structures/models/AAStructureBindingModel.java | 39 +++++--------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index d92c78a..1afa15e 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -1058,16 +1058,16 @@ public abstract class AAStructureBindingModel private List executeCommand(StructureCommandI cmd, boolean getReply, String msg) { + final JalviewStructureDisplayI theViewer = getViewer(); + final long handle = msg == null ? 0 : theViewer.startProgressBar(msg); if (getReply) { /* * synchronous (same thread) execution so reply can be returned */ - final JalviewStructureDisplayI theViewer = getViewer(); - final long handle = msg == null ? 0 : theViewer.startProgressBar(msg); try { - return executeCommand(cmd, getReply); + return executeCommand(cmd, true); } finally { if (msg != null) @@ -1081,9 +1081,6 @@ public abstract class AAStructureBindingModel /* * asynchronous (new thread) execution if no reply needed */ - final JalviewStructureDisplayI theViewer = getViewer(); - final long handle = msg == null ? 0 : theViewer.startProgressBar(msg); - SwingUtilities.invokeLater(new Runnable() { @Override @@ -1116,8 +1113,7 @@ public abstract class AAStructureBindingModel boolean getReply); /** - * Executes one or more structure viewer commands. If a progress message is - * provided, it is shown first, and removed after all commands have been run. + * Executes one or more structure viewer commands * * @param commands * @param getReply @@ -1126,31 +1122,16 @@ public abstract class AAStructureBindingModel protected List executeCommands(List commands, boolean getReply, String msg) { - /* - * show progress message if specified - */ - final JalviewStructureDisplayI theViewer = getViewer(); - final long handle = msg == null ? 0 : theViewer.startProgressBar(msg); - List response = getReply ? new ArrayList<>() : null; - try - { - for (StructureCommandI cmd : commands) - { - List replies = executeCommand(cmd, getReply, null); - if (getReply && replies != null) - { - response.addAll(replies); - } - } - return response; - } finally + for (StructureCommandI cmd : commands) { - if (msg != null) + List replies = executeCommand(cmd, getReply, msg); + if (replies != null) { - theViewer.stopProgressBar(null, handle); + response.addAll(replies); } } + return response; } /** @@ -1168,7 +1149,7 @@ public abstract class AAStructureBindingModel List colourBySequenceCommands = commandGenerator .colourBySequence(colourMap); - executeCommands(colourBySequenceCommands, false, null); + executeCommands(colourBySequenceCommands, false, COLOURING_STRUCTURES); } /** -- 1.7.10.2