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.ParamDatastoreI;
36 import jalview.ws.params.WsParamSetI;
37 import jalview.ws.uimodel.AlignAnalysisUIText;
39 import java.awt.event.ActionEvent;
40 import java.awt.event.ActionListener;
41 import java.util.List;
43 import javax.swing.JCheckBoxMenuItem;
44 import javax.swing.JMenu;
45 import javax.swing.JMenuItem;
46 import javax.swing.event.MenuEvent;
47 import javax.swing.event.MenuListener;
49 import compbio.metadata.Argument;
52 * provides metadata for a jabaws2 service instance - resolves names, etc.
57 public abstract class Jws2Client extends jalview.ws.WSClient
59 protected AlignFrame alignFrame;
61 protected WsParamSetI preset;
63 protected List<Argument> paramset;
65 public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset,
66 List<Argument> arguments)
68 alignFrame = _alignFrame;
72 if (!((preset instanceof JabaPreset)
73 || preset instanceof JabaWsParamSet))
76 * { this.preset = ((JabaPreset) preset).p; } else if (preset instanceof
77 * JabaWsParamSet) { List<Argument> newargs = new ArrayList<Argument>();
78 * JabaWsParamSet pset = ((JabaWsParamSet) preset); for (Option opt :
79 * pset.getjabaArguments()) { newargs.add(opt); } if (arguments != null
80 * && arguments.size() > 0) { // merge arguments with preset's own
81 * arguments. for (Argument opt : arguments) { newargs.add(opt); } }
82 * paramset = newargs; } else {
84 throw new Error(MessageManager.getString(
85 "error.implementation_error_can_only_instantiate_jaba_param_sets"));
90 // just provided with a bunch of arguments
91 this.paramset = arguments;
95 boolean processParams(Jws2Instance sh, boolean editParams)
97 return processParams(sh, editParams, false);
100 protected boolean processParams(Jws2Instance sh, boolean editParams,
101 boolean adjustingExisting)
106 if (sh.paramStore == null)
108 sh.paramStore = new JabaParamStore(sh,
109 Desktop.getUserParameterStore());
111 WsJobParameters jobParams = (preset == null && paramset != null
112 && paramset.size() > 0)
113 ? new WsJobParameters((ParamDatastoreI) null, sh,
116 : new WsJobParameters((ParamDatastoreI) null, sh,
118 (List<Argument>) null);
119 if (adjustingExisting)
121 jobParams.setName(MessageManager
122 .getString("label.adjusting_parameters_for_calculation"));
124 if (!jobParams.showRunDialog())
126 return false; // dialog cancelled
129 WsParamSetI prset = jobParams.getPreset();
132 paramset = jobParams.isServiceDefaults() ? null
134 .getJabafromJwsArgs(jobParams.getJobParams());
139 this.preset = prset; // ((JabaPreset) prset).p;
140 paramset = null; // no user supplied parameters.
149 // anonymous constructor - used for headless method calls only
152 protected WebserviceInfo setWebService(UIinfo serv, boolean b)
155 WebServiceName = serv.getName();
156 WebServiceJobTitle = serv.getActionText();
157 WsURL = serv.getHostURL();
160 return new WebserviceInfo(WebServiceJobTitle,
161 WebServiceJobTitle + " using service hosted at "
163 + (serv.getDescription() != null
164 ? serv.getDescription()
172 * Jws2Instance serviceHandle; (non-Javadoc)
174 * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
175 * jalview.gui.AlignFrame)
177 * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
178 * alignFrame) { if (serviceHandle==null) { throw new
179 * Error("Implementation error: No service handle for this Jws2 service."); }
180 * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
183 * add the menu item for a particular jws2 service instance
189 abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
190 final AlignFrame alignFrame);
192 static boolean registerAAConWSInstance(final JMenu wsmenu,
193 final Jws2Instance service, final AlignFrame alignFrame)
195 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
196 // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
199 // not an instantaneous calculation GUI type service
202 // create the instaneous calculation GUI bits and update state if existing
203 // GUI elements already present
205 JCheckBoxMenuItem _aaConEnabled = null;
206 for (int i = 0; i < wsmenu.getItemCount(); i++)
208 JMenuItem item = wsmenu.getItem(i);
209 if (item instanceof JCheckBoxMenuItem
210 && item.getText().equals(aaui.getAAconToggle()))
212 _aaConEnabled = (JCheckBoxMenuItem) item;
215 // is there an aaCon worker already present - if so, set it to use the
216 // given service handle
218 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
220 .getRegisteredWorkersOfClass(aaui.getClient());
221 if (aaconClient != null && aaconClient.size() > 0)
223 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
225 if (!worker.service.getHostURL().equals(service.getHostURL()))
227 // javax.swing.SwingUtilities.invokeLater(new Runnable()
232 removeCurrentAAConWorkerFor(aaui, alignFrame);
233 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
240 // is there a service already registered ? there shouldn't be if we are
241 // being called correctly
242 if (_aaConEnabled == null)
244 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
245 aaui.getAAconToggle());
247 aaConEnabled.setToolTipText(
248 JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
249 aaConEnabled.addActionListener(new ActionListener()
252 public void actionPerformed(ActionEvent arg0)
254 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
256 .getRegisteredWorkersOfClass(aaui.getClient());
257 if (aaconClient != null && aaconClient.size() > 0)
259 removeCurrentAAConWorkerFor(aaui, alignFrame);
263 buildCurrentAAConWorkerFor(aaui, alignFrame);
269 wsmenu.add(aaConEnabled);
270 final JMenuItem modifyParams = new JMenuItem(
271 aaui.getAAeditSettings());
272 modifyParams.setToolTipText(JvSwingUtils.wrapTooltip(true,
273 aaui.getAAeditSettingsTooltip()));
274 modifyParams.addActionListener(new ActionListener()
278 public void actionPerformed(ActionEvent arg0)
280 showAAConAnnotationSettingsFor(aaui, alignFrame);
283 wsmenu.add(modifyParams);
284 wsmenu.addMenuListener(new MenuListener()
288 public void menuSelected(MenuEvent arg0)
290 // TODO: refactor to the implementing class.
291 if (alignFrame.getViewport().getAlignment().isNucleotide()
295 aaConEnabled.setEnabled(true);
296 modifyParams.setEnabled(true);
300 aaConEnabled.setEnabled(false);
301 modifyParams.setEnabled(false);
303 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
305 .getRegisteredWorkersOfClass(aaui.getClient());
306 if (aaconClient != null && aaconClient.size() > 0)
308 aaConEnabled.setSelected(true);
312 aaConEnabled.setSelected(false);
317 public void menuDeselected(MenuEvent arg0)
319 // TODO Auto-generated method stub
324 public void menuCanceled(MenuEvent arg0)
326 // TODO Auto-generated method stub
335 private static void showAAConAnnotationSettingsFor(
336 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
339 * preferred settings Whether AACon is automatically recalculated Which
340 * AACon server to use What parameters to use
342 // could actually do a class search for this too
343 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
344 .getCalcIdSettingsFor(aaui.getCalcId());
347 fave = createDefaultAAConSettings(aaui);
349 new SequenceAnnotationWSClient(fave, alignFrame, true);
353 private static void buildCurrentAAConWorkerFor(
354 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
356 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
359 private static void buildCurrentAAConWorkerFor(
360 final AlignAnalysisUIText aaui, AlignFrame alignFrame,
361 Jws2Instance service)
364 * preferred settings Whether AACon is automatically recalculated Which
365 * AACon server to use What parameters to use
367 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
368 .getCalcIdSettingsFor(aaui.getCalcId());
371 fave = createDefaultAAConSettings(aaui, service);
376 && !fave.getService().getHostURL()
377 .equals(service.getHostURL()))
379 Cache.log.debug("Changing AACon service to " + service.getHostURL()
380 + " from " + fave.getService().getHostURL());
381 fave.setService(service);
384 new SequenceAnnotationWSClient(fave, alignFrame, false);
387 private static AAConSettings createDefaultAAConSettings(
388 AlignAnalysisUIText aaui)
390 return createDefaultAAConSettings(aaui, null);
393 private static AAConSettings createDefaultAAConSettings(
394 AlignAnalysisUIText aaui, Jws2Instance service)
398 if (!service.getServiceType()
399 .equals(compbio.ws.client.Services.AAConWS.toString()))
402 "Ignoring invalid preferred service for AACon calculations (service type was "
403 + service.getServiceType() + ")");
408 // check service is actually in the list of currently avaialable
410 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
419 // get the default service for AACon
420 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
421 aaui.getServiceType());
425 // TODO raise dialog box explaining error, and/or open the JABA
428 MessageManager.getString("error.no_aacon_service_found"));
430 return new AAConSettings(true, service, null, null);
433 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
434 AlignFrame alignFrame)
436 alignFrame.getViewport().getCalcManager()
437 .removeRegisteredWorkersOfClass(aaui.getClient());