JAL-3070 pull up logic for offering a parameters dialog for a service to base client...
[jalview.git] / src / jalview / ws / WSClient.java
index 68bd4b0..d031142 100755 (executable)
 package jalview.ws;
 
 import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
 import jalview.gui.WebserviceInfo;
+import jalview.gui.WsJobParameters;
+import jalview.util.MessageManager;
+import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.api.UIinfo;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.WsParamSetI;
+
+import java.util.List;
 
 public abstract class WSClient // implements WSMenuEntryProviderI
 {
@@ -78,10 +87,37 @@ public abstract class WSClient // implements WSMenuEntryProviderI
     ServiceActions.put("SecStrPred", "Secondary Structure Prediction");
   };
 
+  /**
+   * The preset for the job executed by this client (may be null)
+   */
+  protected WsParamSetI preset;
+
+  /**
+   * The parameters for the job executed by this client (may be null)
+   */
+  protected List<ArgumentI> paramset;
+
   public WSClient()
   {
   }
 
+  /**
+   * base constructor for a web service with parameters. Extending classes
+   * should implement this constructor with additional logic to verify that
+   * preset and arguments are compatible with the service being configured.
+   * 
+   * @param _alignFrame
+   * @param preset
+   * @param arguments
+   */
+  public WSClient(AlignFrame _alignFrame, WsParamSetI preset,
+          List<ArgumentI> arguments)
+  {
+    alignFrame = _alignFrame;
+    this.preset = preset;
+    this.paramset = arguments;
+  }
+
   protected WebserviceInfo setWebService(UIinfo serv, boolean b)
   {
     WebServiceName = serv.getName();
@@ -99,4 +135,60 @@ public abstract class WSClient // implements WSMenuEntryProviderI
     }
     return null;
   }
+
+  /**
+   * called to open a parameter editing dialog for parameterised services
+   * 
+   * @param sh
+   * @param editParams
+   * @return
+   */
+  protected boolean processParams(ServiceWithParameters sh,
+          boolean editParams)
+  {
+    return processParams(sh, editParams, false);
+  }
+
+  protected boolean processParams(ServiceWithParameters sh,
+          boolean editParams,
+          boolean adjustingExisting)
+  {
+
+    if (editParams)
+    {
+      // always do this
+      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);
+      if (adjustingExisting)
+      {
+        jobParams.setName(MessageManager
+                .getString("label.adjusting_parameters_for_calculation"));
+      }
+      if (!jobParams.showRunDialog())
+      {
+        return false; // dialog cancelled
+      }
+
+      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.
+      }
+    }
+    return true;
+  }
+
 }