import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
+import javax.swing.JSplitPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class WsJobParameters extends JPanel implements ItemListener,
ActionListener
{
- private static final int PARAM_WIDTH = 340, PARAM_HEIGHT = 150,PARAM_CLOSEDHEIGHT=80;
+ private static final int PARAM_WIDTH = 340, PARAM_HEIGHT = 150,
+ PARAM_CLOSEDHEIGHT = 80;
private static final int OPTSET_HEIGHT = 30;
JPanel setDetails = new JPanel();
- JPanel settingsPanel = new JPanel();
+ JSplitPane settingsPanel = new JSplitPane();
+
+ JSplitPane jobPanel = new JSplitPane();
JPanel jobOptions = new JPanel();
JPanel jobParameters = new JPanel();
- JPanel paramButtons = new JPanel();
-
- JPanel paramPanel = new JPanel();
+ JButton savmodified = new JButton();
- JLabel modified = new JLabel();
+ JButton renmodified = new JButton();
JButton startjob = new JButton();
JButton canceljob = new JButton();
- JButton exportParams = new JButton();
-
- JButton importParams = new JButton();
-
- JButton resetParams = new JButton();
-
- JButton addParam = new JButton();
-
- JButton removeParam = new JButton();
-
- JButton editParam = new JButton();
-
JComboBox setName = new JComboBox();
JTextArea setDescr = new JTextArea();
RunnerConfig serviceOptions;
- List<Parameter> availableParameters;
-
private BorderLayout jparamLayout;
WsJobParameters(Jws2Instance service)
{
super();
jbInit();
- argSetModified(false);
+ // argSetModified(false);
// populate parameter table
initForService(service, p, jobArgset);
// display in new JFrame attached to parent.
private void jbInit()
{
- modified.setText("*");
- modified.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- modified.setForeground(Color.red);
- modified.setHorizontalAlignment(SwingConstants.RIGHT);
-
- exportParams.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- exportParams.setText("Export");
- exportParams.setToolTipText("Export parameters to a file");
- exportParams.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- exportParams_actionPerformed(e);
- }
- });
- importParams.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- importParams.setText("Import");
- importParams.setToolTipText("Import parameters from a file");
- importParams.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- importParams_actionPerformed(e);
- }
- });
- resetParams.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- resetParams.setText("Defaults");
- resetParams.setToolTipText("Reset to defaults");
- resetParams.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- resetParams_actionPerformed(e);
- }
- });
- addParam.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- addParam.setText("Add");
- addParam.setToolTipText("Add new parameter");
- addParam.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- addParam_actionPerformed(e);
- }
- });
- removeParam.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- removeParam.setText("Remove");
- removeParam.setToolTipText("Remove selected parameter");
- removeParam.addActionListener(new ActionListener()
+ 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()
{
+
public void actionPerformed(ActionEvent e)
{
- removeParam_actionPerformed(e);
+ savModified_actionPerformed(e);
}
});
- editParam.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- editParam.setText("Edit");
- editParam.setToolTipText("Edit selected parameter");
- editParam.addActionListener(new ActionListener()
+ 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)
{
- editParam_actionPerformed(e);
+ renModified_actionPerformed(e);
}
});
+ renmodified.setVisible(false);
startjob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
startjob.setText("Start");
startjob.setToolTipText("Start Job");
setName.setEditable(true);
setName.addItemListener(this);
setName.getEditor().addActionListener(this);
- modified.setPreferredSize(new Dimension(15, 15));
+ 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(modified, BorderLayout.EAST);
+ SetNamePanel.add(renmodified, BorderLayout.CENTER);
+ SetNamePanel.add(savmodified, BorderLayout.EAST);
setDetails.add(SetNamePanel, BorderLayout.NORTH);
setDetails.add(setDescrView, BorderLayout.CENTER);
// setDetails.setPreferredSize(new Dimension(360, 100));
paramPane.setPreferredSize(new Dimension(360, 300));
paramPane.getVerticalScrollBar().setUnitIncrement(20);
// paramPanel.setPreferredSize(new Dimension(360, 300));
- paramButtons.setLayout(new GridLayout(2, 3));
- paramButtons.add(addParam);
- paramButtons.add(editParam);
- paramButtons.add(removeParam);
// TODO: relayout buttons nicely
- paramButtons.add(exportParams);
- paramButtons.add(importParams);
- paramButtons.add(resetParams);
paramPane.getViewport().setView(paramList);
- jobParameters.add(paramPane, BorderLayout.NORTH);
- // jobParameters.add(paramButtons, BorderLayout.SOUTH);
- settingsPanel.setLayout(new GridLayout(2,1));
- // settingsPanel.add(modified, BorderLayout.NORTH);
+ jobParameters.add(paramPane, BorderLayout.CENTER);
JPanel jobOptionsPanel = new JPanel();
jobOptionsPanel.setLayout(new BorderLayout());
jobOptionsPanel.setBorder(new TitledBorder("Options"));
jobOptionsPane.getViewport().setView(jobOptions);
jobOptionsPanel.add(jobOptionsPane, BorderLayout.CENTER);
- settingsPanel.add(jobOptionsPanel);
- settingsPanel.add(jobParameters);
+ settingsPanel.setLeftComponent(jobOptionsPanel);
+ settingsPanel.setRightComponent(jobParameters);
+ settingsPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
+ settingsPanel.setDividerLocation(0.4);
setLayout(new BorderLayout());
// setPreferredSize(new Dimension(400, 600));
// setSize(new Dimension(400, 600));
- add(setDetails, BorderLayout.NORTH);
- add(settingsPanel, BorderLayout.CENTER);
+ jobPanel.setLeftComponent(setDetails);
+ jobPanel.setRightComponent(settingsPanel);
+ jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
+ jobPanel.setDividerLocation(0.8);
+ add(jobPanel, BorderLayout.CENTER);
JPanel dialogpanel = new JPanel();
dialogpanel.add(startjob);
dialogpanel.add(canceljob);
add(dialogpanel, BorderLayout.SOUTH);
}
+ protected void renModified_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)
+ {
+ // TODO Auto-generated method stub
+ // Store the current settings
+ // write out param file and name.
+ // update gui
+ initArgSetModified(); // reset the modification state
+
+ }
+
protected void canceljob_actionPerformed(ActionEvent e)
{
response = 0;
}
}
- protected void editParam_actionPerformed(ActionEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- protected void removeParam_actionPerformed(ActionEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- protected void addParam_actionPerformed(ActionEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- protected void resetParams_actionPerformed(ActionEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- protected void importParams_actionPerformed(ActionEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- protected void exportParams_actionPerformed(ActionEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
Jws2Instance service;
+ /**
+ * set if dialog is being set - so handlers will avoid spurious events
+ */
+ boolean settingDialog = false;
+
void initForService(Jws2Instance service, Preset p,
List<Argument> jobArgset)
{
+ settingDialog = true;
this.service = service;
+ // TODO: Recover window geometry prefs for this service
+ // jobPanel.setDividerLocation(proportionalLocation)
+ // settingsPanel.setDividerLocation(proportionalLocation)
+ Hashtable exnames = new Hashtable();
+ for (int i=0,iSize=setName.getItemCount(); i<iSize; i++)
+ {
+ exnames.put((String) setName.getItemAt(i),setName.getItemAt(i));
+ }
+ // Add the default entry - if not present already.
+ if (!exnames.contains("Defaults"))
+ {
+ setName.addItem("Defaults");
+ exnames.put("Defaults", "Defaults");
+ }
serviceOptions = service.getRunnerConfig();
// add any presets not already added.
String curname = (p == null ? "" : p.getName());
{
for (Object pr : prList)
{
- if (p == null || !curname.equals(((Preset) pr).getName()))
+ if (!exnames.contains(((Preset) pr).getName()))
{
setName.addItem(((Preset) pr).getName());
}
}
}
updateTable(p, jobArgset);
+ initArgSetModified();
+ settingDialog = false;
+
}
@SuppressWarnings("unchecked")
private void updateTable(Preset p, List<Argument> jobArgset)
{
- availableParameters = new ArrayList<Parameter>();
List<Parameter> setargs = new ArrayList<Parameter>();
// populate table from default parameter set.
List<Argument> args = serviceOptions.getArguments();
if (myarg instanceof Parameter)
{
Parameter parm = (Parameter) myarg;
- if (true) // parm.isRequired())
- {
- addParameter(parm);
- }
- else
- {
- availableParameters.add(parm);
- }
+ addParameter(parm);
}
else
{
{
Option opt = (Option) myarg;
addOption(opt);
- if (opt.isRequired())
- {
- selectOption(opt, opt.getDefaultValue());
- }
+ // Apply default value, always.
+ selectOption(opt, opt.getDefaultValue());
}
else
{
}
if (p != null)
{
- if (lastParmSet == null)
- {
- // initialise setname
- setName.addItem(p.getName());
- }
- setDescr.setText(p.getDescription());
+ // initialise setname
+ setName.setSelectedItem(lastSetName=p.getName());
+ setDescr.setText(lastDescrText=p.getDescription());
// TODO - URL link
try
{
args = p.getArguments(serviceOptions);
+ // quick test of getArguments
+ for (Object rg: p.getOptions())
+ {
+ String _rg = ((String) rg).substring(1);// remove initial arg character -
+ String _rgv = _rg;
+ // select arg name
+ int _rgs = _rg.indexOf(" ");
+ if (_rgs>0)
+ {
+ _rgv = _rg.substring(_rgs+1);
+ _rg = _rg.substring(0,_rgs);
+ }
+ boolean found=false;
+ for (Argument ar:args)
+ {
+ if (ar.getName().equalsIgnoreCase(_rg) || ar.getDefaultValue()!=null && ar.getDefaultValue().equalsIgnoreCase(_rgv))
+ {
+ found = true;
+ continue;
+ }
+ }
+ if (!found)
+ {
+ System.err.println("Couldn't set Argument: "+rg.toString());
+ }
+ }
} catch (Exception e)
{
e.printStackTrace();
if (lastParmSet == null)
{
// first call - so create a dummy name
- setName.addItem("Defaults *");
+ setName.setSelectedItem(lastSetName="Defaults");
}
}
+
if (jobArgset != null)
{
- argSetModified(true);
+ argSetModified(jobArgset, true);
args = jobArgset;
}
// get setargs from current object
{
if (arg instanceof Option)
{
+ System.out.println("Setting option "+arg.getName()+" with "+arg.getDefaultValue());
selectOption((Option) arg, arg.getDefaultValue());
}
}
private boolean isModified()
{
- return modified.isVisible();
+ return savmodified.isEnabled();
}
- private void argSetModified(boolean b)
+ private Hashtable modifiedElements = new Hashtable();
+ /**
+ * reset gui and modification state settings
+ */
+ private void initArgSetModified() {
+ curSetName = null;
+ modifiedElements.clear();
+ renmodified.setVisible(false);
+ savmodified.setEnabled(false);
+
+ }
+ private void argSetModified(Object modifiedElement, boolean b)
{
- modified.setVisible(b);
- /*
- * String setn = (String)setName.getSelectedItem(); if (setn==null) return;
- * int p = setName.getSelectedIndex(); if (b) { if (setn.length()<2 ||
- * setn.lastIndexOf(" *")!=setn.length()-2) { setn = setn+" *"; } } else {
- * if (setn.lastIndexOf(" *")==setn.length()-2) { setn =
- * setn.substring(0,setn.length()-2); } } // edit the list
- *
- * Object[] objects = new Object[setName.getItemCount()]; for (int
- * i=0;i<objects.length; i++) { objects[i] = setName.getItemAt(i); }
- * objects[p] = setn; setName.removeAllItems(); for (int
- * i=0;i<objects.length; i++) { setName.addItem(objects[i]); }
- * setName.setSelectedIndex(p);
- */
+ if (!b)
+ {
+ modifiedElements.remove(modifiedElement);
+ }
+ else
+ {
+ modifiedElements.put(modifiedElement, modifiedElement);
+ }
+ // set mod status based on presence of elements in table
+ savmodified.setEnabled(modifiedElements.size() > 0);
+ // special reveal if setName has been modified
+ if (modifiedElements.get(setName) != null)
+ {
+ if (curSetName != null && lastSetName!=null && !lastSetName.equals(curSetName))
+ {
+ // also test to see if lastSetName exists in preset store
+ renmodified.setVisible(true);
+ }
+ }
+ else
+ {
+ // setname isn't in modlist - so don't rename
+ renmodified.setEnabled(false);
+ }
validate();
}
paramSet.put(parm.getName(), pb);
paramList.add(pb);
}
+ pb.init();
+ // take the defaults from the parameter
+ pb.updateControls(parm);
}
private void selectOption(Option opt, String string)
}
}
+ cb.setInitialValue();
}
Map<String, ParamBox> paramSet = new Hashtable<String, ParamBox>();
JButton showDesc = new JButton();
JTextArea string = new JTextArea();
+
JScrollPane descPanel = new JScrollPane();
JSlider slider = null;
JTextField valueField = null;
ValueConstrain validator = null;
+
JPanel settingPanel = new JPanel();
- JPanel controlPanel=new JPanel();
+
+ JPanel controlPanel = new JPanel();
boolean integ = false;
boolean choice = false;
- boolean descisvisible=false;
+
+ boolean descisvisible = false;
+
+ final WsJobParameters pmdialogbox;
+
public ParamBox(final WsJobParameters pmlayout, Parameter parm)
{
+ pmdialogbox = pmlayout;
setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
setBorder(new TitledBorder(parm.getName()));
setLayout(null);
- showDesc.setFont(new Font("Verdana", Font.PLAIN, 11));
- showDesc.setText("?");
+ showDesc.setFont(new Font("Verdana", Font.PLAIN, 6));
+ showDesc.setText("+");
string.setFont(new Font("Verdana", Font.PLAIN, 11));
string.setBackground(getBackground());
// string.setSize(new Dimension(PARAM_WIDTH, 80));
string.setEditable(false);
descPanel.getViewport().setView(string);
- //descPanel.setLocation(2,17);
+ // descPanel.setLocation(2,17);
descPanel.setVisible(false);
// string.setMinimumSize(new Dimension(140,80));
// string.setMaximumSize(new Dimension(280,80));
- final ParamBox me=this;
- showDesc.addActionListener(new ActionListener() {
+ final ParamBox me = this;
+ showDesc.addActionListener(new ActionListener()
+ {
@Override
public void actionPerformed(ActionEvent e)
{
- descisvisible=!descisvisible;
+ descisvisible = !descisvisible;
descPanel.setVisible(descisvisible);
- me.setPreferredSize(new Dimension(PARAM_WIDTH, (descisvisible) ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT));
+ me.setPreferredSize(new Dimension(PARAM_WIDTH,
+ (descisvisible) ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT));
me.validate();
pmlayout.refreshParamLayout();
}
string.setLineWrap(true);
string.setColumns(32);
string.setText(parm.getDescription());
- // name.setToolTipText(parm.getDescription());
JPanel firstrow = new JPanel();
firstrow.setLayout(null);
controlPanel.setLayout(new BorderLayout());
- controlPanel.setBounds(new Rectangle(39, 10, PARAM_WIDTH-70,PARAM_CLOSEDHEIGHT-50));
- showDesc.setBounds(new Rectangle(10,10,16,16));
+ controlPanel.setBounds(new Rectangle(39, 10, PARAM_WIDTH - 70,
+ PARAM_CLOSEDHEIGHT - 50));
+ showDesc.setBounds(new Rectangle(10, 10, 16, 16));
firstrow.add(showDesc);
firstrow.add(controlPanel);
- firstrow.setBounds(new Rectangle(10,20,PARAM_WIDTH-30, PARAM_CLOSEDHEIGHT-30));
+ firstrow.setBounds(new Rectangle(10, 20, PARAM_WIDTH - 30,
+ PARAM_CLOSEDHEIGHT - 30));
add(firstrow);
validator = parm.getValidValue();
parameter = parm;
}
}
updateControls(parm);
- descPanel.setBounds(new Rectangle(10,PARAM_CLOSEDHEIGHT+10, PARAM_WIDTH-20, PARAM_HEIGHT-PARAM_CLOSEDHEIGHT-30));
+ descPanel.setBounds(new Rectangle(10, PARAM_CLOSEDHEIGHT,
+ PARAM_WIDTH - 20, PARAM_HEIGHT - PARAM_CLOSEDHEIGHT - 5));
add(descPanel);
validate();
}
+ public void init()
+ {
+ // reset the widget's initial value.
+ lastVal = null;
+ }
boolean adjusting = false;
Parameter parameter;
JComboBox choicebox;
+
public int getBoxHeight()
{
return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT);
}
+
public void updateControls(Parameter parm)
{
adjusting = true;
- boolean init = valueField == null;
+ boolean init = (choicebox==null && valueField==null);
float fVal = 0f;
int iVal = 0;
if (init)
{
choicebox = new JComboBox();
choicebox.addActionListener(this);
- controlPanel.add(choicebox,BorderLayout.CENTER);
+ controlPanel.add(choicebox, BorderLayout.CENTER);
}
else
{
valueField = new JTextField();
valueField.addActionListener(this);
valueField.setPreferredSize(new Dimension(60, 25));
- controlPanel.add(slider,BorderLayout.WEST);
+ controlPanel.add(slider, BorderLayout.WEST);
controlPanel.add(valueField, BorderLayout.EAST);
}
{
if (choice)
{
- List vals = parm.getPossibleValues();
- for (Object val : vals)
- {
- choicebox.addItem(val);
+ if (init) {
+ List vals = parm.getPossibleValues();
+ for (Object val : vals)
+ {
+ choicebox.addItem(val);
+ }
}
+
if (parm.getDefaultValue() != null)
{
choicebox.setSelectedItem(parm.getDefaultValue());
valueField.setText(parm.getDefaultValue());
}
}
- updateSliderFromValueField();
+ lastVal = updateSliderFromValueField();
adjusting = false;
}
+ Object lastVal;
+
public Parameter getParameter()
{
try
valueField.setText(""
+ ((integ) ? ("" + (int) slider.getValue())
: ("" + (float) (slider.getValue() / 1000f))));
+ checkIfModified();
}
+
}
@Override
public void actionPerformed(ActionEvent e)
{
- if (choice)
+ if (adjusting)
{
+ return;
}
- else if (!adjusting)
+ if (!choice)
{
updateSliderFromValueField();
}
- argSetModified(true);
+ checkIfModified();
}
+ private void checkIfModified()
+ {
+ Object cstate = updateSliderFromValueField();
+ boolean notmod = false;
+ if (cstate.getClass() == lastVal.getClass())
+ {
+ if (cstate instanceof int[])
+ {
+ notmod = (((int[]) cstate)[0] == ((int[]) lastVal)[0]);
+ }
+ else if (cstate instanceof float[])
+ {
+ notmod = (((float[]) cstate)[0] == ((float[]) lastVal)[0]);
+ }
+ else if (cstate instanceof String[])
+ {
+ notmod = (((String[]) cstate)[0].equals(((String[]) lastVal)[0]));
+ }
+ }
+ pmdialogbox.argSetModified(this, !notmod);
+ }
}
Map<String, OptionBox> optSet = new Hashtable<String, OptionBox>();
{
option = opt;
setLayout(new BorderLayout());
- enabled.setSelected(opt.isRequired());
+ enabled.setSelected(opt.isRequired()); // TODO: lock required options
enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
enabled.setText(opt.getName());
enabled.setToolTipText(opt.getDescription());
+ enabled.addActionListener(this);
add(enabled, BorderLayout.NORTH);
if (opt.getPossibleValues().size() > 1)
{
// TODO: add actionListeners for popup (to open further info),
// and to update list of parameters if an option is enabled
// that takes a value.
+ setInitialValue();
+ }
+
+ boolean initEnabled = false;
+
+ String initVal = null;
+
+ public void setInitialValue()
+ {
+ initEnabled = enabled.isSelected();
+ if (option.getPossibleValues() != null
+ && option.getPossibleValues().size() > 1)
+ {
+ initVal = (String) val.getSelectedItem();
+ }
}
public Option getOptionIfEnabled()
@Override
public void actionPerformed(ActionEvent e)
{
- argSetModified(true);
- enabled.setSelected(true);
+ if (e.getSource() != enabled)
+ {
+ enabled.setSelected(true);
+ }
+ checkIfModified();
+ }
+
+ private void checkIfModified()
+ {
+ boolean notmod = (initEnabled == enabled.isSelected());
+ if (initVal != null)
+ {
+ notmod = initVal.equals(val.getSelectedItem());
+ }
+ argSetModified(this, !notmod);
}
}
protected void refreshParamLayout()
{
- int s=100;
- for (ParamBox pbox : paramSet.values()){
- s+=pbox.getBoxHeight();
+ int s = 100;
+ for (ParamBox pbox : paramSet.values())
+ {
+ s += pbox.getBoxHeight();
}
paramList.setPreferredSize(new Dimension(PARAM_WIDTH, s));
paramList.setLayout(new FlowLayout());
WsJobParameters pgui = new WsJobParameters(lastserv, pr);
JFrame jf = new JFrame("Parameters for " + lastserv.getActionText());
JPanel cont = new JPanel();
- jf.setPreferredSize(new Dimension(600, 800));
+ // jf.setPreferredSize(new Dimension(600, 800));
cont.add(pgui);
jf.add(cont);
final Thread thr = Thread.currentThread();
Hashtable<String, Object[]> editedParams = new Hashtable<String, Object[]>();
+ /**
+ * 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<Argument> 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;
+ }
+
+ private Object[] _getUserPreset(String setName)
+ {
+ return editedParams.get(setName);
+ }
+
+ private void reInitDialog(String nextPreset)
+ {
+ settingDialog = true;
+ // updateTable(null,null);
+ Object[] pset = _getUserPreset(nextPreset);
+ if (pset != null)
+ {
+ setDescr.setText((String) pset[1]);
+ updateTable(null, (List<Argument>) pset[2]);
+ lastParmSet = nextPreset;
+ validate();
+ }
+ else
+ {
+ // must be a default preset from service
+ Preset p = null;
+ try
+ {
+ PresetManager prman = service.getPresets();
+ if (prman != null)
+ {
+ p = prman.getPresetByName(nextPreset);
+ }
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ if (p != null)
+ {
+ updateTable(p, null);
+ lastParmSet = nextPreset;
+ }
+ }
+ initArgSetModified();
+ validate();
+ settingDialog = false;
+
+ }
+
+ String curSetName = null;
+
@Override
public void itemStateChanged(ItemEvent e)
{
+ if (settingDialog)
+ {
+ // ignore event
+ return;
+ }
if (e.getSource() == setName)
{
String setname = (String) setName.getSelectedItem();
{
return;
}
- // if modified - warn user - or at least save current edited set.
- if (lastParmSet != null)
+ if (curSetName == null || !setname.equals(curSetName))
{
- // save current state
- Object[] pset;
- editedParams.put(lastParmSet, pset = new Object[3]);
- pset[0] = lastParmSet;
- pset[1] = setDescr.getText();
- pset[2] = getJobParams();
- }
- Object[] pset = editedParams.get(setname);
- if (pset != null)
- {
- setDescr.setText((String) pset[1]);
- updateTable(null, (List<Argument>) pset[2]);
- lastParmSet = setname;
- validate();
- }
- else
- {
- // must be a default preset from service
- Preset p = null;
- try
- {
- PresetManager prman = service.getPresets();
- if (prman!=null)
- {
- p = prman.getPresetByName(setname);
- }
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- if (p != null)
+ if (isModified())
{
- updateTable(p, null);
- validate();
- lastParmSet = setname;
+ raiseQueryAndSave();
}
+ 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;
+
+ /**
+ * last saved value of the description text for this user preset
+ */
+ String lastDescrText = null;
+
@Override
public void actionPerformed(ActionEvent e)
{
- if (e.getSource() == setName)
+ if (e.getSource() instanceof Component)
+ {
+ Component src = (Component) e.getSource();
+ if (src.getParent() == setName)
+ {
+ // rename any existing records we know about for this set.
+ curSetName = (String) e.getActionCommand();
+ System.err.println("Command " + curSetName + " : "
+ + setName.getSelectedItem());
+ if (curSetName.trim().equals(setName.getSelectedItem()))
+ {
+ curSetName=null;
+ }
+ if (curSetName!=null)
+ {
+ argSetModified(setName, lastSetName!=null || !curSetName.equals(lastSetName));
+ return;
+ }
+
+ }
+ }
+ if (e.getSource() == setDescr)
{
- // rename any existing records we know about for this set.
- String newname = (String) setName.getSelectedItem();
- System.err.println("Command " + newname + " : "
- + e.getActionCommand());
+ if (lastDescrText != null)
+ {
+ argSetModified(setDescr, !setDescr.getText().equals(lastDescrText));
+ }
}
}
-}
+}
\ No newline at end of file