import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
import javax.swing.table.*;
import compbio.metadata.Argument;
import jalview.ws.jws2.Jws2Discoverer;
import jalview.ws.jws2.Jws2Discoverer.Jws2Instance;
+/**
+ * job parameter editing/browsing dialog box. User can browse existing settings
+ * (user + presets + Defaults), and any changes to parameters creates a modified
+ * user parameter set. LOGIC: If the parameter set is modified, and its name is
+ * a valid, non-existant user parameter set, then a save button is shown. If the
+ * parameter set is modified and its name is a valid, extant user parameter set,
+ * then an update button is shown. If user parameter set's name is edited, and
+ * old name exists as a writable user parameter set, then rename button is
+ * shown. If current parameter set is associated with a user defined parameter
+ * set, then : if set is modifed, a 'revert' button is shown. if set is not
+ * modified, a 'delete' button is shown.
+ *
+ * @author JimP
+ *
+ */
public class WsJobParameters extends JPanel implements ItemListener,
- ActionListener
+ ActionListener, DocumentListener
{
+ private static final String SVC_DEF = "Defaults"; // this is the null
+ // parameter set as shown to
+ // user
+
private static final int PARAM_WIDTH = 340, PARAM_HEIGHT = 150,
PARAM_CLOSEDHEIGHT = 80;
private static final int OPTSET_HEIGHT = 30;
+ JPanel SetNamePanel = new JPanel();
+
JPanel setDetails = new JPanel();
JSplitPane settingsPanel = new JSplitPane();
JButton renmodified = new JButton();
+ JButton deletesetting = new JButton();
+
+ JButton revertsetting = new JButton();
+
JButton startjob = new JButton();
JButton canceljob = new JButton();
return false;
}
+ protected JButton makeButton(String label, String tooltip,
+ ActionListener action)
+ {
+ JButton button = new JButton();
+ button.setText(label);
+ button.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
+ button.setForeground(Color.black);
+ button.setHorizontalAlignment(SwingConstants.CENTER);
+ button.setToolTipText(tooltip);
+ button.addActionListener(action);
+ return button;
+ }
+
private void jbInit()
{
- savmodified.setText("Save");
- savmodified.setToolTipText("Not implemented yet :) ");
- savmodified.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- savmodified.setForeground(Color.red);
- savmodified.setHorizontalAlignment(SwingConstants.RIGHT);
- savmodified.addActionListener(new ActionListener()
- {
+ savmodified = makeButton("Save", "Not implemented yet :) ",
+ new ActionListener()
+ {
- public void actionPerformed(ActionEvent e)
- {
- savModified_actionPerformed(e);
- }
- });
- renmodified.setText("Rename");
- renmodified.setToolTipText("Not implemented yet :) ");
- renmodified.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- renmodified.setForeground(Color.red);
- renmodified.setHorizontalAlignment(SwingConstants.CENTER);
- renmodified.addActionListener(new ActionListener()
- {
+ public void actionPerformed(ActionEvent e)
+ {
+ savModified_actionPerformed(e);
+ }
+ });
+ renmodified = makeButton("Rename", "Not implemented yet :) ",
+ new ActionListener()
+ {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ renModified_actionPerformed(e);
+ }
+ });
+ deletesetting = makeButton("Delete", "Not implemented yet :) ",
+ new ActionListener()
+ {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ deleteSetting_actionPerformed(e);
+ }
+ });
+ revertsetting = makeButton("Revert", "Undo changes to parameters.",
+ new ActionListener()
+ {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ revertSetting_actionPerformed(e);
+ }
+ });
- public void actionPerformed(ActionEvent e)
- {
- renModified_actionPerformed(e);
- }
- });
- renmodified.setVisible(false);
startjob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
startjob.setText("Start");
startjob.setToolTipText("Start Job");
setDescr.setWrapStyleWord(true);
setDescr.setLineWrap(true);
setDescr.setBackground(getBackground());
- setDescr.setEditable(false);
+ setDescr.setEditable(true);
+ setDescr.getDocument().addDocumentListener(this);
JScrollPane setDescrView = new JScrollPane();
// setDescrView.setPreferredSize(new Dimension(350, 200));
setDescrView.getViewport().setView(setDescr);
setName.setEditable(true);
setName.addItemListener(this);
setName.getEditor().addActionListener(this);
- savmodified.setEnabled(false); // initially unmodified parameters
- // modified.setPreferredSize(new Dimension(15, 15));
- JPanel SetNamePanel = new JPanel();
SetNamePanel.setLayout(new BorderLayout());
SetNamePanel.add(setName, BorderLayout.WEST);
- SetNamePanel.add(renmodified, BorderLayout.CENTER);
- SetNamePanel.add(savmodified, BorderLayout.EAST);
- setDetails.add(SetNamePanel, BorderLayout.NORTH);
+ // initial button visibility
+ deletesetting.setVisible(false);
+ revertsetting.setVisible(false);
+ renmodified.setVisible(false);
+ savmodified.setVisible(false);
+ JPanel setsavebuts = new JPanel();
+ setsavebuts.setLayout(new FlowLayout());
+ setsavebuts.add(revertsetting, BorderLayout.CENTER);
+ setsavebuts.add(renmodified, BorderLayout.CENTER);
+ setsavebuts.add(deletesetting, BorderLayout.CENTER);
+ setsavebuts.add(savmodified, BorderLayout.EAST);
+ SetNamePanel.add(setsavebuts,BorderLayout.EAST);
setDetails.add(setDescrView, BorderLayout.CENTER);
// setDetails.setPreferredSize(new Dimension(360, 100));
jobParameters.setBorder(new TitledBorder("Parameters"));
jobPanel.setRightComponent(settingsPanel);
jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
jobPanel.setDividerLocation(0.8);
+ add(SetNamePanel, BorderLayout.NORTH);
add(jobPanel, BorderLayout.CENTER);
JPanel dialogpanel = new JPanel();
dialogpanel.add(startjob);
add(dialogpanel, BorderLayout.SOUTH);
}
- protected void renModified_actionPerformed(ActionEvent e)
+ protected void revertSetting_actionPerformed(ActionEvent e)
{
-
// TODO Auto-generated method stub
- // save current prefs with new name and delete user pref with old name
}
- protected void savModified_actionPerformed(ActionEvent e)
+ protected void deleteSetting_actionPerformed(ActionEvent e)
{
- // TODO Auto-generated method stub
- // Store the current settings
- // write out param file and name.
- // update gui
- initArgSetModified(); // reset the modification state
+ String setname = (String) setName.getSelectedItem();
+ int p=setName.getSelectedIndex();
+ if (_getUserPreset(setname)!=null)
+ {
+ _deleteUserPreset(setname);
+
+ }
+ if (p>0 && p+1==setName.getItemCount())
+ {
+ p--;
+ }
+ setName.setSelectedIndex(p);
+
+ }
+ protected void renModified_actionPerformed(ActionEvent e)
+ {
+ if (curSetName==null || _getUserPreset(lastSetName)==null) {
+ System.err.println("can't rename - names unchanged or original name not a preset.");
+ return;
+ }
+ _deleteUserPreset(lastSetName);
+ lastSetName=curSetName;
+ savModified_actionPerformed(e);
+ curSetName=null;
+ boolean setd = settingDialog;
+ settingDialog=true;
+ syncSetNamesWithStore();
+ settingDialog=setd;
+ }
+
+ protected void savModified_actionPerformed(ActionEvent e)
+ {
+ _storeUserPreset(lastSetName=(String) setName.getSelectedItem(), setDescr.getText(), getJobParams());
+ curSetName=null;
+ initArgSetModified(); // reset the modification state
}
protected void canceljob_actionPerformed(ActionEvent e)
Jws2Instance service;
/**
+ * list of service presets in the gui
+ */
+ Hashtable servicePresets = null;
+
+ /**
* set if dialog is being set - so handlers will avoid spurious events
*/
boolean settingDialog = false;
// jobPanel.setDividerLocation(proportionalLocation)
// settingsPanel.setDividerLocation(proportionalLocation)
Hashtable exnames = new Hashtable();
- for (int i=0,iSize=setName.getItemCount(); i<iSize; i++)
+ for (int i = 0, iSize = setName.getItemCount(); i < iSize; i++)
{
- exnames.put((String) setName.getItemAt(i),setName.getItemAt(i));
+ exnames.put((String) setName.getItemAt(i), setName.getItemAt(i));
}
// Add the default entry - if not present already.
- if (!exnames.contains("Defaults"))
+ if (!exnames.contains(SVC_DEF))
{
- setName.addItem("Defaults");
- exnames.put("Defaults", "Defaults");
+ setName.addItem(SVC_DEF);
+ exnames.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)
{
List prList = service.getPresets().getPresets();
{
for (Object pr : prList)
{
+ servicePresets.put(((Preset) pr).getName(), "preset");
if (!exnames.contains(((Preset) pr).getName()))
{
setName.addItem(((Preset) pr).getName());
if (myarg instanceof Option)
{
Option opt = (Option) myarg;
- addOption(opt);
- // Apply default value, always.
- selectOption(opt, opt.getDefaultValue());
+ addOption(opt).resetToDefault();
}
else
{
if (p != null)
{
// initialise setname
- setName.setSelectedItem(lastSetName=p.getName());
- setDescr.setText(lastDescrText=p.getDescription());
+ setName.setSelectedItem(lastSetName = p.getName());
+ setDescr.setText(lastDescrText = p.getDescription());
// TODO - URL link
try
{
if (lastParmSet == null)
{
// first call - so create a dummy name
- setName.setSelectedItem(lastSetName="Defaults");
+ setName.setSelectedItem(lastSetName = SVC_DEF);
}
}
{
if (arg instanceof Parameter)
{
- setargs.add((Parameter) arg);
+ setParameter((Parameter) arg);
}
else
{
if (arg instanceof Option)
{
- System.out.println("Setting option "+arg.getName()+" with "+arg.getDefaultValue());
+ System.out.println("Setting option " + arg.getName() + " with "
+ + arg.getDefaultValue());
selectOption((Option) arg, arg.getDefaultValue());
}
}
}
}
- // mdl.setData(setargs);
- // jobOptions.setLayout(new GridLayout(optSet.size() / 2 + 1, 2));
jobOptions.setPreferredSize(new Dimension(PARAM_WIDTH, optSet.size()
* OPTSET_HEIGHT));
jobOptions.setLayout(new GridLayout(optSet.size(), 1));
refreshParamLayout();
- // paramPanel.setLayout(new GridLayout(paramSet.size(), 1));
- // paramList.va
- // paramPane.getViewport().validate();
paramPane.validate();
validate();
}
private boolean isModified()
{
- return savmodified.isEnabled();
+ return modifiedElements.size() > 0;
}
private Hashtable modifiedElements = new Hashtable();
+
/**
* reset gui and modification state settings
*/
- private void initArgSetModified() {
+ private void initArgSetModified()
+ {
curSetName = null;
modifiedElements.clear();
renmodified.setVisible(false);
- savmodified.setEnabled(false);
-
+ savmodified.setVisible(false);
+
}
+
private void argSetModified(Object modifiedElement, boolean b)
{
+ if (settingDialog)
+ {
+ return;
+ }
+
if (!b)
{
modifiedElements.remove(modifiedElement);
modifiedElements.put(modifiedElement, modifiedElement);
}
// set mod status based on presence of elements in table
- savmodified.setEnabled(modifiedElements.size() > 0);
+ 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 (curSetName != null && lastSetName != null
+ && !lastSetName.equals(curSetName))
{
- // also test to see if lastSetName exists in preset store
- renmodified.setVisible(true);
+ renmodified.setVisible(!isServicePreset(lastSetName));
}
}
else
{
// setname isn't in modlist - so don't rename
- renmodified.setEnabled(false);
+ renmodified.setVisible(false);
}
validate();
}
+ private boolean isServicePreset(String selectedItem)
+ {
+ return selectedItem.equals(SVC_DEF)
+ || servicePresets.containsKey(selectedItem);
+ }
+
+ /**
+ * check if the current set name is a valid set name for saving, if not, then
+ * fix it.
+ */
+ private void makeSetNameValid()
+ {
+ boolean stn = settingDialog;
+ boolean renamed = false;
+ settingDialog = true;
+ String nm = (String) setName.getSelectedItem();
+ // check if the name is reserved - if it is, rename it.
+ if (isServicePreset(nm))
+ {
+ nm = "User " + nm;
+ renamed = true;
+ }
+ // 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
+ for (int i = 0, iS = setName.getItemCount(); i < iS; i++)
+ {
+ String snm = (String) setName.getItemAt(i);
+ if (snm.equals(nm))
+ {
+ makeupdate = true;
+ setName.setSelectedIndex(i);
+ }
+ }
+
+ if (_getUserPreset(nm) != null)
+ {
+ savmodified.setText("Update");
+ }
+ else
+ {
+ if (renamed)
+ {
+ setName.addItem(nm);
+ setName.setSelectedIndex(setName.getItemCount() - 1);
+ }
+ savmodified.setText("Save");
+ }
+ settingDialog = stn;
+ }
+
private void addParameter(Parameter parm)
{
ParamBox pb = paramSet.get(parm.getName());
pb.updateControls(parm);
}
+ private void setParameter(Parameter arg)
+ {
+ ParamBox pb = paramSet.get(arg.getName());
+ if (pb == null)
+ {
+ addParameter(arg);
+ }
+ else
+ {
+ pb.updateControls(arg);
+ }
+
+ }
+
private void selectOption(Option opt, String string)
{
OptionBox cb = optSet.get(opt.getName());
{
cb = addOption(opt);
}
- if (string == null)
- {
- // no value specified. Either a ..
-// if (opt.getPossibleValues()==null || opt.getPossibleValues().size()<=1) {
- // switch
-// cb.enabled.setSelected(true);
-// } else {
-// // or unselected option
-// cb.enabled.setSelected(false);
-// }
- if (opt.isRequired())
- {
- // indicate option needs to be selected!
- }
- else
- {
- cb.enabled.setSelected(false);
- }
- }
- else
+ cb.enabled.setSelected(true); // initial state for an option.
+ if (string != null)
{
- cb.enabled.setSelected(true);
-
if (opt.getPossibleValues().contains(string))
{
cb.val.setSelectedItem(string);
public void updateControls(Parameter parm)
{
adjusting = true;
- boolean init = (choicebox==null && valueField==null);
+ boolean init = (choicebox == null && valueField == null);
float fVal = 0f;
int iVal = 0;
if (init)
{
if (choice)
{
- if (init) {
+ if (init)
+ {
List vals = parm.getPossibleValues();
for (Object val : vals)
{
choicebox.addItem(val);
}
}
-
+
if (parm.getDefaultValue() != null)
{
choicebox.setSelectedItem(parm.getDefaultValue());
setInitialValue();
}
+ public void resetToDefault()
+ {
+ enabled.setSelected(false);
+ if (option.isRequired())
+ {
+ // Apply default value
+ selectOption(option, option.getDefaultValue());
+ }
+ }
+
boolean initEnabled = false;
String initVal = null;
{
initVal = (String) val.getSelectedItem();
}
+ else
+ {
+ initVal = null;
+ }
}
public Option getOptionIfEnabled()
private void checkIfModified()
{
boolean notmod = (initEnabled == enabled.isSelected());
- if (initVal != null)
+ if (enabled.isSelected() && initVal != null)
{
- notmod = initVal.equals(val.getSelectedItem());
+ notmod |= initVal.equals(val.getSelectedItem());
}
argSetModified(this, !notmod);
}
return editedParams.get(setName);
}
+ /**
+ * remove the given user preset from the preset stash
+ *
+ * @param setName
+ */
+ private void _deleteUserPreset(String setName)
+ {
+ editedParams.remove(setName);
+ }
+
+ private void syncSetNamesWithStore()
+ {
+ int n = 0;
+ // remove any set names in the drop down menu that aren't either a reserved
+ // setting, or a user defined or service preset.
+ while (n < setName.getItemCount())
+ {
+ String item = (String) setName.getItemAt(n);
+ if (!isServicePreset(item) && _getUserPreset(item) == null)
+ {
+ setName.removeItemAt(n);
+ }
+ else
+ {
+ n++;
+ }
+
+ }
+ }
+
private void reInitDialog(String nextPreset)
{
settingDialog = true;
+ syncSetNamesWithStore();
// updateTable(null,null);
Object[] pset = _getUserPreset(nextPreset);
if (pset != null)
}
else
{
+ setDescr.setText("");
// must be a default preset from service
Preset p = null;
try
updateTable(p, null);
lastParmSet = nextPreset;
}
+ else
+ {
+ updateTable(null, null);
+ }
}
initArgSetModified();
validate();
}
if (curSetName == null || !setname.equals(curSetName))
{
- if (isModified())
+ if (isModified()
+ && javax.swing.JOptionPane.showConfirmDialog(this,
+ "Parameter set is modifed - save ?",
+ "Save changes ?",
+ javax.swing.JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
{
- raiseQueryAndSave();
+ savModified_actionPerformed(null);
}
reInitDialog(setname);
}
}
/**
- * ask the user if they wan't to save the current settings before switching
- */
- private void raiseQueryAndSave()
- {
-
- }
-
- /**
* last saved name for this user preset
*/
String lastSetName = null;
if (src.getParent() == setName)
{
// rename any existing records we know about for this set.
- curSetName = (String) e.getActionCommand();
+ String newname = (String) e.getActionCommand();
+ String msg=null;
+ if (isServicePreset(newname)) {
+ JOptionPane.showConfirmDialog(this, "Invalid name - preset already exists.", "Invalid name", JOptionPane.OK_OPTION);
+ return;
+ }
+ curSetName = newname;
System.err.println("Command " + curSetName + " : "
+ setName.getSelectedItem());
if (curSetName.trim().equals(setName.getSelectedItem()))
{
- curSetName=null;
+ curSetName = null;
}
- if (curSetName!=null)
+ if (curSetName != null)
{
- argSetModified(setName, lastSetName!=null || !curSetName.equals(lastSetName));
+ setName.addItem(curSetName);
+ setName.setSelectedItem(curSetName);
+ argSetModified(setName,
+ lastSetName != null && !curSetName.equals(lastSetName));
return;
}
}
}
- if (e.getSource() == setDescr)
+ }
+
+ private void checkDescrModified()
+ {
+ if (!settingDialog)
{
- if (lastDescrText != null)
- {
- argSetModified(setDescr, !setDescr.getText().equals(lastDescrText));
- }
+
+ argSetModified(
+ setDescr,
+ (lastDescrText == null ? setDescr.getText().trim().length() > 0
+ : !setDescr.getText().equals(lastDescrText)));
+
}
}
+
+ @Override
+ public void insertUpdate(DocumentEvent e)
+ {
+ checkDescrModified();
+ }
+
+ @Override
+ public void removeUpdate(DocumentEvent e)
+ {
+ checkDescrModified();
+ }
+
+ @Override
+ public void changedUpdate(DocumentEvent e)
+ {
+ checkDescrModified();
+ }
}
\ No newline at end of file