JAL-3878 Make openEditsParamsDialog an interface static method.
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 24 Nov 2021 16:31:59 +0000 (17:31 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 24 Nov 2021 16:41:45 +0000 (17:41 +0100)
src/jalview/ws2/gui/AlignmentMenuBuilder.java
src/jalview/ws2/gui/AnnotationMenuBuilder.java
src/jalview/ws2/gui/MenuEntryProviderI.java

index b29bde5..23ef2ae 100644 (file)
@@ -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<List<ArgumentI>> openEditParamsDialog(
-      ParamDatastoreI paramStore, WsParamSetI preset,
-      List<ArgumentI> 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<ArgumentI> arguments, boolean submitGaps)
   {
index 5ddaa19..e007ce9 100644 (file)
@@ -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<List<ArgumentI>> openEditParamsDialog(
-      ParamDatastoreI paramStore, WsParamSetI preset,
-      List<ArgumentI> 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<ArgumentI> arguments, AlignFrame frame)
   {
     /* What is the purpose of AlignViewport and AlignmentViewPanel? */
index fbea582..3a828e7 100644 (file)
@@ -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<List<ArgumentI>> openEditParamsDialog(
+      ParamDatastoreI paramStore, WsParamSetI preset,
+      List<ArgumentI> 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;
+      }
+    });
+  }
+
 }