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.ParamDatastoreI;
35 import jalview.ws.params.WsParamSetI;
36 import jalview.ws.uimodel.AlignAnalysisUIText;
38 import java.awt.event.ActionEvent;
39 import java.awt.event.ActionListener;
40 import java.util.List;
42 import javax.swing.JCheckBoxMenuItem;
43 import javax.swing.JMenu;
44 import javax.swing.JMenuItem;
45 import javax.swing.event.MenuEvent;
46 import javax.swing.event.MenuListener;
48 import compbio.metadata.Argument;
51 * provides metadata for a jabaws2 service instance - resolves names, etc.
56 public abstract class Jws2Client extends jalview.ws.WSClient
58 protected AlignFrame alignFrame;
60 protected WsParamSetI preset;
62 protected List<Argument> paramset;
64 public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset,
65 List<Argument> arguments)
67 alignFrame = _alignFrame;
71 if (!((preset instanceof JabaPreset)
72 || preset instanceof JabaWsParamSet))
75 * { this.preset = ((JabaPreset) preset).p; } else if (preset instanceof
76 * JabaWsParamSet) { List<Argument> newargs = new ArrayList<Argument>();
77 * JabaWsParamSet pset = ((JabaWsParamSet) preset); for (Option opt :
78 * pset.getjabaArguments()) { newargs.add(opt); } if (arguments != null
79 * && arguments.size() > 0) { // merge arguments with preset's own
80 * arguments. for (Argument opt : arguments) { newargs.add(opt); } }
81 * paramset = newargs; } else {
83 throw new Error(MessageManager.getString(
84 "error.implementation_error_can_only_instantiate_jaba_param_sets"));
89 // just provided with a bunch of arguments
90 this.paramset = arguments;
94 boolean processParams(Jws2Instance sh, boolean editParams)
96 return processParams(sh, editParams, false);
99 protected boolean processParams(Jws2Instance sh, boolean editParams,
100 boolean adjustingExisting)
105 if (sh.paramStore == null)
107 sh.paramStore = new JabaParamStore(sh,
108 Desktop.getUserParameterStore());
110 WsJobParameters jobParams = (preset == null && paramset != null
111 && paramset.size() > 0)
112 ? new WsJobParameters((ParamDatastoreI) null, sh,
115 : new WsJobParameters((ParamDatastoreI) null, sh,
117 (List<Argument>) null);
118 if (adjustingExisting)
120 jobParams.setName(MessageManager
121 .getString("label.adjusting_parameters_for_calculation"));
123 if (!jobParams.showRunDialog())
125 return false; // dialog cancelled
128 WsParamSetI prset = jobParams.getPreset();
131 paramset = jobParams.isServiceDefaults() ? null
133 .getJabafromJwsArgs(jobParams.getJobParams());
138 this.preset = prset; // ((JabaPreset) prset).p;
139 paramset = null; // no user supplied parameters.
148 // anonymous constructor - used for headless method calls only
151 protected WebserviceInfo setWebService(Jws2Instance serv, boolean b)
153 // serviceHandle = serv;
154 String serviceInstance = serv.action; // serv.service.getClass().getName();
155 WebServiceName = serv.serviceType;
156 WebServiceJobTitle = serv.getActionText();
157 WsURL = serv.hosturl;
160 return new WebserviceInfo(WebServiceJobTitle,
161 WebServiceJobTitle + " using service hosted at "
162 + serv.hosturl + "\n"
163 + (serv.description != null ? serv.description : ""),
170 * Jws2Instance serviceHandle; (non-Javadoc)
172 * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
173 * jalview.gui.AlignFrame)
175 * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
176 * alignFrame) { if (serviceHandle==null) { throw new
177 * Error("Implementation error: No service handle for this Jws2 service."); }
178 * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
181 * add the menu item for a particular jws2 service instance
187 abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
188 final AlignFrame alignFrame);
190 protected boolean registerAAConWSInstance(final JMenu wsmenu,
191 final Jws2Instance service, final AlignFrame alignFrame)
193 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
194 // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
197 // not an instantaneous calculation GUI type service
200 // create the instaneous calculation GUI bits and update state if existing
201 // GUI elements already present
203 JCheckBoxMenuItem _aaConEnabled = null;
204 for (int i = 0; i < wsmenu.getItemCount(); i++)
206 JMenuItem item = wsmenu.getItem(i);
207 if (item instanceof JCheckBoxMenuItem
208 && item.getText().equals(aaui.getAAconToggle()))
210 _aaConEnabled = (JCheckBoxMenuItem) item;
213 // is there an aaCon worker already present - if so, set it to use the
214 // given service handle
216 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
218 .getRegisteredWorkersOfClass(aaui.getClient());
219 if (aaconClient != null && aaconClient.size() > 0)
221 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
223 if (!worker.service.hosturl.equals(service.hosturl))
225 // javax.swing.SwingUtilities.invokeLater(new Runnable()
230 removeCurrentAAConWorkerFor(aaui, alignFrame);
231 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
238 // is there a service already registered ? there shouldn't be if we are
239 // being called correctly
240 if (_aaConEnabled == null)
242 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
243 aaui.getAAconToggle());
245 aaConEnabled.setToolTipText(
246 JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
247 aaConEnabled.addActionListener(new ActionListener()
250 public void actionPerformed(ActionEvent arg0)
252 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
254 .getRegisteredWorkersOfClass(aaui.getClient());
255 if (aaconClient != null && aaconClient.size() > 0)
257 removeCurrentAAConWorkerFor(aaui, alignFrame);
261 buildCurrentAAConWorkerFor(aaui, alignFrame);
267 wsmenu.add(aaConEnabled);
268 final JMenuItem modifyParams = new JMenuItem(
269 aaui.getAAeditSettings());
270 modifyParams.setToolTipText(JvSwingUtils.wrapTooltip(true,
271 aaui.getAAeditSettingsTooltip()));
272 modifyParams.addActionListener(new ActionListener()
276 public void actionPerformed(ActionEvent arg0)
278 showAAConAnnotationSettingsFor(aaui, alignFrame);
281 wsmenu.add(modifyParams);
282 wsmenu.addMenuListener(new MenuListener()
286 public void menuSelected(MenuEvent arg0)
288 // TODO: refactor to the implementing class.
289 if (alignFrame.getViewport().getAlignment().isNucleotide()
293 aaConEnabled.setEnabled(true);
294 modifyParams.setEnabled(true);
298 aaConEnabled.setEnabled(false);
299 modifyParams.setEnabled(false);
301 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
303 .getRegisteredWorkersOfClass(aaui.getClient());
304 if (aaconClient != null && aaconClient.size() > 0)
306 aaConEnabled.setSelected(true);
310 aaConEnabled.setSelected(false);
315 public void menuDeselected(MenuEvent arg0)
317 // TODO Auto-generated method stub
322 public void menuCanceled(MenuEvent arg0)
324 // TODO Auto-generated method stub
333 private static void showAAConAnnotationSettingsFor(
334 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
337 * preferred settings Whether AACon is automatically recalculated Which
338 * AACon server to use What parameters to use
340 // could actually do a class search for this too
341 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
342 .getCalcIdSettingsFor(aaui.getCalcId());
345 fave = createDefaultAAConSettings(aaui);
347 new SequenceAnnotationWSClient(fave, alignFrame, true);
351 private static void buildCurrentAAConWorkerFor(
352 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
354 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
357 private static void buildCurrentAAConWorkerFor(
358 final AlignAnalysisUIText aaui, AlignFrame alignFrame,
359 Jws2Instance service)
362 * preferred settings Whether AACon is automatically recalculated Which
363 * AACon server to use What parameters to use
365 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
366 .getCalcIdSettingsFor(aaui.getCalcId());
369 fave = createDefaultAAConSettings(aaui, service);
374 && !fave.getService().hosturl.equals(service.hosturl))
376 Cache.log.debug("Changing AACon service to " + service.hosturl
377 + " from " + fave.getService().hosturl);
378 fave.setService(service);
381 new SequenceAnnotationWSClient(fave, alignFrame, false);
384 private static AAConSettings createDefaultAAConSettings(
385 AlignAnalysisUIText aaui)
387 return createDefaultAAConSettings(aaui, null);
390 private static AAConSettings createDefaultAAConSettings(
391 AlignAnalysisUIText aaui, Jws2Instance service)
395 if (!service.serviceType.toString()
396 .equals(compbio.ws.client.Services.AAConWS.toString()))
399 "Ignoring invalid preferred service for AACon calculations (service type was "
400 + service.serviceType + ")");
405 // check service is actually in the list of currently avaialable
407 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
416 // get the default service for AACon
417 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
418 aaui.getServiceType());
422 // TODO raise dialog box explaining error, and/or open the JABA
425 MessageManager.getString("error.no_aacon_service_found"));
427 return new AAConSettings(true, service, null, null);
430 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
431 AlignFrame alignFrame)
433 alignFrame.getViewport().getCalcManager()
434 .removeRegisteredWorkersOfClass(aaui.getClient());