From a58cab7213a42e6329854bcc7b7b7fed8a4005e6 Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Wed, 24 Nov 2021 17:31:59 +0100 Subject: [PATCH] JAL-3878 Make openEditsParamsDialog an interface static method. --- src/jalview/ws2/gui/AlignmentMenuBuilder.java | 42 ++-------------------- src/jalview/ws2/gui/AnnotationMenuBuilder.java | 44 +++--------------------- src/jalview/ws2/gui/MenuEntryProviderI.java | 43 +++++++++++++++++++++++ 3 files changed, 50 insertions(+), 79 deletions(-) diff --git a/src/jalview/ws2/gui/AlignmentMenuBuilder.java b/src/jalview/ws2/gui/AlignmentMenuBuilder.java index b29bde5..23ef2ae 100644 --- a/src/jalview/ws2/gui/AlignmentMenuBuilder.java +++ b/src/jalview/ws2/gui/AlignmentMenuBuilder.java @@ -7,7 +7,7 @@ import java.awt.event.MouseEvent; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.concurrent.CompletionStage; + import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.ToolTipManager; @@ -17,11 +17,8 @@ import jalview.gui.AlignFrame; import jalview.gui.AlignViewport; import jalview.gui.JvSwingUtils; import jalview.gui.WebserviceInfo; -import jalview.gui.WsJobParameters; import jalview.util.MessageManager; import jalview.ws.params.ArgumentI; -import jalview.ws.params.ParamDatastoreI; -import jalview.ws.params.WsParamSetI; import jalview.ws2.PollingTaskExecutor; import jalview.ws2.operations.AlignmentOperation; import jalview.ws2.operations.AlignmentWorker; @@ -86,7 +83,8 @@ public class AlignmentMenuBuilder implements MenuEntryProviderI AlignmentView msa = frame.gatherSequencesForAlignment(); if (msa != null) { - openEditParamsDialog(operation.getParamStore(), null, null) + MenuEntryProviderI.openEditParamsDialog(operation.getParamStore(), + null, null) .thenAcceptAsync((arguments) -> { if (arguments != null) { @@ -140,40 +138,6 @@ public class AlignmentMenuBuilder implements MenuEntryProviderI } } - private CompletionStage> openEditParamsDialog( - ParamDatastoreI paramStore, WsParamSetI preset, - List arguments) - { - WsJobParameters jobParams; - if (preset == null && arguments != null && arguments.size() > 0) - jobParams = new WsJobParameters(paramStore, preset, arguments); - else - jobParams = new WsJobParameters(paramStore, preset, null); - if (preset != null) - { - jobParams.setName(MessageManager.getString( - "label.adjusting_parameters_for_calculation")); - } - var stage = jobParams.showRunDialog(); - return stage.thenApply((startJob) -> { - if (startJob) - { - if (jobParams.getPreset() == null) - { - return jobParams.getJobParams(); - } - else - { - return jobParams.getPreset().getArguments(); - } - } - else - { - return null; - } - }); - } - private void startWorker(AlignFrame frame, AlignmentView msa, List arguments, boolean submitGaps) { diff --git a/src/jalview/ws2/gui/AnnotationMenuBuilder.java b/src/jalview/ws2/gui/AnnotationMenuBuilder.java index 5ddaa19..e007ce9 100644 --- a/src/jalview/ws2/gui/AnnotationMenuBuilder.java +++ b/src/jalview/ws2/gui/AnnotationMenuBuilder.java @@ -3,7 +3,6 @@ package jalview.ws2.gui; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.concurrent.CompletionStage; import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenu; @@ -12,11 +11,8 @@ import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; import jalview.gui.AlignFrame; -import jalview.gui.WsJobParameters; import jalview.util.MessageManager; import jalview.ws.params.ArgumentI; -import jalview.ws.params.ParamDatastoreI; -import jalview.ws.params.WsParamSetI; import jalview.ws2.operations.AnnotationOperation; import jalview.ws2.operations.AnnotationWorker; @@ -58,7 +54,8 @@ public class AnnotationMenuBuilder implements MenuEntryProviderI item.setToolTipText(MessageManager.getString( "label.view_and_change_parameters_before_running_calculation")); item.addActionListener((event) -> { - openEditParamsDialog(operation.getParamStore(), null, null) + MenuEntryProviderI.openEditParamsDialog(operation.getParamStore(), + null, null) .thenAcceptAsync((arguments) -> { if (arguments != null) { @@ -95,7 +92,8 @@ public class AnnotationMenuBuilder implements MenuEntryProviderI _editItem = new JMenuItem( String.format("Edit %s settings", calcName)); _editItem.addActionListener((event) -> { - openEditParamsDialog(operation.getParamStore(), null, null) + MenuEntryProviderI.openEditParamsDialog(operation.getParamStore(), + null, null) .thenAcceptAsync((args) -> { if (arguments != null) { @@ -138,40 +136,6 @@ public class AnnotationMenuBuilder implements MenuEntryProviderI }); } - private CompletionStage> openEditParamsDialog( - ParamDatastoreI paramStore, WsParamSetI preset, - List arguments) - { - WsJobParameters jobParams; - if (preset == null && arguments != null && arguments.size() > 0) - jobParams = new WsJobParameters(paramStore, preset, arguments); - else - jobParams = new WsJobParameters(paramStore, preset, null); - if (preset != null) - { - jobParams.setName(MessageManager.getString( - "label.adjusting_parameters_for_calculation")); - } - var stage = jobParams.showRunDialog(); - return stage.thenApply((startJob) -> { - if (startJob) - { - if (jobParams.getPreset() == null) - { - return jobParams.getJobParams(); - } - else - { - return jobParams.getPreset().getArguments(); - } - } - else - { - return null; - } - }); - } - private AnnotationWorker createWorker(List arguments, AlignFrame frame) { /* What is the purpose of AlignViewport and AlignmentViewPanel? */ diff --git a/src/jalview/ws2/gui/MenuEntryProviderI.java b/src/jalview/ws2/gui/MenuEntryProviderI.java index fbea582..3a828e7 100644 --- a/src/jalview/ws2/gui/MenuEntryProviderI.java +++ b/src/jalview/ws2/gui/MenuEntryProviderI.java @@ -1,8 +1,16 @@ package jalview.ws2.gui; +import java.util.List; +import java.util.concurrent.CompletionStage; + import javax.swing.JMenu; import jalview.gui.AlignFrame; +import jalview.gui.WsJobParameters; +import jalview.util.MessageManager; +import jalview.ws.params.ArgumentI; +import jalview.ws.params.ParamDatastoreI; +import jalview.ws.params.WsParamSetI; /** * Functional interface provided by {@link jalview.ws2.operations.Operation} @@ -25,4 +33,39 @@ public interface MenuEntryProviderI * current alignFrame */ public void buildMenu(JMenu parent, AlignFrame frame); + + static CompletionStage> openEditParamsDialog( + ParamDatastoreI paramStore, WsParamSetI preset, + List arguments) + { + WsJobParameters jobParams; + if (preset == null && arguments != null && arguments.size() > 0) + jobParams = new WsJobParameters(paramStore, preset, arguments); + else + jobParams = new WsJobParameters(paramStore, preset, null); + if (preset != null) + { + jobParams.setName(MessageManager.getString( + "label.adjusting_parameters_for_calculation")); + } + var stage = jobParams.showRunDialog(); + return stage.thenApply((startJob) -> { + if (startJob) + { + if (jobParams.getPreset() == null) + { + return jobParams.getJobParams(); + } + else + { + return jobParams.getPreset().getArguments(); + } + } + else + { + return null; + } + }); + } + } -- 1.7.10.2