From: jprocter Date: Mon, 6 Sep 2010 10:53:04 +0000 (+0000) Subject: abstracted GUI to use jalview.ws.params objects (JAL-591, JAL-633) X-Git-Tag: Release_2_6~70 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=85037c7f026acf289a22eaf0bd0d368351b5905e;p=jalview.git abstracted GUI to use jalview.ws.params objects (JAL-591, JAL-633) --- diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 3facfa1..58c9646 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -73,9 +73,19 @@ import compbio.metadata.WrongParameterException; import compbio.metadata.ValueConstrain.Type; import jalview.util.jarInputStreamProvider; +import jalview.ws.jws2.JabaParamStore; +import jalview.ws.jws2.JabaPreset; import jalview.ws.jws2.Jws2Discoverer; import jalview.ws.jws2.ParameterUtils; import jalview.ws.jws2.Jws2Discoverer.Jws2Instance; +import jalview.ws.jws2.dm.JabaOption; +import jalview.ws.jws2.dm.JabaParameter; +import jalview.ws.params.ArgumentI; +import jalview.ws.params.OptionI; +import jalview.ws.params.ParamDatastoreI; +import jalview.ws.params.ParameterI; +import jalview.ws.params.ValueConstrainI; +import jalview.ws.params.WsParamSetI; /** * job parameter editing/browsing dialog box. User can browse existing settings @@ -136,21 +146,20 @@ public class WsJobParameters extends JPanel implements ItemListener, JScrollPane paramPane = new JScrollPane(); - // JList paramList = new JList(); JPanel paramList = new JPanel(); RunnerConfig serviceOptions; - private BorderLayout jparamLayout; + ParamDatastoreI paramStore; WsJobParameters(Jws2Instance service) { this(service, null); } - public WsJobParameters(Jws2Instance service, Preset p) + public WsJobParameters(Jws2Instance service, WsParamSetI preset) { - this(null, service, p, null); + this(null, service, preset, null); } /** @@ -158,16 +167,36 @@ public class WsJobParameters extends JPanel implements ItemListener, * @param desktop * - if null, create new JFrame outside of desktop * @param service - * @param p + * @param preset */ - public WsJobParameters(JFrame parent, Jws2Instance service, Preset p, + public WsJobParameters(JFrame parent, Jws2Instance service, WsParamSetI preset, List jobArgset) { + this(parent, null, service, preset, jobArgset); + } + + /** + * + * @param parent + * @param paramStorei + * @param service + * @param preset + * @param jobArgset + */ + public WsJobParameters(JFrame parent, ParamDatastoreI paramStorei, + Jws2Instance service, WsParamSetI preset, List jobArgset) + { super(); jbInit(); + this.paramStore = paramStorei; + if (paramStore == null) + { + paramStore = service.getParamStore(); + } + this.service = service; // argSetModified(false); // populate parameter table - initForService(service, p, jobArgset); + initForService(service, preset, jobArgset); // display in new JFrame attached to parent. validate(); } @@ -319,7 +348,7 @@ public class WsJobParameters extends JPanel implements ItemListener, setDetails.add(setDescrView, BorderLayout.CENTER); // setDetails.setPreferredSize(new Dimension(360, 100)); jobParameters.setBorder(new TitledBorder("Parameters")); - jobParameters.setLayout(jparamLayout = new BorderLayout()); + jobParameters.setLayout(new BorderLayout()); paramPane.setPreferredSize(new Dimension(360, 300)); paramPane.getVerticalScrollBar().setUnitIncrement(20); // paramPanel.setPreferredSize(new Dimension(360, 300)); @@ -372,6 +401,11 @@ public class WsJobParameters extends JPanel implements ItemListener, } } + private void _deleteUserPreset(String lastParmSet2) + { + paramStore.deletePreset(lastParmSet2); + } + protected void delete_actionPerformed(ActionEvent e) { if (isUserPreset) @@ -429,11 +463,17 @@ public class WsJobParameters extends JPanel implements ItemListener, */ boolean settingDialog = false; - void initForService(Jws2Instance service, Preset p, - List jobArgset) + void initForService(Jws2Instance service, WsParamSetI jabap, + List jabajobArgset) { + WsParamSetI p = null; + List jobArgset = null; settingDialog = true; - this.service = service; + { // instantiate the abstract proxy for Jaba objects + jobArgset = jabajobArgset == null ? null : JabaParamStore + .getJwsArgsfromJaba(jabajobArgset); + p = jabap; // (jabap != null) ? paramStore.getPreset(jabap.getName()) : null; + } // TODO: Recover window geometry prefs for this service // jobPanel.setDividerLocation(proportionalLocation) // settingsPanel.setDividerLocation(proportionalLocation) @@ -442,30 +482,27 @@ public class WsJobParameters extends JPanel implements ItemListener, { exnames.put((String) setName.getItemAt(i), setName.getItemAt(i)); } + servicePresets = new Hashtable(); // Add the default entry - if not present already. if (!exnames.contains(SVC_DEF)) { setName.addItem(SVC_DEF); exnames.put(SVC_DEF, SVC_DEF); + servicePresets.put(SVC_DEF, SVC_DEF); } - serviceOptions = service.getRunnerConfig(); - // add any presets not already added. String curname = (p == null ? "" : p.getName()); - PresetManager prman = service.getPresets(); - servicePresets = new Hashtable(); - if (prman != null) + for (WsParamSetI pr : paramStore.getPresets()) { - List prList = service.getPresets().getPresets(); - if (prList != null) + if (!pr.isModifiable()) { - for (Object pr : prList) - { - servicePresets.put(((Preset) pr).getName(), "preset"); - if (!exnames.contains(((Preset) pr).getName())) - { - setName.addItem(((Preset) pr).getName()); - } - } + servicePresets.put(pr.getName(), "preset"); + } + else + { + } + if (!exnames.contains(pr.getName())) + { + setName.addItem(pr.getName()); } } // TODO: if initial jobArgset matches a given user setting or preset then @@ -494,34 +531,32 @@ public class WsJobParameters extends JPanel implements ItemListener, } @SuppressWarnings("unchecked") - private void updateTable(Preset p, List jobArgset) + private void updateTable(WsParamSetI p, List jobArgset) { - List setargs = new ArrayList(); // populate table from default parameter set. - List args = serviceOptions.getArguments(); + List args = paramStore.getServiceParameters(); // split to params and required arguments { - for (Argument arg : args) + for (ArgumentI myarg : args) { - Argument myarg = (Argument) arg; // Ideally, Argument would implement isRequired ! - if (myarg instanceof Parameter) + if (myarg instanceof ParameterI) { - Parameter parm = (Parameter) myarg; + ParameterI parm = (ParameterI) myarg; addParameter(parm); } else { - if (myarg instanceof Option) + if (myarg instanceof OptionI) { - Option opt = (Option) myarg; + OptionI opt = (OptionI) myarg; addOption(opt).resetToDefault(); } else { System.err.println("Ignoring unknown service argument type " - + arg.getClass().getName()); + + myarg.getClass().getName()); } } } @@ -536,14 +571,13 @@ public class WsJobParameters extends JPanel implements ItemListener, // TODO - URL link try { - args = p.getArguments(serviceOptions); + args = p.getArguments(); } catch (Exception e) { e.printStackTrace(); } // TODO: check if args should be unselected prior to resetting using the // preset - setargs.clear(); } else { @@ -551,6 +585,7 @@ public class WsJobParameters extends JPanel implements ItemListener, { isUserPreset = false; // first call - so create a dummy name + setName.setSelectedItem(lastSetName = SVC_DEF); } } @@ -563,20 +598,20 @@ public class WsJobParameters extends JPanel implements ItemListener, // get setargs from current object if (args != null) { - for (Argument arg : args) + for (ArgumentI arg : args) { - if (arg instanceof Parameter) + if (arg instanceof ParameterI) { - setParameter((Parameter) arg); + setParameter((ParameterI) arg); } else { - if (arg instanceof Option) + if (arg instanceof OptionI) { // System.out.println("Setting option " // + System.identityHashCode(arg) + ":" + arg.getName() // + " with " + arg.getDefaultValue()); - selectOption((Option) arg, arg.getDefaultValue()); + selectOption((OptionI) arg, arg.getDefaultValue()); } } @@ -642,13 +677,18 @@ public class WsJobParameters extends JPanel implements ItemListener, { return; } - if (!b) { modifiedElements.remove(modifiedElement); } else { + if (b && modifiedElement == setName + && modifiedElements.contains(modifiedElement)) + { + // HACK! prevents iteration on makeSetNameValid + b = false; + } modifiedElements.put(modifiedElement, modifiedElement); } // set mod status based on presence of elements in table @@ -686,7 +726,7 @@ public class WsJobParameters extends JPanel implements ItemListener, if (newuserset) { int i = 0; - while (_getUserPreset(tnm) != null) + while (paramStore.getPreset(tnm) != null) { tnm = nm + " (" + (++i) + ")"; renamed = true; @@ -721,21 +761,21 @@ public class WsJobParameters extends JPanel implements ItemListener, settingDialog = stn; } - private void addParameter(Parameter parm) + private void addParameter(ParameterI arg) { - ParamBox pb = paramSet.get(parm.getName()); + ParamBox pb = paramSet.get(arg.getName()); if (pb == null) { - pb = new ParamBox(this, parm); - paramSet.put(parm.getName(), pb); + pb = new ParamBox(this, arg); + paramSet.put(arg.getName(), pb); paramList.add(pb); } pb.init(); // take the defaults from the parameter - pb.updateControls(parm); + pb.updateControls(arg); } - private void setParameter(Parameter arg) + private void setParameter(ParameterI arg) { ParamBox pb = paramSet.get(arg.getName()); if (pb == null) @@ -749,27 +789,27 @@ public class WsJobParameters extends JPanel implements ItemListener, } - private void selectOption(Option opt, String string) + private void selectOption(OptionI option, String string) { - OptionBox cb = optSet.get(opt.getName()); + OptionBox cb = optSet.get(option.getName()); if (cb == null) { - cb = addOption(opt); + cb = addOption(option); } cb.enabled.setSelected(string != null); // initial state for an option. if (string != null) { - if (opt.getPossibleValues().contains(string)) + if (option.getPossibleValues().contains(string)) { cb.val.setSelectedItem(string); } else { - throw new Error("Invalid value " + string + " for option " + opt); + throw new Error("Invalid value " + string + " for option " + option); } } - if (opt.isRequired() && !cb.enabled.isSelected()) + if (option.isRequired() && !cb.enabled.isSelected()) { // TODO: indicate paramset is not valid.. option needs to be selected! } @@ -791,7 +831,7 @@ public class WsJobParameters extends JPanel implements ItemListener, JTextField valueField = null; - ValueConstrain validator = null; + ValueConstrainI validator = null; JPanel settingPanel = new JPanel(); @@ -807,7 +847,7 @@ public class WsJobParameters extends JPanel implements ItemListener, final URL finfo; - public ParamBox(final WsJobParameters pmlayout, Parameter parm) + public ParamBox(final WsJobParameters pmlayout, ParameterI parm) { pmdialogbox = pmlayout; setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT)); @@ -891,7 +931,7 @@ public class WsJobParameters extends JPanel implements ItemListener, boolean adjusting = false; - Parameter parameter; + ParameterI parameter; JComboBox choicebox; @@ -900,7 +940,7 @@ public class WsJobParameters extends JPanel implements ItemListener, return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT); } - public void updateControls(Parameter parm) + public void updateControls(ParameterI parm) { adjusting = true; boolean init = (choicebox == null && valueField == null); @@ -956,23 +996,16 @@ public class WsJobParameters extends JPanel implements ItemListener, Object lastVal; - public Parameter getParameter() + public ParameterI getParameter() { - Parameter prm = ParameterUtils.copyParameter(parameter); - try + ParameterI prm = parameter.copy(); + if (choice) { - if (choice) - { - prm.setDefaultValue((String) choicebox.getSelectedItem()); - } - else - { - prm.setDefaultValue(valueField.getText()); - } - } catch (WrongParameterException e) + prm.setDefaultValue((String) choicebox.getSelectedItem()); + } + else { - e.printStackTrace(); - return null; + prm.setDefaultValue(valueField.getText()); } return prm; } @@ -990,6 +1023,16 @@ public class WsJobParameters extends JPanel implements ItemListener, { valueField.setText(valueField.getText().trim()); iVal = Integer.valueOf(valueField.getText()); + if (validator.getMin()!=null && validator.getMin().intValue()>iVal) + { + iVal = validator.getMin().intValue(); + // TODO: provide visual indication that hard limit was reached for this parameter + } + if (validator.getMax()!=null && validator.getMax().intValue()fVal) + { + fVal = validator.getMin().floatValue(); + // TODO: provide visual indication that hard limit was reached for this parameter + } + if (validator.getMax()!=null && validator.getMax().floatValue() o=pr.getOptions().iterator(),s = writeparam.iterator(), t = readparam - .iterator(); - boolean failed=false; + Iterator o = pr.getOptions().iterator(), s = writeparam + .iterator(), t = readparam.iterator(); + boolean failed = false; while (s.hasNext() && t.hasNext()) { - String on=o.next(),sn = s.next(),st=t.next(); + String on = o.next(), sn = s.next(), st = t.next(); if (!sn.equals(st)) { - System.out.println("Original was "+on+" Phase 1 wrote " + sn - + "\tPhase 2 wrote " + st); - failed=true; + System.out.println("Original was " + on + + " Phase 1 wrote " + sn + "\tPhase 2 wrote " + + st); + failed = true; } } if (failed) { - System.out.println("Original parameters:\n"+pr.getOptions()); - System.out.println("Wrote parameters in first set:\n"+writeparam); - System.out.println("Wrote parameters in second set:\n"+readparam); + System.out.println("Original parameters:\n" + + pr.getOptions()); + System.out.println("Wrote parameters in first set:\n" + + writeparam); + System.out.println("Wrote parameters in second set:\n" + + readparam); } } catch (Exception e) @@ -1501,7 +1550,7 @@ public class WsJobParameters extends JPanel implements ItemListener, e.printStackTrace(); } } - WsJobParameters pgui = new WsJobParameters(lastserv, pr); + WsJobParameters pgui = new WsJobParameters(lastserv, new JabaPreset(lastserv, pr)); JFrame jf = new JFrame("Parameters for " + lastserv.getActionText()); JPanel cont = new JPanel(); @@ -1573,13 +1622,13 @@ public class WsJobParameters extends JPanel implements ItemListener, } } - public List getJobParams() + public List getJobParams() { - List argSet = new ArrayList(); + List argSet = new ArrayList(); // recover options and parameters from GUI for (OptionBox opts : optSet.values()) { - Option opt = opts.getOptionIfEnabled(); + OptionI opt = opts.getOptionIfEnabled(); if (opt != null) { argSet.add(opt); @@ -1587,7 +1636,7 @@ public class WsJobParameters extends JPanel implements ItemListener, } for (ParamBox parambox : paramSet.values()) { - Parameter parm = parambox.getParameter(); + ParameterI parm = parambox.getParameter(); if (parm != null) { argSet.add(parm); @@ -1599,56 +1648,39 @@ public class WsJobParameters extends JPanel implements ItemListener, String lastParmSet = null; - Hashtable editedParams = new Hashtable(); - - /** + /* + * Hashtable editedParams = new Hashtable(); + * * store the given parameters in the user parameter set database. * - * @param storeSetName - * - lastParmSet - * @param descr - * - setDescr.getText() - * @param jobParams - * - getJobParams() - */ - private void _storeUserPreset(String storeSetName, String descr, - List jobParams) - { - // this is a simple hash store. - Object[] pset; - editedParams.put(storeSetName, pset = new Object[3]); - pset[0] = storeSetName; - pset[1] = descr; - pset[2] = jobParams; - // writeParam("Saving " + storeSetName + ": ", jobParams); - } - - private void writeParam(String nm, List params) - { - for (Argument p : params) - { - System.out.println(nm + ":" + System.identityHashCode(p) + " Name: " - + p.getName() + " Value: " + p.getDefaultValue()); - } - } - - private Object[] _getUserPreset(String setName) - { - Object[] pset = editedParams.get(setName); - // if (pset != null) - // writeParam("Retrieving " + setName + ": ", (List) pset[2]); - return pset; - } - - /** - * remove the given user preset from the preset stash + * @param storeSetName - lastParmSet + * + * @param descr - setDescr.getText() + * + * @param jobParams - getJobParams() + * + * private void _storeUserPreset(String storeSetName, String descr, + * List jobParams) { // this is a simple hash store. Object[] pset; + * editedParams.put(storeSetName, pset = new Object[3]); pset[0] = + * storeSetName; pset[1] = descr; pset[2] = jobParams; // writeParam("Saving " + * + storeSetName + ": ", jobParams); } + * + * private void writeParam(String nm, List params) { for (ArgumentI + * p : params) { System.out.println(nm + ":" + System.identityHashCode(p) + + * " Name: " + p.getName() + " Value: " + p.getDefaultValue()); } } + * + * private Object[] _getUserPreset(String setName) { Object[] pset = + * editedParams.get(setName); // if (pset != null) // writeParam("Retrieving " + * + setName + ": ", (List) pset[2]); return pset; } + * + * * remove the given user preset from the preset stash * * @param setName + * + * private void _deleteUserPreset(String setName) { + * editedParams.remove(setName); } */ - private void _deleteUserPreset(String setName) - { - editedParams.remove(setName); - } private void syncSetNamesWithStore() { @@ -1659,7 +1691,7 @@ public class WsJobParameters extends JPanel implements ItemListener, while (n < setName.getItemCount()) { String item = (String) setName.getItemAt(n); - if (!isServicePreset(item) && _getUserPreset(item) == null) + if (!item.equals(SVC_DEF) && !paramStore.presetExists(item)) { setName.removeItemAt(n); } @@ -1669,11 +1701,15 @@ public class WsJobParameters extends JPanel implements ItemListener, n++; } } - for (String upn : editedParams.keySet()) + if (!items.contains(SVC_DEF)) + { + setName.addItem(SVC_DEF); + } + for (WsParamSetI upn : paramStore.getPresets()) { - if (!items.contains(upn)) + if (!items.contains(upn.getName())) { - setName.addItem(upn); + setName.addItem(upn.getName()); } } } @@ -1687,47 +1723,37 @@ public class WsJobParameters extends JPanel implements ItemListener, { settingDialog = true; // updateTable(null,null); // first reset to defaults - Object[] pset = null; + WsParamSetI pset = null; if (nextPreset != null && nextPreset.length() > 0) { - pset = _getUserPreset(nextPreset); + pset = paramStore.getPreset(nextPreset); } if (pset != null) { - isUserPreset = true; - setDescr.setText((String) pset[1]); - updateTable(null, (List) pset[2]); - lastParmSet = nextPreset; - } - else - { - isUserPreset = false; - setDescr.setText(""); - // must be a default preset from service - Preset p = null; - try - { - PresetManager prman = service.getPresets(); - if (prman != null) - { - isUserPreset = false; - p = prman.getPresetByName(nextPreset); - } - } catch (Exception ex) - { - ex.printStackTrace(); - } - if (p != null) + if (pset.isModifiable()) { - updateTable(p, null); + isUserPreset = true; + setDescr.setText(pset.getDescription()); + updateTable(null, pset.getArguments()); lastParmSet = nextPreset; } else { - updateTable(null, null); - lastParmSet = SVC_DEF; + isUserPreset = false; + setDescr.setText(""); + // must be a default preset from service + updateTable(pset, null); + lastParmSet = nextPreset; } } + else + { + isUserPreset = false; + // Service defaults + updateTable(null, null); + lastParmSet = SVC_DEF; + } + initArgSetModified(); syncSetNamesWithStore(); setName.setSelectedItem(lastParmSet); @@ -1788,7 +1814,7 @@ public class WsJobParameters extends JPanel implements ItemListener, */ private void _storeCurrentPreset(String curSetName2) { - _storeUserPreset(curSetName2, setDescr.getText(), getJobParams()); + paramStore.storePreset(curSetName2, setDescr.getText(), getJobParams()); } /** @@ -1865,7 +1891,11 @@ public class WsJobParameters extends JPanel implements ItemListener, checkDescrModified(); } - public Preset getPreset() + /** + * + * @return null or the service preset selected by the user + */ + public WsParamSetI getPreset() { if (isUserPreset || isModified() || (lastParmSet != null && lastParmSet.equals(SVC_DEF))) @@ -1874,15 +1904,7 @@ public class WsJobParameters extends JPanel implements ItemListener, } else { - Preset p = null; - try - { - return (Preset) service.getPresets().getPresetByName(lastParmSet); - } catch (Exception e) - { - e.printStackTrace(); - return null; - } + return paramStore.getPreset(lastParmSet); } } } \ No newline at end of file diff --git a/src/jalview/ws/jws2/JabaParamStore.java b/src/jalview/ws/jws2/JabaParamStore.java new file mode 100644 index 0000000..0f7d6fa --- /dev/null +++ b/src/jalview/ws/jws2/JabaParamStore.java @@ -0,0 +1,246 @@ +package jalview.ws.jws2; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +import compbio.metadata.Argument; +import compbio.metadata.Option; +import compbio.metadata.Parameter; +import compbio.metadata.Preset; +import compbio.metadata.PresetManager; +import compbio.metadata.RunnerConfig; + +import jalview.ws.jws2.Jws2Discoverer.Jws2Instance; +import jalview.ws.jws2.dm.JabaOption; +import jalview.ws.jws2.dm.JabaParameter; +import jalview.ws.jws2.dm.JabaWsParamSet; +import jalview.ws.params.ArgumentI; +import jalview.ws.params.ParamDatastoreI; +import jalview.ws.params.WsParamSetI; + +public class JabaParamStore implements ParamDatastoreI +{ + + Hashtable editedParams = new Hashtable(); + + private Jws2Instance service; + + private RunnerConfig serviceOptions; + + private Hashtable servicePresets; + + public JabaParamStore(Jws2Instance service) + { + this.service = service; + serviceOptions = service.getRunnerConfig(); + // TODO: discover all the user's locally sored presets for this service and populate the hash table + // TODO: for JAL-632 + } + + /** + * store the given parameters in the user parameter set database. + * + * @param storeSetName + * - lastParmSet + * @param descr + * - setDescr.getText() + * @param jobParams + * - getJobParams() + */ + private void _storeUserPreset(String storeSetName, String descr, + List jobParams) + { + // this is a simple hash store. + editedParams.put(storeSetName, new JabaWsParamSet(storeSetName, descr, + JabaParamStore.getJwsArgsfromJaba(jobParams))); + // writeParam("Saving " + storeSetName + ": ", jobParams); + } + + private void writeParam(String nm, List params) + { + for (Argument p : params) + { + System.out.println(nm + ":" + System.identityHashCode(p) + " Name: " + + p.getName() + " Value: " + p.getDefaultValue()); + } + } + + private JabaWsParamSet _getUserPreset(String setName) + { + JabaWsParamSet pset = editedParams.get(setName); + return pset; + } + + /** + * remove the given user preset from the preset stash + * + * @param setName + */ + private void _deleteUserPreset(String setName) + { + editedParams.remove(setName); + } + + @Override + public List getPresets() + { + List prefs = new ArrayList(); + if (servicePresets == null) + { + servicePresets = new Hashtable(); + PresetManager prman; + if ((prman = service.getPresets()) != null) + { + List pset = prman.getPresets(); + if (pset != null) + { + for (Object pr : pset) + { + JabaPreset prset = new JabaPreset(service, (Preset) pr); + servicePresets.put(prset.getName(), prset); + } + } + } + } + for (JabaPreset pr : servicePresets.values()) + { + prefs.add(pr); + } + for (WsParamSetI wspset : editedParams.values()) + { + prefs.add(wspset); + } + return prefs; + } + + @Override + public WsParamSetI getPreset(String name) + { + for (WsParamSetI pr : getPresets()) + { + if (pr.getName().equals(name)) + { + return pr; + } + } + return null; + } + + public static List getJwsArgsfromJaba(List jabargs) + { + List rgs = new ArrayList(); + for (Object rg : jabargs) + { + ArgumentI narg = (rg instanceof Parameter) ? new JabaParameter( + (Parameter) rg) : (rg instanceof Option) ? new JabaOption( + (Option) rg) : null; + if (narg == null) + { + throw new Error( + "Implementation Error: Cannot handle Jaba parameter object " + + rg.getClass()); + } + else + { + rgs.add(narg); + } + } + return rgs; + } + + public static List getJabafromJwsArgs(List jwsargs) + { + List rgs = new ArrayList(); + for (ArgumentI rg : jwsargs) + { + Argument narg = (rg instanceof JabaOption) ? ((JabaOption) rg) + .getOption() : null; + if (narg == null) + { + throw new Error( + "Implementation Error: Cannot handle Jaba parameter object " + + rg.getClass()); + } + else + { + rgs.add(narg); + } + } + return rgs; + } + + @Override + public List getServiceParameters() + { + return getJwsArgsfromJaba(serviceOptions.getArguments()); + } + + @Override + public boolean presetExists(String name) + { + return (editedParams.containsKey(name) || servicePresets + .containsKey(name)); + } + + @Override + public void deletePreset(String name) + { + if (editedParams.containsKey(name)) + { + editedParams.remove(name); + return; + } + if (servicePresets.containsKey(name)) + { + throw new Error( + "Implementation error: Attempt to delete a service preset!"); + } + } + + + @Override + public void storePreset(String presetName, String text, + List jobParams) + { + JabaWsParamSet jps = new JabaWsParamSet(presetName, text, jobParams); + editedParams.put(jps.getName(), jps); + } + + @Override + public boolean readParamSet(WsParamSetI wsp, + Reader reader) throws IOException + { + if (!(wsp instanceof JabaWsParamSet)) + { + throw new Error("Implementation error: JabaWsParamSets can only be handled by JabaParamStore"); + } + List lines=new ArrayList(); + String line; + BufferedReader br = new BufferedReader(reader); + while ((line=br.readLine())!=null) + { + lines.add(line); + } + ((JabaWsParamSet) wsp).setjabaArguments(ParameterUtils.processParameters(lines, serviceOptions, " ")); + return true; + } + + @Override + public boolean writeParamSet(WsParamSetI wsp, + Writer writer) throws IOException + { + if (!(wsp instanceof JabaWsParamSet)) + { + throw new Error("Implementation error: JabaWsParamSets can only be handled by JabaParamStore"); + } + writer.write(ParameterUtils.writeParameterSet(((JabaWsParamSet)wsp).getjabaArguments(), " ") + .toString()); + return true; + } + +} diff --git a/src/jalview/ws/jws2/JabaPreset.java b/src/jalview/ws/jws2/JabaPreset.java new file mode 100644 index 0000000..1f8517e --- /dev/null +++ b/src/jalview/ws/jws2/JabaPreset.java @@ -0,0 +1,65 @@ +package jalview.ws.jws2; + +import jalview.ws.jws2.Jws2Discoverer.Jws2Instance; +import jalview.ws.params.ArgumentI; +import jalview.ws.params.WsParamSetI; + +import java.util.List; + +import compbio.metadata.Preset; + +public class JabaPreset implements WsParamSetI { + Preset p=null; + Jws2Instance service; + public JabaPreset(Jws2Instance svc, Preset preset) { + service=svc; + p=preset; + } + @Override + public String getName() + { + return p.getName(); + } + @Override + public String getDescription() + { + return p.getDescription(); + } + @Override + public String[] getApplicableUrls() + { + return new String[] { service.getHost()}; + } + @Override + public String getSourceFile() + { + return null; + } + @Override + public boolean isModifiable() + { + return false; + } + @Override + public void setSourceFile(String newfile) + { + throw new Error("Cannot set source file for "+getClass()); + } + @Override + public List getArguments() + { + try { + return JabaParamStore.getJwsArgsfromJaba(p.getArguments(service.getRunnerConfig())); + } + catch (Exception e) + { + e.printStackTrace(); + throw new Error("Probable mismatch between service instance and preset!"); + } + } + @Override + public void setArguments(List args) + { + throw new Error("Cannot set Parameters for a Jaba Web service's preset"); + } +} \ No newline at end of file diff --git a/src/jalview/ws/jws2/dm/JabaOption.java b/src/jalview/ws/jws2/dm/JabaOption.java new file mode 100644 index 0000000..27ecf85 --- /dev/null +++ b/src/jalview/ws/jws2/dm/JabaOption.java @@ -0,0 +1,84 @@ +package jalview.ws.jws2.dm; + +import jalview.ws.jws2.ParameterUtils; +import jalview.ws.params.OptionI; + +import java.net.URL; +import java.util.List; + +import compbio.metadata.Option; + +public class JabaOption implements jalview.ws.params.OptionI +{ + public JabaOption(Option rg) + { + opt = rg; + } + + Option opt; + + @Override + public String getDefaultValue() + { + return opt.getDefaultValue(); + } + + @Override + public String getName() + { + return opt.getName(); + } + + @Override + public URL getFurtherDetails() + { + return opt.getFurtherDetails(); + } + + @Override + public boolean isRequired() + { + return opt.isRequired(); + } + + @Override + public String getDescription() + { + return opt.getDescription(); + } + + @Override + public List getPossibleValues() + { + // TODO: assert typesafety + return opt.getPossibleValues(); + } + + @Override + public void setDefaultValue(String selectedItem) + { + try { + opt.setDefaultValue(selectedItem); + } catch (Exception e) + { + e.printStackTrace(); + throw new Error("Implementation error: cannot set Jaba Option to a value outside its allowed value range!"); + } + } + + @Override + public OptionI copy() + { + return new JabaOption(ParameterUtils.copyOption(opt)); + } + + /** + * get the underlying Jaba option or parameter object. Note - use copy first if you want to modify the value of the option. + * @return + */ + public Option getOption() + { + return opt; + } + +} diff --git a/src/jalview/ws/jws2/dm/JabaParameter.java b/src/jalview/ws/jws2/dm/JabaParameter.java new file mode 100644 index 0000000..44f3a02 --- /dev/null +++ b/src/jalview/ws/jws2/dm/JabaParameter.java @@ -0,0 +1,35 @@ +package jalview.ws.jws2.dm; + +import jalview.ws.jws2.ParameterUtils; +import jalview.ws.params.ParameterI; +import jalview.ws.params.ValueConstrainI; +import compbio.metadata.Argument; +import compbio.metadata.Parameter; +import compbio.metadata.ValueConstrain; + +public class JabaParameter extends JabaOption implements ParameterI +{ + + public JabaParameter(Parameter rg) + { + super(rg); + + } + + @Override + public ValueConstrainI getValidValue() + { + ValueConstrain vc =((Parameter) opt).getValidValue(); + if (vc==null){ + return null; + } else { + return new JabaValueConstrain(vc); + } + } + + @Override + public ParameterI copy() + { + return new JabaParameter(ParameterUtils.copyParameter((Parameter)opt)); + } +} diff --git a/src/jalview/ws/jws2/dm/JabaValueConstrain.java b/src/jalview/ws/jws2/dm/JabaValueConstrain.java new file mode 100644 index 0000000..bb21d4a --- /dev/null +++ b/src/jalview/ws/jws2/dm/JabaValueConstrain.java @@ -0,0 +1,36 @@ +package jalview.ws.jws2.dm; + +import compbio.metadata.ValueConstrain; +import compbio.metadata.ValueConstrain.Type; + +import jalview.ws.params.ValueConstrainI; + +public class JabaValueConstrain implements ValueConstrainI +{ + + ValueConstrain vc=null; + public JabaValueConstrain(ValueConstrain vc) + { + this.vc = vc; + } + + @Override + public Type getType() + { + // TODO: refactor to local Jalview parameter type system. + return vc.getType(); + } + + @Override + public Number getMax() + { + return vc.getMax(); + } + + @Override + public Number getMin() + { + return vc.getMin(); + } + +} diff --git a/src/jalview/ws/jws2/dm/JabaWsParamSet.java b/src/jalview/ws/jws2/dm/JabaWsParamSet.java new file mode 100644 index 0000000..ac90baa --- /dev/null +++ b/src/jalview/ws/jws2/dm/JabaWsParamSet.java @@ -0,0 +1,187 @@ +package jalview.ws.jws2.dm; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + +import compbio.metadata.Argument; +import compbio.metadata.Option; + +import jalview.ws.jws2.JabaParamStore; +import jalview.ws.jws2.ParameterUtils; +import jalview.ws.params.ArgumentI; +import jalview.ws.params.ParamDatastoreI; +import jalview.ws.params.WsParamSetI; + +public class JabaWsParamSet implements WsParamSetI +{ + /** + * raw jaba arguments. + */ + List