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.
21 package jalview.ws.jws2;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.awt.event.MouseAdapter;
26 import java.awt.event.MouseEvent;
27 import java.util.List;
29 import javax.swing.JMenu;
30 import javax.swing.JMenuItem;
31 import javax.swing.ToolTipManager;
33 import compbio.data.msa.MsaWS;
34 import compbio.metadata.Argument;
35 import jalview.datamodel.AlignmentI;
36 import jalview.datamodel.AlignmentView;
37 import jalview.gui.AlignFrame;
38 import jalview.gui.Desktop;
39 import jalview.gui.JvOptionPane;
40 import jalview.gui.JvSwingUtils;
41 import jalview.util.MessageManager;
42 import jalview.ws.jws2.jabaws2.Jws2Instance;
43 import jalview.ws.params.WsParamSetI;
51 public class MsaWSClient extends Jws2Client
54 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
58 public MsaWSClient(Jws2Instance sh, String altitle,
59 jalview.datamodel.AlignmentView msa, boolean submitGaps,
60 boolean preserveOrder, AlignmentI seqdataset,
61 AlignFrame _alignFrame)
63 this(sh, null, null, false, altitle, msa, submitGaps, preserveOrder,
64 seqdataset, _alignFrame);
65 // TODO Auto-generated constructor stub
68 public MsaWSClient(Jws2Instance sh, WsParamSetI preset, String altitle,
69 jalview.datamodel.AlignmentView msa, boolean submitGaps,
70 boolean preserveOrder, AlignmentI seqdataset,
71 AlignFrame _alignFrame)
73 this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder,
74 seqdataset, _alignFrame);
75 // TODO Auto-generated constructor stub
79 * Creates a new MsaWSClient object that uses a service given by an externally
80 * retrieved ServiceHandle
83 * service handle of type AbstractName(MsaWS)
90 * @param preserveOrder
94 public MsaWSClient(Jws2Instance sh, WsParamSetI preset,
95 List<Argument> arguments, boolean editParams, String altitle,
96 jalview.datamodel.AlignmentView msa, boolean submitGaps,
97 boolean preserveOrder, AlignmentI seqdataset,
98 AlignFrame _alignFrame)
100 super(_alignFrame, preset, arguments);
101 if (!processParams(sh, editParams))
106 if (!(sh.service instanceof MsaWS))
108 // redundant at mo - but may change
109 JvOptionPane.showMessageDialog(Desktop.desktop,
110 MessageManager.formatMessage(
111 "label.service_called_is_not_msa_service",
114 MessageManager.getString("label.internal_jalview_error"),
115 JvOptionPane.WARNING_MESSAGE);
119 server = (MsaWS) sh.service;
120 if ((wsInfo = setWebService(sh, false)) == null)
122 JvOptionPane.showMessageDialog(Desktop.desktop, MessageManager
123 .formatMessage("label.msa_service_is_unknown", new String[]
125 MessageManager.getString("label.internal_jalview_error"),
126 JvOptionPane.WARNING_MESSAGE);
131 startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
138 // add a class reference to the list
141 private void startMsaWSClient(String altitle, AlignmentView msa,
142 boolean submitGaps, boolean preserveOrder, AlignmentI seqdataset)
144 // if (!locateWebService())
149 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")
150 + " of " + altitle + "\nJob details\n");
151 String jobtitle = WebServiceName.toLowerCase();
152 if (jobtitle.endsWith("alignment"))
154 if (submitGaps && (!jobtitle.endsWith("realignment")
155 || jobtitle.indexOf("profile") == -1))
157 int pos = jobtitle.indexOf("alignment");
158 jobtitle = WebServiceName.substring(0, pos) + "re-alignment of "
163 jobtitle = WebServiceName + " of " + altitle;
168 jobtitle = WebServiceName + (submitGaps ? " re" : " ")
169 + "alignment of " + altitle;
172 MsaWSThread msathread = new MsaWSThread(server, preset, paramset, WsURL,
173 wsInfo, alignFrame, WebServiceName, jobtitle, msa, submitGaps,
174 preserveOrder, seqdataset);
175 if (msathread.hasValidInput())
177 wsInfo.setthisService(msathread);
178 wsInfo.setVisible(true);
183 wsInfo.setVisible(false);
184 JvOptionPane.showMessageDialog(alignFrame,
185 MessageManager.getString("info.invalid_msa_input_mininfo"),
186 MessageManager.getString("info.invalid_msa_notenough"),
187 JvOptionPane.INFORMATION_MESSAGE);
191 protected String getServiceActionKey()
196 protected String getServiceActionDescription()
198 return "Multiple Sequence Alignment";
202 * look at ourselves and work out if we are a service that can take a profile
205 * @return true if we can send gapped sequences to the alignment service
207 private boolean canSubmitGaps()
209 // TODO: query service or extract service handle props to check if we can
211 return (WebServiceName.indexOf("lustal") > -1); // cheat!
215 public void attachWSMenuEntry(JMenu rmsawsmenu,
216 final Jws2Instance service, final AlignFrame af)
218 if (registerAAConWSInstance(rmsawsmenu, service, af))
220 // Alignment dependent analysis calculation WS gui
223 setWebService(service, true); // headless
224 boolean finished = true, submitGaps = false;
225 JMenu msawsmenu = rmsawsmenu;
226 String svcname = WebServiceName;
227 if (svcname.endsWith("WS"))
229 svcname = svcname.substring(0, svcname.length() - 2);
231 String calcName = svcname + " ";
234 msawsmenu = new JMenu(svcname);
235 rmsawsmenu.add(msawsmenu);
238 boolean hasparams = service.hasParameters();
241 String action = "Align ";
242 if (submitGaps == true)
245 msawsmenu = new JMenu(MessageManager
246 .formatMessage("label.realign_with_params", new String[]
248 msawsmenu.setToolTipText(MessageManager
249 .getString("label.align_sequences_to_existing_alignment"));
250 rmsawsmenu.add(msawsmenu);
252 final boolean withGaps = submitGaps;
254 JMenuItem method = new JMenuItem(MessageManager.formatMessage(
255 "label.calcname_with_default_settings", new String[]
257 method.setToolTipText(MessageManager.formatMessage(
258 "label.action_with_default_settings", new String[]
261 method.addActionListener(new ActionListener()
264 public void actionPerformed(ActionEvent e)
266 AlignmentView msa = af.gatherSequencesForAlignment();
270 new MsaWSClient(service, af.getTitle(), msa, withGaps,
272 af.getViewport().getAlignment().getDataset(),
278 msawsmenu.add(method);
281 // only add these menu options if the service has user-modifiable
283 method = new JMenuItem(
284 MessageManager.getString("label.edit_settings_and_run"));
285 method.setToolTipText(MessageManager.getString(
286 "label.view_and_change_parameters_before_alignment"));
288 method.addActionListener(new ActionListener()
291 public void actionPerformed(ActionEvent e)
293 AlignmentView msa = af.gatherSequencesForAlignment();
296 startJob(service, af, withGaps, msa);
301 msawsmenu.add(method);
302 List<WsParamSetI> presets = service.getParamStore().getPresets();
303 if (presets != null && presets.size() > 0)
305 JMenu presetlist = new JMenu(MessageManager.formatMessage(
306 "label.run_with_preset_params", new String[]
309 final int showToolTipFor = ToolTipManager.sharedInstance()
311 for (final WsParamSetI preSet : presets)
313 final JMenuItem methodR = new JMenuItem(preSet.getName());
314 final int QUICK_TOOLTIP = 1500;
315 // JAL-1582 shorten tooltip display time in these menu items as
316 // they can obscure other options
317 methodR.addMouseListener(new MouseAdapter()
320 public void mouseEntered(MouseEvent e)
322 ToolTipManager.sharedInstance()
323 .setDismissDelay(QUICK_TOOLTIP);
327 public void mouseExited(MouseEvent e)
329 ToolTipManager.sharedInstance()
330 .setDismissDelay(showToolTipFor);
334 String tooltip = JvSwingUtils.wrapTooltip(true, "<strong>"
335 + (preSet.isModifiable()
336 ? MessageManager.getString("label.user_preset")
338 .getString("label.service_preset"))
339 + "</strong><br/>" + preSet.getDescription());
340 methodR.setToolTipText(tooltip);
341 methodR.addActionListener(new ActionListener()
344 public void actionPerformed(ActionEvent e)
346 AlignmentView msa = af
347 .gatherSequencesForAlignment();
351 MsaWSClient msac = new MsaWSClient(service, preSet,
352 af.getTitle(), msa, false, true,
353 af.getViewport().getAlignment()
361 presetlist.add(methodR);
363 msawsmenu.add(presetlist);
366 if (!submitGaps && canSubmitGaps())
378 protected void startJob(final Jws2Instance service, final AlignFrame af,
379 final boolean withGaps, AlignmentView msa)
382 new MsaWSClient(service, null, null, true,
383 af.getTitle(), msa, withGaps, true,
384 af.getViewport().getAlignment().getDataset(),
386 } catch (Exception e) {
387 JvOptionPane.showMessageDialog(alignFrame, e.getMessage(),
388 MessageManager.getString("label.state_job_error"),
389 JvOptionPane.WARNING_MESSAGE);