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.JPanel;
65 import javax.swing.JScrollPane;
66 import javax.swing.JSplitPane;
67 import javax.swing.JTextArea;
68 import javax.swing.border.TitledBorder;
69 import javax.swing.event.DocumentEvent;
70 import javax.swing.event.DocumentListener;
72 import compbio.metadata.Argument;
73 import compbio.metadata.Option;
74 import compbio.metadata.Parameter;
75 import compbio.metadata.Preset;
76 import compbio.metadata.PresetManager;
77 import compbio.metadata.RunnerConfig;
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 System.err.println("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;
645 System.err.println("Ignoring unknown service argument type "
646 + myarg.getClass().getName());
650 args = null; // no more args to process.
654 isUserPreset = false;
655 // initialise setname
656 setName.setSelectedItem(lastSetName = p.getName());
657 setDescr.setText(lastDescrText = p.getDescription());
661 args = p.getArguments();
662 } catch (Exception e)
666 // TODO: check if args should be unselected prior to resetting using the
670 if (jobArgset != null)
672 argSetModified(jobArgset, true);
675 // get setargs from current object
678 for (ArgumentI arg : args)
680 if (arg instanceof ParameterI)
682 opanp.setParameter((ParameterI) arg);
686 if (arg instanceof OptionI)
688 // System.out.println("Setting option "
689 // + System.identityHashCode(arg) + ":" + arg.getName()
690 // + " with " + arg.getDefaultValue());
691 opanp.selectOption((OptionI) arg, arg.getValue());
698 refreshParamLayout();
702 private boolean isModified()
704 return modifiedElements.size() > 0;
707 private Hashtable modifiedElements = new Hashtable();
710 * reset gui and modification state settings
712 private void initArgSetModified()
715 modifiedElements.clear();
716 updateButtonDisplay();
719 private void updateButtonDisplay()
721 boolean _update = false, _create = false, _delete = false,
723 if (modifiedElements.size() > 0)
727 _update = isUserPreset; // can only update user presets
728 if (!isUserPreset || modifiedElements.containsKey(setName))
730 // name modified - can create new preset
738 // can still delete a user preset
739 _delete = isUserPreset;
741 createpref.setVisible(_create);
742 updatepref.setVisible(_update);
743 deletepref.setVisible(_delete);
744 revertpref.setVisible(_revert);
749 public void argSetModified(Object modifiedElement, boolean b)
757 modifiedElements.remove(modifiedElement);
761 if (b && modifiedElement == setName
762 && modifiedElements.contains(modifiedElement))
764 // HACK! prevents iteration on makeSetNameValid
767 modifiedElements.put(modifiedElement, modifiedElement);
769 // set mod status based on presence of elements in table
770 if (b && modifiedElements.size() > 0)
772 makeSetNameValid(!isUserPreset);
773 SetNamePanel.revalidate();
775 updateButtonDisplay();
778 private boolean isServicePreset(String selectedItem)
780 return selectedItem.equals(SVC_DEF)
781 || servicePresets.containsKey(selectedItem);
785 * check if the current set name is a valid set name for saving, if not, then
788 private void makeSetNameValid(boolean newuserset)
790 boolean stn = settingDialog;
791 boolean renamed = false;
792 settingDialog = true;
793 String nm = (curSetName != null ? curSetName
794 : (String) setName.getSelectedItem());
795 // check if the name is reserved - if it is, rename it.
796 if (isServicePreset(nm))
805 while (paramStore.getPreset(tnm) != null)
807 tnm = nm + " (" + (++i) + ")";
816 boolean makeupdate = false;
817 // sync the gui with the preset database
818 for (int i = 0, iS = setName.getItemCount(); i < iS; i++)
820 String snm = (String) setName.getItemAt(i);
824 // setName.setSelectedIndex(i);
829 setName.addItem(curSetName = nm);
830 setName.setSelectedItem(curSetName);
834 settingDialog = false; // we need this name change to be registered.
835 argSetModified(setName, renamed);
841 public void refreshParamLayout()
843 // optsAndparams.setPreferredSize(null);
844 FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
845 int sep = fl.getVgap();
848 s = jobOptions.getBorder().getBorderInsets(jobOptions).bottom
849 + jobOptions.getBorder().getBorderInsets(jobOptions).top
852 * final height for viewport
855 int panewidth = paramPane.getViewport().getSize().width - 120
856 - jobOptions.getBorder().getBorderInsets(jobOptions).left
857 + jobOptions.getBorder().getBorderInsets(jobOptions).right;
859 int w = 2 * fl.getHgap()
860 + (MAX_OPTWIDTH > OptsAndParamsPage.PARAM_WIDTH ? MAX_OPTWIDTH
861 : OptsAndParamsPage.PARAM_WIDTH);
862 int hgap = fl.getHgap(), cw = hgap;
864 if (opanp.getOptSet().size() > 0)
867 jobOptions.setLayout(new MigLayout("", "", ""));
868 jobOptions.removeAll();
870 for (OptionBox pbox : opanp.getOptSet().values())
873 cw += pbox.getSize().width + hgap;
874 if (cw + 120 > panewidth)
876 jobOptions.add(pbox, "wrap");
877 // System.out.println("Wrap on "+pbox.option.getName());
878 cw = hgap + pbox.getSize().width;
883 jobOptions.add(pbox);
887 finalh += pbox.getSize().height + fl.getVgap();
891 jobOptions.revalidate();
895 jobOptions.setVisible(false);
898 // Now layout the parameters assuming they occupy one column - to calculate
899 // total height of options+parameters
900 fl = new FlowLayout(FlowLayout.LEFT);
902 // http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
903 fl.setAlignOnBaseline(true);
904 if (opanp.getParamSet().size() > 0)
906 paramList.removeAll();
907 paramList.setLayout(new MigLayout("", "", ""));
909 for (ParamBox pbox : opanp.getParamSet().values())
912 cw += pbox.getSize().width + hgap;
913 if (cw + 160 > panewidth)
915 paramList.add(pbox, "wrap");
916 cw = pbox.getSize().width + hgap;
925 finalh += pbox.getSize().height + fl.getVgap();
931 * s = 2 * sep; for (ParamBox pbox : opanp.getParamSet().values()) {
932 * pbox.validate(); s += sep +
933 * pbox.getPreferredSize().height+pbox.getBorder
934 * ().getBorderInsets(pbox).bottom; }
936 * // paramList.setPreferredSize(new Dimension(w, s));
937 * os+=s+2*sep+paramList
938 * .getBorder().getBorderInsets(paramList).bottom+paramList
939 * .getBorder().getBorderInsets(paramList).top;
941 paramList.revalidate();
945 paramList.setVisible(false);
947 // TODO: waste some time trying to eliminate any unnecessary .validate calls
949 // System.out.println("Size will be : "+w+","+os);
950 // optsAndparams.setPreferredSize(null);
951 // paramPane.getViewport().setView(optsAndparams);
952 paramPane.getViewport().setAutoscrolls(true);
953 paramPane.revalidate();
958 * testing method - grab a service and parameter set and show the window
963 public static void main(String[] args)
965 jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer
970 Vector<String> services = new Vector<>();
971 services.addElement(args[p++]);
972 Jws2Discoverer.getDiscoverer().setServiceUrls(services);
977 } catch (Exception e)
979 System.err.println("Aborting. Problem discovering services.");
983 Jws2Instance lastserv = null;
984 for (Jws2Instance service : disc.getServices())
987 if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p]))
989 if (lastserv != null)
991 List<Preset> prl = null;
993 if (++p < args.length)
995 PresetManager prman = lastserv.getPresets();
998 pr = prman.getPresetByName(args[p]);
1001 // just grab the last preset.
1002 prl = prman.getPresets();
1008 PresetManager prman = lastserv.getPresets();
1011 prl = prman.getPresets();
1014 Iterator<Preset> en = (prl == null) ? null : prl.iterator();
1015 while (en != null && en.hasNext())
1021 en = prl.iterator();
1026 System.out.println("Testing opts dupes for "
1027 + lastserv.getUri() + " : " + lastserv.getActionText()
1028 + ":" + pr.getName());
1029 List<Option> rg = lastserv.getRunnerConfig().getOptions();
1034 Option cpy = jalview.ws.jws2.ParameterUtils.copyOption(o);
1035 } catch (Exception e)
1037 System.err.println("Failed to copy " + o.getName());
1038 e.printStackTrace();
1041 System.err.println("Failed to copy " + o.getName());
1042 e.printStackTrace();
1047 System.out.println("Testing param dupes:");
1048 List<Parameter> rg = lastserv.getRunnerConfig()
1050 for (Parameter o : rg)
1054 Parameter cpy = jalview.ws.jws2.ParameterUtils
1056 } catch (Exception e)
1058 System.err.println("Failed to copy " + o.getName());
1059 e.printStackTrace();
1062 System.err.println("Failed to copy " + o.getName());
1063 e.printStackTrace();
1068 System.out.println("Testing param write:");
1069 List<String> writeparam = null, readparam = null;
1072 writeparam = jalview.ws.jws2.ParameterUtils
1074 pr.getArguments(lastserv.getRunnerConfig()),
1076 System.out.println("Testing param read :");
1077 List<Option> pset = jalview.ws.jws2.ParameterUtils
1078 .processParameters(writeparam,
1079 lastserv.getRunnerConfig(), " ");
1080 readparam = jalview.ws.jws2.ParameterUtils
1081 .writeParameterSet(pset, " ");
1082 Iterator<String> o = pr.getOptions().iterator(),
1083 s = writeparam.iterator(), t = readparam.iterator();
1084 boolean failed = false;
1085 while (s.hasNext() && t.hasNext())
1087 String on = o.next(), sn = s.next(), st = t.next();
1091 "Original was " + on + " Phase 1 wrote " + sn
1092 + "\tPhase 2 wrote " + st);
1099 "Original parameters:\n" + pr.getOptions());
1101 "Wrote parameters in first set:\n" + writeparam);
1103 "Wrote parameters in second set:\n" + readparam);
1106 } catch (Exception e)
1108 e.printStackTrace();
1111 WsJobParameters pgui = new WsJobParameters(lastserv,
1112 new JabaPreset(lastserv, pr));
1113 JFrame jf = new JFrame(MessageManager
1114 .formatMessage("label.ws_parameters_for", new String[]
1115 { lastserv.getActionText() }));
1116 JPanel cont = new JPanel(new BorderLayout());
1118 cont.setPreferredSize(pgui.getPreferredSize());
1119 cont.add(pgui, BorderLayout.CENTER);
1120 jf.setLayout(new BorderLayout());
1121 jf.add(cont, BorderLayout.CENTER);
1123 final Thread thr = Thread.currentThread();
1124 jf.addWindowListener(new WindowListener()
1128 public void windowActivated(WindowEvent e)
1130 // TODO Auto-generated method stub
1135 public void windowClosed(WindowEvent e)
1140 public void windowClosing(WindowEvent e)
1147 public void windowDeactivated(WindowEvent e)
1149 // TODO Auto-generated method stub
1154 public void windowDeiconified(WindowEvent e)
1156 // TODO Auto-generated method stub
1161 public void windowIconified(WindowEvent e)
1163 // TODO Auto-generated method stub
1168 public void windowOpened(WindowEvent e)
1170 // TODO Auto-generated method stub
1175 jf.setVisible(true);
1176 boolean inter = false;
1181 Thread.sleep(10000);
1182 } catch (Exception e)
1194 public boolean isServiceDefaults()
1196 return (!isModified()
1197 && (lastParmSet != null && lastParmSet.equals(SVC_DEF)));
1200 public List<ArgumentI> getJobParams()
1202 return opanp.getCurrentSettings();
1205 String lastParmSet = null;
1208 * Hashtable<String, Object[]> editedParams = new Hashtable<String,
1211 * store the given parameters in the user parameter set database.
1213 * @param storeSetName - lastParmSet
1215 * @param descr - setDescr.getText()
1217 * @param jobParams - getJobParams()
1219 * private void _storeUserPreset(String storeSetName, String descr,
1220 * List<ArgumentI> jobParams) { // this is a simple hash store. Object[] pset;
1221 * editedParams.put(storeSetName, pset = new Object[3]); pset[0] =
1222 * storeSetName; pset[1] = descr; pset[2] = jobParams; // writeParam("Saving "
1223 * + storeSetName + ": ", jobParams); }
1225 * private void writeParam(String nm, List<ArgumentI> params) { for (ArgumentI
1226 * p : params) { System.out.println(nm + ":" + System.identityHashCode(p) +
1227 * " Name: " + p.getName() + " Value: " + p.getDefaultValue()); } }
1229 * private Object[] _getUserPreset(String setName) { Object[] pset =
1230 * editedParams.get(setName); // if (pset != null) // writeParam("Retrieving "
1231 * + setName + ": ", (List<Argument>) pset[2]); return pset; }
1233 * * remove the given user preset from the preset stash
1237 * private void _deleteUserPreset(String setName) {
1238 * editedParams.remove(setName); }
1241 private void syncSetNamesWithStore()
1244 // remove any set names in the drop down menu that aren't either a reserved
1245 // setting, or a user defined or service preset.
1246 Vector items = new Vector();
1247 while (n < setName.getItemCount())
1249 String item = (String) setName.getItemAt(n);
1250 if (!item.equals(SVC_DEF) && !paramStore.presetExists(item))
1252 setName.removeItemAt(n);
1256 items.addElement(item);
1260 if (!items.contains(SVC_DEF))
1262 setName.addItem(SVC_DEF);
1264 for (WsParamSetI upn : paramStore.getPresets())
1266 if (!items.contains(upn.getName()))
1268 setName.addItem(upn.getName());
1274 * true if lastParmSet is a user preset
1276 boolean isUserPreset = false;
1278 private void reInitDialog(String nextPreset)
1280 settingDialog = true;
1281 // updateTable(null,null); // first reset to defaults
1282 WsParamSetI pset = null;
1283 if (nextPreset != null && nextPreset.length() > 0)
1285 pset = paramStore.getPreset(nextPreset);
1289 if (pset.isModifiable())
1291 isUserPreset = true;
1292 setDescr.setText(pset.getDescription());
1293 updateTable(null, pset.getArguments());
1294 lastParmSet = nextPreset;
1298 isUserPreset = false;
1299 setDescr.setText("");
1300 // must be a default preset from service
1301 updateTable(pset, null);
1302 lastParmSet = nextPreset;
1307 isUserPreset = false;
1309 setDescr.setText("");
1310 updateTable(null, null);
1311 lastParmSet = SVC_DEF;
1314 initArgSetModified();
1315 syncSetNamesWithStore();
1316 setName.setSelectedItem(lastParmSet);
1317 SetNamePanel.validate();
1319 settingDialog = false;
1323 * Rebuild the AlignFrame web service menus (after add/delete of a preset
1326 protected void updateWebServiceMenus()
1328 for (AlignFrame alignFrame : Desktop.getAlignFrames())
1330 alignFrame.BuildWebServiceMenu();
1334 String curSetName = null;
1337 public void itemStateChanged(ItemEvent e)
1339 if (e.getSource() == setName && e.getStateChange() == e.SELECTED)
1341 final String setname = (String) setName.getSelectedItem();
1342 System.out.println("Item state changed for " + setname
1343 + " (handling ? " + !settingDialog + ")");
1349 if (setname == null)
1353 javax.swing.SwingUtilities.invokeLater(new Runnable()
1358 doPreferenceComboStateChange(setname);
1364 private void doPreferenceComboStateChange(String setname)
1366 // user has selected a different item from combo-box
1369 String lsetname = (curSetName != null) ? curSetName : lastParmSet;
1370 if (lsetname.equals(setname))
1372 // setname was just edited - so ignore this event.
1375 settingDialog = true;
1376 System.out.println("Prompting to save " + lsetname);
1377 if (JvOptionPane.showConfirmDialog(this, "Parameter set '" + lsetname
1378 + "' is modifed, and your changes will be lost.\nReally change preset ?",
1379 "Warning: Unsaved Changes",
1380 JvOptionPane.OK_CANCEL_OPTION) != JvOptionPane.OK_OPTION)
1382 // revert the combobox to the current item
1383 settingDialog = true;
1384 setName.setSelectedItem(lsetname);
1385 settingDialog = false;
1388 // System.out.println("Saving for " + lsetname);
1389 // _storeCurrentPreset(lsetname);
1393 settingDialog = true;
1394 reInitDialog(setname);
1395 settingDialog = false;
1399 private void _renameExistingPreset(String oldName, String curSetName2)
1401 paramStore.updatePreset(oldName, curSetName2, setDescr.getText(),
1406 * store current settings as given name. You should then reset gui.
1408 * @param curSetName2
1410 private void _storeCurrentPreset(String curSetName2)
1412 paramStore.storePreset(curSetName2, setDescr.getText(), getJobParams());
1415 private void _updatePreset(String lastParmSet2, String curname)
1417 paramStore.updatePreset(lastParmSet2, curname, setDescr.getText(),
1423 * last saved name for this user preset
1425 String lastSetName = null;
1428 * last saved value of the description text for this user preset
1430 String lastDescrText = null;
1433 public void actionPerformed(ActionEvent e)
1435 if (e.getSource() instanceof Component)
1437 Component src = (Component) e.getSource();
1438 if (src.getParent() == setName)
1440 // rename any existing records we know about for this set.
1441 String newname = e.getActionCommand().trim();
1443 if (isServicePreset(newname))
1445 final String oldname = curSetName != null ? curSetName
1447 final Component ourframe = this;
1448 settingDialog = true;
1449 setName.getEditor().setItem(oldname);
1450 settingDialog = false;
1451 javax.swing.SwingUtilities.invokeLater(new Runnable()
1456 JvOptionPane.showMessageDialog(ourframe,
1457 MessageManager.getString(
1458 "label.invalid_name_preset_exists"),
1459 MessageManager.getString("label.invalid_name"),
1460 JvOptionPane.WARNING_MESSAGE);
1466 curSetName = newname;
1467 System.err.println("New name for user setting " + curSetName
1468 + " (was " + setName.getSelectedItem() + ")");
1469 if (curSetName.equals(setName.getSelectedItem()))
1473 if (curSetName != null)
1475 argSetModified(setName, true);
1483 private void checkDescrModified()
1488 argSetModified(setDescr,
1489 (lastDescrText == null
1490 ? setDescr.getText().trim().length() > 0
1491 : !setDescr.getText().equals(lastDescrText)));
1497 public void insertUpdate(DocumentEvent e)
1499 checkDescrModified();
1503 public void removeUpdate(DocumentEvent e)
1505 checkDescrModified();
1509 public void changedUpdate(DocumentEvent e)
1511 checkDescrModified();
1516 * @return null or the service preset selected by the user
1518 public WsParamSetI getPreset()
1520 if (isUserPreset || isModified()
1521 || (lastParmSet != null && lastParmSet.equals(SVC_DEF)))
1527 return paramStore.getPreset(lastParmSet);