2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.gui.OptsAndParamsPage.OptionBox;
24 import jalview.gui.OptsAndParamsPage.ParamBox;
25 import jalview.util.MessageManager;
26 import jalview.ws.jws2.JabaParamStore;
27 import jalview.ws.jws2.JabaPreset;
28 import jalview.ws.jws2.Jws2Discoverer;
29 import jalview.ws.jws2.jabaws2.Jws2Instance;
30 import jalview.ws.params.ArgumentI;
31 import jalview.ws.params.OptionI;
32 import jalview.ws.params.ParamDatastoreI;
33 import jalview.ws.params.ParameterI;
34 import jalview.ws.params.WsParamSetI;
36 import java.awt.BorderLayout;
37 import java.awt.Component;
38 import java.awt.Dimension;
39 import java.awt.FlowLayout;
41 import java.awt.GridBagConstraints;
42 import java.awt.GridBagLayout;
43 import java.awt.GridLayout;
44 import java.awt.Rectangle;
45 import java.awt.event.ActionEvent;
46 import java.awt.event.ActionListener;
47 import java.awt.event.HierarchyBoundsListener;
48 import java.awt.event.HierarchyEvent;
49 import java.awt.event.ItemEvent;
50 import java.awt.event.ItemListener;
51 import java.awt.event.WindowEvent;
52 import java.awt.event.WindowListener;
54 import java.util.Hashtable;
55 import java.util.Iterator;
56 import java.util.List;
57 import java.util.Vector;
59 import javax.swing.JButton;
60 import javax.swing.JComboBox;
61 import javax.swing.JDialog;
62 import javax.swing.JFrame;
63 import javax.swing.JLabel;
64 import javax.swing.JOptionPane;
65 import javax.swing.JPanel;
66 import javax.swing.JScrollPane;
67 import javax.swing.JSplitPane;
68 import javax.swing.JTextArea;
69 import javax.swing.border.TitledBorder;
70 import javax.swing.event.DocumentEvent;
71 import javax.swing.event.DocumentListener;
73 import net.miginfocom.swing.MigLayout;
75 import compbio.metadata.Argument;
76 import compbio.metadata.Option;
77 import compbio.metadata.Parameter;
78 import compbio.metadata.Preset;
79 import compbio.metadata.PresetManager;
80 import compbio.metadata.RunnerConfig;
83 * job parameter editing/browsing dialog box. User can browse existing settings
84 * (user + presets + Defaults), and any changes to parameters creates a modified
85 * user parameter set. LOGIC: If the parameter set is modified, and its name is
86 * a valid, non-existant user parameter set, then a save button is shown. If the
87 * parameter set is modified and its name is a valid, extant user parameter set,
88 * then an update button is shown. If user parameter set's name is edited, and
89 * old name exists as a writable user parameter set, then rename button is
90 * shown. If current parameter set is associated with a user defined parameter
91 * set, then : if set is modifed, a 'revert' button is shown. if set is not
92 * modified, a 'delete' button is shown.
97 public class WsJobParameters extends JPanel implements ItemListener,
98 ActionListener, DocumentListener, OptsParametersContainerI
100 URL linkImageURL = getClass().getResource("/images/link.gif");
102 private static final String SVC_DEF = "Defaults"; // this is the null
103 // parameter set as shown to
107 * manager for options and parameters.
109 OptsAndParamsPage opanp = new OptsAndParamsPage(this);
112 * panel containing job options
114 JPanel jobOptions = new JPanel();
117 * panel containing job parameters
119 JPanel paramList = new JPanel();
121 JPanel SetNamePanel = new JPanel();
123 JPanel setDetails = new JPanel();
125 JSplitPane settingsPanel = new JSplitPane();
127 JPanel jobPanel = new JPanel();
129 JScrollPane jobOptionsPane = new JScrollPane();
131 JButton createpref = new JButton();
133 JButton deletepref = new JButton();
135 JButton revertpref = new JButton();
137 JButton updatepref = new JButton();
139 JButton startjob = new JButton();
141 JButton canceljob = new JButton();
143 JComboBox setName = new JComboBox();
145 JTextArea setDescr = new JTextArea();
147 JScrollPane paramPane = new JScrollPane();
149 // ScrollablePanel optsAndparams = new ScrollablePanel();
150 JPanel optsAndparams = new JPanel();
152 RunnerConfig serviceOptions;
154 ParamDatastoreI paramStore;
156 private int MAX_OPTWIDTH = 200;
158 WsJobParameters(Jws2Instance service)
163 public WsJobParameters(Jws2Instance service, WsParamSetI preset)
165 this(null, service, preset, null);
171 * - if null, create new JFrame outside of desktop
175 public WsJobParameters(JFrame parent, Jws2Instance service,
176 WsParamSetI preset, List<Argument> jobArgset)
178 this(parent, null, service, preset, jobArgset);
189 public WsJobParameters(JFrame parent, ParamDatastoreI paramStorei,
190 Jws2Instance service, WsParamSetI preset, List<Argument> jobArgset)
194 this.paramStore = paramStorei;
195 if (paramStore == null)
197 paramStore = service.getParamStore();
199 this.service = service;
200 // argSetModified(false);
201 // populate parameter table
202 initForService(service, preset, jobArgset);
203 // display in new JFrame attached to parent.
209 JDialog frame = null;
212 * shows a modal dialog containing the parameters.
216 public boolean showRunDialog()
219 frame = new JDialog(Desktop.instance, true);
221 frame.setTitle(MessageManager.formatMessage("label.edit_params_for",
222 new String[] { service.getActionText() }));
223 Rectangle deskr = Desktop.instance.getBounds();
224 Dimension pref = this.getPreferredSize();
225 frame.setBounds(new Rectangle(
226 (int) (deskr.getCenterX() - pref.width / 2), (int) (deskr
227 .getCenterY() - pref.height / 2), pref.width,
229 frame.setContentPane(this);
231 // should perhaps recover defaults from user prefs.
234 javax.swing.SwingUtilities.invokeLater(new Runnable()
238 // jobPanel.setDividerLocation(0.25);
242 frame.setVisible(true);
251 private void jbInit()
253 this.addHierarchyBoundsListener(new HierarchyBoundsListener()
257 public void ancestorResized(HierarchyEvent arg0)
259 refreshParamLayout();
263 public void ancestorMoved(HierarchyEvent arg0)
265 // TODO Auto-generated method stub
269 updatepref = JvSwingUtils.makeButton(
270 MessageManager.getString("action.update"),
271 MessageManager.getString("label.update_user_parameter_set"),
275 public void actionPerformed(ActionEvent e)
277 update_actionPerformed(e);
280 deletepref = JvSwingUtils.makeButton(
281 MessageManager.getString("action.delete"),
282 MessageManager.getString("label.delete_user_parameter_set"),
286 public void actionPerformed(ActionEvent e)
288 delete_actionPerformed(e);
291 createpref = JvSwingUtils.makeButton(
292 MessageManager.getString("action.create"),
293 MessageManager.getString("label.create_user_parameter_set"),
297 public void actionPerformed(ActionEvent e)
299 create_actionPerformed(e);
302 revertpref = JvSwingUtils.makeButton(MessageManager
303 .getString("action.revert"), MessageManager
304 .getString("label.revert_changes_user_parameter_set"),
308 public void actionPerformed(ActionEvent e)
310 revert_actionPerformed(e);
313 startjob = JvSwingUtils.makeButton(
314 MessageManager.getString("action.start_job"),
315 MessageManager.getString("label.start_job_current_settings"),
318 public void actionPerformed(ActionEvent e)
320 startjob_actionPerformed(e);
323 canceljob = JvSwingUtils.makeButton(
324 MessageManager.getString("action.cancel_job"),
325 MessageManager.getString("label.cancel_job_close_dialog"),
328 public void actionPerformed(ActionEvent e)
330 canceljob_actionPerformed(e);
334 setDetails.setBorder(new TitledBorder(MessageManager
335 .getString("label.details")));
336 setDetails.setLayout(new BorderLayout());
337 setDescr.setColumns(40);
338 setDescr.setWrapStyleWord(true);
339 setDescr.setLineWrap(true);
340 setDescr.setBackground(getBackground());
341 setDescr.setEditable(true);
342 setDescr.getDocument().addDocumentListener(this);
343 setDescr.setToolTipText(MessageManager
344 .getString("label.edit_notes_parameter_set"));
345 JScrollPane setDescrView = new JScrollPane();
346 setDescrView.getViewport().setView(setDescr);
347 setName.setEditable(true);
348 setName.addItemListener(this);
349 setName.getEditor().addActionListener(this);
350 JPanel setNameInfo = new JPanel(new FlowLayout(FlowLayout.LEFT));
351 GridBagLayout gbl = new GridBagLayout();
352 SetNamePanel.setLayout(gbl);
354 JLabel setNameLabel = new JLabel(
355 MessageManager.getString("label.current_parameter_set_name"));
356 setNameLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
358 setNameInfo.add(setNameLabel);
359 setNameInfo.add(setName);
361 // initial button visibility
362 updatepref.setVisible(false);
363 deletepref.setVisible(false);
364 revertpref.setVisible(false);
365 createpref.setVisible(false);
366 JPanel setsavebuts = new JPanel();
367 setsavebuts.setLayout(new FlowLayout(FlowLayout.LEFT)); // GridLayout(1,2));
368 ((FlowLayout) setsavebuts.getLayout()).setHgap(10);
369 ((FlowLayout) setsavebuts.getLayout()).setVgap(0);
370 JPanel spacer = new JPanel();
371 spacer.setPreferredSize(new Dimension(2, 30));
372 setsavebuts.add(spacer);
373 setsavebuts.add(deletepref);
374 setsavebuts.add(revertpref);
375 setsavebuts.add(createpref);
376 setsavebuts.add(updatepref);
377 // setsavebuts.setSize(new Dimension(150, 30));
378 JPanel buttonArea = new JPanel(new GridLayout(1, 1));
379 buttonArea.add(setsavebuts);
380 SetNamePanel.add(setNameInfo);
381 GridBagConstraints gbc = new GridBagConstraints();
383 gbl.setConstraints(setNameInfo, gbc);
384 SetNamePanel.add(buttonArea);
385 gbc = new GridBagConstraints();
389 gbl.setConstraints(buttonArea, gbc);
390 setDetails.add(setDescrView, BorderLayout.CENTER);
392 // paramPane.setPreferredSize(new Dimension(360, 400));
393 // paramPane.setPreferredSize(null);
394 jobOptions.setBorder(new TitledBorder(MessageManager
395 .getString("label.options")));
396 jobOptions.setOpaque(true);
397 paramList.setBorder(new TitledBorder(MessageManager
398 .getString("label.parameters")));
399 paramList.setOpaque(true);
400 JPanel bjo = new JPanel(new BorderLayout()), bjp = new JPanel(
402 bjo.add(jobOptions, BorderLayout.CENTER);
403 bjp.add(paramList, BorderLayout.CENTER);
406 // optsAndparams.setScrollableWidth(ScrollableSizeHint.FIT);
407 // optsAndparams.setScrollableHeight(ScrollableSizeHint.NONE);
408 // optsAndparams.setLayout(new BorderLayout());
409 optsAndparams.setLayout(new BorderLayout());
410 optsAndparams.add(jobOptions, BorderLayout.NORTH);
411 optsAndparams.add(paramList, BorderLayout.CENTER);
412 JPanel jp = new JPanel(new BorderLayout());
413 jp.add(optsAndparams, BorderLayout.CENTER);
414 paramPane.getViewport().setView(jp);
415 paramPane.setBorder(null);
416 setLayout(new BorderLayout());
417 jobPanel.setPreferredSize(null);
418 jobPanel.setLayout(new BorderLayout());
419 jobPanel.add(setDetails, BorderLayout.NORTH);
420 jobPanel.add(paramPane, BorderLayout.CENTER);
421 // jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
423 add(SetNamePanel, BorderLayout.NORTH);
424 add(jobPanel, BorderLayout.CENTER);
426 JPanel dialogpanel = new JPanel();
427 dialogpanel.add(startjob);
428 dialogpanel.add(canceljob);
429 // JAL-1580: setMaximumSize() doesn't work, so just size for the worst case:
430 // check for null is for JUnit usage
431 final int windowHeight = Desktop.instance == null ? 540
432 : Desktop.instance.getHeight();
433 setPreferredSize(new Dimension(540, windowHeight));
434 add(dialogpanel, BorderLayout.SOUTH);
438 protected void revert_actionPerformed(ActionEvent e)
440 reInitDialog(lastParmSet);
441 updateWebServiceMenus();
444 protected void update_actionPerformed(ActionEvent e)
448 String curname = ((String) setName.getSelectedItem()).trim();
449 _updatePreset(lastParmSet, curname);
450 lastParmSet = curname;
452 initArgSetModified();
453 syncSetNamesWithStore();
457 private void _deleteUserPreset(String lastParmSet2)
459 paramStore.deletePreset(lastParmSet2);
462 protected void delete_actionPerformed(ActionEvent e)
466 // delete current preset's saved entry
467 _deleteUserPreset(lastParmSet);
469 reInitDialog(null); // service default
470 updateWebServiceMenus();
473 protected void create_actionPerformed(ActionEvent e)
475 String curname = ((String) setName.getSelectedItem()).trim();
476 if (curname.length() > 0)
478 _storeCurrentPreset(curname);
479 lastParmSet = curname;
481 reInitDialog(curname);
482 initArgSetModified();
483 updateWebServiceMenus();
487 // TODO: show warning
488 System.err.println("Invalid name. Not saved.");
492 protected void canceljob_actionPerformed(ActionEvent e)
497 frame.setVisible(false);
501 protected void startjob_actionPerformed(ActionEvent e)
506 frame.setVisible(false);
510 Jws2Instance service;
513 * list of service presets in the gui
515 Hashtable servicePresets = null;
518 * set if dialog is being set - so handlers will avoid spurious events
520 boolean settingDialog = false;
522 void initForService(Jws2Instance service, WsParamSetI jabap,
523 List<Argument> jabajobArgset)
525 WsParamSetI p = null;
526 List<ArgumentI> jobArgset = null;
527 settingDialog = true;
528 { // instantiate the abstract proxy for Jaba objects
529 jobArgset = jabajobArgset == null ? null : JabaParamStore
530 .getJwsArgsfromJaba(jabajobArgset);
531 p = jabap; // (jabap != null) ? paramStore.getPreset(jabap.getName()) :
535 Hashtable exnames = new Hashtable();
536 for (int i = 0, iSize = setName.getItemCount(); i < iSize; i++)
538 exnames.put(setName.getItemAt(i), setName.getItemAt(i));
540 servicePresets = new Hashtable();
541 // Add the default entry - if not present already.
542 if (!exnames.contains(SVC_DEF))
544 setName.addItem(SVC_DEF);
545 exnames.put(SVC_DEF, SVC_DEF);
546 servicePresets.put(SVC_DEF, SVC_DEF);
548 String curname = (p == null ? "" : p.getName());
549 for (WsParamSetI pr : paramStore.getPresets())
551 if (!pr.isModifiable())
553 servicePresets.put(pr.getName(), "preset");
558 if (!exnames.contains(pr.getName()))
560 setName.addItem(pr.getName());
563 // TODO: if initial jobArgset matches a given user setting or preset then
564 // should recover setting accordingly
565 // updateTable(p, jobArgset);
568 reInitDialog(p.getName());
569 initArgSetModified();
573 if (jobArgset != null && jobArgset.size() > 0)
575 curSetName = "Supplied Settings";
576 isUserPreset = false;
577 updateTable(p, jobArgset);
578 setName.setSelectedItem(curSetName);
579 updateButtonDisplay();
587 settingDialog = false;
591 @SuppressWarnings("unchecked")
592 private void updateTable(WsParamSetI p, List<ArgumentI> jobArgset)
594 boolean setDefaultParams = false;
595 if (lastParmSet == null)
597 isUserPreset = false;
598 // First call - so provide Service default settings
599 setName.setSelectedItem(lastSetName = SVC_DEF);
601 if (p == null && SVC_DEF.equals("" + setName.getSelectedItem()))
603 // indicate that service defaults should be set if available
604 setDefaultParams = true;
606 // populate table from default parameter set.
607 List<ArgumentI> args = paramStore.getServiceParameters();
609 // split to params and required arguments
612 boolean optset = false;
613 for (ArgumentI myarg : args)
615 // Ideally, Argument would implement isRequired !
616 if (myarg instanceof ParameterI)
618 ParameterI parm = (ParameterI) myarg;
619 opanp.addParameter(parm).validate();
623 if (myarg instanceof OptionI)
625 OptionI opt = (OptionI) myarg;
626 OptionBox ob = opanp.addOption(opt);
627 ob.resetToDefault(setDefaultParams);
628 if (MAX_OPTWIDTH < ob.getPreferredSize().width)
630 MAX_OPTWIDTH = ob.getPreferredSize().width;
633 cw += ob.getPreferredSize().width + 5;
637 System.err.println("Ignoring unknown service argument type "
638 + myarg.getClass().getName());
642 args = null; // no more args to process.
646 isUserPreset = false;
647 // initialise setname
648 setName.setSelectedItem(lastSetName = p.getName());
649 setDescr.setText(lastDescrText = p.getDescription());
653 args = p.getArguments();
654 } catch (Exception e)
658 // TODO: check if args should be unselected prior to resetting using the
662 if (jobArgset != null)
664 argSetModified(jobArgset, true);
667 // get setargs from current object
670 for (ArgumentI arg : args)
672 if (arg instanceof ParameterI)
674 opanp.setParameter((ParameterI) arg);
678 if (arg instanceof OptionI)
680 // System.out.println("Setting option "
681 // + System.identityHashCode(arg) + ":" + arg.getName()
682 // + " with " + arg.getDefaultValue());
683 opanp.selectOption((OptionI) arg, arg.getValue());
690 refreshParamLayout();
694 private boolean isModified()
696 return modifiedElements.size() > 0;
699 private Hashtable modifiedElements = new Hashtable();
702 * reset gui and modification state settings
704 private void initArgSetModified()
707 modifiedElements.clear();
708 updateButtonDisplay();
711 private void updateButtonDisplay()
713 boolean _update = false, _create = false, _delete = false, _revert = false;
714 if (modifiedElements.size() > 0)
718 _update = isUserPreset; // can only update user presets
719 if (!isUserPreset || modifiedElements.containsKey(setName))
721 // name modified - can create new preset
729 // can still delete a user preset
730 _delete = isUserPreset;
732 createpref.setVisible(_create);
733 updatepref.setVisible(_update);
734 deletepref.setVisible(_delete);
735 revertpref.setVisible(_revert);
739 public void argSetModified(Object modifiedElement, boolean b)
747 modifiedElements.remove(modifiedElement);
751 if (b && modifiedElement == setName
752 && modifiedElements.contains(modifiedElement))
754 // HACK! prevents iteration on makeSetNameValid
757 modifiedElements.put(modifiedElement, modifiedElement);
759 // set mod status based on presence of elements in table
760 if (b && modifiedElements.size() > 0)
762 makeSetNameValid(!isUserPreset);
763 SetNamePanel.revalidate();
765 updateButtonDisplay();
768 private boolean isServicePreset(String selectedItem)
770 return selectedItem.equals(SVC_DEF)
771 || servicePresets.containsKey(selectedItem);
775 * check if the current set name is a valid set name for saving, if not, then
778 private void makeSetNameValid(boolean newuserset)
780 boolean stn = settingDialog;
781 boolean renamed = false;
782 settingDialog = true;
783 String nm = (curSetName != null ? curSetName : (String) setName
785 // check if the name is reserved - if it is, rename it.
786 if (isServicePreset(nm))
795 while (paramStore.getPreset(tnm) != null)
797 tnm = nm + " (" + (++i) + ")";
806 boolean makeupdate = false;
807 // sync the gui with the preset database
808 for (int i = 0, iS = setName.getItemCount(); i < iS; i++)
810 String snm = (String) setName.getItemAt(i);
814 // setName.setSelectedIndex(i);
819 setName.addItem(curSetName = nm);
820 setName.setSelectedItem(curSetName);
824 settingDialog = false; // we need this name change to be registered.
825 argSetModified(setName, renamed);
830 public void refreshParamLayout()
832 // optsAndparams.setPreferredSize(null);
833 FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
834 int sep = fl.getVgap();
836 int os = 0, s = jobOptions.getBorder().getBorderInsets(jobOptions).bottom
837 + jobOptions.getBorder().getBorderInsets(jobOptions).top
841 * final height for viewport
844 int panewidth = paramPane.getViewport().getSize().width - 120
845 - jobOptions.getBorder().getBorderInsets(jobOptions).left
846 + jobOptions.getBorder().getBorderInsets(jobOptions).right;
850 + (MAX_OPTWIDTH > OptsAndParamsPage.PARAM_WIDTH ? MAX_OPTWIDTH
851 : OptsAndParamsPage.PARAM_WIDTH);
852 int hgap = fl.getHgap(), cw = hgap;
854 if (opanp.getOptSet().size() > 0)
857 jobOptions.setLayout(new MigLayout("", "", ""));
858 jobOptions.removeAll();
860 for (OptionBox pbox : opanp.getOptSet().values())
863 cw += pbox.getSize().width + hgap;
864 if (cw + 120 > panewidth)
866 jobOptions.add(pbox, "wrap");
867 // System.out.println("Wrap on "+pbox.option.getName());
868 cw = hgap + pbox.getSize().width;
873 jobOptions.add(pbox);
877 finalh += pbox.getSize().height + fl.getVgap();
881 jobOptions.revalidate();
885 jobOptions.setVisible(false);
888 // Now layout the parameters assuming they occupy one column - to calculate
889 // total height of options+parameters
890 fl = new FlowLayout(FlowLayout.LEFT);
892 // http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
893 fl.setAlignOnBaseline(true);
894 if (opanp.getParamSet().size() > 0)
896 paramList.removeAll();
897 paramList.setLayout(new MigLayout("", "", ""));
899 for (ParamBox pbox : opanp.getParamSet().values())
902 cw += pbox.getSize().width + hgap;
903 if (cw + 160 > panewidth)
905 paramList.add(pbox, "wrap");
906 cw = pbox.getSize().width + hgap;
915 finalh += pbox.getSize().height + fl.getVgap();
921 * s = 2 * sep; for (ParamBox pbox : opanp.getParamSet().values()) {
922 * pbox.validate(); s += sep +
923 * pbox.getPreferredSize().height+pbox.getBorder
924 * ().getBorderInsets(pbox).bottom; }
926 * // paramList.setPreferredSize(new Dimension(w, s));
927 * os+=s+2*sep+paramList
928 * .getBorder().getBorderInsets(paramList).bottom+paramList
929 * .getBorder().getBorderInsets(paramList).top;
931 paramList.revalidate();
935 paramList.setVisible(false);
937 // TODO: waste some time trying to eliminate any unnecessary .validate calls
939 // System.out.println("Size will be : "+w+","+os);
940 // optsAndparams.setPreferredSize(null);
941 // paramPane.getViewport().setView(optsAndparams);
942 paramPane.getViewport().setAutoscrolls(true);
943 paramPane.revalidate();
948 * testing method - grab a service and parameter set and show the window
952 public static void main(String[] args)
954 jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer
959 Vector<String> services = new Vector<String>();
960 services.addElement(args[p++]);
961 Jws2Discoverer.getDiscoverer().setServiceUrls(services);
966 } catch (Exception e)
968 System.err.println("Aborting. Problem discovering services.");
972 Jws2Instance lastserv = null;
973 for (Jws2Instance service : disc.getServices())
976 if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p]))
978 if (lastserv != null)
980 List<Preset> prl = null;
982 if (++p < args.length)
984 PresetManager prman = lastserv.getPresets();
987 pr = prman.getPresetByName(args[p]);
990 // just grab the last preset.
991 prl = prman.getPresets();
997 PresetManager prman = lastserv.getPresets();
1000 prl = prman.getPresets();
1003 Iterator<Preset> en = (prl == null) ? null : prl.iterator();
1004 while (en != null && en.hasNext())
1010 en = prl.iterator();
1015 System.out.println("Testing opts dupes for "
1016 + lastserv.getUri() + " : "
1017 + lastserv.getActionText() + ":" + pr.getName());
1018 List<Option> rg = lastserv.getRunnerConfig().getOptions();
1023 Option cpy = jalview.ws.jws2.ParameterUtils.copyOption(o);
1024 } catch (Exception e)
1026 System.err.println("Failed to copy " + o.getName());
1027 e.printStackTrace();
1030 System.err.println("Failed to copy " + o.getName());
1031 e.printStackTrace();
1036 System.out.println("Testing param dupes:");
1037 List<Parameter> rg = lastserv.getRunnerConfig()
1039 for (Parameter o : rg)
1043 Parameter cpy = jalview.ws.jws2.ParameterUtils
1045 } catch (Exception e)
1047 System.err.println("Failed to copy " + o.getName());
1048 e.printStackTrace();
1051 System.err.println("Failed to copy " + o.getName());
1052 e.printStackTrace();
1057 System.out.println("Testing param write:");
1058 List<String> writeparam = null, readparam = null;
1061 writeparam = jalview.ws.jws2.ParameterUtils
1063 pr.getArguments(lastserv.getRunnerConfig()),
1065 System.out.println("Testing param read :");
1066 List<Option> pset = jalview.ws.jws2.ParameterUtils
1067 .processParameters(writeparam,
1068 lastserv.getRunnerConfig(), " ");
1069 readparam = jalview.ws.jws2.ParameterUtils
1070 .writeParameterSet(pset, " ");
1071 Iterator<String> o = pr.getOptions().iterator(), s = writeparam
1072 .iterator(), t = readparam.iterator();
1073 boolean failed = false;
1074 while (s.hasNext() && t.hasNext())
1076 String on = o.next(), sn = s.next(), st = t.next();
1079 System.out.println("Original was " + on
1080 + " Phase 1 wrote " + sn + "\tPhase 2 wrote "
1087 System.out.println("Original parameters:\n"
1089 System.out.println("Wrote parameters in first set:\n"
1091 System.out.println("Wrote parameters in second set:\n"
1095 } catch (Exception e)
1097 e.printStackTrace();
1100 WsJobParameters pgui = new WsJobParameters(lastserv,
1101 new JabaPreset(lastserv, pr));
1102 JFrame jf = new JFrame(MessageManager.formatMessage(
1103 "label.ws_parameters_for",
1104 new String[] { lastserv.getActionText() }));
1105 JPanel cont = new JPanel(new BorderLayout());
1107 cont.setPreferredSize(pgui.getPreferredSize());
1108 cont.add(pgui, BorderLayout.CENTER);
1109 jf.setLayout(new BorderLayout());
1110 jf.add(cont, BorderLayout.CENTER);
1112 final Thread thr = Thread.currentThread();
1113 jf.addWindowListener(new WindowListener()
1116 public void windowActivated(WindowEvent e)
1118 // TODO Auto-generated method stub
1122 public void windowClosed(WindowEvent e)
1126 public void windowClosing(WindowEvent e)
1132 public void windowDeactivated(WindowEvent e)
1134 // TODO Auto-generated method stub
1138 public void windowDeiconified(WindowEvent e)
1140 // TODO Auto-generated method stub
1144 public void windowIconified(WindowEvent e)
1146 // TODO Auto-generated method stub
1150 public void windowOpened(WindowEvent e)
1152 // TODO Auto-generated method stub
1157 jf.setVisible(true);
1158 boolean inter = false;
1163 Thread.sleep(10000);
1164 } catch (Exception e)
1177 public boolean isServiceDefaults()
1179 return (!isModified() && (lastParmSet != null && lastParmSet
1183 public List<ArgumentI> getJobParams()
1185 return opanp.getCurrentSettings();
1188 String lastParmSet = null;
1191 * Hashtable<String, Object[]> editedParams = new Hashtable<String,
1194 * store the given parameters in the user parameter set database.
1196 * @param storeSetName - lastParmSet
1198 * @param descr - setDescr.getText()
1200 * @param jobParams - getJobParams()
1202 * private void _storeUserPreset(String storeSetName, String descr,
1203 * List<ArgumentI> jobParams) { // this is a simple hash store. Object[] pset;
1204 * editedParams.put(storeSetName, pset = new Object[3]); pset[0] =
1205 * storeSetName; pset[1] = descr; pset[2] = jobParams; // writeParam("Saving "
1206 * + storeSetName + ": ", jobParams); }
1208 * private void writeParam(String nm, List<ArgumentI> params) { for (ArgumentI
1209 * p : params) { System.out.println(nm + ":" + System.identityHashCode(p) +
1210 * " Name: " + p.getName() + " Value: " + p.getDefaultValue()); } }
1212 * private Object[] _getUserPreset(String setName) { Object[] pset =
1213 * editedParams.get(setName); // if (pset != null) // writeParam("Retrieving "
1214 * + setName + ": ", (List<Argument>) pset[2]); return pset; }
1216 * * remove the given user preset from the preset stash
1220 * private void _deleteUserPreset(String setName) {
1221 * editedParams.remove(setName); }
1224 private void syncSetNamesWithStore()
1227 // remove any set names in the drop down menu that aren't either a reserved
1228 // setting, or a user defined or service preset.
1229 Vector items = new Vector();
1230 while (n < setName.getItemCount())
1232 String item = (String) setName.getItemAt(n);
1233 if (!item.equals(SVC_DEF) && !paramStore.presetExists(item))
1235 setName.removeItemAt(n);
1239 items.addElement(item);
1243 if (!items.contains(SVC_DEF))
1245 setName.addItem(SVC_DEF);
1247 for (WsParamSetI upn : paramStore.getPresets())
1249 if (!items.contains(upn.getName()))
1251 setName.addItem(upn.getName());
1257 * true if lastParmSet is a user preset
1259 boolean isUserPreset = false;
1261 private void reInitDialog(String nextPreset)
1263 settingDialog = true;
1264 // updateTable(null,null); // first reset to defaults
1265 WsParamSetI pset = null;
1266 if (nextPreset != null && nextPreset.length() > 0)
1268 pset = paramStore.getPreset(nextPreset);
1272 if (pset.isModifiable())
1274 isUserPreset = true;
1275 setDescr.setText(pset.getDescription());
1276 updateTable(null, pset.getArguments());
1277 lastParmSet = nextPreset;
1281 isUserPreset = false;
1282 setDescr.setText("");
1283 // must be a default preset from service
1284 updateTable(pset, null);
1285 lastParmSet = nextPreset;
1290 isUserPreset = false;
1292 setDescr.setText("");
1293 updateTable(null, null);
1294 lastParmSet = SVC_DEF;
1297 initArgSetModified();
1298 syncSetNamesWithStore();
1299 setName.setSelectedItem(lastParmSet);
1300 SetNamePanel.validate();
1302 settingDialog = false;
1306 * Rebuild the AlignFrame web service menus (after add/delete of a preset
1309 protected void updateWebServiceMenus()
1311 for (AlignFrame alignFrame : Desktop.getAlignFrames())
1313 alignFrame.BuildWebServiceMenu();
1317 String curSetName = null;
1319 public void itemStateChanged(ItemEvent e)
1321 if (e.getSource() == setName && e.getStateChange() == e.SELECTED)
1323 final String setname = (String) setName.getSelectedItem();
1324 System.out.println("Item state changed for " + setname
1325 + " (handling ? " + !settingDialog + ")");
1331 if (setname == null)
1335 javax.swing.SwingUtilities.invokeLater(new Runnable()
1339 doPreferenceComboStateChange(setname);
1345 private void doPreferenceComboStateChange(String setname)
1347 // user has selected a different item from combo-box
1350 String lsetname = (curSetName != null) ? curSetName : lastParmSet;
1351 if (lsetname.equals(setname))
1353 // setname was just edited - so ignore this event.
1356 settingDialog = true;
1357 System.out.println("Prompting to save " + lsetname);
1358 if (javax.swing.JOptionPane
1363 + "' is modifed, and your changes will be lost.\nReally change preset ?",
1364 "Warning: Unsaved Changes",
1365 javax.swing.JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION)
1367 // revert the combobox to the current item
1368 settingDialog = true;
1369 setName.setSelectedItem(lsetname);
1370 settingDialog = false;
1373 // System.out.println("Saving for " + lsetname);
1374 // _storeCurrentPreset(lsetname);
1378 settingDialog = true;
1379 reInitDialog(setname);
1380 settingDialog = false;
1384 private void _renameExistingPreset(String oldName, String curSetName2)
1386 paramStore.updatePreset(oldName, curSetName2, setDescr.getText(),
1391 * store current settings as given name. You should then reset gui.
1393 * @param curSetName2
1395 private void _storeCurrentPreset(String curSetName2)
1397 paramStore.storePreset(curSetName2, setDescr.getText(), getJobParams());
1400 private void _updatePreset(String lastParmSet2, String curname)
1402 paramStore.updatePreset(lastParmSet2, curname, setDescr.getText(),
1408 * last saved name for this user preset
1410 String lastSetName = null;
1413 * last saved value of the description text for this user preset
1415 String lastDescrText = null;
1417 public void actionPerformed(ActionEvent e)
1419 if (e.getSource() instanceof Component)
1421 Component src = (Component) e.getSource();
1422 if (src.getParent() == setName)
1424 // rename any existing records we know about for this set.
1425 String newname = e.getActionCommand().trim();
1427 if (isServicePreset(newname))
1429 final String oldname = curSetName != null ? curSetName
1431 final Component ourframe = this;
1432 settingDialog = true;
1433 setName.getEditor().setItem(oldname);
1434 settingDialog = false;
1435 javax.swing.SwingUtilities.invokeLater(new Runnable()
1439 JOptionPane.showMessageDialog(ourframe, MessageManager
1440 .getString("label.invalid_name_preset_exists"),
1441 MessageManager.getString("label.invalid_name"),
1442 JOptionPane.WARNING_MESSAGE);
1448 curSetName = newname;
1449 System.err.println("New name for user setting " + curSetName
1450 + " (was " + setName.getSelectedItem() + ")");
1451 if (curSetName.equals(setName.getSelectedItem()))
1455 if (curSetName != null)
1457 argSetModified(setName, true);
1465 private void checkDescrModified()
1472 (lastDescrText == null ? setDescr.getText().trim().length() > 0
1473 : !setDescr.getText().equals(lastDescrText)));
1478 public void insertUpdate(DocumentEvent e)
1480 checkDescrModified();
1483 public void removeUpdate(DocumentEvent e)
1485 checkDescrModified();
1488 public void changedUpdate(DocumentEvent e)
1490 checkDescrModified();
1495 * @return null or the service preset selected by the user
1497 public WsParamSetI getPreset()
1499 if (isUserPreset || isModified()
1500 || (lastParmSet != null && lastParmSet.equals(SVC_DEF)))
1506 return paramStore.getPreset(lastParmSet);