From 90a1b20c1297ec0d7fc596f89f6323a4b1bc7083 Mon Sep 17 00:00:00 2001 From: jprocter Date: Sun, 27 Jun 2010 17:17:17 +0000 Subject: [PATCH] edit jws2 job parameters before running job --- src/jalview/gui/WsJobParameters.java | 794 ++++++++++++++++++---------------- src/jalview/ws/jws2/MsaWSClient.java | 158 ++++--- src/jalview/ws/jws2/MsaWSThread.java | 5 + 3 files changed, 535 insertions(+), 422 deletions(-) diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 7c4391e..36266d1 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -1,17 +1,21 @@ package jalview.gui; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridLayout; +import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowEvent; @@ -21,6 +25,7 @@ import java.util.ArrayList; import java.util.EventObject; import java.util.HashSet; import java.util.Hashtable; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Vector; @@ -28,17 +33,24 @@ import java.util.Vector; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; +import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; +import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JSlider; import javax.swing.JTable; import javax.swing.JTextArea; +import javax.swing.JTextField; import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.border.TitledBorder; import javax.swing.event.CellEditorListener; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import javax.swing.table.*; import compbio.metadata.Argument; @@ -48,6 +60,7 @@ import compbio.metadata.Preset; import compbio.metadata.PresetManager; import compbio.metadata.RunnerConfig; import compbio.metadata.ValueConstrain; +import compbio.metadata.WrongParameterException; import compbio.metadata.ValueConstrain.Type; import jalview.ws.jws2.Jws2Discoverer; @@ -55,6 +68,8 @@ import jalview.ws.jws2.Jws2Discoverer.Jws2Instance; public class WsJobParameters extends JPanel { + private static final int PARAM_WIDTH = 340, PARAM_HEIGHT = 120; + JPanel setDetails = new JPanel(); JPanel settingsPanel = new JPanel(); @@ -65,6 +80,11 @@ public class WsJobParameters extends JPanel JPanel paramButtons = new JPanel(); + JPanel paramPanel = new JPanel(); + JLabel modified = new JLabel(); + JButton startjob = new JButton(); + JButton canceljob = new JButton(); + JButton exportParams = new JButton(); JButton importParams = new JButton(); @@ -81,10 +101,11 @@ public class WsJobParameters extends JPanel JTextArea setDescr = new JTextArea(); - JTable paramTable = new JTable(); - JScrollPane paramPane = new JScrollPane(); + // JList paramList = new JList(); + JPanel paramList = new JPanel(); + RunnerConfig serviceOptions; List availableParameters; @@ -98,7 +119,7 @@ public class WsJobParameters extends JPanel public WsJobParameters(Jws2Instance service, Preset p) { - this(null, service, p); + this(null, service, p, null); } /** @@ -108,19 +129,46 @@ public class WsJobParameters extends JPanel * @param service * @param p */ - public WsJobParameters(JFrame parent, Jws2Instance service, Preset p) + public WsJobParameters(JFrame parent, Jws2Instance service, Preset p, + List jobArgset) { super(); jbInit(); - initTableUI(); + argSetModified(false); // populate parameter table - initForService(service, p); + initForService(service, p, jobArgset); // display in new JFrame attached to parent. validate(); } + int response=-1; + JDialog frame=null; + public boolean showRunDialog() { + + frame = new JDialog( + Desktop.instance, true); + + frame.setTitle("Edit parameters for "+service.getActionText()); + Rectangle deskr = Desktop.instance.getBounds(); + frame.setBounds(new Rectangle((int) (deskr.getCenterX() - 240), + (int) (deskr.getCenterY() - 92), 380, 385)); + frame.setContentPane(this); + frame.setVisible(true); + + if (response>0) + { + return true; + } + return false; + } + private void jbInit() { + modified.setText("Job Options Modified"); + modified.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + modified.setForeground(Color.red); + modified.setHorizontalAlignment(SwingConstants.CENTER); + exportParams.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); exportParams.setText("Export"); exportParams.setToolTipText("Export parameters to a file"); @@ -181,20 +229,45 @@ public class WsJobParameters extends JPanel editParam_actionPerformed(e); } }); + startjob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + startjob.setText("Start"); + startjob.setToolTipText("Start Job"); + startjob.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + startjob_actionPerformed(e); + } + }); + canceljob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + canceljob.setText("Cancel"); + canceljob.setToolTipText("Cancel Job"); + canceljob.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + canceljob_actionPerformed(e); + } + }); setDetails.setBorder(new TitledBorder("Details")); setDetails.setLayout(new GridLayout(2, 1)); setDescr.setColumns(40); setDescr.setWrapStyleWord(true); - setDescr.setPreferredSize(new Dimension(350, 100)); + setDescr.setLineWrap(true); + setDescr.setPreferredSize(new Dimension(350, 90)); + setDescr.setBackground(getBackground()); + setDescr.setEditable(false); setDetails.add(setName); setDetails.add(setDescr); - setDetails.setPreferredSize(new Dimension(360, 150)); + setDetails.setPreferredSize(new Dimension(360, 100)); settingsPanel.setLayout(new BorderLayout()); jobOptions.setBorder(new TitledBorder("Options")); jobParameters.setBorder(new TitledBorder("Parameters")); jobParameters.setLayout(jparamLayout = new BorderLayout()); paramPane.setPreferredSize(new Dimension(360, 300)); + paramPane.getVerticalScrollBar().setUnitIncrement(20); + // paramPanel.setPreferredSize(new Dimension(360, 300)); paramButtons.setLayout(new GridLayout(2, 3)); paramButtons.add(addParam); paramButtons.add(editParam); @@ -203,163 +276,38 @@ public class WsJobParameters extends JPanel paramButtons.add(exportParams); paramButtons.add(importParams); paramButtons.add(resetParams); + paramPane.getViewport().setView(paramList); jobParameters.add(paramPane, BorderLayout.NORTH); - jobParameters.add(paramButtons, BorderLayout.SOUTH); - settingsPanel.add(jobOptions, BorderLayout.NORTH); + //jobParameters.add(paramButtons, BorderLayout.SOUTH); + settingsPanel.add(modified, BorderLayout.NORTH); + settingsPanel.add(jobOptions, BorderLayout.CENTER); settingsPanel.add(jobParameters, BorderLayout.SOUTH); + setLayout(new BorderLayout()); - setPreferredSize(new Dimension(400, 600)); - setSize(new Dimension(400, 600)); + // setPreferredSize(new Dimension(400, 600)); + // setSize(new Dimension(400, 600)); add(setDetails, BorderLayout.NORTH); add(settingsPanel, BorderLayout.CENTER); + JPanel dialogpanel = new JPanel(); + dialogpanel.add(startjob); + dialogpanel.add(canceljob); + add(dialogpanel, BorderLayout.SOUTH); } - /** - * need to populate table and validate after calling this to set up table and - * add it to pane - */ - public void initTableUI() + protected void canceljob_actionPerformed(ActionEvent e) { - paramTable = new JTable(); - paramTable.getTableHeader() - .setFont(new Font("Verdana", Font.PLAIN, 12)); - paramTable.setFont(new Font("Verdana", Font.PLAIN, 12)); - - paramPane.getViewport().removeAll(); - paramPane.getViewport().add(paramTable); - paramTable.setDefaultRenderer(Argument.class, new ArgumentRenderer()); - paramTable.setDefaultRenderer(Parameter.class, new ArgumentRenderer()); - paramTable.setDefaultRenderer(Option.class, new ArgumentRenderer()); - paramTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - paramTable.addMouseListener(new MouseListener() - { - - @Override - public void mouseClicked(MouseEvent e) - { - if (e.getClickCount() > 1) - { - editParam_actionPerformed(null); - } - } - - @Override - public void mouseEntered(MouseEvent e) - { - // tooltips - // TODO Auto-generated method stub - - } - - @Override - public void mouseExited(MouseEvent e) - { - // tooltips - // TODO Auto-generated method stub - - } - - @Override - public void mousePressed(MouseEvent e) - { - // TODO Auto-generated method stub - - } - - @Override - public void mouseReleased(MouseEvent e) - { - // TODO Auto-generated method stub - - } - - }); - // paramTable.setDefaultEditor(Argument.class, new WsArgumentEditor(this)); + response=0; + if (frame!=null) { + frame.setVisible(false); + } } - public class WsArgumentEditor implements TableCellEditor + protected void startjob_actionPerformed(ActionEvent e) { - - int p; - - Argument arg; - - WsJobParameters wsparm; - - public WsArgumentEditor(WsJobParameters wsJobParameters) - { - wsparm = wsJobParameters; - p = wsparm.paramTable.getSelectedRow(); - arg = (Argument) wsparm.paramTable.getValueAt(p, wsparm.paramTable - .getSelectedColumn()); - /* - * if (arg instanceof Option) { if - * (JOptionPane.showInternalConfirmDialog(Desktop.desktop, - * "Remove option "+arg.getName(), - * "Delete option ?",JOptionPane.YES_NO_OPTION, - * JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { - * - * } } - */ - } - - @Override - public Component getTableCellEditorComponent(JTable table, - Object value, boolean isSelected, int row, int column) - { - // TODO Auto-generated method stub - return null; - } - - @Override - public void addCellEditorListener(CellEditorListener l) - { - // TODO Auto-generated method stub - + response=1; + if (frame!=null) { + frame.setVisible(false); } - - @Override - public void cancelCellEditing() - { - // TODO Auto-generated method stub - - } - - @Override - public Object getCellEditorValue() - { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean isCellEditable(EventObject anEvent) - { - // TODO Auto-generated method stub - return false; - } - - @Override - public void removeCellEditorListener(CellEditorListener l) - { - // TODO Auto-generated method stub - - } - - @Override - public boolean shouldSelectCell(EventObject anEvent) - { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean stopCellEditing() - { - // TODO Auto-generated method stub - return false; - } - } protected void editParam_actionPerformed(ActionEvent e) @@ -398,30 +346,23 @@ public class WsJobParameters extends JPanel } - void initForService(Jws2Instance service, Preset p) + Jws2Instance service; + void initForService(Jws2Instance service, Preset p, + List jobArgset) { + this.service=service; serviceOptions = service.getRunnerConfig(); - updateTable(p); + updateTable(p, jobArgset); } @SuppressWarnings("unchecked") - private void updateTable(Preset p) + private void updateTable(Preset p, List jobArgset) { - WsParameterTableModel mdl = null; - TableModel tmdl = paramTable.getModel(); - if (tmdl instanceof WsParameterTableModel) - { - mdl = (WsParameterTableModel) tmdl; - } - if (mdl == null) - { - paramTable.setModel(mdl = new WsParameterTableModel()); - } availableParameters = new ArrayList(); List setargs = new ArrayList(); // populate table from default parameter set. List args = serviceOptions.getArguments(); - + // split to params and required arguments { for (Argument arg : args) @@ -431,9 +372,9 @@ public class WsJobParameters extends JPanel if (myarg instanceof Parameter) { Parameter parm = (Parameter) myarg; - if (parm.isRequired()) + if (true) // parm.isRequired()) { - setargs.add(parm); + addParameter(parm); } else { @@ -458,12 +399,13 @@ public class WsJobParameters extends JPanel } } } + args=null; // no more args to process. } - if (p != null) { setDescr.setText(p.getDescription()); setName.setText(p.getName()); + setDetails.setVisible(true); // TODO - URL link try { @@ -472,33 +414,70 @@ public class WsJobParameters extends JPanel { e.printStackTrace(); } + // TODO: check if args should be unselected prior to resetting using the preset setargs.clear(); - // get setargs from current object - if (args != null) + } else { + setDetails.setVisible(false); + } + if (jobArgset != null) + { + argSetModified(true); + args = jobArgset; + } + // get setargs from current object + if (args != null) + { + for (Argument arg : args) { - for (Argument arg : args) + if (arg instanceof Parameter) { - if (arg instanceof Parameter) - { - setargs.add((Parameter) arg); - } - else + setargs.add((Parameter) arg); + } + else + { + if (arg instanceof Option) { - if (arg instanceof Option) - { - selectOption((Option) arg, arg.getDefaultValue()); - } + selectOption((Option) arg, arg.getDefaultValue()); } - } + } } - mdl.setData(setargs); - paramTable.setModel(mdl); - // paramTable.validate(); - jobOptions.setLayout(new GridLayout(optSet.size() / 2 + 1, 2)); - jobOptions.validate(); + // mdl.setData(setargs); + // jobOptions.setLayout(new GridLayout(optSet.size() / 2 + 1, 2)); + jobOptions.setLayout(new GridLayout(optSet.size(), 1)); + // paramPanel.setLayout(new GridLayout(paramSet.size(), 1)); + // paramList.va + // paramPane.getViewport().validate(); + paramList.setPreferredSize(new Dimension(350, paramSet.size() + * PARAM_HEIGHT)); + paramList.setLayout(new GridLayout(paramSet.size(), 1)); + paramList.validate(); + paramPane.validate(); + validate(); + } + + private void argSetModified(boolean b) + { + + modified.setVisible(b); + if (isVisible()) + { + validate(); + } + + } + + private void addParameter(Parameter parm) + { + ParamBox pb = paramSet.get(parm.getName()); + if (pb == null) + { + pb = new ParamBox(parm); + paramSet.put(parm.getName(), pb); + paramList.add(pb); + } } private void selectOption(Option opt, String string) @@ -536,226 +515,284 @@ public class WsJobParameters extends JPanel } } - Map optSet = new Hashtable(); + Map paramSet = new Hashtable(); - public class OptionBox extends JPanel + public class ParamBox extends JPanel implements ChangeListener, + ActionListener { - JComboBox val = new JComboBox(); - - JCheckBox enabled = new JCheckBox(); - - public OptionBox(Option opt) - { - setLayout(new BorderLayout()); - enabled.setSelected(opt.isRequired()); - enabled.setFont(new Font("Verdana", Font.PLAIN, 11)); - enabled.setText(opt.getName()); - enabled.setToolTipText(opt.getDescription()); - add(enabled, BorderLayout.NORTH); - if (opt.getPossibleValues().size() > 1) - { - setLayout(new GridLayout(1,2)); - for (Object str : opt.getPossibleValues()) + JLabel name = new JLabel(); + + JTextArea string = new JTextArea(); + JScrollPane descPanel = new JScrollPane(); + JSlider slider = null; + + JTextField valueField = null; + + ValueConstrain validator = null; + + boolean integ = false; + boolean choice=false; + public ParamBox(Parameter parm) + { + setLayout(new FlowLayout()); + setBorder(new TitledBorder(parm.getName())); + setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_HEIGHT)); + string.setFont(new Font("Verdana", Font.PLAIN, 11)); + string.setBackground(getBackground()); + //string.setSize(new Dimension(PARAM_WIDTH, 80)); + string.setEditable(false); + descPanel.setPreferredSize(new Dimension(PARAM_WIDTH, 70)); + descPanel.getViewport().setView(string); + // string.setMinimumSize(new Dimension(140,80)); + // string.setMaximumSize(new Dimension(280,80)); + string.setWrapStyleWord(true); + string.setLineWrap(true); + string.setColumns(40); + string.setText(parm.getDescription()); + descPanel.validate(); + // name.setToolTipText(parm.getDescription()); + add(descPanel); // , BorderLayout.NORTH); + validator = parm.getValidValue(); + parameter=parm; + if (validator != null) + { + integ = validator.getType() == Type.Integer; + } else { + if (parameter.getPossibleValues()!=null) { - val.addItem((String) str); + choice=true; } - val.setSelectedItem((String) opt.getDefaultValue()); - add(val, BorderLayout.SOUTH); } - // TODO: add actionListeners for popup (to open further info), - // and to update list of parameters if an option is enabled - // that takes a value. - } - } - - private OptionBox addOption(Option opt) - { - OptionBox cb = optSet.get(opt.getName()); - if (cb == null) - { - cb = new OptionBox(opt); - optSet.put(opt.getName(), cb); - jobOptions.add(cb); - } - return cb; - } - - class WsParameterTableModel extends AbstractTableModel - { - // arg list - vector for thread safety - public Vector data = new Vector(); - - private String[] colNames = - { "Parameter", "Value" }; - - @Override - public int getColumnCount() - { - return 2; - } - - @Override - public int findColumn(String columnName) - { - // TODO Auto-generated method stub - return super.findColumn(columnName); + updateControls(parm); } - public void setData(List setargs) + boolean adjusting = false; + Parameter parameter; + JComboBox choicebox; + public void updateControls(Parameter parm) { - if (setargs != null) + adjusting = true; + boolean init = valueField == null; + float fVal = 0f; + int iVal = 0; + if (init) { - data = new Vector(setargs); - + if (choice) + { + choicebox = new JComboBox(); + choicebox.addActionListener(this); + add(choicebox); + } else { + slider = new JSlider(); + slider.addChangeListener(this); + valueField = new JTextField(); + valueField.addActionListener(this); + valueField.setPreferredSize(new Dimension(80, 25)); + JPanel container = new JPanel(); + // container.setLayout(new FlowLayout()); + add(slider);// , BorderLayout.SOUTH); + add(valueField);// ,BorderLayout.CENTER); + // add(container, BorderLayout.EAST); + // container.validate(); + + }} + + if (parm != null) + { + if (choice) { + List vals = parm.getPossibleValues(); + for (Object val: vals) + { + choicebox.addItem(val); + } + if (parm.getDefaultValue()!=null) { + choicebox.setSelectedItem(parm.getDefaultValue()); + } + } else { + valueField.setText(parm.getDefaultValue()); + } } - else + updateSliderFromValueField(); + adjusting = false; + } + public Parameter getParameter() { + try { + if (choice) + { + parameter.setDefaultValue((String)choicebox.getSelectedItem()); + } + else { + parameter.setDefaultValue(valueField.getText()); + } + } catch (WrongParameterException e) { - data = new Vector(); + e.printStackTrace(); + return null; } + return parameter; } - - public List getData() - { - return new ArrayList(data); - } - - @Override - public int getRowCount() - { - return data.size(); - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) + public Object updateSliderFromValueField() { - if (rowIndex >= 0 && rowIndex < data.size()) + int iVal; + float fVal; + if (validator != null) { - Parameter prm = data.elementAt(rowIndex); - switch (columnIndex) + if (integ) { - case 0: - return prm.getName(); - case 1: - Object exc = null; - // the accessor name for the parameter value is possibly confusing - String val = prm.getDefaultValue(); + iVal = 0; try { - if (prm.getValidValue().getType().equals(Type.Float)) - { - exc = new Float(0); - return Float.parseFloat(val); - } - if (prm.getValidValue().getType().equals(Type.Integer)) - { - exc = new Integer(0); - return Integer.parseInt(val); - } - } catch (NumberFormatException e) + valueField.setText(valueField.getText().trim()); + iVal = Integer.valueOf(valueField.getText()); + } catch (Exception e) { - return exc; } - // must be a string - return val; - - default: + ; + if (validator.getMin() != null && validator.getMax() != null) + { + slider.getModel().setRangeProperties(iVal, 1, + validator.getMin().intValue(), + validator.getMax().intValue(), true); + } + else + { + slider.setVisible(false); + } + return new int[] + { iVal }; + } + else + { + fVal = 0f; + try + { + fVal = Float.valueOf(valueField.getText()); + } catch (Exception e) + { + } + ; + if (validator.getMin() != null && validator.getMax() != null) + { + slider.getModel().setRangeProperties((int) fVal * 1000, 1, + (int) validator.getMin().floatValue() * 1000, + (int) validator.getMax().floatValue() * 1000, true); + } + else + { + slider.setVisible(false); + } + return new float[] + { fVal }; } } - return null; - } - - /* - * (non-Javadoc) - * - * @see javax.swing.table.AbstractTableModel#getColumnClass(int) - */ - @Override - public Class getColumnClass(int columnIndex) - { - switch (columnIndex) + else { - case 0: - return String.class; - case 1: - return Parameter.class; + if (!choice) { + slider.setVisible(false); + return new String[] + { valueField.getText().trim() }; + } + else { + return new String[] { (String) choicebox.getSelectedItem()}; + } } - return super.getColumnClass(columnIndex); + } - /* - * (non-Javadoc) - * - * @see javax.swing.table.AbstractTableModel#getColumnName(int) - */ @Override - public String getColumnName(int column) + public void stateChanged(ChangeEvent e) { - return colNames[column]; + if (!adjusting) + { + valueField.setText("" + + ((integ) ? ("" + (int) slider.getValue()) + : ("" + (float) (slider.getValue() / 1000f)))); + } } - /* - * (non-Javadoc) - * - * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int) - */ @Override - public boolean isCellEditable(int rowIndex, int columnIndex) + public void actionPerformed(ActionEvent e) { - if (columnIndex == 1) + if (choice) { - return true; + } else if (!adjusting) + { + updateSliderFromValueField(); } - return false; + argSetModified(true); } + } - class ArgumentRenderer implements TableCellRenderer + Map optSet = new Hashtable(); + + public class OptionBox extends JPanel implements ActionListener { + JComboBox val = new JComboBox(); - @Override - public Component getTableCellRendererComponent(JTable table, - Object value, boolean isSelected, boolean hasFocus, int row, - int column) + JCheckBox enabled = new JCheckBox(); + Option option; + public OptionBox(Option opt) { - if (value instanceof Option) + option = opt; + setLayout(new BorderLayout()); + enabled.setSelected(opt.isRequired()); + enabled.setFont(new Font("Verdana", Font.PLAIN, 11)); + enabled.setText(opt.getName()); + enabled.setToolTipText(opt.getDescription()); + add(enabled, BorderLayout.NORTH); + if (opt.getPossibleValues().size() > 1) { - JCheckBox cb = new JCheckBox(); - cb.setSelected(true); - return cb; + setLayout(new GridLayout(1, 2)); + for (Object str : opt.getPossibleValues()) + { + val.addItem((String) str); + } + val.setSelectedItem((String) opt.getDefaultValue()); + val.addActionListener(this); + add(val, BorderLayout.SOUTH); } - if (value instanceof Boolean) + // TODO: add actionListeners for popup (to open further info), + // and to update list of parameters if an option is enabled + // that takes a value. + } + public Option getOptionIfEnabled() { + if (!enabled.isSelected()) { - JCheckBox cb = new JCheckBox(); - cb.setSelected(((Boolean) value).booleanValue()); - return cb; + return null; } - if (value instanceof String) + try { + if (val.getSelectedItem()!=null) + { + option.setDefaultValue((String) val.getSelectedItem()); + } + } catch (WrongParameterException e) { - JLabel lbl = new JLabel(); - lbl.setFont(new Font("Verdana", Font.PLAIN, 11)); - lbl.setText((String) value); - return lbl; - } - if (value instanceof Parameter) - { - String val = ((Parameter) value).getDefaultValue(); - ValueConstrain constr = ((Parameter) value).getValidValue(); - JLabel lbl = new JLabel(); - lbl.setFont(new Font("Verdana", Font.PLAIN, 11)); - lbl.setText(val); - return lbl; - /* - * type dependent return value if - * (constr.getType().equals(Type.Integer)) - * - * { lbl.setText(val); } if (constr.getType().equals(Type.Float)) { } - * return lbl; - */ + e.printStackTrace(); + return null; } - return null; + return option; + } + @Override + public void actionPerformed(ActionEvent e) + { + argSetModified(true); + enabled.setSelected(true); } } + private OptionBox addOption(Option opt) + { + OptionBox cb = optSet.get(opt.getName()); + if (cb == null) + { + cb = new OptionBox(opt); + optSet.put(opt.getName(), cb); + jobOptions.add(cb); + } + return cb; + } + /** * testing method - grab a service and parameter set and show the window * @@ -792,6 +829,7 @@ public class WsJobParameters extends JPanel } if (lastserv != null) { + List prl = null; Preset pr = null; if (++p < args.length) { @@ -802,17 +840,25 @@ public class WsJobParameters extends JPanel if (pr == null) { // just grab the last preset. - List prl = prman.getPresets(); - pr = prl.get(prl.size() - 1); + prl = prman.getPresets(); } } } + Iterator en = (prl == null) ? null : prl.iterator(); while (true) { + if (en != null) + { + if (!en.hasNext()) + { + en = prl.iterator(); + } + pr = en.next(); + } WsJobParameters pgui = new WsJobParameters(lastserv, pr); JFrame jf = new JFrame("Parameters for " + lastserv.getActionText()); JPanel cont = new JPanel(); - cont.setSize(new Dimension(600, 800)); + jf.setPreferredSize(new Dimension(600, 800)); cont.add(pgui); jf.add(cont); final Thread thr = Thread.currentThread(); @@ -884,4 +930,28 @@ public class WsJobParameters extends JPanel } } } + + public List getJobParams() + { + List argSet = new ArrayList(); + // recover options and parameters from GUI + for (OptionBox opts: optSet.values()) + { + Option opt = opts.getOptionIfEnabled(); + if (opt!=null) + { + argSet.add(opt); + } + } + for (ParamBox parambox: paramSet.values()) + { + Parameter parm = parambox.getParameter(); + if (parm!=null) + { + argSet.add(parm); + } + } + + return argSet; + } } diff --git a/src/jalview/ws/jws2/MsaWSClient.java b/src/jalview/ws/jws2/MsaWSClient.java index b65242f..1ad4602 100644 --- a/src/jalview/ws/jws2/MsaWSClient.java +++ b/src/jalview/ws/jws2/MsaWSClient.java @@ -43,28 +43,33 @@ public class MsaWSClient extends Jws2Client * server is a WSDL2Java generated stub for an archetypal MsaWSI service. */ MsaWS server; + AlignFrame alignFrame; + private Preset preset; - private List paramset; + private List paramset; public MsaWSClient(Jws2Discoverer.Jws2Instance sh, String altitle, jalview.datamodel.AlignmentView msa, boolean submitGaps, boolean preserveOrder, Alignment seqdataset, AlignFrame _alignFrame) { - this(sh, null, null, altitle, msa, submitGaps, preserveOrder, seqdataset, _alignFrame); + this(sh, null, null, false, altitle, msa, submitGaps, preserveOrder, + seqdataset, _alignFrame); // TODO Auto-generated constructor stub } - public MsaWSClient(Jws2Discoverer.Jws2Instance sh, Preset preset, String altitle, - jalview.datamodel.AlignmentView msa, boolean submitGaps, - boolean preserveOrder, Alignment seqdataset, + public MsaWSClient(Jws2Discoverer.Jws2Instance sh, Preset preset, + String altitle, jalview.datamodel.AlignmentView msa, + boolean submitGaps, boolean preserveOrder, Alignment seqdataset, AlignFrame _alignFrame) { - this(sh, preset, null, altitle, msa, submitGaps, preserveOrder, seqdataset, _alignFrame); + this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder, + seqdataset, _alignFrame); // TODO Auto-generated constructor stub } + /** * Creates a new MsaWSClient object that uses a service given by an externally * retrieved ServiceHandle @@ -81,10 +86,12 @@ public class MsaWSClient extends Jws2Client * DOCUMENT ME! */ - public MsaWSClient(Jws2Discoverer.Jws2Instance sh, Preset preset, List arguments, String altitle, + public MsaWSClient(Jws2Discoverer.Jws2Instance sh, Preset preset, + List arguments, boolean editParams, String altitle, jalview.datamodel.AlignmentView msa, boolean submitGaps, boolean preserveOrder, Alignment seqdataset, - AlignFrame _alignFrame) { + AlignFrame _alignFrame) + { super(); alignFrame = _alignFrame; if (!(sh.service instanceof MsaWS)) @@ -103,6 +110,17 @@ public class MsaWSClient extends Jws2Client server = sh.service; this.preset = preset; this.paramset = arguments; + if (editParams) + { + WsJobParameters jobParams = new WsJobParameters(sh, preset); + if (!jobParams.showRunDialog()) + { + return; + } + preset = null; + paramset = jobParams.getJobParams(); + } + if ((wsInfo = setWebService(sh, false)) == null) { JOptionPane.showMessageDialog(Desktop.desktop, @@ -125,10 +143,10 @@ public class MsaWSClient extends Jws2Client private void startMsaWSClient(String altitle, AlignmentView msa, boolean submitGaps, boolean preserveOrder, Alignment seqdataset) { - //if (!locateWebService()) - // { - // return; - // } + // if (!locateWebService()) + // { + // return; + // } wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment") + " of " + altitle + "\nJob details\n"); @@ -154,9 +172,9 @@ public class MsaWSClient extends Jws2Client + "alignment of " + altitle; } - MsaWSThread msathread = new MsaWSThread(server, preset, paramset, WsURL, wsInfo, - alignFrame, WebServiceName, jobtitle, msa, submitGaps, - preserveOrder, seqdataset); + MsaWSThread msathread = new MsaWSThread(server, preset, paramset, + WsURL, wsInfo, alignFrame, WebServiceName, jobtitle, msa, + submitGaps, preserveOrder, seqdataset); wsInfo.setthisService(msathread); msathread.start(); } @@ -184,72 +202,92 @@ public class MsaWSClient extends Jws2Client return (WebServiceName.indexOf("lustal") > -1); // cheat! } - public void attachWSMenuEntry(JMenu msawsmenu, + public void attachWSMenuEntry(JMenu rmsawsmenu, final Jws2Instance service, final AlignFrame alignFrame) { setWebService(service, true); // headless - JMenuItem method = new JMenuItem(WebServiceName); - method.setToolTipText(WsURL); - method.addActionListener(new ActionListener() + boolean finished = true, submitGaps = false; + JMenu msawsmenu = rmsawsmenu; + String calcName = WebServiceName + " "; + if (canSubmitGaps()) { - public void actionPerformed(ActionEvent e) - { - AlignmentView msa = alignFrame.gatherSequencesForAlignment(); - new MsaWSClient(service, alignFrame.getTitle(), - msa, false, true, alignFrame.getViewport().getAlignment() - .getDataset(), alignFrame); + msawsmenu = new JMenu(WebServiceName); + rmsawsmenu.add(msawsmenu); + calcName = ""; + } + do + { + if (submitGaps == true) + { + msawsmenu = new JMenu("profile " + WebServiceName); + rmsawsmenu.add(msawsmenu); } + final boolean withGaps = submitGaps; + JMenuItem method = new JMenuItem(calcName + "Defaults"); + method.setToolTipText(WsURL); - }); - msawsmenu.add(method); - if (canSubmitGaps()) - { - // We know that ClustalWS can accept partial alignments for refinement. - final JMenuItem methodR = new JMenuItem(WebServiceName - + " (With Gaps)"); - methodR.setToolTipText(WsURL); - methodR.addActionListener(new ActionListener() + method.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AlignmentView msa = alignFrame.gatherSequencesForAlignment(); - new MsaWSClient(service, alignFrame.getTitle(), - msa, true, true, alignFrame.getViewport().getAlignment() + new MsaWSClient(service, alignFrame.getTitle(), msa, withGaps, + true, alignFrame.getViewport().getAlignment() .getDataset(), alignFrame); } - }); - msawsmenu.add(methodR); + msawsmenu.add(method); + method = new JMenuItem(calcName + " Edit Parameters..."); + method.setToolTipText(WsURL); - } - PresetManager presets = service.getPresets(); - if (presets!=null && presets.getPresets().size()>0) - { - JMenu presetlist = new JMenu("Presets for "+WebServiceName+"(Without gaps)"); - - for (final Preset preset : (List) presets.getPresets()) + method.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + AlignmentView msa = alignFrame.gatherSequencesForAlignment(); + new MsaWSClient(service, null, null, true, alignFrame.getTitle(), + msa, withGaps, true, alignFrame.getViewport() + .getAlignment().getDataset(), alignFrame); + + } + }); + msawsmenu.add(method); + PresetManager presets = service.getPresets(); + if (presets != null && presets.getPresets().size() > 0) { - final JMenuItem methodR = new JMenuItem(preset.getName()); - methodR.setToolTipText(preset.getDescription()); - methodR.addActionListener(new ActionListener() + JMenu presetlist = new JMenu(calcName + "Presets"); + + for (final Preset preset : (List) presets.getPresets()) { - public void actionPerformed(ActionEvent e) + final JMenuItem methodR = new JMenuItem(preset.getName()); + methodR.setToolTipText(preset.getDescription()); + methodR.addActionListener(new ActionListener() { - AlignmentView msa = alignFrame.gatherSequencesForAlignment(); - new MsaWSClient(service, preset, alignFrame.getTitle(), - msa, false, true, alignFrame.getViewport().getAlignment() - .getDataset(), alignFrame); + public void actionPerformed(ActionEvent e) + { + AlignmentView msa = alignFrame.gatherSequencesForAlignment(); + new MsaWSClient(service, preset, alignFrame.getTitle(), msa, + false, true, alignFrame.getViewport().getAlignment() + .getDataset(), alignFrame); - } + } - }); - presetlist.add(methodR); + }); + presetlist.add(methodR); + } + msawsmenu.add(presetlist); } - msawsmenu.add(presetlist); - } - + if (!submitGaps && canSubmitGaps()) + { + submitGaps = true; + finished = false; + } + else + { + finished = true; + } + } while (!finished); } - } diff --git a/src/jalview/ws/jws2/MsaWSThread.java b/src/jalview/ws/jws2/MsaWSThread.java index 416c5d7..d9f92f9 100644 --- a/src/jalview/ws/jws2/MsaWSThread.java +++ b/src/jalview/ws/jws2/MsaWSThread.java @@ -553,6 +553,11 @@ class MsaWSThread extends AWS2Thread implements WSClientI // TODO: get the parameters (if any) for this job and submit the job if (j.arguments!=null && j.arguments.size()>0) { + StringBuffer pset = new StringBuffer(); + for (Argument arg: j.arguments) { + pset.append(arg.getName()+" "+arg.getDefaultValue()+"\n"); + } + j.setStatus("Custom Parameters:\n"+pset.toString()+"\nJob Output:\n"); j.setJobId(server.customAlign(j.seqs, j.arguments)); } else if (j.preset!=null) -- 1.7.10.2