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.JPanel;
52 import javax.swing.JScrollPane;
53 import javax.swing.JSplitPane;
54 import javax.swing.JTextArea;
55 import javax.swing.border.TitledBorder;
56 import javax.swing.event.DocumentEvent;
57 import javax.swing.event.DocumentListener;
59 import compbio.metadata.Argument;
60 import compbio.metadata.Option;
61 import compbio.metadata.Parameter;
62 import compbio.metadata.Preset;
63 import compbio.metadata.PresetManager;
64 import compbio.metadata.RunnerConfig;
65 import jalview.bin.Console;
66 import jalview.gui.OptsAndParamsPage.OptionBox;
67 import jalview.gui.OptsAndParamsPage.ParamBox;
68 import jalview.util.MessageManager;
69 import jalview.ws.jws2.JabaParamStore;
70 import jalview.ws.jws2.JabaPreset;
71 import jalview.ws.jws2.Jws2Discoverer;
72 import jalview.ws.jws2.jabaws2.Jws2Instance;
73 import jalview.ws.params.ArgumentI;
74 import jalview.ws.params.OptionI;
75 import jalview.ws.params.ParamDatastoreI;
76 import jalview.ws.params.ParameterI;
77 import jalview.ws.params.WsParamSetI;
78 import net.miginfocom.swing.MigLayout;
81 * job parameter editing/browsing dialog box. User can browse existing settings
82 * (user + presets + Defaults), and any changes to parameters creates a modified
83 * user parameter set. LOGIC: If the parameter set is modified, and its name is
84 * a valid, non-existant user parameter set, then a save button is shown. If the
85 * parameter set is modified and its name is a valid, extant user parameter set,
86 * then an update button is shown. If user parameter set's name is edited, and
87 * old name exists as a writable user parameter set, then rename button is
88 * shown. If current parameter set is associated with a user defined parameter
89 * set, then : if set is modifed, a 'revert' button is shown. if set is not
90 * modified, a 'delete' button is shown.
95 public class WsJobParameters extends JPanel implements ItemListener,
96 ActionListener, DocumentListener, OptsParametersContainerI
98 URL linkImageURL = getClass().getResource("/images/link.gif");
100 private static final String SVC_DEF = "Defaults"; // this is the null
101 // parameter set as shown to
105 * manager for options and parameters.
107 OptsAndParamsPage opanp = new OptsAndParamsPage(this);
110 * panel containing job options
112 JPanel jobOptions = new JPanel();
115 * panel containing job parameters
117 JPanel paramList = new JPanel();
119 JPanel SetNamePanel = new JPanel();
121 JPanel setDetails = new JPanel();
123 JSplitPane settingsPanel = new JSplitPane();
125 JPanel jobPanel = new JPanel();
127 JScrollPane jobOptionsPane = new JScrollPane();
129 JButton createpref = new JButton();
131 JButton deletepref = new JButton();
133 JButton revertpref = new JButton();
135 JButton updatepref = new JButton();
137 JButton startjob = new JButton();
139 JButton canceljob = new JButton();
141 JComboBox setName = new JComboBox();
143 JTextArea setDescr = new JTextArea();
145 JScrollPane paramPane = new JScrollPane();
147 // ScrollablePanel optsAndparams = new ScrollablePanel();
148 JPanel optsAndparams = new JPanel();
150 RunnerConfig serviceOptions;
152 ParamDatastoreI paramStore;
154 private int MAX_OPTWIDTH = 200;
156 WsJobParameters(Jws2Instance service)
161 public WsJobParameters(Jws2Instance service, WsParamSetI preset)
163 this(null, service, preset, null);
169 * - if null, create new JFrame outside of desktop
173 public WsJobParameters(JFrame parent, Jws2Instance service,
174 WsParamSetI preset, List<Argument> jobArgset)
176 this(parent, null, service, preset, jobArgset);
187 public WsJobParameters(JFrame parent, ParamDatastoreI paramStorei,
188 Jws2Instance service, WsParamSetI preset,
189 List<Argument> jobArgset)
193 this.paramStore = paramStorei;
194 if (paramStore == null)
196 paramStore = service.getParamStore();
198 this.service = service;
199 // argSetModified(false);
200 // populate parameter table
201 initForService(service, preset, jobArgset);
202 // display in new JFrame attached to parent.
208 JDialog frame = null;
211 * shows a modal dialog containing the parameters.
215 public boolean showRunDialog()
218 frame = new JDialog(Desktop.instance, true);
220 frame.setTitle(MessageManager.formatMessage("label.edit_params_for",
222 { service.getActionText() }));
223 Rectangle deskr = Desktop.instance.getBounds();
224 Dimension pref = this.getPreferredSize();
226 new Rectangle((int) (deskr.getCenterX() - pref.width / 2),
227 (int) (deskr.getCenterY() - pref.height / 2),
228 pref.width, pref.height));
229 frame.setContentPane(this);
231 // should perhaps recover defaults from user prefs.
234 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"),
277 public void actionPerformed(ActionEvent e)
279 update_actionPerformed(e);
282 deletepref = JvSwingUtils.makeButton(
283 MessageManager.getString("action.delete"),
284 MessageManager.getString("label.delete_user_parameter_set"),
289 public void actionPerformed(ActionEvent e)
291 delete_actionPerformed(e);
294 createpref = JvSwingUtils.makeButton(
295 MessageManager.getString("action.create"),
296 MessageManager.getString("label.create_user_parameter_set"),
301 public void actionPerformed(ActionEvent e)
303 create_actionPerformed(e);
306 revertpref = JvSwingUtils.makeButton(
307 MessageManager.getString("action.revert"),
309 .getString("label.revert_changes_user_parameter_set"),
314 public void actionPerformed(ActionEvent e)
316 revert_actionPerformed(e);
319 startjob = JvSwingUtils.makeButton(
320 MessageManager.getString("action.start_job"),
321 MessageManager.getString("label.start_job_current_settings"),
325 public void actionPerformed(ActionEvent e)
327 startjob_actionPerformed(e);
330 canceljob = JvSwingUtils.makeButton(
331 MessageManager.getString("action.cancel_job"),
332 MessageManager.getString("label.cancel_job_close_dialog"),
336 public void actionPerformed(ActionEvent e)
338 canceljob_actionPerformed(e);
342 setDetails.setBorder(
343 new TitledBorder(MessageManager.getString("label.details")));
344 setDetails.setLayout(new BorderLayout());
345 setDescr.setColumns(40);
346 setDescr.setWrapStyleWord(true);
347 setDescr.setLineWrap(true);
348 setDescr.setBackground(getBackground());
349 setDescr.setEditable(true);
350 setDescr.getDocument().addDocumentListener(this);
351 setDescr.setToolTipText(
352 MessageManager.getString("label.edit_notes_parameter_set"));
353 JScrollPane setDescrView = new JScrollPane();
354 setDescrView.getViewport().setView(setDescr);
355 setName.setEditable(true);
356 setName.addItemListener(this);
357 setName.getEditor().addActionListener(this);
358 JPanel setNameInfo = new JPanel(new FlowLayout(FlowLayout.LEFT));
359 GridBagLayout gbl = new GridBagLayout();
360 SetNamePanel.setLayout(gbl);
362 JLabel setNameLabel = new JLabel(
363 MessageManager.getString("label.current_parameter_set_name"));
364 setNameLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
366 setNameInfo.add(setNameLabel);
367 setNameInfo.add(setName);
369 // initial button visibility
370 updatepref.setVisible(false);
371 deletepref.setVisible(false);
372 revertpref.setVisible(false);
373 createpref.setVisible(false);
374 JPanel setsavebuts = new JPanel();
375 setsavebuts.setLayout(new FlowLayout(FlowLayout.LEFT)); // GridLayout(1,2));
376 ((FlowLayout) setsavebuts.getLayout()).setHgap(10);
377 ((FlowLayout) setsavebuts.getLayout()).setVgap(0);
378 JPanel spacer = new JPanel();
379 spacer.setPreferredSize(new Dimension(2, 30));
380 setsavebuts.add(spacer);
381 setsavebuts.add(deletepref);
382 setsavebuts.add(revertpref);
383 setsavebuts.add(createpref);
384 setsavebuts.add(updatepref);
385 // setsavebuts.setSize(new Dimension(150, 30));
386 JPanel buttonArea = new JPanel(new GridLayout(1, 1));
387 buttonArea.add(setsavebuts);
388 SetNamePanel.add(setNameInfo);
389 GridBagConstraints gbc = new GridBagConstraints();
391 gbl.setConstraints(setNameInfo, gbc);
392 SetNamePanel.add(buttonArea);
393 gbc = new GridBagConstraints();
397 gbl.setConstraints(buttonArea, gbc);
398 setDetails.add(setDescrView, BorderLayout.CENTER);
400 // paramPane.setPreferredSize(new Dimension(360, 400));
401 // paramPane.setPreferredSize(null);
402 jobOptions.setBorder(
403 new TitledBorder(MessageManager.getString("label.options")));
404 jobOptions.setOpaque(true);
406 new TitledBorder(MessageManager.getString("label.parameters")));
407 paramList.setOpaque(true);
408 JPanel bjo = new JPanel(new BorderLayout()),
409 bjp = new JPanel(new BorderLayout());
410 bjo.add(jobOptions, BorderLayout.CENTER);
411 bjp.add(paramList, BorderLayout.CENTER);
414 // optsAndparams.setScrollableWidth(ScrollableSizeHint.FIT);
415 // optsAndparams.setScrollableHeight(ScrollableSizeHint.NONE);
416 // optsAndparams.setLayout(new BorderLayout());
417 optsAndparams.setLayout(new BorderLayout());
418 optsAndparams.add(jobOptions, BorderLayout.NORTH);
419 optsAndparams.add(paramList, BorderLayout.CENTER);
420 JPanel jp = new JPanel(new BorderLayout());
421 jp.add(optsAndparams, BorderLayout.CENTER);
422 paramPane.getViewport().setView(jp);
423 paramPane.setBorder(null);
424 setLayout(new BorderLayout());
425 jobPanel.setPreferredSize(null);
426 jobPanel.setLayout(new BorderLayout());
427 jobPanel.add(setDetails, BorderLayout.NORTH);
428 jobPanel.add(paramPane, BorderLayout.CENTER);
429 // jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
431 add(SetNamePanel, BorderLayout.NORTH);
432 add(jobPanel, BorderLayout.CENTER);
434 JPanel dialogpanel = new JPanel();
435 dialogpanel.add(startjob);
436 dialogpanel.add(canceljob);
437 // JAL-1580: setMaximumSize() doesn't work, so just size for the worst case:
438 // check for null is for JUnit usage
439 final int windowHeight = Desktop.instance == null ? 540
440 : Desktop.instance.getHeight();
441 setPreferredSize(new Dimension(540, windowHeight));
442 add(dialogpanel, BorderLayout.SOUTH);
446 protected void revert_actionPerformed(ActionEvent e)
448 reInitDialog(lastParmSet);
449 updateWebServiceMenus();
452 protected void update_actionPerformed(ActionEvent e)
456 String curname = ((String) setName.getSelectedItem()).trim();
457 _updatePreset(lastParmSet, curname);
458 lastParmSet = curname;
460 initArgSetModified();
461 syncSetNamesWithStore();
465 private void _deleteUserPreset(String lastParmSet2)
467 paramStore.deletePreset(lastParmSet2);
470 protected void delete_actionPerformed(ActionEvent e)
474 // delete current preset's saved entry
475 _deleteUserPreset(lastParmSet);
477 reInitDialog(null); // service default
478 updateWebServiceMenus();
481 protected void create_actionPerformed(ActionEvent e)
483 String curname = ((String) setName.getSelectedItem()).trim();
484 if (curname.length() > 0)
486 _storeCurrentPreset(curname);
487 lastParmSet = curname;
489 reInitDialog(curname);
490 initArgSetModified();
491 updateWebServiceMenus();
495 // TODO: show warning
496 jalview.bin.Console.errPrintln("Invalid name. Not saved.");
500 protected void canceljob_actionPerformed(ActionEvent e)
505 frame.setVisible(false);
509 protected void startjob_actionPerformed(ActionEvent e)
514 frame.setVisible(false);
518 Jws2Instance service;
521 * list of service presets in the gui
523 Hashtable servicePresets = null;
526 * set if dialog is being set - so handlers will avoid spurious events
528 boolean settingDialog = false;
530 void initForService(Jws2Instance service, WsParamSetI jabap,
531 List<Argument> jabajobArgset)
533 WsParamSetI p = null;
534 List<ArgumentI> jobArgset = null;
535 settingDialog = true;
536 { // instantiate the abstract proxy for Jaba objects
537 jobArgset = jabajobArgset == null ? null
538 : JabaParamStore.getJwsArgsfromJaba(jabajobArgset);
539 p = jabap; // (jabap != null) ? paramStore.getPreset(jabap.getName()) :
543 Hashtable exnames = new Hashtable();
544 for (int i = 0, iSize = setName.getItemCount(); i < iSize; i++)
546 exnames.put(setName.getItemAt(i), setName.getItemAt(i));
548 servicePresets = new Hashtable();
549 // Add the default entry - if not present already.
550 if (!exnames.contains(SVC_DEF))
552 setName.addItem(SVC_DEF);
553 exnames.put(SVC_DEF, SVC_DEF);
554 servicePresets.put(SVC_DEF, SVC_DEF);
556 String curname = (p == null ? "" : p.getName());
557 for (WsParamSetI pr : paramStore.getPresets())
559 if (!pr.isModifiable())
561 servicePresets.put(pr.getName(), "preset");
566 if (!exnames.contains(pr.getName()))
568 setName.addItem(pr.getName());
571 // TODO: if initial jobArgset matches a given user setting or preset then
572 // should recover setting accordingly
573 // updateTable(p, jobArgset);
576 reInitDialog(p.getName());
577 initArgSetModified();
581 if (jobArgset != null && jobArgset.size() > 0)
583 curSetName = "Supplied Settings";
584 isUserPreset = false;
585 updateTable(p, jobArgset);
586 setName.setSelectedItem(curSetName);
587 updateButtonDisplay();
595 settingDialog = false;
599 @SuppressWarnings("unchecked")
600 private void updateTable(WsParamSetI p, List<ArgumentI> jobArgset)
602 boolean setDefaultParams = false;
603 if (lastParmSet == null)
605 isUserPreset = false;
606 // First call - so provide Service default settings
607 setName.setSelectedItem(lastSetName = SVC_DEF);
609 if (p == null && SVC_DEF.equals("" + setName.getSelectedItem()))
611 // indicate that service defaults should be set if available
612 setDefaultParams = true;
614 // populate table from default parameter set.
615 List<ArgumentI> args = paramStore.getServiceParameters();
617 // split to params and required arguments
620 boolean optset = false;
621 for (ArgumentI myarg : args)
623 // Ideally, Argument would implement isRequired !
624 if (myarg instanceof ParameterI)
626 ParameterI parm = (ParameterI) myarg;
627 opanp.addParameter(parm).validate();
631 if (myarg instanceof OptionI)
633 OptionI opt = (OptionI) myarg;
634 OptionBox ob = opanp.addOption(opt);
635 ob.resetToDefault(setDefaultParams);
636 if (MAX_OPTWIDTH < ob.getPreferredSize().width)
638 MAX_OPTWIDTH = ob.getPreferredSize().width;
641 cw += ob.getPreferredSize().width + 5;
646 .errPrintln("Ignoring unknown service argument type "
647 + myarg.getClass().getName());
651 args = null; // no more args to process.
655 isUserPreset = false;
656 // initialise setname
657 setName.setSelectedItem(lastSetName = p.getName());
658 setDescr.setText(lastDescrText = p.getDescription());
662 args = p.getArguments();
663 } catch (Exception e)
667 // TODO: check if args should be unselected prior to resetting using the
671 if (jobArgset != null)
673 argSetModified(jobArgset, true);
676 // get setargs from current object
679 for (ArgumentI arg : args)
681 if (arg instanceof ParameterI)
683 opanp.setParameter((ParameterI) arg);
687 if (arg instanceof OptionI)
689 // jalview.bin.Console.outPrintln("Setting option "
690 // + System.identityHashCode(arg) + ":" + arg.getName()
691 // + " with " + arg.getDefaultValue());
692 opanp.selectOption((OptionI) arg, arg.getValue());
699 refreshParamLayout();
703 private boolean isModified()
705 return modifiedElements.size() > 0;
708 private Hashtable modifiedElements = new Hashtable();
711 * reset gui and modification state settings
713 private void initArgSetModified()
716 modifiedElements.clear();
717 updateButtonDisplay();
720 private void updateButtonDisplay()
722 boolean _update = false, _create = false, _delete = false,
724 if (modifiedElements.size() > 0)
728 _update = isUserPreset; // can only update user presets
729 if (!isUserPreset || modifiedElements.containsKey(setName))
731 // name modified - can create new preset
739 // can still delete a user preset
740 _delete = isUserPreset;
742 createpref.setVisible(_create);
743 updatepref.setVisible(_update);
744 deletepref.setVisible(_delete);
745 revertpref.setVisible(_revert);
750 public void argSetModified(Object modifiedElement, boolean b)
758 modifiedElements.remove(modifiedElement);
762 if (b && modifiedElement == setName
763 && modifiedElements.contains(modifiedElement))
765 // HACK! prevents iteration on makeSetNameValid
768 modifiedElements.put(modifiedElement, modifiedElement);
770 // set mod status based on presence of elements in table
771 if (b && modifiedElements.size() > 0)
773 makeSetNameValid(!isUserPreset);
774 SetNamePanel.revalidate();
776 updateButtonDisplay();
779 private boolean isServicePreset(String selectedItem)
781 return selectedItem.equals(SVC_DEF)
782 || servicePresets.containsKey(selectedItem);
786 * check if the current set name is a valid set name for saving, if not, then
789 private void makeSetNameValid(boolean newuserset)
791 boolean stn = settingDialog;
792 boolean renamed = false;
793 settingDialog = true;
794 String nm = (curSetName != null ? curSetName
795 : (String) setName.getSelectedItem());
796 // check if the name is reserved - if it is, rename it.
797 if (isServicePreset(nm))
806 while (paramStore.getPreset(tnm) != null)
808 tnm = nm + " (" + (++i) + ")";
817 boolean makeupdate = false;
818 // sync the gui with the preset database
819 for (int i = 0, iS = setName.getItemCount(); i < iS; i++)
821 String snm = (String) setName.getItemAt(i);
825 // setName.setSelectedIndex(i);
830 setName.addItem(curSetName = nm);
831 setName.setSelectedItem(curSetName);
835 settingDialog = false; // we need this name change to be registered.
836 argSetModified(setName, renamed);
842 public void refreshParamLayout()
844 // optsAndparams.setPreferredSize(null);
845 FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
846 int sep = fl.getVgap();
849 s = jobOptions.getBorder().getBorderInsets(jobOptions).bottom
850 + jobOptions.getBorder().getBorderInsets(jobOptions).top
853 * final height for viewport
856 int panewidth = paramPane.getViewport().getSize().width - 120
857 - jobOptions.getBorder().getBorderInsets(jobOptions).left
858 + jobOptions.getBorder().getBorderInsets(jobOptions).right;
860 int w = 2 * fl.getHgap()
861 + (MAX_OPTWIDTH > OptsAndParamsPage.PARAM_WIDTH ? MAX_OPTWIDTH
862 : OptsAndParamsPage.PARAM_WIDTH);
863 int hgap = fl.getHgap(), cw = hgap;
865 if (opanp.getOptSet().size() > 0)
868 jobOptions.setLayout(new MigLayout("", "", ""));
869 jobOptions.removeAll();
871 for (OptionBox pbox : opanp.getOptSet().values())
874 cw += pbox.getSize().width + hgap;
875 if (cw + 120 > panewidth)
877 jobOptions.add(pbox, "wrap");
878 // jalview.bin.Console.outPrintln("Wrap on "+pbox.option.getName());
879 cw = hgap + pbox.getSize().width;
884 jobOptions.add(pbox);
888 finalh += pbox.getSize().height + fl.getVgap();
892 jobOptions.revalidate();
896 jobOptions.setVisible(false);
899 // Now layout the parameters assuming they occupy one column - to calculate
900 // total height of options+parameters
901 fl = new FlowLayout(FlowLayout.LEFT);
903 // http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
904 fl.setAlignOnBaseline(true);
905 if (opanp.getParamSet().size() > 0)
907 paramList.removeAll();
908 paramList.setLayout(new MigLayout("", "", ""));
910 for (ParamBox pbox : opanp.getParamSet().values())
913 cw += pbox.getSize().width + hgap;
914 if (cw + 160 > panewidth)
916 paramList.add(pbox, "wrap");
917 cw = pbox.getSize().width + hgap;
926 finalh += pbox.getSize().height + fl.getVgap();
932 * s = 2 * sep; for (ParamBox pbox : opanp.getParamSet().values()) {
933 * pbox.validate(); s += sep +
934 * pbox.getPreferredSize().height+pbox.getBorder
935 * ().getBorderInsets(pbox).bottom; }
937 * // paramList.setPreferredSize(new Dimension(w, s));
938 * os+=s+2*sep+paramList
939 * .getBorder().getBorderInsets(paramList).bottom+paramList
940 * .getBorder().getBorderInsets(paramList).top;
942 paramList.revalidate();
946 paramList.setVisible(false);
948 // TODO: waste some time trying to eliminate any unnecessary .validate calls
950 // jalview.bin.Console.outPrintln("Size will be : "+w+","+os);
951 // optsAndparams.setPreferredSize(null);
952 // paramPane.getViewport().setView(optsAndparams);
953 paramPane.getViewport().setAutoscrolls(true);
954 paramPane.revalidate();
959 * testing method - grab a service and parameter set and show the window
964 public static void main(String[] args)
966 jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer
971 Vector<String> services = new Vector<>();
972 services.addElement(args[p++]);
973 Jws2Discoverer.getDiscoverer().setServiceUrls(services);
978 } catch (Exception e)
981 .errPrintln("Aborting. Problem discovering services.");
985 Jws2Instance lastserv = null;
986 for (Jws2Instance service : disc.getServices())
989 if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p]))
991 if (lastserv != null)
993 List<Preset> prl = null;
995 if (++p < args.length)
997 PresetManager prman = lastserv.getPresets();
1000 pr = prman.getPresetByName(args[p]);
1003 // just grab the last preset.
1004 prl = prman.getPresets();
1010 PresetManager prman = lastserv.getPresets();
1013 prl = prman.getPresets();
1016 Iterator<Preset> en = (prl == null) ? null : prl.iterator();
1017 while (en != null && en.hasNext())
1023 en = prl.iterator();
1028 jalview.bin.Console.outPrintln("Testing opts dupes for "
1029 + lastserv.getUri() + " : " + lastserv.getActionText()
1030 + ":" + pr.getName());
1031 List<Option> rg = lastserv.getRunnerConfig().getOptions();
1036 Option cpy = jalview.ws.jws2.ParameterUtils.copyOption(o);
1037 } catch (Exception e)
1040 .errPrintln("Failed to copy " + o.getName());
1041 e.printStackTrace();
1045 .errPrintln("Failed to copy " + o.getName());
1046 e.printStackTrace();
1051 jalview.bin.Console.outPrintln("Testing param dupes:");
1052 List<Parameter> rg = lastserv.getRunnerConfig()
1054 for (Parameter o : rg)
1058 Parameter cpy = jalview.ws.jws2.ParameterUtils
1060 } catch (Exception e)
1063 .errPrintln("Failed to copy " + o.getName());
1064 e.printStackTrace();
1068 .errPrintln("Failed to copy " + o.getName());
1069 e.printStackTrace();
1074 jalview.bin.Console.outPrintln("Testing param write:");
1075 List<String> writeparam = null, readparam = null;
1078 writeparam = jalview.ws.jws2.ParameterUtils
1080 pr.getArguments(lastserv.getRunnerConfig()),
1082 jalview.bin.Console.outPrintln("Testing param read :");
1083 List<Option> pset = jalview.ws.jws2.ParameterUtils
1084 .processParameters(writeparam,
1085 lastserv.getRunnerConfig(), " ");
1086 readparam = jalview.ws.jws2.ParameterUtils
1087 .writeParameterSet(pset, " ");
1088 Iterator<String> o = pr.getOptions().iterator(),
1089 s = writeparam.iterator(), t = readparam.iterator();
1090 boolean failed = false;
1091 while (s.hasNext() && t.hasNext())
1093 String on = o.next(), sn = s.next(), st = t.next();
1096 jalview.bin.Console.outPrintln(
1097 "Original was " + on + " Phase 1 wrote " + sn
1098 + "\tPhase 2 wrote " + st);
1104 jalview.bin.Console.outPrintln(
1105 "Original parameters:\n" + pr.getOptions());
1106 jalview.bin.Console.outPrintln(
1107 "Wrote parameters in first set:\n" + writeparam);
1108 jalview.bin.Console.outPrintln(
1109 "Wrote parameters in second set:\n" + readparam);
1112 } catch (Exception e)
1114 e.printStackTrace();
1117 WsJobParameters pgui = new WsJobParameters(lastserv,
1118 new JabaPreset(lastserv, pr));
1119 JFrame jf = new JFrame(MessageManager
1120 .formatMessage("label.ws_parameters_for", new String[]
1121 { lastserv.getActionText() }));
1122 JPanel cont = new JPanel(new BorderLayout());
1124 cont.setPreferredSize(pgui.getPreferredSize());
1125 cont.add(pgui, BorderLayout.CENTER);
1126 jf.setLayout(new BorderLayout());
1127 jf.add(cont, BorderLayout.CENTER);
1129 final Thread thr = Thread.currentThread();
1130 jf.addWindowListener(new WindowListener()
1134 public void windowActivated(WindowEvent e)
1136 // TODO Auto-generated method stub
1141 public void windowClosed(WindowEvent e)
1146 public void windowClosing(WindowEvent e)
1153 public void windowDeactivated(WindowEvent e)
1155 // TODO Auto-generated method stub
1160 public void windowDeiconified(WindowEvent e)
1162 // TODO Auto-generated method stub
1167 public void windowIconified(WindowEvent e)
1169 // TODO Auto-generated method stub
1174 public void windowOpened(WindowEvent e)
1176 // TODO Auto-generated method stub
1181 jf.setVisible(true);
1182 boolean inter = false;
1187 Thread.sleep(10000);
1188 } catch (Exception e)
1200 public boolean isServiceDefaults()
1202 return (!isModified()
1203 && (lastParmSet != null && lastParmSet.equals(SVC_DEF)));
1206 public List<ArgumentI> getJobParams()
1208 return opanp.getCurrentSettings();
1211 String lastParmSet = null;
1214 * Hashtable<String, Object[]> editedParams = new Hashtable<String,
1217 * store the given parameters in the user parameter set database.
1219 * @param storeSetName - lastParmSet
1221 * @param descr - setDescr.getText()
1223 * @param jobParams - getJobParams()
1225 * private void _storeUserPreset(String storeSetName, String descr,
1226 * List<ArgumentI> jobParams) { // this is a simple hash store. Object[] pset;
1227 * editedParams.put(storeSetName, pset = new Object[3]); pset[0] =
1228 * storeSetName; pset[1] = descr; pset[2] = jobParams; // writeParam("Saving "
1229 * + storeSetName + ": ", jobParams); }
1231 * private void writeParam(String nm, List<ArgumentI> params) { for (ArgumentI
1232 * p : params) { jalview.bin.Console.outPrintln(nm + ":" + System.identityHashCode(p) +
1233 * " Name: " + p.getName() + " Value: " + p.getDefaultValue()); } }
1235 * private Object[] _getUserPreset(String setName) { Object[] pset =
1236 * editedParams.get(setName); // if (pset != null) // writeParam("Retrieving "
1237 * + setName + ": ", (List<Argument>) pset[2]); return pset; }
1239 * * remove the given user preset from the preset stash
1243 * private void _deleteUserPreset(String setName) {
1244 * editedParams.remove(setName); }
1247 private void syncSetNamesWithStore()
1250 // remove any set names in the drop down menu that aren't either a reserved
1251 // setting, or a user defined or service preset.
1252 Vector items = new Vector();
1253 while (n < setName.getItemCount())
1255 String item = (String) setName.getItemAt(n);
1256 if (!item.equals(SVC_DEF) && !paramStore.presetExists(item))
1258 setName.removeItemAt(n);
1262 items.addElement(item);
1266 if (!items.contains(SVC_DEF))
1268 setName.addItem(SVC_DEF);
1270 for (WsParamSetI upn : paramStore.getPresets())
1272 if (!items.contains(upn.getName()))
1274 setName.addItem(upn.getName());
1280 * true if lastParmSet is a user preset
1282 boolean isUserPreset = false;
1284 private void reInitDialog(String nextPreset)
1286 settingDialog = true;
1287 // updateTable(null,null); // first reset to defaults
1288 WsParamSetI pset = null;
1289 if (nextPreset != null && nextPreset.length() > 0)
1291 pset = paramStore.getPreset(nextPreset);
1295 if (pset.isModifiable())
1297 isUserPreset = true;
1298 setDescr.setText(pset.getDescription());
1299 updateTable(null, pset.getArguments());
1300 lastParmSet = nextPreset;
1304 isUserPreset = false;
1305 setDescr.setText("");
1306 // must be a default preset from service
1307 updateTable(pset, null);
1308 lastParmSet = nextPreset;
1313 isUserPreset = false;
1315 setDescr.setText("");
1316 updateTable(null, null);
1317 lastParmSet = SVC_DEF;
1320 initArgSetModified();
1321 syncSetNamesWithStore();
1322 setName.setSelectedItem(lastParmSet);
1323 SetNamePanel.validate();
1325 settingDialog = false;
1329 * Rebuild the AlignFrame web service menus (after add/delete of a preset
1332 protected void updateWebServiceMenus()
1334 for (AlignFrame alignFrame : Desktop.getDesktopAlignFrames())
1336 alignFrame.BuildWebServiceMenu();
1340 String curSetName = null;
1343 public void itemStateChanged(ItemEvent e)
1345 if (e.getSource() == setName && e.getStateChange() == e.SELECTED)
1347 final String setname = (String) setName.getSelectedItem();
1348 if (Console.isDebugEnabled())
1350 Console.debug("Item state changed for " + setname + " (handling ? "
1351 + !settingDialog + ")");
1358 if (setname == null)
1362 javax.swing.SwingUtilities.invokeLater(new Runnable()
1367 doPreferenceComboStateChange(setname);
1373 private void doPreferenceComboStateChange(String setname)
1375 // user has selected a different item from combo-box
1378 String lsetname = (curSetName != null) ? curSetName : lastParmSet;
1379 if (lsetname.equals(setname))
1381 // setname was just edited - so ignore this event.
1384 settingDialog = true;
1385 jalview.bin.Console.outPrintln("Prompting to save " + lsetname);
1386 if (JvOptionPane.showConfirmDialog(this, "Parameter set '" + lsetname
1387 + "' is modifed, and your changes will be lost.\nReally change preset ?",
1388 "Warning: Unsaved Changes",
1389 JvOptionPane.OK_CANCEL_OPTION) != JvOptionPane.OK_OPTION)
1391 // revert the combobox to the current item
1392 settingDialog = true;
1393 setName.setSelectedItem(lsetname);
1394 settingDialog = false;
1397 // jalview.bin.Console.outPrintln("Saving for " + lsetname);
1398 // _storeCurrentPreset(lsetname);
1402 settingDialog = true;
1403 reInitDialog(setname);
1404 settingDialog = false;
1408 private void _renameExistingPreset(String oldName, String curSetName2)
1410 paramStore.updatePreset(oldName, curSetName2, setDescr.getText(),
1415 * store current settings as given name. You should then reset gui.
1417 * @param curSetName2
1419 private void _storeCurrentPreset(String curSetName2)
1421 paramStore.storePreset(curSetName2, setDescr.getText(), getJobParams());
1424 private void _updatePreset(String lastParmSet2, String curname)
1426 paramStore.updatePreset(lastParmSet2, curname, setDescr.getText(),
1432 * last saved name for this user preset
1434 String lastSetName = null;
1437 * last saved value of the description text for this user preset
1439 String lastDescrText = null;
1442 public void actionPerformed(ActionEvent e)
1444 if (e.getSource() instanceof Component)
1446 Component src = (Component) e.getSource();
1447 if (src.getParent() == setName)
1449 // rename any existing records we know about for this set.
1450 String newname = e.getActionCommand().trim();
1452 if (isServicePreset(newname))
1454 final String oldname = curSetName != null ? curSetName
1456 final Component ourframe = this;
1457 settingDialog = true;
1458 setName.getEditor().setItem(oldname);
1459 settingDialog = false;
1460 javax.swing.SwingUtilities.invokeLater(new Runnable()
1465 JvOptionPane.showMessageDialog(ourframe,
1466 MessageManager.getString(
1467 "label.invalid_name_preset_exists"),
1468 MessageManager.getString("label.invalid_name"),
1469 JvOptionPane.WARNING_MESSAGE);
1475 curSetName = newname;
1476 jalview.bin.Console.errPrintln("New name for user setting "
1477 + curSetName + " (was " + setName.getSelectedItem() + ")");
1478 if (curSetName.equals(setName.getSelectedItem()))
1482 if (curSetName != null)
1484 argSetModified(setName, true);
1492 private void checkDescrModified()
1497 argSetModified(setDescr,
1498 (lastDescrText == null
1499 ? setDescr.getText().trim().length() > 0
1500 : !setDescr.getText().equals(lastDescrText)));
1506 public void insertUpdate(DocumentEvent e)
1508 checkDescrModified();
1512 public void removeUpdate(DocumentEvent e)
1514 checkDescrModified();
1518 public void changedUpdate(DocumentEvent e)
1520 checkDescrModified();
1525 * @return null or the service preset selected by the user
1527 public WsParamSetI getPreset()
1529 if (isUserPreset || isModified()
1530 || (lastParmSet != null && lastParmSet.equals(SVC_DEF)))
1536 return paramStore.getPreset(lastParmSet);