From: Jim Procter Date: Thu, 26 Jul 2018 16:07:08 +0000 (+0100) Subject: JAL-3070 pull up logic for offering a parameters dialog for a service to base client... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=686783e6402dd664d29a0ebd01a8b9149f134cfa;p=jalview.git JAL-3070 pull up logic for offering a parameters dialog for a service to base client class --- diff --git a/src/jalview/ws/WSClient.java b/src/jalview/ws/WSClient.java index 68bd4b0..d031142 100755 --- a/src/jalview/ws/WSClient.java +++ b/src/jalview/ws/WSClient.java @@ -21,8 +21,17 @@ 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 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 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) 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; + } + } diff --git a/src/jalview/ws/jws2/Jws2Client.java b/src/jalview/ws/jws2/Jws2Client.java index 334f3c3..b4d498d 100644 --- a/src/jalview/ws/jws2/Jws2Client.java +++ b/src/jalview/ws/jws2/Jws2Client.java @@ -23,15 +23,12 @@ package jalview.ws.jws2; import jalview.api.AlignCalcWorkerI; import jalview.bin.Cache; import jalview.gui.AlignFrame; -import jalview.gui.Desktop; import jalview.gui.JvSwingUtils; -import jalview.gui.WsJobParameters; import jalview.util.MessageManager; import jalview.ws.jws2.dm.AAConSettings; import jalview.ws.jws2.dm.JabaWsParamSet; import jalview.ws.jws2.jabaws2.Jws2Instance; import jalview.ws.params.ArgumentI; -import jalview.ws.params.ParamDatastoreI; import jalview.ws.params.WsParamSetI; import jalview.ws.uimodel.AlignAnalysisUIText; @@ -53,15 +50,10 @@ import javax.swing.event.MenuListener; */ public abstract class Jws2Client extends jalview.ws.WSClient { - protected WsParamSetI preset; - - protected List paramset; - public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset, List arguments) { - alignFrame = _alignFrame; - this.preset = preset; + super(_alignFrame, preset, arguments); if (preset != null) { if (!((preset instanceof JabaPreset) @@ -82,63 +74,11 @@ public abstract class Jws2Client extends jalview.ws.WSClient } else { - // just provided with a bunch of arguments - this.paramset = arguments; + // TODO: verify that paramset is compatible with the service being + // contacted } } - boolean processParams(Jws2Instance sh, boolean editParams) - { - return processParams(sh, editParams, false); - } - - protected boolean processParams(Jws2Instance sh, boolean editParams, - boolean adjustingExisting) - { - - if (editParams) - { - if (sh.paramStore == null) - { - sh.paramStore = new JabaParamStore(sh, - Desktop.getUserParameterStore()); - } - WsJobParameters jobParams = (preset == null && paramset != null - && paramset.size() > 0) - ? new WsJobParameters((ParamDatastoreI) null, sh, - (WsParamSetI) null, - JabaParamStore.getJwsArgsfromJaba(paramset)) - : new WsJobParameters((ParamDatastoreI) null, sh, - preset, - (List) 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 - : JabaParamStore - .getJabafromJwsArgs(jobParams.getJobParams()); - this.preset = null; - } - else - { - this.preset = prset; // ((JabaPreset) prset).p; - paramset = null; // no user supplied parameters. - } - } - return true; - - } - public Jws2Client() { // anonymous constructor - used for headless method calls only