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());
}
}
}
@@ -497,26 +610,28 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
if (p != null)
{
+ isUserPreset = false;
// initialise setname
setName.setSelectedItem(lastSetName = p.getName());
setDescr.setText(lastDescrText = p.getDescription());
// 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
{
if (lastParmSet == null)
{
+ isUserPreset = false;
// first call - so create a dummy name
+
setName.setSelectedItem(lastSetName = SVC_DEF);
}
}
@@ -529,20 +644,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());
+ // System.out.println("Setting option "
+ // + System.identityHashCode(arg) + ":" + arg.getName()
+ // + " with " + arg.getDefaultValue());
+ selectOption((OptionI) arg, arg.getDefaultValue());
}
}
@@ -551,10 +666,12 @@ public class WsJobParameters extends JPanel implements ItemListener,
jobOptions.setPreferredSize(new Dimension(PARAM_WIDTH, optSet.size()
* OPTSET_HEIGHT));
- jobOptions.setLayout(new GridLayout(optSet.size(), 1));
+ FlowLayout fl;
+ jobOptions.setLayout(fl=new FlowLayout(FlowLayout.LEFT));
+
refreshParamLayout();
paramPane.validate();
- validate();
+ revalidate();
}
private boolean isModified()
@@ -571,9 +688,35 @@ public class WsJobParameters extends JPanel implements ItemListener,
{
curSetName = null;
modifiedElements.clear();
- renmodified.setVisible(false);
- savmodified.setVisible(false);
+ updateButtonDisplay();
+ }
+
+ private void updateButtonDisplay()
+ {
+ boolean _update = false, _create = false, _delete = false, _revert = false;
+ if (modifiedElements.size() > 0)
+ {
+ // set modified
+ _revert = true;
+ _update = isUserPreset; // can only update user presets
+ if (!isUserPreset || modifiedElements.containsKey(setName))
+ {
+ // name modified - can create new preset
+ _create = true;
+ }
+ }
+ else
+ {
+ // set unmodified
+ }
+ // can still delete a user preset
+ _delete = isUserPreset;
+ createpref.setVisible(_create);
+ updatepref.setVisible(_update);
+ deletepref.setVisible(_delete);
+ revertpref.setVisible(_revert);
+ validate();
}
private void argSetModified(Object modifiedElement, boolean b)
@@ -582,46 +725,27 @@ public class WsJobParameters extends JPanel implements ItemListener,
{
return;
}
-
if (!b)
{
modifiedElements.remove(modifiedElement);
}
else
{
- modifiedElements.put(modifiedElement, modifiedElement);
- }
- // set mod status based on presence of elements in table
- if (modifiedElements.size() > 0)
- {
- makeSetNameValid();
- savmodified.setVisible(true);
- revertsetting.setVisible(false);
- }
- else
- {
- revertsetting.setVisible(false);
- deletesetting
- .setVisible(!isServicePreset((String) setName
- .getSelectedItem())
- && _getUserPreset((String) setName.getSelectedItem()) != null);
- savmodified.setVisible(false);
- }
- // special reveal if setName has been modified
- if (modifiedElements.get(setName) != null)
- {
- if (curSetName != null && lastSetName != null
- && !lastSetName.equals(curSetName))
+ if (b && modifiedElement == setName
+ && modifiedElements.contains(modifiedElement))
{
- renmodified.setVisible(!isServicePreset(lastSetName));
+ // HACK! prevents iteration on makeSetNameValid
+ b = false;
}
+ modifiedElements.put(modifiedElement, modifiedElement);
}
- else
+ // set mod status based on presence of elements in table
+ if (b && modifiedElements.size() > 0)
{
- // setname isn't in modlist - so don't rename
- renmodified.setVisible(false);
+ makeSetNameValid(!isUserPreset);
+ SetNamePanel.revalidate();
}
- validate();
+ updateButtonDisplay();
}
private boolean isServicePreset(String selectedItem)
@@ -634,32 +758,33 @@ public class WsJobParameters extends JPanel implements ItemListener,
* check if the current set name is a valid set name for saving, if not, then
* fix it.
*/
- private void makeSetNameValid()
+ private void makeSetNameValid(boolean newuserset)
{
boolean stn = settingDialog;
boolean renamed = false;
settingDialog = true;
- String nm = (String) setName.getSelectedItem();
+ String nm = (curSetName != null ? curSetName : (String) setName
+ .getSelectedItem());
// check if the name is reserved - if it is, rename it.
if (isServicePreset(nm))
{
nm = "User " + nm;
- String tnm=nm;
renamed = true;
- int i=0;
- while (_getUserPreset(tnm)!=null)
+ }
+ String tnm = nm;
+ if (newuserset)
+ {
+ int i = 0;
+ while (paramStore.getPreset(tnm) != null)
{
- tnm = nm+" ("+(++i)+")";
+ tnm = nm + " (" + (++i) + ")";
+ renamed = true;
}
- if (i>0)
+ if (i > 0)
{
nm = tnm;
}
}
- // if ()
- // if nm exists in user's preset store then savmodified will update an
- // existing user defined preset
- // if nm doesn't exist, then the button will create a new preset.
boolean makeupdate = false;
// sync the gui with the preset database
@@ -669,41 +794,37 @@ public class WsJobParameters extends JPanel implements ItemListener,
if (snm.equals(nm))
{
makeupdate = true;
- setName.setSelectedIndex(i);
+ // setName.setSelectedIndex(i);
}
}
-
- if (_getUserPreset(nm) != null)
+ if (!makeupdate)
{
- savmodified.setText("Update");
+ setName.addItem(curSetName = nm);
+ setName.setSelectedItem(curSetName);
}
- else
+ if (renamed)
{
- if (renamed)
- {
- setName.addItem(nm);
- setName.setSelectedIndex(setName.getItemCount() - 1);
- }
- savmodified.setText("Save");
+ settingDialog = false; // we need this name change to be registered.
+ argSetModified(setName, renamed);
}
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)
@@ -717,27 +838,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(true); // initial state for an 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!
}
@@ -759,7 +880,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
JTextField valueField = null;
- ValueConstrain validator = null;
+ ValueConstrainI validator = null;
JPanel settingPanel = new JPanel();
@@ -775,7 +896,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));
@@ -796,12 +917,20 @@ public class WsJobParameters extends JPanel implements ItemListener,
finfo = parm.getFurtherDetails();
if (finfo != null)
{
- showDesc.setToolTipText("Click to show brief description, and right click to open link for further information.
");
+ showDesc.setToolTipText(""
+ + JvSwingUtils
+ .wrapTooltip("Click to show brief description
Right click for further information.")
+ + "");
showDesc.addMouseListener(this);
}
else
{
- showDesc.setToolTipText("Click to show brief description.
");
+ showDesc.setToolTipText(""
+ + JvSwingUtils
+ .wrapTooltip("Click to show brief description.")
+ + "");
}
showDesc.addActionListener(new ActionListener()
{
@@ -859,7 +988,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
boolean adjusting = false;
- Parameter parameter;
+ ParameterI parameter;
JComboBox choicebox;
@@ -868,7 +997,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);
@@ -924,23 +1053,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;
}
@@ -958,6 +1080,20 @@ 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() < iVal)
+ {
+ iVal = validator.getMax().intValue();
+ // TODO: provide visual indication that hard limit was reached for
+ // this parameter
+ }
} catch (Exception e)
{
}
@@ -981,6 +1117,20 @@ public class WsJobParameters extends JPanel implements ItemListener,
try
{
fVal = Float.valueOf(valueField.getText());
+ if (validator.getMin() != null
+ && validator.getMin().floatValue() > fVal)
+ {
+ fVal = validator.getMin().floatValue();
+ // TODO: provide visual indication that hard limit was reached for
+ // this parameter
+ }
+ if (validator.getMax() != null
+ && validator.getMax().floatValue() < fVal)
+ {
+ fVal = validator.getMax().floatValue();
+ // TODO: provide visual indication that hard limit was reached for
+ // this parameter
+ }
} catch (Exception e)
{
}
@@ -1067,7 +1217,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
{
if (javax.swing.SwingUtilities.isRightMouseButton(e))
{
- Desktop.showUrl(finfo.toString());
+ showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
}
}
@@ -1108,15 +1258,13 @@ public class WsJobParameters extends JPanel implements ItemListener,
JLabel optlabel = new JLabel();
- URL linkImageURL = getClass().getResource("/images/link.gif");
-
final URL finfo;
boolean hasLink = false;
- Option option;
+ OptionI option;
- public OptionBox(Option opt)
+ public OptionBox(OptionI opt)
{
option = opt;
setLayout(new BorderLayout());
@@ -1130,15 +1278,19 @@ public class WsJobParameters extends JPanel implements ItemListener,
{
hasLink = true;
// optlabel.setToolTipText(""+opt.getDescription()+"
");
- enabled.setToolTipText("" + opt.getDescription()
- + "
");
+ enabled.setToolTipText(""
+ + JvSwingUtils.wrapTooltip(opt.getDescription()
+ + "
")
+ + "");
// optlabel.addMouseListener(this);
enabled.addMouseListener(this);
}
else
{
// optlabel.setToolTipText(opt.getDescription());
- enabled.setToolTipText(opt.getDescription());
+ enabled.setToolTipText(""
+ + JvSwingUtils.wrapTooltip(opt.getDescription())
+ + "");
}
add(enabled, BorderLayout.NORTH);
if (opt.getPossibleValues().size() > 1)
@@ -1182,30 +1334,23 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
else
{
- initVal = null;
+ initVal = (initEnabled) ? option.getDefaultValue() : null;
}
}
- public Option getOptionIfEnabled()
+ public OptionI getOptionIfEnabled()
{
if (!enabled.isSelected())
{
return null;
}
- try
- {
- Option opt = jalview.ws.jws2.ParameterUtils.copyOption(option);
+ OptionI opt = option.copy();
- if (val.getSelectedItem() != null)
- {
- opt.setDefaultValue((String) val.getSelectedItem());
- }
- } catch (WrongParameterException e)
+ if (val.getSelectedItem() != null)
{
- e.printStackTrace();
- return null;
+ opt.setDefaultValue((String) val.getSelectedItem());
}
- return option;
+ return opt;
}
public void actionPerformed(ActionEvent e)
@@ -1220,9 +1365,22 @@ public class WsJobParameters extends JPanel implements ItemListener,
private void checkIfModified()
{
boolean notmod = (initEnabled == enabled.isSelected());
- if (enabled.isSelected() && initVal != null)
+ if (enabled.isSelected())
{
- notmod |= initVal.equals(val.getSelectedItem());
+ if (initVal != null)
+ {
+ notmod &= initVal.equals(val.getSelectedItem());
+ }
+ else
+ {
+ // compare against default service setting
+ notmod &= option.getDefaultValue() == null
+ || option.getDefaultValue().equals(val.getSelectedItem());
+ }
+ }
+ else
+ {
+ notmod &= initVal == null;
}
argSetModified(this, !notmod);
}
@@ -1261,7 +1419,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
- private OptionBox addOption(Option opt)
+ private OptionBox addOption(OptionI opt)
{
OptionBox cb = optSet.get(opt.getName());
if (cb == null)
@@ -1295,13 +1453,14 @@ public class WsJobParameters extends JPanel implements ItemListener,
protected void refreshParamLayout()
{
- int s = 100;
+ FlowLayout fl = new FlowLayout();
+ paramList.setLayout(fl);
+ int s = 2 * fl.getVgap();
for (ParamBox pbox : paramSet.values())
{
- s += pbox.getBoxHeight();
+ s += fl.getVgap() + pbox.getBoxHeight(); // getBoxHeight();
}
paramList.setPreferredSize(new Dimension(PARAM_WIDTH, s));
- paramList.setLayout(new FlowLayout());
validate();
}
@@ -1352,14 +1511,17 @@ public class WsJobParameters extends JPanel implements ItemListener,
prl = prman.getPresets();
}
}
- } else {
+ }
+ else
+ {
PresetManager prman = lastserv.getPresets();
- if (prman!=null) {
+ if (prman != null)
+ {
prl = prman.getPresets();
}
}
Iterator en = (prl == null) ? null : prl.iterator();
- while (en!=null && en.hasNext())
+ while (en != null && en.hasNext())
{
if (en != null)
{
@@ -1370,7 +1532,9 @@ public class WsJobParameters extends JPanel implements ItemListener,
pr = en.next();
}
{
- System.out.println("Testing opts dupes for "+lastserv.getHost()+" : "+lastserv.getActionText()+":"+pr.getName());
+ System.out.println("Testing opts dupes for "
+ + lastserv.getUri() + " : "
+ + lastserv.getActionText() + ":" + pr.getName());
List