JPanel jobParameters = new JPanel();
- JButton savmodified = new JButton();
+ JButton createpref = new JButton();
- JButton renmodified = new JButton();
+ JButton deletepref = new JButton();
- JButton deletesetting = new JButton();
+ JButton revertpref = new JButton();
- JButton revertsetting = new JButton();
+ JButton updatepref = new JButton();
JButton startjob = new JButton();
private void jbInit()
{
- savmodified = makeButton("Save", "Not implemented yet :) ",
+ updatepref = makeButton("Update", "Update the stored user preference",
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
- savModified_actionPerformed(e);
+ update_actionPerformed(e);
}
});
- renmodified = makeButton("Rename", "Not implemented yet :) ",
+ deletepref = makeButton("Delete", "Delete the user preference",
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
- renModified_actionPerformed(e);
+ delete_actionPerformed(e);
}
});
- deletesetting = makeButton("Delete", "Not implemented yet :) ",
+ createpref = makeButton("Create", "Create a new preference",
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
- deleteSetting_actionPerformed(e);
+ create_actionPerformed(e);
}
});
- revertsetting = makeButton("Revert", "Undo changes to parameters.",
- new ActionListener()
+ revertpref = makeButton("Revert",
+ "Undo all changes to the current set", new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
- revertSetting_actionPerformed(e);
+ revert_actionPerformed(e);
}
});
-
startjob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
startjob.setText("Start");
startjob.setToolTipText("Start Job");
setName.addItemListener(this);
setName.getEditor().addActionListener(this);
SetNamePanel.setLayout(new BorderLayout());
+ SetNamePanel.setMinimumSize(new Dimension(300, 35));
SetNamePanel.add(setName, BorderLayout.WEST);
// initial button visibility
- deletesetting.setVisible(false);
- revertsetting.setVisible(false);
- renmodified.setVisible(false);
- savmodified.setVisible(false);
+ updatepref.setVisible(false);
+ deletepref.setVisible(false);
+ revertpref.setVisible(false);
+ createpref.setVisible(false);
JPanel setsavebuts = new JPanel();
+ setsavebuts.setMinimumSize(new Dimension(150, 35));
setsavebuts.setLayout(new FlowLayout());
- setsavebuts.add(revertsetting, BorderLayout.CENTER);
- setsavebuts.add(renmodified, BorderLayout.CENTER);
- setsavebuts.add(deletesetting, BorderLayout.CENTER);
- setsavebuts.add(savmodified, BorderLayout.EAST);
+ setsavebuts.add(createpref, BorderLayout.CENTER);
+ setsavebuts.add(updatepref, BorderLayout.CENTER);
+ setsavebuts.add(revertpref, BorderLayout.EAST);
+ setsavebuts.add(deletepref, BorderLayout.EAST);
SetNamePanel.add(setsavebuts, BorderLayout.EAST);
setDetails.add(setDescrView, BorderLayout.CENTER);
// setDetails.setPreferredSize(new Dimension(360, 100));
add(dialogpanel, BorderLayout.SOUTH);
}
- protected void revertSetting_actionPerformed(ActionEvent e)
+ protected void revert_actionPerformed(ActionEvent e)
{
- // TODO Auto-generated method stub
+ reInitDialog(lastParmSet);
}
- protected void deleteSetting_actionPerformed(ActionEvent e)
+ protected void update_actionPerformed(ActionEvent e)
{
- String setname = (String) setName.getSelectedItem();
- int p = setName.getSelectedIndex();
- if (_getUserPreset(setname) != null)
+ if (isUserPreset)
{
- _deleteUserPreset(setname);
-
- }
- if (p > 0 && p + 1 == setName.getItemCount())
- {
- p--;
+ String curname = ((String) setName.getSelectedItem()).trim();
+ if (curname.length() > 0 && !curname.equals(lastParmSet))
+ {
+ _deleteUserPreset(lastParmSet);
+ }
+ _storeCurrentPreset(curname);
+ lastParmSet = curname;
+ isUserPreset = true;
+ initArgSetModified();
}
- setName.setSelectedIndex(p);
-
}
- protected void renModified_actionPerformed(ActionEvent e)
+ protected void delete_actionPerformed(ActionEvent e)
{
- if (curSetName == null || _getUserPreset(lastSetName) == null)
+ if (isUserPreset)
{
- System.err
- .println("can't rename - names unchanged or original name not a preset.");
- return;
+ // delete current preset's saved entry
+ _deleteUserPreset(lastParmSet);
}
- _deleteUserPreset(lastSetName);
- lastSetName = curSetName;
- savModified_actionPerformed(e);
- curSetName = null;
- boolean setd = settingDialog;
- settingDialog = true;
- syncSetNamesWithStore();
- settingDialog = setd;
+ reInitDialog(null); // service default
}
- protected void savModified_actionPerformed(ActionEvent e)
+ protected void create_actionPerformed(ActionEvent e)
{
- _storeUserPreset(lastSetName=(String) setName.getSelectedItem(), setDescr.getText(), getJobParams());
- curSetName = null;
- initArgSetModified(); // reset the modification state
+ String curname = ((String) setName.getSelectedItem()).trim();
+ if (curname.length() > 0)
+ {
+ _storeCurrentPreset(curname);
+ lastParmSet = curname;
+ isUserPreset = true;
+ initArgSetModified();
+ }
+ else
+ {
+ // TODO: show warning
+ System.err.println("Invalid name. Not saved.");
+ }
}
protected void canceljob_actionPerformed(ActionEvent e)
}
}
}
- updateTable(p, jobArgset);
- initArgSetModified();
+ // TODO: if initial jobArgset matches a given user setting or preset then
+ // should recover setting accordingly
+ // updateTable(p, jobArgset);
+ if (p != null)
+ {
+ reInitDialog(p.getName());
+ initArgSetModified();
+ }
+ else
+ {
+ if (jobArgset != null && jobArgset.size() > 0)
+ {
+ curSetName = "Supplied Settings";
+ updateTable(p, jobArgset);
+ }
+ else
+ {
+ curSetName = null;
+ reInitDialog(null);
+ }
+ }
settingDialog = false;
}
}
if (p != null)
{
+ isUserPreset = false;
// initialise setname
setName.setSelectedItem(lastSetName = p.getName());
setDescr.setText(lastDescrText = p.getDescription());
{
if (lastParmSet == null)
{
+ isUserPreset = false;
// first call - so create a dummy name
setName.setSelectedItem(lastSetName = SVC_DEF);
}
{
if (arg instanceof Option)
{
-// System.out.println("Setting option "
-// + System.identityHashCode(arg) + ":" + arg.getName()
-// + " with " + arg.getDefaultValue());
+ // System.out.println("Setting option "
+ // + System.identityHashCode(arg) + ":" + arg.getName()
+ // + " with " + arg.getDefaultValue());
selectOption((Option) arg, arg.getDefaultValue());
}
}
{
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)
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))
- {
- renmodified.setVisible(!isServicePreset(lastSetName));
- }
- }
- else
+ if (b && modifiedElements.size() > 0)
{
- // setname isn't in modlist - so don't rename
- renmodified.setVisible(false);
+ makeSetNameValid(!isUserPreset);
}
- validate();
+ updateButtonDisplay();
}
private boolean isServicePreset(String selectedItem)
* 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;
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 (_getUserPreset(tnm) != null)
{
- tnm = nm+" ("+(++i)+")";
+ tnm = nm + " (" + (++i) + ")";
}
- 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
if (snm.equals(nm))
{
makeupdate = true;
- setName.setSelectedIndex(i);
+ // setName.setSelectedIndex(i);
}
}
-
- if (_getUserPreset(nm) != null)
- {
- savmodified.setText("Update");
- }
- else
+ if (!makeupdate)
{
- if (renamed)
- {
- setName.addItem(nm);
- setName.setSelectedIndex(setName.getItemCount() - 1);
- }
- savmodified.setText("Save");
+ setName.setSelectedItem(curSetName = nm);
}
settingDialog = stn;
}
}
else
{
- initVal = null;
+ initVal = (initEnabled) ? option.getDefaultValue() : null;
}
}
private void checkIfModified()
{
boolean notmod = (initEnabled == enabled.isSelected());
- if (enabled.isSelected() && initVal != null)
+ if (enabled.isSelected())
+ {
+ if (initVal != null)
+ {
+ notmod |= initVal.equals(val.getSelectedItem());
+ } else {
+ notmod |= false;
+ }
+ }
+ else
{
- notmod |= initVal.equals(val.getSelectedItem());
+ notmod |= initVal == null;
}
argSetModified(this, !notmod);
}
prl = prman.getPresets();
}
}
- } else {
+ }
+ else
+ {
PresetManager prman = lastserv.getPresets();
- if (prman!=null) {
+ if (prman != null)
+ {
prl = prman.getPresets();
}
}
Iterator<Preset> en = (prl == null) ? null : prl.iterator();
- while (en!=null && en.hasNext())
+ while (en != null && en.hasNext())
{
if (en != null)
{
pr = en.next();
}
{
- System.out.println("Testing opts dupes for "+lastserv.getHost()+" : "+lastserv.getActionText()+":"+pr.getName());
+ System.out.println("Testing opts dupes for "
+ + lastserv.getHost() + " : "
+ + lastserv.getActionText() + ":" + pr.getName());
List<Option> rg = lastserv.getRunnerConfig().getOptions();
for (Option o : rg)
{
pset[0] = storeSetName;
pset[1] = descr;
pset[2] = jobParams;
- //writeParam("Saving " + storeSetName + ": ", jobParams);
+ // writeParam("Saving " + storeSetName + ": ", jobParams);
}
private void writeParam(String nm, List<Argument> params)
private Object[] _getUserPreset(String setName)
{
Object[] pset = editedParams.get(setName);
- //if (pset != null)
- // writeParam("Retrieving " + setName + ": ", (List<Argument>) pset[2]);
+ // if (pset != null)
+ // writeParam("Retrieving " + setName + ": ", (List<Argument>) pset[2]);
return pset;
}
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.
+ Vector items = new Vector();
while (n < setName.getItemCount())
{
String item = (String) setName.getItemAt(n);
}
else
{
+ items.addElement(item);
n++;
}
-
+ }
+ for (String upn : editedParams.keySet())
+ {
+ if (!items.contains(upn))
+ {
+ setName.addItem(upn);
+ }
}
}
+ /**
+ * true if lastParmSet is a user preset
+ */
+ boolean isUserPreset = false;
+
private void reInitDialog(String nextPreset)
{
settingDialog = true;
- syncSetNamesWithStore();
// updateTable(null,null); // first reset to defaults
-
- Object[] pset = _getUserPreset(nextPreset);
+ Object[] pset = null;
+ if (nextPreset != null && nextPreset.length() > 0)
+ {
+ pset = _getUserPreset(nextPreset);
+ }
if (pset != null)
{
+ isUserPreset = true;
setDescr.setText((String) pset[1]);
updateTable(null, (List<Argument>) pset[2]);
lastParmSet = nextPreset;
- validate();
}
else
{
+ isUserPreset = false;
setDescr.setText("");
// must be a default preset from service
Preset p = null;
PresetManager prman = service.getPresets();
if (prman != null)
{
+ isUserPreset = false;
p = prman.getPresetByName(nextPreset);
}
} catch (Exception ex)
else
{
updateTable(null, null);
+ lastParmSet = SVC_DEF;
}
}
initArgSetModified();
+ syncSetNamesWithStore();
+ setName.setSelectedItem(lastParmSet);
validate();
settingDialog = false;
public void itemStateChanged(ItemEvent e)
{
- if (settingDialog)
- {
- // ignore event
- return;
- }
- if (e.getSource() == setName)
+ if (e.getSource() == setName && e.getStateChange() == e.SELECTED)
{
String setname = (String) setName.getSelectedItem();
+ System.out.println("Item state changed for " + setname
+ + " (handling ? " + !settingDialog + ")");
+ if (settingDialog)
+ {
+ // ignore event
+ return;
+ }
if (setname == null)
{
return;
}
- if (curSetName == null || !setname.equals(curSetName))
+ // user has selected a different item from combo-box
+ if (isModified())
{
- settingDialog = true;
- if (isModified())
+ String lsetname = (curSetName != null) ? curSetName : lastParmSet;
+ System.out.println("Prompting to save " + lsetname);
+ if (javax.swing.JOptionPane.showConfirmDialog(this,
+ "Parameter set is modifed - save ?", "Save changes ?",
+ javax.swing.JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
{
- System.out.println("Prompting for "+setname);
- if (javax.swing.JOptionPane.showConfirmDialog(this,
- "Parameter set is modifed - save ?", "Save changes ?",
- javax.swing.JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
- {
- System.out.println("Saving for "+setname);
- savModified_actionPerformed(null);
- }
- }
- reInitDialog(setname);
+ System.out.println("Saving for " + setname);
+ _storeCurrentPreset(curSetName);
+ }
}
+ settingDialog = true;
+ reInitDialog(setname);
+ settingDialog = false;
+
}
}
/**
+ * store current settings as given name. You should then reset gui.
+ *
+ * @param curSetName2
+ */
+ private void _storeCurrentPreset(String curSetName2)
+ {
+ _storeUserPreset(curSetName2, setDescr.getText(), getJobParams());
+ }
+
+ /**
* last saved name for this user preset
*/
String lastSetName = null;
if (src.getParent() == setName)
{
// rename any existing records we know about for this set.
- String newname = (String) e.getActionCommand();
+ String newname = (String) e.getActionCommand().trim();
String msg = null;
if (isServicePreset(newname))
{
JOptionPane.showConfirmDialog(this,
"Invalid name - preset already exists.", "Invalid name",
JOptionPane.OK_OPTION);
+ // reset name
+ setName.setSelectedItem(curSetName);
return;
}
curSetName = newname;
- System.err.println("Command " + curSetName + " : "
- + setName.getSelectedItem());
- if (curSetName.trim().equals(setName.getSelectedItem()))
+ System.err.println("New name for user setting " + curSetName
+ + " (was " + setName.getSelectedItem() + ")");
+ if (curSetName.equals(setName.getSelectedItem()))
{
curSetName = null;
}
if (curSetName != null)
{
- setName.addItem(curSetName);
- setName.setSelectedItem(curSetName);
- argSetModified(setName,
- lastSetName != null && !curSetName.equals(lastSetName));
+ argSetModified(setName, true);
return;
}