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.jws2.dm.AAConSettings;
32 import jalview.ws.jws2.dm.JabaWsParamSet;
33 import jalview.ws.jws2.jabaws2.Jws2Instance;
34 import jalview.ws.params.WsParamSetI;
35 import jalview.ws.uimodel.AlignAnalysisUIText;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.ActionListener;
39 import java.util.List;
41 import javax.swing.JCheckBoxMenuItem;
42 import javax.swing.JMenu;
43 import javax.swing.JMenuItem;
44 import javax.swing.event.MenuEvent;
45 import javax.swing.event.MenuListener;
47 import compbio.metadata.Argument;
50 * provides metadata for a jabaws2 service instance - resolves names, etc.
55 public abstract class Jws2Client extends jalview.ws.WSClient
57 protected AlignFrame alignFrame;
59 protected WsParamSetI preset;
61 protected List<Argument> paramset;
63 public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset,
64 List<Argument> arguments)
66 alignFrame = _alignFrame;
70 if (!((preset instanceof JabaPreset) || preset instanceof JabaWsParamSet))
73 * { this.preset = ((JabaPreset) preset).p; } else if (preset instanceof
74 * JabaWsParamSet) { List<Argument> newargs = new ArrayList<Argument>();
75 * JabaWsParamSet pset = ((JabaWsParamSet) preset); for (Option opt :
76 * pset.getjabaArguments()) { newargs.add(opt); } if (arguments != null
77 * && arguments.size() > 0) { // merge arguments with preset's own
78 * arguments. for (Argument opt : arguments) { newargs.add(opt); } }
79 * paramset = newargs; } else {
83 .getString("error.implementation_error_can_only_instantiate_jaba_param_sets"));
88 // just provided with a bunch of arguments
89 this.paramset = arguments;
93 boolean processParams(Jws2Instance sh, boolean editParams)
95 return processParams(sh, editParams, false);
98 protected boolean processParams(Jws2Instance sh, boolean editParams,
99 boolean adjustingExisting)
104 if (sh.paramStore == null)
106 sh.paramStore = new JabaParamStore(sh,
107 Desktop.getUserParameterStore());
109 WsJobParameters jobParams = (preset == null && paramset != null && paramset
110 .size() > 0) ? new WsJobParameters(null, sh, null, paramset)
111 : new WsJobParameters(sh, preset);
112 if (adjustingExisting)
114 jobParams.setName(MessageManager
115 .getString("label.adjusting_parameters_for_calculation"));
117 if (!jobParams.showRunDialog())
121 WsParamSetI prset = jobParams.getPreset();
124 paramset = jobParams.isServiceDefaults() ? null : JabaParamStore
125 .getJabafromJwsArgs(jobParams.getJobParams());
130 this.preset = prset; // ((JabaPreset) prset).p;
131 paramset = null; // no user supplied parameters.
140 // anonymous constructor - used for headless method calls only
143 protected WebserviceInfo setWebService(Jws2Instance serv, boolean b)
145 // serviceHandle = serv;
146 String serviceInstance = serv.action; // serv.service.getClass().getName();
147 WebServiceName = serv.serviceType;
148 WebServiceJobTitle = serv.getActionText();
149 WsURL = serv.hosturl;
152 return new WebserviceInfo(WebServiceJobTitle, WebServiceJobTitle
153 + " using service hosted at " + serv.hosturl + "\n"
154 + (serv.description != null ? serv.description : ""), false);
160 * Jws2Instance serviceHandle; (non-Javadoc)
162 * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
163 * jalview.gui.AlignFrame)
165 * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
166 * alignFrame) { if (serviceHandle==null) { throw new
167 * Error("Implementation error: No service handle for this Jws2 service."); }
168 * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
171 * add the menu item for a particular jws2 service instance
177 abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
178 final AlignFrame alignFrame);
180 protected boolean registerAAConWSInstance(final JMenu wsmenu,
181 final Jws2Instance service, final AlignFrame alignFrame)
183 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
184 // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
187 // not an instantaneous calculation GUI type service
190 // create the instaneous calculation GUI bits and update state if existing
191 // GUI elements already present
193 JCheckBoxMenuItem _aaConEnabled = null;
194 for (int i = 0; i < wsmenu.getItemCount(); i++)
196 JMenuItem item = wsmenu.getItem(i);
197 if (item instanceof JCheckBoxMenuItem
198 && item.getText().equals(aaui.getAAconToggle()))
200 _aaConEnabled = (JCheckBoxMenuItem) item;
203 // is there an aaCon worker already present - if so, set it to use the
204 // given service handle
206 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
208 .getRegisteredWorkersOfClass(aaui.getClient());
209 if (aaconClient != null && aaconClient.size() > 0)
211 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
213 if (!worker.service.hosturl.equals(service.hosturl))
215 // javax.swing.SwingUtilities.invokeLater(new Runnable()
220 removeCurrentAAConWorkerFor(aaui, alignFrame);
221 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
228 // is there a service already registered ? there shouldn't be if we are
229 // being called correctly
230 if (_aaConEnabled == null)
232 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
233 aaui.getAAconToggle());
235 aaConEnabled.setToolTipText(JvSwingUtils.wrapTooltip(true,
236 aaui.getAAconToggleTooltip()));
237 aaConEnabled.addActionListener(new ActionListener()
240 public void actionPerformed(ActionEvent arg0)
242 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
244 .getRegisteredWorkersOfClass(aaui.getClient());
245 if (aaconClient != null && aaconClient.size() > 0)
247 removeCurrentAAConWorkerFor(aaui, alignFrame);
251 buildCurrentAAConWorkerFor(aaui, alignFrame);
257 wsmenu.add(aaConEnabled);
258 final JMenuItem modifyParams = new JMenuItem(aaui.getAAeditSettings());
260 .setToolTipText("<html><p>"
261 + JvSwingUtils.wrapTooltip(false,
262 aaui.getAAeditSettingsTooltip() + "</p>")
264 modifyParams.addActionListener(new ActionListener()
268 public void actionPerformed(ActionEvent arg0)
270 showAAConAnnotationSettingsFor(aaui, alignFrame);
273 wsmenu.add(modifyParams);
274 wsmenu.addMenuListener(new MenuListener()
278 public void menuSelected(MenuEvent arg0)
280 // TODO: refactor to the implementing class.
281 if (alignFrame.getViewport().getAlignment().isNucleotide() ? aaui
282 .isNa() : aaui.isPr())
284 aaConEnabled.setEnabled(true);
285 modifyParams.setEnabled(true);
289 aaConEnabled.setEnabled(false);
290 modifyParams.setEnabled(false);
292 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
294 .getRegisteredWorkersOfClass(aaui.getClient());
295 if (aaconClient != null && aaconClient.size() > 0)
297 aaConEnabled.setSelected(true);
301 aaConEnabled.setSelected(false);
306 public void menuDeselected(MenuEvent arg0)
308 // TODO Auto-generated method stub
313 public void menuCanceled(MenuEvent arg0)
315 // TODO Auto-generated method stub
324 private static void showAAConAnnotationSettingsFor(
325 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
328 * preferred settings Whether AACon is automatically recalculated Which
329 * AACon server to use What parameters to use
331 // could actually do a class search for this too
332 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
333 .getCalcIdSettingsFor(aaui.getCalcId());
336 fave = createDefaultAAConSettings(aaui);
338 new SequenceAnnotationWSClient(fave, alignFrame, true);
342 private static void buildCurrentAAConWorkerFor(
343 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
345 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
348 private static void buildCurrentAAConWorkerFor(
349 final AlignAnalysisUIText aaui, AlignFrame alignFrame,
350 Jws2Instance service)
353 * preferred settings Whether AACon is automatically recalculated Which
354 * AACon server to use What parameters to use
356 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
357 .getCalcIdSettingsFor(aaui.getCalcId());
360 fave = createDefaultAAConSettings(aaui, service);
365 && !fave.getService().hosturl.equals(service.hosturl))
367 Cache.log.debug("Changing AACon service to " + service.hosturl
368 + " from " + fave.getService().hosturl);
369 fave.setService(service);
372 new SequenceAnnotationWSClient(fave, alignFrame, false);
375 private static AAConSettings createDefaultAAConSettings(
376 AlignAnalysisUIText aaui)
378 return createDefaultAAConSettings(aaui, null);
381 private static AAConSettings createDefaultAAConSettings(
382 AlignAnalysisUIText aaui, Jws2Instance service)
386 if (!service.serviceType.toString().equals(
387 compbio.ws.client.Services.AAConWS.toString()))
390 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
391 + service.serviceType + ")");
396 // check service is actually in the list of currently avaialable
398 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
407 // get the default service for AACon
408 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
409 aaui.getServiceType());
413 // TODO raise dialog box explaining error, and/or open the JABA
416 MessageManager.getString("error.no_aacon_service_found"));
418 return new AAConSettings(true, service, null, null);
421 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
422 AlignFrame alignFrame)
424 alignFrame.getViewport().getCalcManager()
425 .removeRegisteredWorkersOfClass(aaui.getClient());