From: jprocter Date: Wed, 11 Aug 2010 14:15:45 +0000 (+0000) Subject: improved dialog layout and flow and fixed switching between presets. No preset save... X-Git-Tag: Release_2_6~134 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8a72704baf5131ce36224f1a837a986d4fe98f81;p=jalview.git improved dialog layout and flow and fixed switching between presets. No preset save/load support yet. --- diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 36f416c..ce1c868 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -43,6 +43,7 @@ import javax.swing.JOptionPane; 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; @@ -71,13 +72,16 @@ import jalview.ws.jws2.Jws2Discoverer.Jws2Instance; 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(); @@ -85,28 +89,14 @@ public class WsJobParameters extends JPanel implements ItemListener, 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(); @@ -118,8 +108,6 @@ public class WsJobParameters extends JPanel implements ItemListener, RunnerConfig serviceOptions; - List availableParameters; - private BorderLayout jparamLayout; WsJobParameters(Jws2Instance service) @@ -144,7 +132,7 @@ public class WsJobParameters extends JPanel implements ItemListener, { super(); jbInit(); - argSetModified(false); + // argSetModified(false); // populate parameter table initForService(service, p, jobArgset); // display in new JFrame attached to parent. @@ -177,71 +165,33 @@ public class WsJobParameters extends JPanel implements ItemListener, 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"); @@ -276,11 +226,13 @@ public class WsJobParameters extends JPanel implements ItemListener, 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)); @@ -289,38 +241,51 @@ public class WsJobParameters extends JPanel implements ItemListener, 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; @@ -339,48 +304,32 @@ public class WsJobParameters extends JPanel implements ItemListener, } } - 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 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 jobArgset) { - availableParameters = new ArrayList(); List setargs = new ArrayList(); // populate table from default parameter set. List args = serviceOptions.getArguments(); @@ -419,14 +370,7 @@ public class WsJobParameters extends JPanel implements ItemListener, if (myarg instanceof Parameter) { Parameter parm = (Parameter) myarg; - if (true) // parm.isRequired()) - { - addParameter(parm); - } - else - { - availableParameters.add(parm); - } + addParameter(parm); } else { @@ -434,10 +378,8 @@ public class WsJobParameters extends JPanel implements ItemListener, { Option opt = (Option) myarg; addOption(opt); - if (opt.isRequired()) - { - selectOption(opt, opt.getDefaultValue()); - } + // Apply default value, always. + selectOption(opt, opt.getDefaultValue()); } else { @@ -450,16 +392,39 @@ public class WsJobParameters extends JPanel implements ItemListener, } 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(); @@ -473,12 +438,13 @@ public class WsJobParameters extends JPanel implements ItemListener, 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 @@ -494,6 +460,7 @@ public class WsJobParameters extends JPanel implements ItemListener, { if (arg instanceof Option) { + System.out.println("Setting option "+arg.getName()+" with "+arg.getDefaultValue()); selectOption((Option) arg, arg.getDefaultValue()); } } @@ -516,25 +483,46 @@ public class WsJobParameters extends JPanel implements ItemListener, 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 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(); } @@ -547,6 +535,9 @@ public class WsJobParameters extends JPanel implements ItemListener, 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) @@ -582,6 +573,7 @@ public class WsJobParameters extends JPanel implements ItemListener, } } + cb.setInitialValue(); } Map paramSet = new Hashtable(); @@ -592,6 +584,7 @@ public class WsJobParameters extends JPanel implements ItemListener, JButton showDesc = new JButton(); JTextArea string = new JTextArea(); + JScrollPane descPanel = new JScrollPane(); JSlider slider = null; @@ -599,38 +592,47 @@ public class WsJobParameters extends JPanel implements ItemListener, 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(); } @@ -639,15 +641,16 @@ public class WsJobParameters extends JPanel implements ItemListener, 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; @@ -663,25 +666,33 @@ public class WsJobParameters extends JPanel implements ItemListener, } } 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) @@ -690,7 +701,7 @@ public class WsJobParameters extends JPanel implements ItemListener, { choicebox = new JComboBox(); choicebox.addActionListener(this); - controlPanel.add(choicebox,BorderLayout.CENTER); + controlPanel.add(choicebox, BorderLayout.CENTER); } else { @@ -699,7 +710,7 @@ public class WsJobParameters extends JPanel implements ItemListener, 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); } @@ -709,11 +720,14 @@ public class WsJobParameters extends JPanel implements ItemListener, { 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()); @@ -724,10 +738,12 @@ public class WsJobParameters extends JPanel implements ItemListener, valueField.setText(parm.getDefaultValue()); } } - updateSliderFromValueField(); + lastVal = updateSliderFromValueField(); adjusting = false; } + Object lastVal; + public Parameter getParameter() { try @@ -827,22 +843,46 @@ public class WsJobParameters extends JPanel implements ItemListener, 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 optSet = new Hashtable(); @@ -859,10 +899,11 @@ public class WsJobParameters extends JPanel implements ItemListener, { 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) { @@ -878,6 +919,21 @@ public class WsJobParameters extends JPanel implements ItemListener, // 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() @@ -903,8 +959,21 @@ public class WsJobParameters extends JPanel implements ItemListener, @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); } } @@ -922,9 +991,10 @@ public class WsJobParameters extends JPanel implements ItemListener, 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()); @@ -996,7 +1066,7 @@ public class WsJobParameters extends JPanel implements ItemListener, 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(); @@ -1097,9 +1167,81 @@ public class WsJobParameters extends JPanel implements ItemListener, Hashtable editedParams = new Hashtable(); + /** + * 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 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) 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(); @@ -1107,59 +1249,65 @@ public class WsJobParameters extends JPanel implements ItemListener, { 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) 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