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.util.Locale;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.MouseAdapter;
28 import java.awt.event.MouseEvent;
29 import java.util.List;
31 import javax.swing.JMenu;
32 import javax.swing.JMenuItem;
33 import javax.swing.ToolTipManager;
35 import compbio.data.msa.MsaWS;
36 import compbio.metadata.Argument;
37 import jalview.datamodel.AlignmentI;
38 import jalview.datamodel.AlignmentView;
39 import jalview.gui.AlignFrame;
40 import jalview.gui.Desktop;
41 import jalview.gui.JvOptionPane;
42 import jalview.gui.JvSwingUtils;
43 import jalview.util.MessageManager;
44 import jalview.ws.jws2.jabaws2.Jws2Instance;
45 import jalview.ws.params.WsParamSetI;
53 public class MsaWSClient extends Jws2Client
56 * server is a WSDL2Java generated stub for an archetypal MsaWSI service.
60 public MsaWSClient(Jws2Instance sh, String altitle,
61 jalview.datamodel.AlignmentView msa, boolean submitGaps,
62 boolean preserveOrder, AlignmentI seqdataset,
63 AlignFrame _alignFrame)
65 this(sh, null, null, false, altitle, msa, submitGaps, preserveOrder,
66 seqdataset, _alignFrame);
67 // TODO Auto-generated constructor stub
70 public MsaWSClient(Jws2Instance sh, WsParamSetI preset, String altitle,
71 jalview.datamodel.AlignmentView msa, boolean submitGaps,
72 boolean preserveOrder, AlignmentI seqdataset,
73 AlignFrame _alignFrame)
75 this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder,
76 seqdataset, _alignFrame);
77 // TODO Auto-generated constructor stub
81 * Creates a new MsaWSClient object that uses a service given by an externally
82 * retrieved ServiceHandle
85 * service handle of type AbstractName(MsaWS)
92 * @param preserveOrder
96 public MsaWSClient(Jws2Instance sh, WsParamSetI preset,
97 List<Argument> arguments, boolean editParams, String altitle,
98 jalview.datamodel.AlignmentView msa, boolean submitGaps,
99 boolean preserveOrder, AlignmentI seqdataset,
100 AlignFrame _alignFrame)
102 super(_alignFrame, preset, arguments);
103 if (!processParams(sh, editParams))
108 if (!(sh.service instanceof MsaWS))
110 // redundant at mo - but may change
111 JvOptionPane.showMessageDialog(Desktop.desktop,
112 MessageManager.formatMessage(
113 "label.service_called_is_not_msa_service",
116 MessageManager.getString("label.internal_jalview_error"),
117 JvOptionPane.WARNING_MESSAGE);
121 server = (MsaWS) sh.service;
122 if ((wsInfo = setWebService(sh, false)) == null)
124 JvOptionPane.showMessageDialog(Desktop.desktop, MessageManager
125 .formatMessage("label.msa_service_is_unknown", new String[]
127 MessageManager.getString("label.internal_jalview_error"),
128 JvOptionPane.WARNING_MESSAGE);
133 startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
140 // add a class reference to the list
143 private void startMsaWSClient(String altitle, AlignmentView msa,
144 boolean submitGaps, boolean preserveOrder, AlignmentI seqdataset)
146 // if (!locateWebService())
151 wsInfo.setProgressText(((submitGaps) ? "Re-alignment" : "Alignment")
152 + " of " + altitle + "\nJob details\n");
153 String jobtitle = WebServiceName.toLowerCase(Locale.ROOT);
154 if (jobtitle.endsWith("alignment"))
156 if (submitGaps && (!jobtitle.endsWith("realignment")
157 || jobtitle.indexOf("profile") == -1))
159 int pos = jobtitle.indexOf("alignment");
160 jobtitle = WebServiceName.substring(0, pos) + "re-alignment of "
165 jobtitle = WebServiceName + " of " + altitle;
170 jobtitle = WebServiceName + (submitGaps ? " re" : " ")
171 + "alignment of " + altitle;
174 MsaWSThread msathread = new MsaWSThread(server, preset, paramset, WsURL,
175 wsInfo, alignFrame, WebServiceName, jobtitle, msa, submitGaps,
176 preserveOrder, seqdataset);
177 if (msathread.hasValidInput())
179 wsInfo.setthisService(msathread);
180 wsInfo.setVisible(true);
185 wsInfo.setVisible(false);
186 JvOptionPane.showMessageDialog(alignFrame,
187 MessageManager.getString("info.invalid_msa_input_mininfo"),
188 MessageManager.getString("info.invalid_msa_notenough"),
189 JvOptionPane.INFORMATION_MESSAGE);
193 protected String getServiceActionKey()
198 protected String getServiceActionDescription()
200 return "Multiple Sequence Alignment";
204 * look at ourselves and work out if we are a service that can take a profile
207 * @return true if we can send gapped sequences to the alignment service
209 private boolean canSubmitGaps()
211 // TODO: query service or extract service handle props to check if we can
213 return (WebServiceName.indexOf("lustal") > -1); // cheat!
217 public void attachWSMenuEntry(JMenu rmsawsmenu,
218 final Jws2Instance service, final AlignFrame af)
220 if (registerAAConWSInstance(rmsawsmenu, service, af))
222 // Alignment dependent analysis calculation WS gui
225 setWebService(service, true); // headless
226 boolean finished = true, submitGaps = false;
227 JMenu msawsmenu = rmsawsmenu;
228 String svcname = WebServiceName;
229 if (svcname.endsWith("WS"))
231 svcname = svcname.substring(0, svcname.length() - 2);
233 String calcName = svcname + " ";
236 msawsmenu = new JMenu(svcname);
237 rmsawsmenu.add(msawsmenu);
240 boolean hasparams = service.hasParameters();
243 String action = "Align ";
244 if (submitGaps == true)
247 msawsmenu = new JMenu(MessageManager
248 .formatMessage("label.realign_with_params", new String[]
250 msawsmenu.setToolTipText(MessageManager
251 .getString("label.align_sequences_to_existing_alignment"));
252 rmsawsmenu.add(msawsmenu);
254 final boolean withGaps = submitGaps;
256 JMenuItem method = new JMenuItem(MessageManager.formatMessage(
257 "label.calcname_with_default_settings", new String[]
259 method.setToolTipText(MessageManager.formatMessage(
260 "label.action_with_default_settings", new String[]
263 method.addActionListener(new ActionListener()
266 public void actionPerformed(ActionEvent e)
268 AlignmentView msa = af.gatherSequencesForAlignment();
272 new MsaWSClient(service, af.getTitle(), msa, withGaps, true,
273 af.getViewport().getAlignment().getDataset(), af);
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.gatherSequencesForAlignment();
350 MsaWSClient msac = new MsaWSClient(service, preSet,
351 af.getTitle(), msa, false, true,
352 af.getViewport().getAlignment().getDataset(), af);
358 presetlist.add(methodR);
360 msawsmenu.add(presetlist);
363 if (!submitGaps && canSubmitGaps())
375 protected void startJob(final Jws2Instance service, final AlignFrame af,
376 final boolean withGaps, AlignmentView msa)
380 new MsaWSClient(service, null, null, true, af.getTitle(), msa,
381 withGaps, true, af.getViewport().getAlignment().getDataset(),
383 } catch (Exception e)
385 JvOptionPane.showMessageDialog(alignFrame, e.getMessage(),
386 MessageManager.getString("label.state_job_error"),
387 JvOptionPane.WARNING_MESSAGE);