2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.util.List;
27 import javax.swing.JCheckBoxMenuItem;
28 import javax.swing.JMenu;
29 import javax.swing.JMenuItem;
30 import javax.swing.event.MenuEvent;
31 import javax.swing.event.MenuListener;
33 import compbio.metadata.Argument;
34 import jalview.api.AlignCalcWorkerI;
35 import jalview.bin.Cache;
36 import jalview.gui.AlignFrame;
37 import jalview.gui.Desktop;
38 import jalview.gui.JvSwingUtils;
39 import jalview.gui.WebserviceInfo;
40 import jalview.gui.WsJobParameters;
41 import jalview.util.MessageManager;
42 import jalview.ws.jws2.dm.AAConSettings;
43 import jalview.ws.jws2.dm.JabaWsParamSet;
44 import jalview.ws.jws2.jabaws2.Jws2Instance;
45 import jalview.ws.params.WsParamSetI;
46 import jalview.ws.uimodel.AlignAnalysisUIText;
49 * provides metadata for a jabaws2 service instance - resolves names, etc.
54 public abstract class Jws2Client extends jalview.ws.WSClient
56 protected AlignFrame alignFrame;
58 protected WsParamSetI preset;
60 protected List<Argument> paramset;
62 public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset,
63 List<Argument> arguments)
65 alignFrame = _alignFrame;
69 if (!((preset instanceof JabaPreset) || preset instanceof JabaWsParamSet))
72 * { this.preset = ((JabaPreset) preset).p; } else if (preset instanceof
73 * JabaWsParamSet) { List<Argument> newargs = new ArrayList<Argument>();
74 * JabaWsParamSet pset = ((JabaWsParamSet) preset); for (Option opt :
75 * pset.getjabaArguments()) { newargs.add(opt); } if (arguments != null
76 * && arguments.size() > 0) { // merge arguments with preset's own
77 * arguments. for (Argument opt : arguments) { newargs.add(opt); } }
78 * paramset = newargs; } else {
80 throw new Error(MessageManager.getString("error.implementation_error_can_only_instantiate_jaba_param_sets"));
85 // just provided with a bunch of arguments
86 this.paramset = arguments;
90 boolean processParams(Jws2Instance sh, boolean editParams)
92 return processParams(sh, editParams, false);
95 protected boolean processParams(Jws2Instance sh, boolean editParams,
96 boolean adjustingExisting)
101 if (sh.paramStore == null)
103 sh.paramStore = new JabaParamStore(sh,
104 Desktop.getUserParameterStore());
106 WsJobParameters jobParams = (preset == null && paramset != null && paramset
107 .size() > 0) ? new WsJobParameters(null, sh, null, paramset)
108 : new WsJobParameters(sh, preset);
109 if (adjustingExisting)
111 jobParams.setName(MessageManager
112 .getString("label.adjusting_parameters_for_calculation"));
114 if (!jobParams.showRunDialog())
118 WsParamSetI prset = jobParams.getPreset();
121 paramset = jobParams.isServiceDefaults() ? null : JabaParamStore
122 .getJabafromJwsArgs(jobParams.getJobParams());
127 this.preset = prset; // ((JabaPreset) prset).p;
128 paramset = null; // no user supplied parameters.
137 // anonymous constructor - used for headless method calls only
140 protected WebserviceInfo setWebService(Jws2Instance serv, boolean b)
142 // serviceHandle = serv;
143 String serviceInstance = serv.action; // serv.service.getClass().getName();
144 WebServiceName = serv.serviceType;
145 WebServiceJobTitle = serv.getActionText();
146 WsURL = serv.hosturl;
149 return new WebserviceInfo(WebServiceJobTitle, WebServiceJobTitle
150 + " using service hosted at " + serv.hosturl + "\n"
151 + (serv.description != null ? serv.description : ""));
157 * Jws2Instance serviceHandle; (non-Javadoc)
159 * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
160 * jalview.gui.AlignFrame)
162 * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
163 * alignFrame) { if (serviceHandle==null) { throw new
164 * Error("Implementation error: No service handle for this Jws2 service."); }
165 * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
168 * add the menu item for a particular jws2 service instance
174 abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
175 final AlignFrame alignFrame);
178 protected boolean registerAAConWSInstance(final JMenu wsmenu,
179 final Jws2Instance service, final AlignFrame alignFrame)
181 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
182 // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
185 // not an instantaneous calculation GUI type service
188 // create the instaneous calculation GUI bits and update state if existing
189 // GUI elements already present
191 JCheckBoxMenuItem _aaConEnabled = null;
192 for (int i = 0; i < wsmenu.getItemCount(); i++)
194 JMenuItem item = wsmenu.getItem(i);
195 if (item instanceof JCheckBoxMenuItem
196 && item.getText().equals(aaui.getAAconToggle()))
198 _aaConEnabled = (JCheckBoxMenuItem) item;
201 // is there an aaCon worker already present - if so, set it to use the
202 // given service handle
204 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
206 .getRegisteredWorkersOfClass(aaui.getClient());
207 if (aaconClient != null && aaconClient.size() > 0)
209 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
211 if (!worker.service.hosturl.equals(service.hosturl))
213 // javax.swing.SwingUtilities.invokeLater(new Runnable()
218 removeCurrentAAConWorkerFor(aaui, alignFrame);
219 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
226 // is there a service already registered ? there shouldn't be if we are
227 // being called correctly
228 if (_aaConEnabled == null)
230 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
231 aaui.getAAconToggle());
233 aaConEnabled.setToolTipText(JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
234 aaConEnabled.addActionListener(new ActionListener()
237 public void actionPerformed(ActionEvent arg0)
239 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
241 .getRegisteredWorkersOfClass(aaui.getClient());
242 if (aaconClient != null && aaconClient.size() > 0)
244 removeCurrentAAConWorkerFor(aaui, alignFrame);
248 buildCurrentAAConWorkerFor(aaui, alignFrame);
254 wsmenu.add(aaConEnabled);
255 final JMenuItem modifyParams = new JMenuItem(aaui.getAAeditSettings());
256 modifyParams.setToolTipText("<html><p>"
257 + JvSwingUtils.wrapTooltip(false, aaui.getAAeditSettingsTooltip()
258 + "</p>") + "</html>");
259 modifyParams.addActionListener(new ActionListener()
263 public void actionPerformed(ActionEvent arg0)
265 showAAConAnnotationSettingsFor(aaui, alignFrame);
268 wsmenu.add(modifyParams);
269 wsmenu.addMenuListener(new MenuListener()
273 public void menuSelected(MenuEvent arg0)
275 // TODO: refactor to the implementing class.
276 if (alignFrame.getViewport().getAlignment().isNucleotide() ? aaui
277 .isNa() : aaui.isPr())
279 aaConEnabled.setEnabled(true);
280 modifyParams.setEnabled(true);
284 aaConEnabled.setEnabled(false);
285 modifyParams.setEnabled(false);
287 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
289 .getRegisteredWorkersOfClass(aaui.getClient());
290 if (aaconClient != null && aaconClient.size() > 0)
292 aaConEnabled.setSelected(true);
296 aaConEnabled.setSelected(false);
301 public void menuDeselected(MenuEvent arg0)
303 // TODO Auto-generated method stub
308 public void menuCanceled(MenuEvent arg0)
310 // TODO Auto-generated method stub
319 private static void showAAConAnnotationSettingsFor(
320 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
323 * preferred settings Whether AACon is automatically recalculated Which
324 * AACon server to use What parameters to use
326 // could actually do a class search for this too
327 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
328 .getCalcIdSettingsFor(aaui.getCalcId());
331 fave = createDefaultAAConSettings(aaui);
333 new SequenceAnnotationWSClient(fave, alignFrame, true);
337 private static void buildCurrentAAConWorkerFor(
338 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
340 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
343 private static void buildCurrentAAConWorkerFor(
344 final AlignAnalysisUIText aaui, AlignFrame alignFrame,
345 Jws2Instance service)
348 * preferred settings Whether AACon is automatically recalculated Which
349 * AACon server to use What parameters to use
351 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
352 .getCalcIdSettingsFor(aaui.getCalcId());
355 fave = createDefaultAAConSettings(aaui, service);
360 && !fave.getService().hosturl.equals(service.hosturl))
362 Cache.log.debug("Changing AACon service to " + service.hosturl
363 + " from " + fave.getService().hosturl);
364 fave.setService(service);
367 new SequenceAnnotationWSClient(fave, alignFrame, false);
370 private static AAConSettings createDefaultAAConSettings(
371 AlignAnalysisUIText aaui)
373 return createDefaultAAConSettings(aaui, null);
376 private static AAConSettings createDefaultAAConSettings(
377 AlignAnalysisUIText aaui, Jws2Instance service)
381 if (!service.serviceType.toString().equals(
382 compbio.ws.client.Services.AAConWS.toString()))
385 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
386 + service.serviceType + ")");
391 // check service is actually in the list of currently avaialable
393 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
402 // get the default service for AACon
403 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
404 aaui.getServiceType());
408 // TODO raise dialog box explaining error, and/or open the JABA
410 throw new Error(MessageManager.getString("error.no_aacon_service_found"));
412 return new AAConSettings(true, service, null, null);
415 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
416 AlignFrame alignFrame)
418 alignFrame.getViewport().getCalcManager()
419 .removeRegisteredWorkersOfClass(aaui.getClient());