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 jalview.api.AlignCalcWorkerI;
24 import jalview.bin.Cache;
25 import jalview.gui.AlignFrame;
26 import jalview.gui.Desktop;
27 import jalview.gui.JvSwingUtils;
28 import jalview.gui.WebserviceInfo;
29 import jalview.gui.WsJobParameters;
30 import jalview.util.MessageManager;
31 import jalview.ws.api.UIinfo;
32 import jalview.ws.jws2.dm.AAConSettings;
33 import jalview.ws.jws2.dm.JabaWsParamSet;
34 import jalview.ws.jws2.jabaws2.Jws2Instance;
35 import jalview.ws.params.ArgumentI;
36 import jalview.ws.params.ParamDatastoreI;
37 import jalview.ws.params.WsParamSetI;
38 import jalview.ws.uimodel.AlignAnalysisUIText;
40 import java.awt.event.ActionEvent;
41 import java.awt.event.ActionListener;
42 import java.util.List;
44 import javax.swing.JCheckBoxMenuItem;
45 import javax.swing.JMenu;
46 import javax.swing.JMenuItem;
47 import javax.swing.event.MenuEvent;
48 import javax.swing.event.MenuListener;
50 import compbio.metadata.Argument;
53 * provides metadata for a jabaws2 service instance - resolves names, etc.
58 public abstract class Jws2Client extends jalview.ws.WSClient
60 protected AlignFrame alignFrame;
62 protected WsParamSetI preset;
64 protected List<Argument> paramset;
66 public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset,
67 List<Argument> arguments)
69 alignFrame = _alignFrame;
73 if (!((preset instanceof JabaPreset)
74 || preset instanceof JabaWsParamSet))
77 * { this.preset = ((JabaPreset) preset).p; } else if (preset instanceof
78 * JabaWsParamSet) { List<Argument> newargs = new ArrayList<Argument>();
79 * JabaWsParamSet pset = ((JabaWsParamSet) preset); for (Option opt :
80 * pset.getjabaArguments()) { newargs.add(opt); } if (arguments != null
81 * && arguments.size() > 0) { // merge arguments with preset's own
82 * arguments. for (Argument opt : arguments) { newargs.add(opt); } }
83 * paramset = newargs; } else {
85 throw new Error(MessageManager.getString(
86 "error.implementation_error_can_only_instantiate_jaba_param_sets"));
91 // just provided with a bunch of arguments
92 this.paramset = arguments;
96 boolean processParams(Jws2Instance sh, boolean editParams)
98 return processParams(sh, editParams, false);
101 protected boolean processParams(Jws2Instance sh, boolean editParams,
102 boolean adjustingExisting)
107 if (sh.paramStore == null)
109 sh.paramStore = new JabaParamStore(sh,
110 Desktop.getUserParameterStore());
112 WsJobParameters jobParams = (preset == null && paramset != null
113 && paramset.size() > 0)
114 ? new WsJobParameters((ParamDatastoreI) null, sh,
116 JabaParamStore.getJwsArgsfromJaba(paramset))
117 : new WsJobParameters((ParamDatastoreI) null, sh,
119 (List<ArgumentI>) null);
120 if (adjustingExisting)
122 jobParams.setName(MessageManager
123 .getString("label.adjusting_parameters_for_calculation"));
125 if (!jobParams.showRunDialog())
127 return false; // dialog cancelled
130 WsParamSetI prset = jobParams.getPreset();
133 paramset = jobParams.isServiceDefaults() ? null
135 .getJabafromJwsArgs(jobParams.getJobParams());
140 this.preset = prset; // ((JabaPreset) prset).p;
141 paramset = null; // no user supplied parameters.
150 // anonymous constructor - used for headless method calls only
153 protected WebserviceInfo setWebService(UIinfo serv, boolean b)
156 WebServiceName = serv.getName();
157 WebServiceJobTitle = serv.getActionText();
158 WsURL = serv.getHostURL();
161 return new WebserviceInfo(WebServiceJobTitle,
162 WebServiceJobTitle + " using service hosted at "
164 + (serv.getDescription() != null
165 ? serv.getDescription()
173 * Jws2Instance serviceHandle; (non-Javadoc)
175 * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
176 * jalview.gui.AlignFrame)
178 * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
179 * alignFrame) { if (serviceHandle==null) { throw new
180 * Error("Implementation error: No service handle for this Jws2 service."); }
181 * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
184 * add the menu item for a particular jws2 service instance
190 abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
191 final AlignFrame alignFrame);
193 static boolean registerAAConWSInstance(final JMenu wsmenu,
194 final Jws2Instance service, final AlignFrame alignFrame)
196 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
197 // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
200 // not an instantaneous calculation GUI type service
203 // create the instaneous calculation GUI bits and update state if existing
204 // GUI elements already present
206 JCheckBoxMenuItem _aaConEnabled = null;
207 for (int i = 0; i < wsmenu.getItemCount(); i++)
209 JMenuItem item = wsmenu.getItem(i);
210 if (item instanceof JCheckBoxMenuItem
211 && item.getText().equals(aaui.getAAconToggle()))
213 _aaConEnabled = (JCheckBoxMenuItem) item;
216 // is there an aaCon worker already present - if so, set it to use the
217 // given service handle
219 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
221 .getRegisteredWorkersOfClass(aaui.getClient());
222 if (aaconClient != null && aaconClient.size() > 0)
224 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
226 if (!worker.service.getHostURL().equals(service.getHostURL()))
228 // javax.swing.SwingUtilities.invokeLater(new Runnable()
233 removeCurrentAAConWorkerFor(aaui, alignFrame);
234 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
241 // is there a service already registered ? there shouldn't be if we are
242 // being called correctly
243 if (_aaConEnabled == null)
245 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
246 aaui.getAAconToggle());
248 aaConEnabled.setToolTipText(
249 JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
250 aaConEnabled.addActionListener(new ActionListener()
253 public void actionPerformed(ActionEvent arg0)
255 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
257 .getRegisteredWorkersOfClass(aaui.getClient());
258 if (aaconClient != null && aaconClient.size() > 0)
260 removeCurrentAAConWorkerFor(aaui, alignFrame);
264 buildCurrentAAConWorkerFor(aaui, alignFrame);
270 wsmenu.add(aaConEnabled);
271 final JMenuItem modifyParams = new JMenuItem(
272 aaui.getAAeditSettings());
273 modifyParams.setToolTipText(JvSwingUtils.wrapTooltip(true,
274 aaui.getAAeditSettingsTooltip()));
275 modifyParams.addActionListener(new ActionListener()
279 public void actionPerformed(ActionEvent arg0)
281 showAAConAnnotationSettingsFor(aaui, alignFrame);
284 wsmenu.add(modifyParams);
285 wsmenu.addMenuListener(new MenuListener()
289 public void menuSelected(MenuEvent arg0)
291 // TODO: refactor to the implementing class.
292 if (alignFrame.getViewport().getAlignment().isNucleotide()
296 aaConEnabled.setEnabled(true);
297 modifyParams.setEnabled(true);
301 aaConEnabled.setEnabled(false);
302 modifyParams.setEnabled(false);
304 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
306 .getRegisteredWorkersOfClass(aaui.getClient());
307 if (aaconClient != null && aaconClient.size() > 0)
309 aaConEnabled.setSelected(true);
313 aaConEnabled.setSelected(false);
318 public void menuDeselected(MenuEvent arg0)
320 // TODO Auto-generated method stub
325 public void menuCanceled(MenuEvent arg0)
327 // TODO Auto-generated method stub
336 private static void showAAConAnnotationSettingsFor(
337 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
340 * preferred settings Whether AACon is automatically recalculated Which
341 * AACon server to use What parameters to use
343 // could actually do a class search for this too
344 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
345 .getCalcIdSettingsFor(aaui.getCalcId());
348 fave = createDefaultAAConSettings(aaui);
350 new SequenceAnnotationWSClient(fave, alignFrame, true);
354 private static void buildCurrentAAConWorkerFor(
355 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
357 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
360 private static void buildCurrentAAConWorkerFor(
361 final AlignAnalysisUIText aaui, AlignFrame alignFrame,
362 Jws2Instance service)
365 * preferred settings Whether AACon is automatically recalculated Which
366 * AACon server to use What parameters to use
368 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
369 .getCalcIdSettingsFor(aaui.getCalcId());
372 fave = createDefaultAAConSettings(aaui, service);
377 && !fave.getService().getHostURL()
378 .equals(service.getHostURL()))
380 Cache.log.debug("Changing AACon service to " + service.getHostURL()
381 + " from " + fave.getService().getHostURL());
382 fave.setService(service);
385 new SequenceAnnotationWSClient(fave, alignFrame, false);
388 private static AAConSettings createDefaultAAConSettings(
389 AlignAnalysisUIText aaui)
391 return createDefaultAAConSettings(aaui, null);
394 private static AAConSettings createDefaultAAConSettings(
395 AlignAnalysisUIText aaui, Jws2Instance service)
399 if (!service.getServiceType()
400 .equals(compbio.ws.client.Services.AAConWS.toString()))
403 "Ignoring invalid preferred service for AACon calculations (service type was "
404 + service.getServiceType() + ")");
409 // check service is actually in the list of currently avaialable
411 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
420 // get the default service for AACon
421 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
422 aaui.getServiceType());
426 // TODO raise dialog box explaining error, and/or open the JABA
429 MessageManager.getString("error.no_aacon_service_found"));
431 return new AAConSettings(true, service, null, null);
434 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
435 AlignFrame alignFrame)
437 alignFrame.getViewport().getCalcManager()
438 .removeRegisteredWorkersOfClass(aaui.getClient());