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(JFrame parent, ParamDatastoreI store,
163 List<ArgumentI> args)
167 this.paramStore = store;
169 // argSetModified(false);
170 // populate parameter table
172 // display in new JFrame attached to parent.
176 public WsJobParameters(Jws2Instance service, WsParamSetI preset)
178 this(null, service, preset, null);
184 * - if null, create new JFrame outside of desktop
188 public WsJobParameters(JFrame parent, Jws2Instance service,
189 WsParamSetI preset, List<Argument> jobArgset)
191 this(parent, null, service, preset, jobArgset);
202 public WsJobParameters(JFrame parent, ParamDatastoreI paramStorei,
203 Jws2Instance service, WsParamSetI preset,
204 List<Argument> jobArgset)
208 this.paramStore = paramStorei;
209 if (paramStore == null)
211 paramStore = service.getParamStore();
213 this.service = service;
214 // argSetModified(false);
215 // populate parameter table
216 initForService(service, preset, jobArgset);
217 // display in new JFrame attached to parent.
223 JDialog frame = null;
226 * shows a modal dialog containing the parameters.
230 public boolean showRunDialog()
233 frame = new JDialog(Desktop.instance, true);
236 frame.setTitle(MessageManager.formatMessage("label.edit_params_for",
238 { service.getActionText() }));
241 Rectangle deskr = Desktop.instance.getBounds();
242 Dimension pref = this.getPreferredSize();
244 new Rectangle((int) (deskr.getCenterX() - pref.width / 2),
245 (int) (deskr.getCenterY() - pref.height / 2),
246 pref.width, pref.height));
247 frame.setContentPane(this);
249 // should perhaps recover defaults from user prefs.
252 javax.swing.SwingUtilities.invokeLater(new Runnable()
257 // jobPanel.setDividerLocation(0.25);
261 frame.setVisible(true);
270 private void jbInit()
272 this.addHierarchyBoundsListener(new HierarchyBoundsListener()
276 public void ancestorResized(HierarchyEvent arg0)
278 refreshParamLayout();
282 public void ancestorMoved(HierarchyEvent arg0)
284 // TODO Auto-generated method stub
288 updatepref = JvSwingUtils.makeButton(
289 MessageManager.getString("action.update"),
290 MessageManager.getString("label.update_user_parameter_set"),
295 public void actionPerformed(ActionEvent e)
297 update_actionPerformed(e);
300 deletepref = JvSwingUtils.makeButton(
301 MessageManager.getString("action.delete"),
302 MessageManager.getString("label.delete_user_parameter_set"),
307 public void actionPerformed(ActionEvent e)
309 delete_actionPerformed(e);
312 createpref = JvSwingUtils.makeButton(
313 MessageManager.getString("action.create"),
314 MessageManager.getString("label.create_user_parameter_set"),
319 public void actionPerformed(ActionEvent e)
321 create_actionPerformed(e);
324 revertpref = JvSwingUtils.makeButton(
325 MessageManager.getString("action.revert"),
327 .getString("label.revert_changes_user_parameter_set"),
332 public void actionPerformed(ActionEvent e)
334 revert_actionPerformed(e);
337 startjob = JvSwingUtils.makeButton(
338 MessageManager.getString("action.start_job"),
339 MessageManager.getString("label.start_job_current_settings"),
343 public void actionPerformed(ActionEvent e)
345 startjob_actionPerformed(e);
348 canceljob = JvSwingUtils.makeButton(
349 MessageManager.getString("action.cancel_job"),
350 MessageManager.getString("label.cancel_job_close_dialog"),
354 public void actionPerformed(ActionEvent e)
356 canceljob_actionPerformed(e);
360 setDetails.setBorder(
361 new TitledBorder(MessageManager.getString("label.details")));
362 setDetails.setLayout(new BorderLayout());
363 setDescr.setColumns(40);
364 setDescr.setWrapStyleWord(true);
365 setDescr.setLineWrap(true);
366 setDescr.setBackground(getBackground());
367 setDescr.setEditable(true);
368 setDescr.getDocument().addDocumentListener(this);
369 setDescr.setToolTipText(
370 MessageManager.getString("label.edit_notes_parameter_set"));
371 JScrollPane setDescrView = new JScrollPane();
372 setDescrView.getViewport().setView(setDescr);
373 setName.setEditable(true);
374 setName.addItemListener(this);
375 setName.getEditor().addActionListener(this);
376 JPanel setNameInfo = new JPanel(new FlowLayout(FlowLayout.LEFT));
377 GridBagLayout gbl = new GridBagLayout();
378 SetNamePanel.setLayout(gbl);
380 JLabel setNameLabel = new JLabel(
381 MessageManager.getString("label.current_parameter_set_name"));
382 setNameLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
384 setNameInfo.add(setNameLabel);
385 setNameInfo.add(setName);
387 // initial button visibility
388 updatepref.setVisible(false);
389 deletepref.setVisible(false);
390 revertpref.setVisible(false);
391 createpref.setVisible(false);
392 JPanel setsavebuts = new JPanel();
393 setsavebuts.setLayout(new FlowLayout(FlowLayout.LEFT)); // GridLayout(1,2));
394 ((FlowLayout) setsavebuts.getLayout()).setHgap(10);
395 ((FlowLayout) setsavebuts.getLayout()).setVgap(0);
396 JPanel spacer = new JPanel();
397 spacer.setPreferredSize(new Dimension(2, 30));
398 setsavebuts.add(spacer);
399 setsavebuts.add(deletepref);
400 setsavebuts.add(revertpref);
401 setsavebuts.add(createpref);
402 setsavebuts.add(updatepref);
403 // setsavebuts.setSize(new Dimension(150, 30));
404 JPanel buttonArea = new JPanel(new GridLayout(1, 1));
405 buttonArea.add(setsavebuts);
406 SetNamePanel.add(setNameInfo);
407 GridBagConstraints gbc = new GridBagConstraints();
409 gbl.setConstraints(setNameInfo, gbc);
410 SetNamePanel.add(buttonArea);
411 gbc = new GridBagConstraints();
415 gbl.setConstraints(buttonArea, gbc);
416 setDetails.add(setDescrView, BorderLayout.CENTER);
418 // paramPane.setPreferredSize(new Dimension(360, 400));
419 // paramPane.setPreferredSize(null);
420 jobOptions.setBorder(
421 new TitledBorder(MessageManager.getString("label.options")));
422 jobOptions.setOpaque(true);
424 new TitledBorder(MessageManager.getString("label.parameters")));
425 paramList.setOpaque(true);
426 JPanel bjo = new JPanel(new BorderLayout()),
427 bjp = new JPanel(new BorderLayout());
428 bjo.add(jobOptions, BorderLayout.CENTER);
429 bjp.add(paramList, BorderLayout.CENTER);
432 // optsAndparams.setScrollableWidth(ScrollableSizeHint.FIT);
433 // optsAndparams.setScrollableHeight(ScrollableSizeHint.NONE);
434 // optsAndparams.setLayout(new BorderLayout());
435 optsAndparams.setLayout(new BorderLayout());
436 optsAndparams.add(jobOptions, BorderLayout.NORTH);
437 optsAndparams.add(paramList, BorderLayout.CENTER);
438 JPanel jp = new JPanel(new BorderLayout());
439 jp.add(optsAndparams, BorderLayout.CENTER);
440 paramPane.getViewport().setView(jp);
441 paramPane.setBorder(null);
442 setLayout(new BorderLayout());
443 jobPanel.setPreferredSize(null);
444 jobPanel.setLayout(new BorderLayout());
445 jobPanel.add(setDetails, BorderLayout.NORTH);
446 jobPanel.add(paramPane, BorderLayout.CENTER);
447 // jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
449 add(SetNamePanel, BorderLayout.NORTH);
450 add(jobPanel, BorderLayout.CENTER);
452 JPanel dialogpanel = new JPanel();
453 dialogpanel.add(startjob);
454 dialogpanel.add(canceljob);
455 // JAL-1580: setMaximumSize() doesn't work, so just size for the worst case:
456 // check for null is for JUnit usage
457 final int windowHeight = Desktop.instance == null ? 540
458 : Desktop.instance.getHeight();
459 setPreferredSize(new Dimension(540, windowHeight));
460 add(dialogpanel, BorderLayout.SOUTH);
464 protected void revert_actionPerformed(ActionEvent e)
466 reInitDialog(lastParmSet);
467 updateWebServiceMenus();
470 protected void update_actionPerformed(ActionEvent e)
474 String curname = ((String) setName.getSelectedItem()).trim();
475 _updatePreset(lastParmSet, curname);
476 lastParmSet = curname;
478 initArgSetModified();
479 syncSetNamesWithStore();
483 private void _deleteUserPreset(String lastParmSet2)
485 paramStore.deletePreset(lastParmSet2);
488 protected void delete_actionPerformed(ActionEvent e)
492 // delete current preset's saved entry
493 _deleteUserPreset(lastParmSet);
495 reInitDialog(null); // service default
496 updateWebServiceMenus();
499 protected void create_actionPerformed(ActionEvent e)
501 String curname = ((String) setName.getSelectedItem()).trim();
502 if (curname.length() > 0)
504 _storeCurrentPreset(curname);
505 lastParmSet = curname;
507 reInitDialog(curname);
508 initArgSetModified();
509 updateWebServiceMenus();
513 // TODO: show warning
514 System.err.println("Invalid name. Not saved.");
518 protected void canceljob_actionPerformed(ActionEvent e)
523 frame.setVisible(false);
527 protected void startjob_actionPerformed(ActionEvent e)
532 frame.setVisible(false);
536 Jws2Instance service;
539 * list of service presets in the gui
541 Hashtable servicePresets = null;
544 * set if dialog is being set - so handlers will avoid spurious events
546 boolean settingDialog = false;
548 void initForService(Jws2Instance service, WsParamSetI jabap,
549 List<Argument> jabajobArgset)
551 WsParamSetI p = null;
552 List<ArgumentI> jobArgset = null;
553 settingDialog = true;
554 { // instantiate the abstract proxy for Jaba objects
555 jobArgset = jabajobArgset == null ? null
556 : JabaParamStore.getJwsArgsfromJaba(jabajobArgset);
557 p = jabap; // (jabap != null) ? paramStore.getPreset(jabap.getName()) :
565 void init(WsParamSetI p, List<ArgumentI> jobArgset)
567 Hashtable exnames = new Hashtable();
568 for (int i = 0, iSize = setName.getItemCount(); i < iSize; i++)
570 exnames.put(setName.getItemAt(i), setName.getItemAt(i));
572 servicePresets = new Hashtable();
573 // Add the default entry - if not present already.
574 if (!exnames.contains(SVC_DEF))
576 setName.addItem(SVC_DEF);
577 exnames.put(SVC_DEF, SVC_DEF);
578 servicePresets.put(SVC_DEF, SVC_DEF);
580 String curname = (p == null ? "" : p.getName());
581 for (WsParamSetI pr : paramStore.getPresets())
583 if (!pr.isModifiable())
585 servicePresets.put(pr.getName(), "preset");
590 if (!exnames.contains(pr.getName()))
592 setName.addItem(pr.getName());
595 // TODO: if initial jobArgset matches a given user setting or preset then
596 // should recover setting accordingly
597 // updateTable(p, jobArgset);
600 reInitDialog(p.getName());
601 initArgSetModified();
605 if (jobArgset != null && jobArgset.size() > 0)
607 curSetName = "Supplied Settings";
608 isUserPreset = false;
609 updateTable(p, jobArgset);
610 setName.setSelectedItem(curSetName);
611 updateButtonDisplay();
619 settingDialog = false;
622 @SuppressWarnings("unchecked")
623 private void updateTable(WsParamSetI p, List<ArgumentI> jobArgset)
625 boolean setDefaultParams = false;
626 if (lastParmSet == null)
628 isUserPreset = false;
629 // First call - so provide Service default settings
630 setName.setSelectedItem(lastSetName = SVC_DEF);
632 if (p == null && SVC_DEF.equals("" + setName.getSelectedItem()))
634 // indicate that service defaults should be set if available
635 setDefaultParams = true;
637 // populate table from default parameter set.
638 List<ArgumentI> args = paramStore.getServiceParameters();
640 // split to params and required arguments
643 boolean optset = false;
644 for (ArgumentI myarg : args)
646 // Ideally, Argument would implement isRequired !
647 if (myarg instanceof ParameterI)
649 ParameterI parm = (ParameterI) myarg;
650 opanp.addParameter(parm).validate();
654 if (myarg instanceof OptionI)
656 OptionI opt = (OptionI) myarg;
657 OptionBox ob = opanp.addOption(opt);
658 ob.resetToDefault(setDefaultParams);
659 if (MAX_OPTWIDTH < ob.getPreferredSize().width)
661 MAX_OPTWIDTH = ob.getPreferredSize().width;
664 cw += ob.getPreferredSize().width + 5;
668 System.err.println("Ignoring unknown service argument type "
669 + myarg.getClass().getName());
673 args = null; // no more args to process.
677 isUserPreset = false;
678 // initialise setname
679 setName.setSelectedItem(lastSetName = p.getName());
680 setDescr.setText(lastDescrText = p.getDescription());
684 args = p.getArguments();
685 } catch (Exception e)
689 // TODO: check if args should be unselected prior to resetting using the
693 if (jobArgset != null)
695 argSetModified(jobArgset, true);
698 // get setargs from current object
701 for (ArgumentI arg : args)
703 if (arg instanceof ParameterI)
705 opanp.setParameter((ParameterI) arg);
709 if (arg instanceof OptionI)
711 // System.out.println("Setting option "
712 // + System.identityHashCode(arg) + ":" + arg.getName()
713 // + " with " + arg.getDefaultValue());
714 opanp.selectOption((OptionI) arg, arg.getValue());
721 refreshParamLayout();
725 private boolean isModified()
727 return modifiedElements.size() > 0;
730 private Hashtable modifiedElements = new Hashtable();
733 * reset gui and modification state settings
735 private void initArgSetModified()
738 modifiedElements.clear();
739 updateButtonDisplay();
742 private void updateButtonDisplay()
744 boolean _update = false, _create = false, _delete = false,
746 if (modifiedElements.size() > 0)
750 _update = isUserPreset; // can only update user presets
751 if (!isUserPreset || modifiedElements.containsKey(setName))
753 // name modified - can create new preset
761 // can still delete a user preset
762 _delete = isUserPreset;
764 createpref.setVisible(_create);
765 updatepref.setVisible(_update);
766 deletepref.setVisible(_delete);
767 revertpref.setVisible(_revert);
772 public void argSetModified(Object modifiedElement, boolean b)
780 modifiedElements.remove(modifiedElement);
784 if (b && modifiedElement == setName
785 && modifiedElements.contains(modifiedElement))
787 // HACK! prevents iteration on makeSetNameValid
790 modifiedElements.put(modifiedElement, modifiedElement);
792 // set mod status based on presence of elements in table
793 if (b && modifiedElements.size() > 0)
795 makeSetNameValid(!isUserPreset);
796 SetNamePanel.revalidate();
798 updateButtonDisplay();
801 private boolean isServicePreset(String selectedItem)
803 return selectedItem.equals(SVC_DEF)
804 || servicePresets.containsKey(selectedItem);
808 * check if the current set name is a valid set name for saving, if not, then
811 private void makeSetNameValid(boolean newuserset)
813 boolean stn = settingDialog;
814 boolean renamed = false;
815 settingDialog = true;
816 String nm = (curSetName != null ? curSetName
817 : (String) setName.getSelectedItem());
818 // check if the name is reserved - if it is, rename it.
819 if (isServicePreset(nm))
828 while (paramStore.getPreset(tnm) != null)
830 tnm = nm + " (" + (++i) + ")";
839 boolean makeupdate = false;
840 // sync the gui with the preset database
841 for (int i = 0, iS = setName.getItemCount(); i < iS; i++)
843 String snm = (String) setName.getItemAt(i);
847 // setName.setSelectedIndex(i);
852 setName.addItem(curSetName = nm);
853 setName.setSelectedItem(curSetName);
857 settingDialog = false; // we need this name change to be registered.
858 argSetModified(setName, renamed);
864 public void refreshParamLayout()
866 // optsAndparams.setPreferredSize(null);
867 FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
868 int sep = fl.getVgap();
871 s = jobOptions.getBorder().getBorderInsets(jobOptions).bottom
872 + jobOptions.getBorder().getBorderInsets(jobOptions).top
875 * final height for viewport
878 int panewidth = paramPane.getViewport().getSize().width - 120
879 - jobOptions.getBorder().getBorderInsets(jobOptions).left
880 + jobOptions.getBorder().getBorderInsets(jobOptions).right;
882 int w = 2 * fl.getHgap()
883 + (MAX_OPTWIDTH > OptsAndParamsPage.PARAM_WIDTH ? MAX_OPTWIDTH
884 : OptsAndParamsPage.PARAM_WIDTH);
885 int hgap = fl.getHgap(), cw = hgap;
887 if (opanp.getOptSet().size() > 0)
890 jobOptions.setLayout(new MigLayout("", "", ""));
891 jobOptions.removeAll();
893 for (OptionBox pbox : opanp.getOptSet().values())
896 cw += pbox.getSize().width + hgap;
897 if (cw + 120 > panewidth)
899 jobOptions.add(pbox, "wrap");
900 // System.out.println("Wrap on "+pbox.option.getName());
901 cw = hgap + pbox.getSize().width;
906 jobOptions.add(pbox);
910 finalh += pbox.getSize().height + fl.getVgap();
914 jobOptions.revalidate();
918 jobOptions.setVisible(false);
921 // Now layout the parameters assuming they occupy one column - to calculate
922 // total height of options+parameters
923 fl = new FlowLayout(FlowLayout.LEFT);
925 // http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
926 fl.setAlignOnBaseline(true);
927 if (opanp.getParamSet().size() > 0)
929 paramList.removeAll();
930 paramList.setLayout(new MigLayout("", "", ""));
932 for (ParamBox pbox : opanp.getParamSet().values())
935 cw += pbox.getSize().width + hgap;
936 if (cw + 160 > panewidth)
938 paramList.add(pbox, "wrap");
939 cw = pbox.getSize().width + hgap;
948 finalh += pbox.getSize().height + fl.getVgap();
954 * s = 2 * sep; for (ParamBox pbox : opanp.getParamSet().values()) {
955 * pbox.validate(); s += sep +
956 * pbox.getPreferredSize().height+pbox.getBorder
957 * ().getBorderInsets(pbox).bottom; }
959 * // paramList.setPreferredSize(new Dimension(w, s));
960 * os+=s+2*sep+paramList
961 * .getBorder().getBorderInsets(paramList).bottom+paramList
962 * .getBorder().getBorderInsets(paramList).top;
964 paramList.revalidate();
968 paramList.setVisible(false);
970 // TODO: waste some time trying to eliminate any unnecessary .validate calls
972 // System.out.println("Size will be : "+w+","+os);
973 // optsAndparams.setPreferredSize(null);
974 // paramPane.getViewport().setView(optsAndparams);
975 paramPane.getViewport().setAutoscrolls(true);
976 paramPane.revalidate();
981 * testing method - grab a service and parameter set and show the window
985 public static void main(String[] args)
987 jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer
992 Vector<String> services = new Vector<>();
993 services.addElement(args[p++]);
994 Jws2Discoverer.getDiscoverer().setServiceUrls(services);
999 } catch (Exception e)
1001 System.err.println("Aborting. Problem discovering services.");
1002 e.printStackTrace();
1005 Jws2Instance lastserv = null;
1006 for (Jws2Instance service : disc.getServices())
1009 if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p]))
1011 if (lastserv != null)
1013 List<Preset> prl = null;
1015 if (++p < args.length)
1017 PresetManager prman = lastserv.getPresets();
1020 pr = prman.getPresetByName(args[p]);
1023 // just grab the last preset.
1024 prl = prman.getPresets();
1030 PresetManager prman = lastserv.getPresets();
1033 prl = prman.getPresets();
1036 Iterator<Preset> en = (prl == null) ? null : prl.iterator();
1037 while (en != null && en.hasNext())
1043 en = prl.iterator();
1048 System.out.println("Testing opts dupes for "
1049 + lastserv.getUri() + " : " + lastserv.getActionText()
1050 + ":" + pr.getName());
1051 List<Option> rg = lastserv.getRunnerConfig().getOptions();
1056 Option cpy = jalview.ws.jws2.ParameterUtils.copyOption(o);
1057 } catch (Exception e)
1059 System.err.println("Failed to copy " + o.getName());
1060 e.printStackTrace();
1063 System.err.println("Failed to copy " + o.getName());
1064 e.printStackTrace();
1069 System.out.println("Testing param dupes:");
1070 List<Parameter> rg = lastserv.getRunnerConfig()
1072 for (Parameter o : rg)
1076 Parameter cpy = jalview.ws.jws2.ParameterUtils
1078 } catch (Exception e)
1080 System.err.println("Failed to copy " + o.getName());
1081 e.printStackTrace();
1084 System.err.println("Failed to copy " + o.getName());
1085 e.printStackTrace();
1090 System.out.println("Testing param write:");
1091 List<String> writeparam = null, readparam = null;
1094 writeparam = jalview.ws.jws2.ParameterUtils
1096 pr.getArguments(lastserv.getRunnerConfig()),
1098 System.out.println("Testing param read :");
1099 List<Option> pset = jalview.ws.jws2.ParameterUtils
1100 .processParameters(writeparam,
1101 lastserv.getRunnerConfig(), " ");
1102 readparam = jalview.ws.jws2.ParameterUtils
1103 .writeParameterSet(pset, " ");
1104 Iterator<String> o = pr.getOptions().iterator(),
1105 s = writeparam.iterator(), t = readparam.iterator();
1106 boolean failed = false;
1107 while (s.hasNext() && t.hasNext())
1109 String on = o.next(), sn = s.next(), st = t.next();
1113 "Original was " + on + " Phase 1 wrote " + sn
1114 + "\tPhase 2 wrote " + st);
1121 "Original parameters:\n" + pr.getOptions());
1123 "Wrote parameters in first set:\n" + writeparam);
1125 "Wrote parameters in second set:\n" + readparam);
1128 } catch (Exception e)
1130 e.printStackTrace();
1133 WsJobParameters pgui = new WsJobParameters(lastserv,
1134 new JabaPreset(lastserv, pr));
1135 JFrame jf = new JFrame(MessageManager
1136 .formatMessage("label.ws_parameters_for", new String[]
1137 { lastserv.getActionText() }));
1138 JPanel cont = new JPanel(new BorderLayout());
1140 cont.setPreferredSize(pgui.getPreferredSize());
1141 cont.add(pgui, BorderLayout.CENTER);
1142 jf.setLayout(new BorderLayout());
1143 jf.add(cont, BorderLayout.CENTER);
1145 final Thread thr = Thread.currentThread();
1146 jf.addWindowListener(new WindowListener()
1150 public void windowActivated(WindowEvent e)
1152 // TODO Auto-generated method stub
1157 public void windowClosed(WindowEvent e)
1162 public void windowClosing(WindowEvent e)
1169 public void windowDeactivated(WindowEvent e)
1171 // TODO Auto-generated method stub
1176 public void windowDeiconified(WindowEvent e)
1178 // TODO Auto-generated method stub
1183 public void windowIconified(WindowEvent e)
1185 // TODO Auto-generated method stub
1190 public void windowOpened(WindowEvent e)
1192 // TODO Auto-generated method stub
1197 jf.setVisible(true);
1198 boolean inter = false;
1203 Thread.sleep(10000);
1204 } catch (Exception e)
1217 public boolean isServiceDefaults()
1219 return (!isModified()
1220 && (lastParmSet != null && lastParmSet.equals(SVC_DEF)));
1223 public List<ArgumentI> getJobParams()
1225 return opanp.getCurrentSettings();
1228 String lastParmSet = null;
1231 * Hashtable<String, Object[]> editedParams = new Hashtable<String,
1234 * store the given parameters in the user parameter set database.
1236 * @param storeSetName - lastParmSet
1238 * @param descr - setDescr.getText()
1240 * @param jobParams - getJobParams()
1242 * private void _storeUserPreset(String storeSetName, String descr,
1243 * List<ArgumentI> jobParams) { // this is a simple hash store. Object[] pset;
1244 * editedParams.put(storeSetName, pset = new Object[3]); pset[0] =
1245 * storeSetName; pset[1] = descr; pset[2] = jobParams; // writeParam("Saving "
1246 * + storeSetName + ": ", jobParams); }
1248 * private void writeParam(String nm, List<ArgumentI> params) { for (ArgumentI
1249 * p : params) { System.out.println(nm + ":" + System.identityHashCode(p) +
1250 * " Name: " + p.getName() + " Value: " + p.getDefaultValue()); } }
1252 * private Object[] _getUserPreset(String setName) { Object[] pset =
1253 * editedParams.get(setName); // if (pset != null) // writeParam("Retrieving "
1254 * + setName + ": ", (List<Argument>) pset[2]); return pset; }
1256 * * remove the given user preset from the preset stash
1260 * private void _deleteUserPreset(String setName) {
1261 * editedParams.remove(setName); }
1264 private void syncSetNamesWithStore()
1267 // remove any set names in the drop down menu that aren't either a reserved
1268 // setting, or a user defined or service preset.
1269 Vector items = new Vector();
1270 while (n < setName.getItemCount())
1272 String item = (String) setName.getItemAt(n);
1273 if (!item.equals(SVC_DEF) && !paramStore.presetExists(item))
1275 setName.removeItemAt(n);
1279 items.addElement(item);
1283 if (!items.contains(SVC_DEF))
1285 setName.addItem(SVC_DEF);
1287 for (WsParamSetI upn : paramStore.getPresets())
1289 if (!items.contains(upn.getName()))
1291 setName.addItem(upn.getName());
1297 * true if lastParmSet is a user preset
1299 boolean isUserPreset = false;
1301 private void reInitDialog(String nextPreset)
1303 settingDialog = true;
1304 // updateTable(null,null); // first reset to defaults
1305 WsParamSetI pset = null;
1306 if (nextPreset != null && nextPreset.length() > 0)
1308 pset = paramStore.getPreset(nextPreset);
1312 if (pset.isModifiable())
1314 isUserPreset = true;
1315 setDescr.setText(pset.getDescription());
1316 updateTable(null, pset.getArguments());
1317 lastParmSet = nextPreset;
1321 isUserPreset = false;
1322 setDescr.setText("");
1323 // must be a default preset from service
1324 updateTable(pset, null);
1325 lastParmSet = nextPreset;
1330 isUserPreset = false;
1332 setDescr.setText("");
1333 updateTable(null, null);
1334 lastParmSet = SVC_DEF;
1337 initArgSetModified();
1338 syncSetNamesWithStore();
1339 setName.setSelectedItem(lastParmSet);
1340 SetNamePanel.validate();
1342 settingDialog = false;
1346 * Rebuild the AlignFrame web service menus (after add/delete of a preset
1349 protected void updateWebServiceMenus()
1351 for (AlignFrame alignFrame : Desktop.getAlignFrames())
1353 alignFrame.BuildWebServiceMenu();
1357 String curSetName = null;
1360 public void itemStateChanged(ItemEvent e)
1362 if (e.getSource() == setName && e.getStateChange() == e.SELECTED)
1364 final String setname = (String) setName.getSelectedItem();
1365 // System.out.println("Item state changed for " + setname
1366 // + " (handling ? " + !settingDialog + ")");
1372 if (setname == null)
1376 javax.swing.SwingUtilities.invokeLater(new Runnable()
1381 doPreferenceComboStateChange(setname);
1387 private void doPreferenceComboStateChange(String setname)
1389 // user has selected a different item from combo-box
1392 String lsetname = (curSetName != null) ? curSetName : lastParmSet;
1393 if (lsetname.equals(setname))
1395 // setname was just edited - so ignore this event.
1398 settingDialog = true;
1399 System.out.println("Prompting to save " + lsetname);
1400 if (JvOptionPane.showConfirmDialog(this, "Parameter set '" + lsetname
1401 + "' is modifed, and your changes will be lost.\nReally change preset ?",
1402 "Warning: Unsaved Changes",
1403 JvOptionPane.OK_CANCEL_OPTION) != JvOptionPane.OK_OPTION)
1405 // revert the combobox to the current item
1406 settingDialog = true;
1407 setName.setSelectedItem(lsetname);
1408 settingDialog = false;
1411 // System.out.println("Saving for " + lsetname);
1412 // _storeCurrentPreset(lsetname);
1416 settingDialog = true;
1417 reInitDialog(setname);
1418 settingDialog = false;
1422 private void _renameExistingPreset(String oldName, String curSetName2)
1424 paramStore.updatePreset(oldName, curSetName2, setDescr.getText(),
1429 * store current settings as given name. You should then reset gui.
1431 * @param curSetName2
1433 private void _storeCurrentPreset(String curSetName2)
1435 paramStore.storePreset(curSetName2, setDescr.getText(), getJobParams());
1438 private void _updatePreset(String lastParmSet2, String curname)
1440 paramStore.updatePreset(lastParmSet2, curname, setDescr.getText(),
1446 * last saved name for this user preset
1448 String lastSetName = null;
1451 * last saved value of the description text for this user preset
1453 String lastDescrText = null;
1456 public void actionPerformed(ActionEvent e)
1458 if (e.getSource() instanceof Component)
1460 Component src = (Component) e.getSource();
1461 if (src.getParent() == setName)
1463 // rename any existing records we know about for this set.
1464 String newname = e.getActionCommand().trim();
1466 if (isServicePreset(newname))
1468 final String oldname = curSetName != null ? curSetName
1470 final Component ourframe = this;
1471 settingDialog = true;
1472 setName.getEditor().setItem(oldname);
1473 settingDialog = false;
1474 javax.swing.SwingUtilities.invokeLater(new Runnable()
1479 JvOptionPane.showMessageDialog(ourframe,
1480 MessageManager.getString(
1481 "label.invalid_name_preset_exists"),
1482 MessageManager.getString("label.invalid_name"),
1483 JvOptionPane.WARNING_MESSAGE);
1489 curSetName = newname;
1490 System.err.println("New name for user setting " + curSetName
1491 + " (was " + setName.getSelectedItem() + ")");
1492 if (curSetName.equals(setName.getSelectedItem()))
1496 if (curSetName != null)
1498 argSetModified(setName, true);
1506 private void checkDescrModified()
1511 argSetModified(setDescr,
1512 (lastDescrText == null
1513 ? setDescr.getText().trim().length() > 0
1514 : !setDescr.getText().equals(lastDescrText)));
1520 public void insertUpdate(DocumentEvent e)
1522 checkDescrModified();
1526 public void removeUpdate(DocumentEvent e)
1528 checkDescrModified();
1532 public void changedUpdate(DocumentEvent e)
1534 checkDescrModified();
1539 * @return null or the service preset selected by the user
1541 public WsParamSetI getPreset()
1543 if (isUserPreset || isModified()
1544 || (lastParmSet != null && lastParmSet.equals(SVC_DEF)))
1550 return paramStore.getPreset(lastParmSet);