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 java.awt.BorderLayout;
24 import java.awt.Component;
25 import java.awt.Dimension;
26 import java.awt.FlowLayout;
28 import java.awt.GridBagConstraints;
29 import java.awt.GridBagLayout;
30 import java.awt.GridLayout;
31 import java.awt.Rectangle;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.awt.event.HierarchyBoundsListener;
35 import java.awt.event.HierarchyEvent;
36 import java.awt.event.ItemEvent;
37 import java.awt.event.ItemListener;
38 import java.awt.event.WindowEvent;
39 import java.awt.event.WindowListener;
41 import java.util.Hashtable;
42 import java.util.Iterator;
43 import java.util.List;
44 import java.util.Vector;
46 import javax.swing.JButton;
47 import javax.swing.JComboBox;
48 import javax.swing.JDialog;
49 import javax.swing.JFrame;
50 import javax.swing.JLabel;
51 import javax.swing.JOptionPane;
52 import javax.swing.JPanel;
53 import javax.swing.JScrollPane;
54 import javax.swing.JSplitPane;
55 import javax.swing.JTextArea;
56 import javax.swing.border.TitledBorder;
57 import javax.swing.event.DocumentEvent;
58 import javax.swing.event.DocumentListener;
60 import net.miginfocom.swing.MigLayout;
62 import compbio.metadata.Argument;
63 import compbio.metadata.Option;
64 import compbio.metadata.Parameter;
65 import compbio.metadata.Preset;
66 import compbio.metadata.PresetManager;
67 import compbio.metadata.RunnerConfig;
69 import jalview.gui.OptsAndParamsPage.OptionBox;
70 import jalview.gui.OptsAndParamsPage.ParamBox;
71 import jalview.util.MessageManager;
72 import jalview.ws.jws2.JabaParamStore;
73 import jalview.ws.jws2.JabaPreset;
74 import jalview.ws.jws2.Jws2Discoverer;
75 import jalview.ws.jws2.jabaws2.Jws2Instance;
76 import jalview.ws.params.ArgumentI;
77 import jalview.ws.params.OptionI;
78 import jalview.ws.params.ParamDatastoreI;
79 import jalview.ws.params.ParameterI;
80 import jalview.ws.params.WsParamSetI;
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",
223 { service.getActionText() }));
224 Rectangle deskr = Desktop.instance.getBounds();
225 Dimension pref = this.getPreferredSize();
226 frame.setBounds(new Rectangle(
227 (int) (deskr.getCenterX() - pref.width / 2), (int) (deskr
228 .getCenterY() - pref.height / 2), pref.width,
230 frame.setContentPane(this);
232 // should perhaps recover defaults from user prefs.
235 javax.swing.SwingUtilities.invokeLater(new Runnable()
239 // jobPanel.setDividerLocation(0.25);
243 frame.setVisible(true);
252 private void jbInit()
254 this.addHierarchyBoundsListener(new HierarchyBoundsListener()
258 public void ancestorResized(HierarchyEvent arg0)
260 refreshParamLayout();
264 public void ancestorMoved(HierarchyEvent arg0)
266 // TODO Auto-generated method stub
270 updatepref = JvSwingUtils.makeButton(
271 MessageManager.getString("action.update"),
272 MessageManager.getString("label.update_user_parameter_set"),
276 public void actionPerformed(ActionEvent e)
278 update_actionPerformed(e);
281 deletepref = JvSwingUtils.makeButton(
282 MessageManager.getString("action.delete"),
283 MessageManager.getString("label.delete_user_parameter_set"),
287 public void actionPerformed(ActionEvent e)
289 delete_actionPerformed(e);
292 createpref = JvSwingUtils.makeButton(
293 MessageManager.getString("action.create"),
294 MessageManager.getString("label.create_user_parameter_set"),
298 public void actionPerformed(ActionEvent e)
300 create_actionPerformed(e);
303 revertpref = JvSwingUtils.makeButton(MessageManager
304 .getString("action.revert"), MessageManager
305 .getString("label.revert_changes_user_parameter_set"),
309 public void actionPerformed(ActionEvent e)
311 revert_actionPerformed(e);
314 startjob = JvSwingUtils.makeButton(
315 MessageManager.getString("action.start_job"),
316 MessageManager.getString("label.start_job_current_settings"),
319 public void actionPerformed(ActionEvent e)
321 startjob_actionPerformed(e);
324 canceljob = JvSwingUtils.makeButton(
325 MessageManager.getString("action.cancel_job"),
326 MessageManager.getString("label.cancel_job_close_dialog"),
329 public void actionPerformed(ActionEvent e)
331 canceljob_actionPerformed(e);
335 setDetails.setBorder(new TitledBorder(MessageManager
336 .getString("label.details")));
337 setDetails.setLayout(new BorderLayout());
338 setDescr.setColumns(40);
339 setDescr.setWrapStyleWord(true);
340 setDescr.setLineWrap(true);
341 setDescr.setBackground(getBackground());
342 setDescr.setEditable(true);
343 setDescr.getDocument().addDocumentListener(this);
344 setDescr.setToolTipText(MessageManager
345 .getString("label.edit_notes_parameter_set"));
346 JScrollPane setDescrView = new JScrollPane();
347 setDescrView.getViewport().setView(setDescr);
348 setName.setEditable(true);
349 setName.addItemListener(this);
350 setName.getEditor().addActionListener(this);
351 JPanel setNameInfo = new JPanel(new FlowLayout(FlowLayout.LEFT));
352 GridBagLayout gbl = new GridBagLayout();
353 SetNamePanel.setLayout(gbl);
355 JLabel setNameLabel = new JLabel(
356 MessageManager.getString("label.current_parameter_set_name"));
357 setNameLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
359 setNameInfo.add(setNameLabel);
360 setNameInfo.add(setName);
362 // initial button visibility
363 updatepref.setVisible(false);
364 deletepref.setVisible(false);
365 revertpref.setVisible(false);
366 createpref.setVisible(false);
367 JPanel setsavebuts = new JPanel();
368 setsavebuts.setLayout(new FlowLayout(FlowLayout.LEFT)); // GridLayout(1,2));
369 ((FlowLayout) setsavebuts.getLayout()).setHgap(10);
370 ((FlowLayout) setsavebuts.getLayout()).setVgap(0);
371 JPanel spacer = new JPanel();
372 spacer.setPreferredSize(new Dimension(2, 30));
373 setsavebuts.add(spacer);
374 setsavebuts.add(deletepref);
375 setsavebuts.add(revertpref);
376 setsavebuts.add(createpref);
377 setsavebuts.add(updatepref);
378 // setsavebuts.setSize(new Dimension(150, 30));
379 JPanel buttonArea = new JPanel(new GridLayout(1, 1));
380 buttonArea.add(setsavebuts);
381 SetNamePanel.add(setNameInfo);
382 GridBagConstraints gbc = new GridBagConstraints();
384 gbl.setConstraints(setNameInfo, gbc);
385 SetNamePanel.add(buttonArea);
386 gbc = new GridBagConstraints();
390 gbl.setConstraints(buttonArea, gbc);
391 setDetails.add(setDescrView, BorderLayout.CENTER);
393 // paramPane.setPreferredSize(new Dimension(360, 400));
394 // paramPane.setPreferredSize(null);
395 jobOptions.setBorder(new TitledBorder(MessageManager
396 .getString("label.options")));
397 jobOptions.setOpaque(true);
398 paramList.setBorder(new TitledBorder(MessageManager
399 .getString("label.parameters")));
400 paramList.setOpaque(true);
401 JPanel bjo = new JPanel(new BorderLayout()), bjp = new JPanel(
403 bjo.add(jobOptions, BorderLayout.CENTER);
404 bjp.add(paramList, BorderLayout.CENTER);
407 // optsAndparams.setScrollableWidth(ScrollableSizeHint.FIT);
408 // optsAndparams.setScrollableHeight(ScrollableSizeHint.NONE);
409 // optsAndparams.setLayout(new BorderLayout());
410 optsAndparams.setLayout(new BorderLayout());
411 optsAndparams.add(jobOptions, BorderLayout.NORTH);
412 optsAndparams.add(paramList, BorderLayout.CENTER);
413 JPanel jp = new JPanel(new BorderLayout());
414 jp.add(optsAndparams, BorderLayout.CENTER);
415 paramPane.getViewport().setView(jp);
416 paramPane.setBorder(null);
417 setLayout(new BorderLayout());
418 jobPanel.setPreferredSize(null);
419 jobPanel.setLayout(new BorderLayout());
420 jobPanel.add(setDetails, BorderLayout.NORTH);
421 jobPanel.add(paramPane, BorderLayout.CENTER);
422 // jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
424 add(SetNamePanel, BorderLayout.NORTH);
425 add(jobPanel, BorderLayout.CENTER);
427 JPanel dialogpanel = new JPanel();
428 dialogpanel.add(startjob);
429 dialogpanel.add(canceljob);
430 // JAL-1580: setMaximumSize() doesn't work, so just size for the worst case:
431 // check for null is for JUnit usage
432 final int windowHeight = Desktop.instance == null ? 540
433 : Desktop.instance.getHeight();
434 setPreferredSize(new Dimension(540, windowHeight));
435 add(dialogpanel, BorderLayout.SOUTH);
439 protected void revert_actionPerformed(ActionEvent e)
441 reInitDialog(lastParmSet);
442 updateWebServiceMenus();
445 protected void update_actionPerformed(ActionEvent e)
449 String curname = ((String) setName.getSelectedItem()).trim();
450 _updatePreset(lastParmSet, curname);
451 lastParmSet = curname;
453 initArgSetModified();
454 syncSetNamesWithStore();
458 private void _deleteUserPreset(String lastParmSet2)
460 paramStore.deletePreset(lastParmSet2);
463 protected void delete_actionPerformed(ActionEvent e)
467 // delete current preset's saved entry
468 _deleteUserPreset(lastParmSet);
470 reInitDialog(null); // service default
471 updateWebServiceMenus();
474 protected void create_actionPerformed(ActionEvent e)
476 String curname = ((String) setName.getSelectedItem()).trim();
477 if (curname.length() > 0)
479 _storeCurrentPreset(curname);
480 lastParmSet = curname;
482 reInitDialog(curname);
483 initArgSetModified();
484 updateWebServiceMenus();
488 // TODO: show warning
489 System.err.println("Invalid name. Not saved.");
493 protected void canceljob_actionPerformed(ActionEvent e)
498 frame.setVisible(false);
502 protected void startjob_actionPerformed(ActionEvent e)
507 frame.setVisible(false);
511 Jws2Instance service;
514 * list of service presets in the gui
516 Hashtable servicePresets = null;
519 * set if dialog is being set - so handlers will avoid spurious events
521 boolean settingDialog = false;
523 void initForService(Jws2Instance service, WsParamSetI jabap,
524 List<Argument> jabajobArgset)
526 WsParamSetI p = null;
527 List<ArgumentI> jobArgset = null;
528 settingDialog = true;
529 { // instantiate the abstract proxy for Jaba objects
530 jobArgset = jabajobArgset == null ? null : JabaParamStore
531 .getJwsArgsfromJaba(jabajobArgset);
532 p = jabap; // (jabap != null) ? paramStore.getPreset(jabap.getName()) :
536 Hashtable exnames = new Hashtable();
537 for (int i = 0, iSize = setName.getItemCount(); i < iSize; i++)
539 exnames.put(setName.getItemAt(i), setName.getItemAt(i));
541 servicePresets = new Hashtable();
542 // Add the default entry - if not present already.
543 if (!exnames.contains(SVC_DEF))
545 setName.addItem(SVC_DEF);
546 exnames.put(SVC_DEF, SVC_DEF);
547 servicePresets.put(SVC_DEF, SVC_DEF);
549 String curname = (p == null ? "" : p.getName());
550 for (WsParamSetI pr : paramStore.getPresets())
552 if (!pr.isModifiable())
554 servicePresets.put(pr.getName(), "preset");
559 if (!exnames.contains(pr.getName()))
561 setName.addItem(pr.getName());
564 // TODO: if initial jobArgset matches a given user setting or preset then
565 // should recover setting accordingly
566 // updateTable(p, jobArgset);
569 reInitDialog(p.getName());
570 initArgSetModified();
574 if (jobArgset != null && jobArgset.size() > 0)
576 curSetName = "Supplied Settings";
577 isUserPreset = false;
578 updateTable(p, jobArgset);
579 setName.setSelectedItem(curSetName);
580 updateButtonDisplay();
588 settingDialog = false;
592 @SuppressWarnings("unchecked")
593 private void updateTable(WsParamSetI p, List<ArgumentI> jobArgset)
595 boolean setDefaultParams = false;
596 if (lastParmSet == null)
598 isUserPreset = false;
599 // First call - so provide Service default settings
600 setName.setSelectedItem(lastSetName = SVC_DEF);
602 if (p == null && SVC_DEF.equals("" + setName.getSelectedItem()))
604 // indicate that service defaults should be set if available
605 setDefaultParams = true;
607 // populate table from default parameter set.
608 List<ArgumentI> args = paramStore.getServiceParameters();
610 // split to params and required arguments
613 boolean optset = false;
614 for (ArgumentI myarg : args)
616 // Ideally, Argument would implement isRequired !
617 if (myarg instanceof ParameterI)
619 ParameterI parm = (ParameterI) myarg;
620 opanp.addParameter(parm).validate();
624 if (myarg instanceof OptionI)
626 OptionI opt = (OptionI) myarg;
627 OptionBox ob = opanp.addOption(opt);
628 ob.resetToDefault(setDefaultParams);
629 if (MAX_OPTWIDTH < ob.getPreferredSize().width)
631 MAX_OPTWIDTH = ob.getPreferredSize().width;
634 cw += ob.getPreferredSize().width + 5;
638 System.err.println("Ignoring unknown service argument type "
639 + myarg.getClass().getName());
643 args = null; // no more args to process.
647 isUserPreset = false;
648 // initialise setname
649 setName.setSelectedItem(lastSetName = p.getName());
650 setDescr.setText(lastDescrText = p.getDescription());
654 args = p.getArguments();
655 } catch (Exception e)
659 // TODO: check if args should be unselected prior to resetting using the
663 if (jobArgset != null)
665 argSetModified(jobArgset, true);
668 // get setargs from current object
671 for (ArgumentI arg : args)
673 if (arg instanceof ParameterI)
675 opanp.setParameter((ParameterI) arg);
679 if (arg instanceof OptionI)
681 // System.out.println("Setting option "
682 // + System.identityHashCode(arg) + ":" + arg.getName()
683 // + " with " + arg.getDefaultValue());
684 opanp.selectOption((OptionI) arg, arg.getValue());
691 refreshParamLayout();
695 private boolean isModified()
697 return modifiedElements.size() > 0;
700 private Hashtable modifiedElements = new Hashtable();
703 * reset gui and modification state settings
705 private void initArgSetModified()
708 modifiedElements.clear();
709 updateButtonDisplay();
712 private void updateButtonDisplay()
714 boolean _update = false, _create = false, _delete = false, _revert = false;
715 if (modifiedElements.size() > 0)
719 _update = isUserPreset; // can only update user presets
720 if (!isUserPreset || modifiedElements.containsKey(setName))
722 // name modified - can create new preset
730 // can still delete a user preset
731 _delete = isUserPreset;
733 createpref.setVisible(_create);
734 updatepref.setVisible(_update);
735 deletepref.setVisible(_delete);
736 revertpref.setVisible(_revert);
740 public void argSetModified(Object modifiedElement, boolean b)
748 modifiedElements.remove(modifiedElement);
752 if (b && modifiedElement == setName
753 && modifiedElements.contains(modifiedElement))
755 // HACK! prevents iteration on makeSetNameValid
758 modifiedElements.put(modifiedElement, modifiedElement);
760 // set mod status based on presence of elements in table
761 if (b && modifiedElements.size() > 0)
763 makeSetNameValid(!isUserPreset);
764 SetNamePanel.revalidate();
766 updateButtonDisplay();
769 private boolean isServicePreset(String selectedItem)
771 return selectedItem.equals(SVC_DEF)
772 || servicePresets.containsKey(selectedItem);
776 * check if the current set name is a valid set name for saving, if not, then
779 private void makeSetNameValid(boolean newuserset)
781 boolean stn = settingDialog;
782 boolean renamed = false;
783 settingDialog = true;
784 String nm = (curSetName != null ? curSetName : (String) setName
786 // check if the name is reserved - if it is, rename it.
787 if (isServicePreset(nm))
796 while (paramStore.getPreset(tnm) != null)
798 tnm = nm + " (" + (++i) + ")";
807 boolean makeupdate = false;
808 // sync the gui with the preset database
809 for (int i = 0, iS = setName.getItemCount(); i < iS; i++)
811 String snm = (String) setName.getItemAt(i);
815 // setName.setSelectedIndex(i);
820 setName.addItem(curSetName = nm);
821 setName.setSelectedItem(curSetName);
825 settingDialog = false; // we need this name change to be registered.
826 argSetModified(setName, renamed);
831 public void refreshParamLayout()
833 // optsAndparams.setPreferredSize(null);
834 FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
835 int sep = fl.getVgap();
837 int os = 0, s = jobOptions.getBorder().getBorderInsets(jobOptions).bottom
838 + jobOptions.getBorder().getBorderInsets(jobOptions).top
842 * final height for viewport
845 int panewidth = paramPane.getViewport().getSize().width - 120
846 - jobOptions.getBorder().getBorderInsets(jobOptions).left
847 + jobOptions.getBorder().getBorderInsets(jobOptions).right;
851 + (MAX_OPTWIDTH > OptsAndParamsPage.PARAM_WIDTH ? MAX_OPTWIDTH
852 : OptsAndParamsPage.PARAM_WIDTH);
853 int hgap = fl.getHgap(), cw = hgap;
855 if (opanp.getOptSet().size() > 0)
858 jobOptions.setLayout(new MigLayout("", "", ""));
859 jobOptions.removeAll();
861 for (OptionBox pbox : opanp.getOptSet().values())
864 cw += pbox.getSize().width + hgap;
865 if (cw + 120 > panewidth)
867 jobOptions.add(pbox, "wrap");
868 // System.out.println("Wrap on "+pbox.option.getName());
869 cw = hgap + pbox.getSize().width;
874 jobOptions.add(pbox);
878 finalh += pbox.getSize().height + fl.getVgap();
882 jobOptions.revalidate();
886 jobOptions.setVisible(false);
889 // Now layout the parameters assuming they occupy one column - to calculate
890 // total height of options+parameters
891 fl = new FlowLayout(FlowLayout.LEFT);
893 // http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
894 fl.setAlignOnBaseline(true);
895 if (opanp.getParamSet().size() > 0)
897 paramList.removeAll();
898 paramList.setLayout(new MigLayout("", "", ""));
900 for (ParamBox pbox : opanp.getParamSet().values())
903 cw += pbox.getSize().width + hgap;
904 if (cw + 160 > panewidth)
906 paramList.add(pbox, "wrap");
907 cw = pbox.getSize().width + hgap;
916 finalh += pbox.getSize().height + fl.getVgap();
922 * s = 2 * sep; for (ParamBox pbox : opanp.getParamSet().values()) {
923 * pbox.validate(); s += sep +
924 * pbox.getPreferredSize().height+pbox.getBorder
925 * ().getBorderInsets(pbox).bottom; }
927 * // paramList.setPreferredSize(new Dimension(w, s));
928 * os+=s+2*sep+paramList
929 * .getBorder().getBorderInsets(paramList).bottom+paramList
930 * .getBorder().getBorderInsets(paramList).top;
932 paramList.revalidate();
936 paramList.setVisible(false);
938 // TODO: waste some time trying to eliminate any unnecessary .validate calls
940 // System.out.println("Size will be : "+w+","+os);
941 // optsAndparams.setPreferredSize(null);
942 // paramPane.getViewport().setView(optsAndparams);
943 paramPane.getViewport().setAutoscrolls(true);
944 paramPane.revalidate();
949 * testing method - grab a service and parameter set and show the window
953 public static void main(String[] args)
955 jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer
960 Vector<String> services = new Vector<String>();
961 services.addElement(args[p++]);
962 Jws2Discoverer.getDiscoverer().setServiceUrls(services);
967 } catch (Exception e)
969 System.err.println("Aborting. Problem discovering services.");
973 Jws2Instance lastserv = null;
974 for (Jws2Instance service : disc.getServices())
977 if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p]))
979 if (lastserv != null)
981 List<Preset> prl = null;
983 if (++p < args.length)
985 PresetManager prman = lastserv.getPresets();
988 pr = prman.getPresetByName(args[p]);
991 // just grab the last preset.
992 prl = prman.getPresets();
998 PresetManager prman = lastserv.getPresets();
1001 prl = prman.getPresets();
1004 Iterator<Preset> en = (prl == null) ? null : prl.iterator();
1005 while (en != null && en.hasNext())
1011 en = prl.iterator();
1016 System.out.println("Testing opts dupes for "
1017 + lastserv.getUri() + " : "
1018 + lastserv.getActionText() + ":" + pr.getName());
1019 List<Option> rg = lastserv.getRunnerConfig().getOptions();
1024 Option cpy = jalview.ws.jws2.ParameterUtils.copyOption(o);
1025 } catch (Exception e)
1027 System.err.println("Failed to copy " + o.getName());
1028 e.printStackTrace();
1031 System.err.println("Failed to copy " + o.getName());
1032 e.printStackTrace();
1037 System.out.println("Testing param dupes:");
1038 List<Parameter> rg = lastserv.getRunnerConfig()
1040 for (Parameter o : rg)
1044 Parameter cpy = jalview.ws.jws2.ParameterUtils
1046 } catch (Exception e)
1048 System.err.println("Failed to copy " + o.getName());
1049 e.printStackTrace();
1052 System.err.println("Failed to copy " + o.getName());
1053 e.printStackTrace();
1058 System.out.println("Testing param write:");
1059 List<String> writeparam = null, readparam = null;
1062 writeparam = jalview.ws.jws2.ParameterUtils
1064 pr.getArguments(lastserv.getRunnerConfig()),
1066 System.out.println("Testing param read :");
1067 List<Option> pset = jalview.ws.jws2.ParameterUtils
1068 .processParameters(writeparam,
1069 lastserv.getRunnerConfig(), " ");
1070 readparam = jalview.ws.jws2.ParameterUtils
1071 .writeParameterSet(pset, " ");
1072 Iterator<String> o = pr.getOptions().iterator(), s = writeparam
1073 .iterator(), t = readparam.iterator();
1074 boolean failed = false;
1075 while (s.hasNext() && t.hasNext())
1077 String on = o.next(), sn = s.next(), st = t.next();
1080 System.out.println("Original was " + on
1081 + " Phase 1 wrote " + sn + "\tPhase 2 wrote "
1088 System.out.println("Original parameters:\n"
1090 System.out.println("Wrote parameters in first set:\n"
1092 System.out.println("Wrote parameters in second set:\n"
1096 } catch (Exception e)
1098 e.printStackTrace();
1101 WsJobParameters pgui = new WsJobParameters(lastserv,
1102 new JabaPreset(lastserv, pr));
1103 JFrame jf = new JFrame(MessageManager.formatMessage(
1104 "label.ws_parameters_for", new String[]
1105 { lastserv.getActionText() }));
1106 JPanel cont = new JPanel(new BorderLayout());
1108 cont.setPreferredSize(pgui.getPreferredSize());
1109 cont.add(pgui, BorderLayout.CENTER);
1110 jf.setLayout(new BorderLayout());
1111 jf.add(cont, BorderLayout.CENTER);
1113 final Thread thr = Thread.currentThread();
1114 jf.addWindowListener(new WindowListener()
1117 public void windowActivated(WindowEvent e)
1119 // TODO Auto-generated method stub
1123 public void windowClosed(WindowEvent e)
1127 public void windowClosing(WindowEvent e)
1133 public void windowDeactivated(WindowEvent e)
1135 // TODO Auto-generated method stub
1139 public void windowDeiconified(WindowEvent e)
1141 // TODO Auto-generated method stub
1145 public void windowIconified(WindowEvent e)
1147 // TODO Auto-generated method stub
1151 public void windowOpened(WindowEvent e)
1153 // TODO Auto-generated method stub
1158 jf.setVisible(true);
1159 boolean inter = false;
1164 Thread.sleep(10000);
1165 } catch (Exception e)
1178 public boolean isServiceDefaults()
1180 return (!isModified() && (lastParmSet != null && lastParmSet
1184 public List<ArgumentI> getJobParams()
1186 return opanp.getCurrentSettings();
1189 String lastParmSet = null;
1192 * Hashtable<String, Object[]> editedParams = new Hashtable<String,
1195 * store the given parameters in the user parameter set database.
1197 * @param storeSetName - lastParmSet
1199 * @param descr - setDescr.getText()
1201 * @param jobParams - getJobParams()
1203 * private void _storeUserPreset(String storeSetName, String descr,
1204 * List<ArgumentI> jobParams) { // this is a simple hash store. Object[] pset;
1205 * editedParams.put(storeSetName, pset = new Object[3]); pset[0] =
1206 * storeSetName; pset[1] = descr; pset[2] = jobParams; // writeParam("Saving "
1207 * + storeSetName + ": ", jobParams); }
1209 * private void writeParam(String nm, List<ArgumentI> params) { for (ArgumentI
1210 * p : params) { System.out.println(nm + ":" + System.identityHashCode(p) +
1211 * " Name: " + p.getName() + " Value: " + p.getDefaultValue()); } }
1213 * private Object[] _getUserPreset(String setName) { Object[] pset =
1214 * editedParams.get(setName); // if (pset != null) // writeParam("Retrieving "
1215 * + setName + ": ", (List<Argument>) pset[2]); return pset; }
1217 * * remove the given user preset from the preset stash
1221 * private void _deleteUserPreset(String setName) {
1222 * editedParams.remove(setName); }
1225 private void syncSetNamesWithStore()
1228 // remove any set names in the drop down menu that aren't either a reserved
1229 // setting, or a user defined or service preset.
1230 Vector items = new Vector();
1231 while (n < setName.getItemCount())
1233 String item = (String) setName.getItemAt(n);
1234 if (!item.equals(SVC_DEF) && !paramStore.presetExists(item))
1236 setName.removeItemAt(n);
1240 items.addElement(item);
1244 if (!items.contains(SVC_DEF))
1246 setName.addItem(SVC_DEF);
1248 for (WsParamSetI upn : paramStore.getPresets())
1250 if (!items.contains(upn.getName()))
1252 setName.addItem(upn.getName());
1258 * true if lastParmSet is a user preset
1260 boolean isUserPreset = false;
1262 private void reInitDialog(String nextPreset)
1264 settingDialog = true;
1265 // updateTable(null,null); // first reset to defaults
1266 WsParamSetI pset = null;
1267 if (nextPreset != null && nextPreset.length() > 0)
1269 pset = paramStore.getPreset(nextPreset);
1273 if (pset.isModifiable())
1275 isUserPreset = true;
1276 setDescr.setText(pset.getDescription());
1277 updateTable(null, pset.getArguments());
1278 lastParmSet = nextPreset;
1282 isUserPreset = false;
1283 setDescr.setText("");
1284 // must be a default preset from service
1285 updateTable(pset, null);
1286 lastParmSet = nextPreset;
1291 isUserPreset = false;
1293 setDescr.setText("");
1294 updateTable(null, null);
1295 lastParmSet = SVC_DEF;
1298 initArgSetModified();
1299 syncSetNamesWithStore();
1300 setName.setSelectedItem(lastParmSet);
1301 SetNamePanel.validate();
1303 settingDialog = false;
1307 * Rebuild the AlignFrame web service menus (after add/delete of a preset
1310 protected void updateWebServiceMenus()
1312 for (AlignFrame alignFrame : Desktop.getAlignFrames())
1314 alignFrame.BuildWebServiceMenu();
1318 String curSetName = null;
1320 public void itemStateChanged(ItemEvent e)
1322 if (e.getSource() == setName && e.getStateChange() == e.SELECTED)
1324 final String setname = (String) setName.getSelectedItem();
1325 System.out.println("Item state changed for " + setname
1326 + " (handling ? " + !settingDialog + ")");
1332 if (setname == null)
1336 javax.swing.SwingUtilities.invokeLater(new Runnable()
1340 doPreferenceComboStateChange(setname);
1346 private void doPreferenceComboStateChange(String setname)
1348 // user has selected a different item from combo-box
1351 String lsetname = (curSetName != null) ? curSetName : lastParmSet;
1352 if (lsetname.equals(setname))
1354 // setname was just edited - so ignore this event.
1357 settingDialog = true;
1358 System.out.println("Prompting to save " + lsetname);
1359 if (javax.swing.JOptionPane
1364 + "' is modifed, and your changes will be lost.\nReally change preset ?",
1365 "Warning: Unsaved Changes",
1366 javax.swing.JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION)
1368 // revert the combobox to the current item
1369 settingDialog = true;
1370 setName.setSelectedItem(lsetname);
1371 settingDialog = false;
1374 // System.out.println("Saving for " + lsetname);
1375 // _storeCurrentPreset(lsetname);
1379 settingDialog = true;
1380 reInitDialog(setname);
1381 settingDialog = false;
1385 private void _renameExistingPreset(String oldName, String curSetName2)
1387 paramStore.updatePreset(oldName, curSetName2, setDescr.getText(),
1392 * store current settings as given name. You should then reset gui.
1394 * @param curSetName2
1396 private void _storeCurrentPreset(String curSetName2)
1398 paramStore.storePreset(curSetName2, setDescr.getText(), getJobParams());
1401 private void _updatePreset(String lastParmSet2, String curname)
1403 paramStore.updatePreset(lastParmSet2, curname, setDescr.getText(),
1409 * last saved name for this user preset
1411 String lastSetName = null;
1414 * last saved value of the description text for this user preset
1416 String lastDescrText = null;
1418 public void actionPerformed(ActionEvent e)
1420 if (e.getSource() instanceof Component)
1422 Component src = (Component) e.getSource();
1423 if (src.getParent() == setName)
1425 // rename any existing records we know about for this set.
1426 String newname = e.getActionCommand().trim();
1428 if (isServicePreset(newname))
1430 final String oldname = curSetName != null ? curSetName
1432 final Component ourframe = this;
1433 settingDialog = true;
1434 setName.getEditor().setItem(oldname);
1435 settingDialog = false;
1436 javax.swing.SwingUtilities.invokeLater(new Runnable()
1440 JOptionPane.showMessageDialog(ourframe, MessageManager
1441 .getString("label.invalid_name_preset_exists"),
1442 MessageManager.getString("label.invalid_name"),
1443 JOptionPane.WARNING_MESSAGE);
1449 curSetName = newname;
1450 System.err.println("New name for user setting " + curSetName
1451 + " (was " + setName.getSelectedItem() + ")");
1452 if (curSetName.equals(setName.getSelectedItem()))
1456 if (curSetName != null)
1458 argSetModified(setName, true);
1466 private void checkDescrModified()
1473 (lastDescrText == null ? setDescr.getText().trim().length() > 0
1474 : !setDescr.getText().equals(lastDescrText)));
1479 public void insertUpdate(DocumentEvent e)
1481 checkDescrModified();
1484 public void removeUpdate(DocumentEvent e)
1486 checkDescrModified();
1489 public void changedUpdate(DocumentEvent e)
1491 checkDescrModified();
1496 * @return null or the service preset selected by the user
1498 public WsParamSetI getPreset()
1500 if (isUserPreset || isModified()
1501 || (lastParmSet != null && lastParmSet.equals(SVC_DEF)))
1507 return paramStore.getPreset(lastParmSet);