JAL-3809 - Fixed param edit dialog for jalviewjs.
[jalview.git] / src / jalview / ws / WSClient.java
index 33aea90..a68f3f3 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.ws;
 
+import jalview.bin.Cache;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.gui.WebserviceInfo;
@@ -32,6 +33,8 @@ import jalview.ws.params.ParamDatastoreI;
 import jalview.ws.params.WsParamSetI;
 
 import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
 
 public abstract class WSClient // implements WSMenuEntryProviderI
 {
@@ -116,7 +119,7 @@ public abstract class WSClient // implements WSMenuEntryProviderI
    * @param arguments
    */
   public WSClient(AlignFrame _alignFrame, WsParamSetI preset,
-          List<ArgumentI> arguments)
+      List<ArgumentI> arguments)
   {
     alignFrame = _alignFrame;
     this.preset = preset;
@@ -131,12 +134,12 @@ public abstract class WSClient // implements WSMenuEntryProviderI
     if (!b)
     {
       return new WebserviceInfo(WebServiceJobTitle,
-              WebServiceJobTitle + " using service hosted at "
-                      + WsURL + "\n"
-                      + (serv.getDescription() != null
-                              ? serv.getDescription()
-                              : ""),
-              false);
+          WebServiceJobTitle + " using service hosted at "
+              + WsURL + "\n"
+              + (serv.getDescription() != null
+                  ? serv.getDescription()
+                  : ""),
+          false);
     }
     return null;
   }
@@ -148,15 +151,14 @@ public abstract class WSClient // implements WSMenuEntryProviderI
    * @param editParams
    * @return
    */
-  protected boolean processParams(ServiceWithParameters sh,
-          boolean editParams)
+  protected CompletionStage<Boolean> processParams(ServiceWithParameters sh,
+      boolean editParams)
   {
     return processParams(sh, editParams, false);
   }
 
-  protected boolean processParams(ServiceWithParameters sh,
-          boolean editParams,
-          boolean adjustingExisting)
+  protected CompletionStage<Boolean> processParams(ServiceWithParameters sh,
+      boolean editParams, boolean adjustingExisting)
   {
 
     if (editParams)
@@ -165,35 +167,38 @@ public abstract class WSClient // implements WSMenuEntryProviderI
       sh.initParamStore(Desktop.getUserParameterStore());
 
       WsJobParameters jobParams = (preset == null && paramset != null
-              && paramset.size() > 0)
-                      ? new WsJobParameters((ParamDatastoreI) null, sh,
-                              (WsParamSetI) null, paramset)
-                      : new WsJobParameters((ParamDatastoreI) null, sh,
-                              preset, (List<ArgumentI>) null);
+          && paramset.size() > 0)
+              ? new WsJobParameters((ParamDatastoreI) null, sh,
+                  (WsParamSetI) null, paramset)
+              : new WsJobParameters((ParamDatastoreI) null, sh,
+                  preset, (List<ArgumentI>) null);
       if (adjustingExisting)
       {
         jobParams.setName(MessageManager
-                .getString("label.adjusting_parameters_for_calculation"));
+            .getString("label.adjusting_parameters_for_calculation"));
       }
-      if (!jobParams.showRunDialog())
-      {
-        return false; // dialog cancelled
-      }
-
-      WsParamSetI prset = jobParams.getPreset();
-      if (prset == null)
-      {
-        paramset = jobParams.isServiceDefaults() ? null
+      var stage = jobParams.showRunDialog();
+      return stage.thenApply((startJob) -> {
+        if (startJob)
+        {
+          WsParamSetI prset = jobParams.getPreset();
+          if (prset == null)
+          {
+            paramset = jobParams.isServiceDefaults() ? null
                 : jobParams.getJobParams();
-        this.preset = null;
-      }
-      else
-      {
-        this.preset = prset; // ((JabaPreset) prset).p;
-        paramset = null; // no user supplied parameters.
-      }
+            this.preset = null;
+          }
+          else
+          {
+            this.preset = prset; // ((JabaPreset) prset).p;
+            paramset = null; // no user supplied parameters.
+          }
+        }
+        return startJob;
+      });
+
     }
-    return true;
+    return CompletableFuture.completedFuture(true);
   }
 
 }