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 {
81 throw new Error(MessageManager.getString("error.implementation_error_can_only_instantiate_jaba_param_sets"));
86 // just provided with a bunch of arguments
87 this.paramset = arguments;
91 boolean processParams(Jws2Instance sh, boolean editParams)
93 return processParams(sh, editParams, false);
96 protected boolean processParams(Jws2Instance sh, boolean editParams,
97 boolean adjustingExisting)
102 if (sh.paramStore == null)
104 sh.paramStore = new JabaParamStore(sh,
105 Desktop.getUserParameterStore());
107 WsJobParameters jobParams = (preset == null && paramset != null && paramset
108 .size() > 0) ? new WsJobParameters(null, sh, null, paramset)
109 : new WsJobParameters(sh, preset);
110 if (adjustingExisting)
112 jobParams.setName(MessageManager
113 .getString("label.adjusting_parameters_for_calculation"));
115 if (!jobParams.showRunDialog())
119 WsParamSetI prset = jobParams.getPreset();
122 paramset = jobParams.isServiceDefaults() ? null : JabaParamStore
123 .getJabafromJwsArgs(jobParams.getJobParams());
128 this.preset = prset; // ((JabaPreset) prset).p;
129 paramset = null; // no user supplied parameters.
138 // anonymous constructor - used for headless method calls only
141 protected WebserviceInfo setWebService(Jws2Instance serv, boolean b)
143 // serviceHandle = serv;
144 String serviceInstance = serv.action; // serv.service.getClass().getName();
145 WebServiceName = serv.serviceType;
146 WebServiceJobTitle = serv.getActionText();
147 WsURL = serv.hosturl;
150 return new WebserviceInfo(WebServiceJobTitle, WebServiceJobTitle
151 + " using service hosted at " + serv.hosturl + "\n"
152 + (serv.description != null ? serv.description : ""), false);
158 * Jws2Instance serviceHandle; (non-Javadoc)
160 * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
161 * jalview.gui.AlignFrame)
163 * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
164 * alignFrame) { if (serviceHandle==null) { throw new
165 * Error("Implementation error: No service handle for this Jws2 service."); }
166 * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
169 * add the menu item for a particular jws2 service instance
175 abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
176 final AlignFrame alignFrame);
179 protected boolean registerAAConWSInstance(final JMenu wsmenu,
180 final Jws2Instance service, final AlignFrame alignFrame)
182 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
183 // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
186 // not an instantaneous calculation GUI type service
189 // create the instaneous calculation GUI bits and update state if existing
190 // GUI elements already present
192 JCheckBoxMenuItem _aaConEnabled = null;
193 for (int i = 0; i < wsmenu.getItemCount(); i++)
195 JMenuItem item = wsmenu.getItem(i);
196 if (item instanceof JCheckBoxMenuItem
197 && item.getText().equals(aaui.getAAconToggle()))
199 _aaConEnabled = (JCheckBoxMenuItem) item;
202 // is there an aaCon worker already present - if so, set it to use the
203 // given service handle
205 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
207 .getRegisteredWorkersOfClass(aaui.getClient());
208 if (aaconClient != null && aaconClient.size() > 0)
210 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
212 if (!worker.service.hosturl.equals(service.hosturl))
214 // javax.swing.SwingUtilities.invokeLater(new Runnable()
219 removeCurrentAAConWorkerFor(aaui, alignFrame);
220 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
227 // is there a service already registered ? there shouldn't be if we are
228 // being called correctly
229 if (_aaConEnabled == null)
231 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
232 aaui.getAAconToggle());
234 aaConEnabled.setToolTipText(JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
235 aaConEnabled.addActionListener(new ActionListener()
238 public void actionPerformed(ActionEvent arg0)
240 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
242 .getRegisteredWorkersOfClass(aaui.getClient());
243 if (aaconClient != null && aaconClient.size() > 0)
245 removeCurrentAAConWorkerFor(aaui, alignFrame);
249 buildCurrentAAConWorkerFor(aaui, alignFrame);
255 wsmenu.add(aaConEnabled);
256 final JMenuItem modifyParams = new JMenuItem(aaui.getAAeditSettings());
257 modifyParams.setToolTipText("<html><p>"
258 + JvSwingUtils.wrapTooltip(false, aaui.getAAeditSettingsTooltip()
259 + "</p>") + "</html>");
260 modifyParams.addActionListener(new ActionListener()
264 public void actionPerformed(ActionEvent arg0)
266 showAAConAnnotationSettingsFor(aaui, alignFrame);
269 wsmenu.add(modifyParams);
270 wsmenu.addMenuListener(new MenuListener()
274 public void menuSelected(MenuEvent arg0)
276 // TODO: refactor to the implementing class.
277 if (alignFrame.getViewport().getAlignment().isNucleotide() ? aaui
278 .isNa() : aaui.isPr())
280 aaConEnabled.setEnabled(true);
281 modifyParams.setEnabled(true);
285 aaConEnabled.setEnabled(false);
286 modifyParams.setEnabled(false);
288 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
290 .getRegisteredWorkersOfClass(aaui.getClient());
291 if (aaconClient != null && aaconClient.size() > 0)
293 aaConEnabled.setSelected(true);
297 aaConEnabled.setSelected(false);
302 public void menuDeselected(MenuEvent arg0)
304 // TODO Auto-generated method stub
309 public void menuCanceled(MenuEvent arg0)
311 // TODO Auto-generated method stub
320 private static void showAAConAnnotationSettingsFor(
321 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
324 * preferred settings Whether AACon is automatically recalculated Which
325 * AACon server to use What parameters to use
327 // could actually do a class search for this too
328 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
329 .getCalcIdSettingsFor(aaui.getCalcId());
332 fave = createDefaultAAConSettings(aaui);
334 new SequenceAnnotationWSClient(fave, alignFrame, true);
338 private static void buildCurrentAAConWorkerFor(
339 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
341 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
344 private static void buildCurrentAAConWorkerFor(
345 final AlignAnalysisUIText aaui, AlignFrame alignFrame,
346 Jws2Instance service)
349 * preferred settings Whether AACon is automatically recalculated Which
350 * AACon server to use What parameters to use
352 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
353 .getCalcIdSettingsFor(aaui.getCalcId());
356 fave = createDefaultAAConSettings(aaui, service);
361 && !fave.getService().hosturl.equals(service.hosturl))
363 Cache.log.debug("Changing AACon service to " + service.hosturl
364 + " from " + fave.getService().hosturl);
365 fave.setService(service);
368 new SequenceAnnotationWSClient(fave, alignFrame, false);
371 private static AAConSettings createDefaultAAConSettings(
372 AlignAnalysisUIText aaui)
374 return createDefaultAAConSettings(aaui, null);
377 private static AAConSettings createDefaultAAConSettings(
378 AlignAnalysisUIText aaui, Jws2Instance service)
382 if (!service.serviceType.toString().equals(
383 compbio.ws.client.Services.AAConWS.toString()))
386 .warn("Ignoring invalid preferred service for AACon calculations (service type was "
387 + service.serviceType + ")");
392 // check service is actually in the list of currently avaialable
394 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
403 // get the default service for AACon
404 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
405 aaui.getServiceType());
409 // TODO raise dialog box explaining error, and/or open the JABA
411 throw new Error(MessageManager.getString("error.no_aacon_service_found"));
413 return new AAConSettings(true, service, null, null);
416 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
417 AlignFrame alignFrame)
419 alignFrame.getViewport().getCalcManager()
420 .removeRegisteredWorkersOfClass(aaui.getClient());