setName.setEditable(true);
setName.addItemListener(this);
setName.getEditor().addActionListener(this);
- JPanel setNameInfo=new JPanel(new FlowLayout(FlowLayout.LEFT));
- SetNamePanel.setLayout(new GridLayout(2,1));
+ JPanel setNameInfo = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ SetNamePanel.setLayout(new GridLayout(2, 1));
SetNamePanel.setMinimumSize(new Dimension(300, 40));
JLabel setNameLabel = new JLabel("Parameter set: ");
setNameLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
createpref.setVisible(false);
JPanel setsavebuts = new JPanel();
setsavebuts.setLayout(new FlowLayout(FlowLayout.LEFT)); // GridLayout(1,2));
- ((FlowLayout)setsavebuts.getLayout()).setHgap(10);
- ((FlowLayout)setsavebuts.getLayout()).setVgap(0);
+ ((FlowLayout) setsavebuts.getLayout()).setHgap(10);
+ ((FlowLayout) setsavebuts.getLayout()).setVgap(0);
setsavebuts.add(deletepref);
setsavebuts.add(revertpref);
setsavebuts.add(createpref);
setsavebuts.add(updatepref);
setsavebuts.setSize(new Dimension(150, 20));
- JPanel buttonArea=new JPanel(new GridLayout(1,1));
+ JPanel buttonArea = new JPanel(new GridLayout(1, 1));
buttonArea.add(setsavebuts);
SetNamePanel.add(setNameInfo);
SetNamePanel.add(buttonArea);
while (_getUserPreset(tnm) != null)
{
tnm = nm + " (" + (++i) + ")";
- renamed=true;
+ renamed = true;
}
if (i > 0)
{
}
if (renamed)
{
- settingDialog=false; // we need this name change to be registered.
+ settingDialog = false; // we need this name change to be registered.
argSetModified(setName, renamed);
}
settingDialog = stn;
{
cb = addOption(opt);
}
- cb.enabled.setSelected(string!=null); // initial state for an option.
+ cb.enabled.setSelected(string != null); // initial state for an option.
if (string != null)
{
if (opt.getPossibleValues().contains(string))
{
return null;
}
- Option opt=null;
+ Option opt = null;
try
{
opt = jalview.ws.jws2.ParameterUtils.copyOption(option);
if (initVal != null)
{
notmod &= initVal.equals(val.getSelectedItem());
- } else {
+ }
+ else
+ {
// compare against default service setting
- notmod &= option.getDefaultValue()==null || option.getDefaultValue().equals(val.getSelectedItem());
+ notmod &= option.getDefaultValue() == null
+ || option.getDefaultValue().equals(val.getSelectedItem());
}
}
else
{
FlowLayout fl = new FlowLayout();
paramList.setLayout(fl);
- int s = 2*fl.getVgap();
+ int s = 2 * fl.getVgap();
for (ParamBox pbox : paramSet.values())
{
- s += fl.getVgap()+pbox.getBoxHeight(); // getBoxHeight();
+ s += fl.getVgap() + pbox.getBoxHeight(); // getBoxHeight();
}
paramList.setPreferredSize(new Dimension(PARAM_WIDTH, s));
validate();
}
}
}
+ {
+ System.out.println("Testing param write:");
+ List<String> writeparam = null, readparam = null;
+ try
+ {
+ writeparam = jalview.ws.jws2.ParameterUtils
+ .writeParameterSet(
+ pr.getArguments(lastserv.getRunnerConfig()),
+ " ");
+ System.out.println("Testing param read :");
+ List<Option> pset = jalview.ws.jws2.ParameterUtils
+ .processParameters(writeparam,
+ lastserv.getRunnerConfig(), " ");
+ readparam = jalview.ws.jws2.ParameterUtils
+ .writeParameterSet(pset, " ");
+ Iterator<String> 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();
+ if (!sn.equals(st))
+ {
+ 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);
+
+ }
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
WsJobParameters pgui = new WsJobParameters(lastserv, pr);
JFrame jf = new JFrame("Parameters for "
+ lastserv.getActionText());
if (isModified())
{
String lsetname = (curSetName != null) ? curSetName : lastParmSet;
- if (lsetname.equals(setname)) {
+ if (lsetname.equals(setname))
+ {
// setname was just edited - so ignore this event.
return;
}
- settingDialog=true;
+ settingDialog = true;
System.out.println("Prompting to save " + lsetname);
if (javax.swing.JOptionPane.showConfirmDialog(this,
- "Parameter set '"+lsetname+"' is modifed\nsave ?", "Save changes ?",
- javax.swing.JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
+ "Parameter set '" + lsetname + "' is modifed\nsave ?",
+ "Save changes ?", javax.swing.JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
{
System.out.println("Saving for " + lsetname);
_storeCurrentPreset(lsetname);
{
checkDescrModified();
}
+
+ public Preset getPreset()
+ {
+ if (isUserPreset || isModified()
+ || (lastParmSet != null && lastParmSet.equals(SVC_DEF)))
+ {
+ return null;
+ }
+ else
+ {
+ Preset p = null;
+ try
+ {
+ return (Preset) service.getPresets().getPresetByName(lastParmSet);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ }
}
\ No newline at end of file
package jalview.ws.jws2;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import compbio.metadata.*;
+
public class ParameterUtils
{
+ public static List<String> writeParameterSet(List<Option> optSet, String pseparator)
+ {
+ List<String> pset = new ArrayList<String>();
+ for (Option o:optSet)
+ {
+ pset.add(o.toCommand(pseparator));
+ }
+ return pset;
+ }
+ /**
+ * Converts options supplied via parameters file into {@code Option} objects
+ * (Refactored from compbio.ws.client.Jws2Client)
+ *
+ * @param <T>
+ * web service type
+ * @param params
+ * @param options
+ * @return List of Options of type T
+ *
+ */
+/* @SuppressWarnings(value =
+ { "true" })
+ public static <T> List<Option<T>> processParameters(List<String> params,
+ RunnerConfig<T> options, String pseparator)
+ */
+ public static List<Option> processParameters(List<String> params,
+ RunnerConfig options, String pseparator)
+ {
+ List<Option> chosenOptions = new ArrayList<Option>();
+ for (String param : params)
+ {
+ String oname = null;
+ if (isParameter(param, pseparator))
+ {
+ oname = getParamName(param, pseparator);
+ }
+ else
+ {
+ oname = param;
+ }
+ Option o = options.getArgumentByOptionName(oname);
+ if (o == null)
+ {
+ System.out.println("WARN ignoring unsuppoted parameter: " + oname);
+ continue;
+ }
+ if (o instanceof Parameter)
+ {
+ o = copyParameter((Parameter) o);
+ }
+ else
+ {
+ o = copyOption(o);
+ }
+ {
+ try
+ {
+ o.setDefaultValue(isParameter(param, pseparator) ? getParamValue(param, pseparator) : param);
+ } catch (WrongParameterException e)
+ {
+ System.out.println("Problem setting value for the parameter: "
+ + param);
+ e.printStackTrace();
+ }
+ }
+ chosenOptions.add(o);
+ }
+ return chosenOptions;
+ }
+
+
+ static String getParamName(String fullName, String pseparator)
+ {
+ assert isParameter(fullName, pseparator);
+ return fullName.substring(0, fullName.indexOf(pseparator));
+ }
+
+ static String getParamValue(String fullName, String pseparator)
+ {
+ assert isParameter(fullName, pseparator);
+ return fullName.substring(fullName.indexOf(pseparator) + 1);
+ }
+
+ static boolean isParameter(String param, String pseparator)
+ {
+ return param.contains(pseparator);
+ }
public static Option copyOption(Option option)
{
setOptionFrom(copy, option);
return copy;
}
+
public static void setOptionFrom(Option copy, Option option)
{
copy.setName(option.getName());
copy.setFurtherDetails(option.getFurtherDetails());
copy.setRequired(option.isRequired());
List<String> names = option.getOptionNames();
- if (names!=null){
- if (names.size()==1)
+ if (names != null)
+ {
+ if (names.size() == 1)
{
HashSet<String> st = new HashSet();
st.add(names.get(0));
copy.setOptionNames(st);
- } else {
- copy.addOptionNames(names.toArray(new String[]{}));
+ }
+ else
+ {
+ copy.addOptionNames(names.toArray(new String[]
+ {}));
}
}
- try {
- if (option.getDefaultValue()!=null)
+ try
+ {
+ if (option.getDefaultValue() != null)
{
copy.setDefaultValue(option.getDefaultValue());
}
public static ValueConstrain copyValueConstrain(ValueConstrain vc)
{
- try {ValueConstrain copy = new ValueConstrain();
- if (vc.getMax()!=null) {
- copy.setMax(vc.getMax().toString());
- }
- if (vc.getMin()!=null) {
- copy.setMin(vc.getMin().toString());
- }
- if (vc.getType()!=null) {
- copy.setType(vc.getType());
- }
- return copy;
- }
- catch (Exception e)
+ try
+ {
+ ValueConstrain copy = new ValueConstrain();
+ if (vc.getMax() != null)
+ {
+ copy.setMax(vc.getMax().toString());
+ }
+ if (vc.getMin() != null)
+ {
+ copy.setMin(vc.getMin().toString());
+ }
+ if (vc.getType() != null)
+ {
+ copy.setType(vc.getType());
+ }
+ return copy;
+ } catch (Exception e)
{
e.printStackTrace();
- throw new Error("Implementation error: could not copy ValueConstrain!");
+ throw new Error(
+ "Implementation error: could not copy ValueConstrain!");
}
}
+
public static Parameter copyParameter(Parameter parameter)
{
- Parameter copy = new Parameter(parameter.getName(), parameter.getDescription());
- if (parameter.getValidValue()!=null) {
+ Parameter copy = new Parameter(parameter.getName(),
+ parameter.getDescription());
+ if (parameter.getValidValue() != null)
+ {
copy.setValidValue(copyValueConstrain(parameter.getValidValue()));
}
List<String> pv = parameter.getPossibleValues();
- if (pv!=null)
+ if (pv != null)
{
- copy.addPossibleValues(pv.toArray(new String[]{}));
+ copy.addPossibleValues(pv.toArray(new String[]
+ {}));
}
setOptionFrom(copy, parameter);
return copy;