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.WsJobParameters;
29 import jalview.util.MessageManager;
30 import jalview.ws.jws2.dm.AAConSettings;
31 import jalview.ws.jws2.dm.JabaWsParamSet;
32 import jalview.ws.jws2.jabaws2.Jws2Instance;
33 import jalview.ws.params.ArgumentI;
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;
49 * provides metadata for a jabaws2 service instance - resolves names, etc.
54 public abstract class Jws2Client extends jalview.ws.WSClient
56 protected WsParamSetI preset;
58 protected List<ArgumentI> paramset;
60 public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset,
61 List<ArgumentI> arguments)
63 alignFrame = _alignFrame;
67 if (!((preset instanceof JabaPreset)
68 || preset instanceof JabaWsParamSet))
71 * { this.preset = ((JabaPreset) preset).p; } else if (preset instanceof
72 * JabaWsParamSet) { List<Argument> newargs = new ArrayList<Argument>();
73 * JabaWsParamSet pset = ((JabaWsParamSet) preset); for (Option opt :
74 * pset.getjabaArguments()) { newargs.add(opt); } if (arguments != null
75 * && arguments.size() > 0) { // merge arguments with preset's own
76 * arguments. for (Argument opt : arguments) { newargs.add(opt); } }
77 * paramset = newargs; } else {
79 throw new Error(MessageManager.getString(
80 "error.implementation_error_can_only_instantiate_jaba_param_sets"));
85 // just provided with a bunch of arguments
86 this.paramset = arguments;
90 boolean processParams(Jws2Instance sh, boolean editParams)
92 return processParams(sh, editParams, false);
95 protected boolean processParams(Jws2Instance sh, boolean editParams,
96 boolean adjustingExisting)
101 if (sh.paramStore == null)
103 sh.paramStore = new JabaParamStore(sh,
104 Desktop.getUserParameterStore());
106 WsJobParameters jobParams = (preset == null && paramset != null
107 && paramset.size() > 0)
108 ? new WsJobParameters((ParamDatastoreI) null, sh,
110 JabaParamStore.getJwsArgsfromJaba(paramset))
111 : new WsJobParameters((ParamDatastoreI) null, sh,
113 (List<ArgumentI>) null);
114 if (adjustingExisting)
116 jobParams.setName(MessageManager
117 .getString("label.adjusting_parameters_for_calculation"));
119 if (!jobParams.showRunDialog())
121 return false; // dialog cancelled
124 WsParamSetI prset = jobParams.getPreset();
127 paramset = jobParams.isServiceDefaults() ? null
129 .getJabafromJwsArgs(jobParams.getJobParams());
134 this.preset = prset; // ((JabaPreset) prset).p;
135 paramset = null; // no user supplied parameters.
144 // anonymous constructor - used for headless method calls only
148 * Jws2Instance serviceHandle; (non-Javadoc)
150 * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
151 * jalview.gui.AlignFrame)
153 * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
154 * alignFrame) { if (serviceHandle==null) { throw new
155 * Error("Implementation error: No service handle for this Jws2 service."); }
156 * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
159 * add the menu item for a particular jws2 service instance
165 abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
166 final AlignFrame alignFrame);
168 static boolean registerAAConWSInstance(final JMenu wsmenu,
169 final Jws2Instance service, final AlignFrame alignFrame)
171 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
172 // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
175 // not an instantaneous calculation GUI type service
178 // create the instaneous calculation GUI bits and update state if existing
179 // GUI elements already present
181 JCheckBoxMenuItem _aaConEnabled = null;
182 for (int i = 0; i < wsmenu.getItemCount(); i++)
184 JMenuItem item = wsmenu.getItem(i);
185 if (item instanceof JCheckBoxMenuItem
186 && item.getText().equals(aaui.getAAconToggle()))
188 _aaConEnabled = (JCheckBoxMenuItem) item;
191 // is there an aaCon worker already present - if so, set it to use the
192 // given service handle
194 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
196 .getRegisteredWorkersOfClass(aaui.getClient());
197 if (aaconClient != null && aaconClient.size() > 0)
199 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
201 if (!worker.service.getHostURL().equals(service.getHostURL()))
203 // javax.swing.SwingUtilities.invokeLater(new Runnable()
208 removeCurrentAAConWorkerFor(aaui, alignFrame);
209 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
216 // is there a service already registered ? there shouldn't be if we are
217 // being called correctly
218 if (_aaConEnabled == null)
220 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
221 aaui.getAAconToggle());
223 aaConEnabled.setToolTipText(
224 JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
225 aaConEnabled.addActionListener(new ActionListener()
228 public void actionPerformed(ActionEvent arg0)
230 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
232 .getRegisteredWorkersOfClass(aaui.getClient());
233 if (aaconClient != null && aaconClient.size() > 0)
235 removeCurrentAAConWorkerFor(aaui, alignFrame);
239 buildCurrentAAConWorkerFor(aaui, alignFrame);
245 wsmenu.add(aaConEnabled);
246 final JMenuItem modifyParams = new JMenuItem(
247 aaui.getAAeditSettings());
248 modifyParams.setToolTipText(JvSwingUtils.wrapTooltip(true,
249 aaui.getAAeditSettingsTooltip()));
250 modifyParams.addActionListener(new ActionListener()
254 public void actionPerformed(ActionEvent arg0)
256 showAAConAnnotationSettingsFor(aaui, alignFrame);
259 wsmenu.add(modifyParams);
260 wsmenu.addMenuListener(new MenuListener()
264 public void menuSelected(MenuEvent arg0)
266 // TODO: refactor to the implementing class.
267 if (alignFrame.getViewport().getAlignment().isNucleotide()
271 aaConEnabled.setEnabled(true);
272 modifyParams.setEnabled(true);
276 aaConEnabled.setEnabled(false);
277 modifyParams.setEnabled(false);
279 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
281 .getRegisteredWorkersOfClass(aaui.getClient());
282 if (aaconClient != null && aaconClient.size() > 0)
284 aaConEnabled.setSelected(true);
288 aaConEnabled.setSelected(false);
293 public void menuDeselected(MenuEvent arg0)
295 // TODO Auto-generated method stub
300 public void menuCanceled(MenuEvent arg0)
302 // TODO Auto-generated method stub
311 private static void showAAConAnnotationSettingsFor(
312 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
315 * preferred settings Whether AACon is automatically recalculated Which
316 * AACon server to use What parameters to use
318 // could actually do a class search for this too
319 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
320 .getCalcIdSettingsFor(aaui.getCalcId());
323 fave = createDefaultAAConSettings(aaui);
325 new SequenceAnnotationWSClient(fave, alignFrame, true);
329 private static void buildCurrentAAConWorkerFor(
330 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
332 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
335 private static void buildCurrentAAConWorkerFor(
336 final AlignAnalysisUIText aaui, AlignFrame alignFrame,
337 Jws2Instance service)
340 * preferred settings Whether AACon is automatically recalculated Which
341 * AACon server to use What parameters to use
343 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
344 .getCalcIdSettingsFor(aaui.getCalcId());
347 fave = createDefaultAAConSettings(aaui, service);
352 && !fave.getService().getHostURL()
353 .equals(service.getHostURL()))
355 Cache.log.debug("Changing AACon service to " + service.getHostURL()
356 + " from " + fave.getService().getHostURL());
357 fave.setService(service);
360 new SequenceAnnotationWSClient(fave, alignFrame, false);
363 private static AAConSettings createDefaultAAConSettings(
364 AlignAnalysisUIText aaui)
366 return createDefaultAAConSettings(aaui, null);
369 private static AAConSettings createDefaultAAConSettings(
370 AlignAnalysisUIText aaui, Jws2Instance service)
374 if (!service.getServiceType()
375 .equals(compbio.ws.client.Services.AAConWS.toString()))
378 "Ignoring invalid preferred service for AACon calculations (service type was "
379 + service.getServiceType() + ")");
384 // check service is actually in the list of currently avaialable
386 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
395 // get the default service for AACon
396 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
397 aaui.getServiceType());
401 // TODO raise dialog box explaining error, and/or open the JABA
404 MessageManager.getString("error.no_aacon_service_found"));
406 return new AAConSettings(true, service, null, null);
409 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
410 AlignFrame alignFrame)
412 alignFrame.getViewport().getCalcManager()
413 .removeRegisteredWorkersOfClass(aaui.getClient());