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;
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 WsParamSetI preset;
60 protected List<Argument> paramset;
62 public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset,
63 List<Argument> arguments)
65 alignFrame = _alignFrame;
69 if (!((preset instanceof JabaPreset)
70 || 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(
82 "error.implementation_error_can_only_instantiate_jaba_param_sets"));
87 // just provided with a bunch of arguments
88 this.paramset = arguments;
92 boolean processParams(Jws2Instance sh, boolean editParams)
94 return processParams(sh, editParams, false);
97 protected boolean processParams(Jws2Instance sh, boolean editParams,
98 boolean adjustingExisting)
103 if (sh.paramStore == null)
105 sh.paramStore = new JabaParamStore(sh,
106 Desktop.getUserParameterStore());
108 WsJobParameters jobParams = (preset == null && paramset != null
109 && paramset.size() > 0)
110 ? new WsJobParameters((ParamDatastoreI) null, sh,
112 JabaParamStore.getJwsArgsfromJaba(paramset))
113 : new WsJobParameters((ParamDatastoreI) null, sh,
115 (List<ArgumentI>) null);
116 if (adjustingExisting)
118 jobParams.setName(MessageManager
119 .getString("label.adjusting_parameters_for_calculation"));
121 if (!jobParams.showRunDialog())
123 return false; // dialog cancelled
126 WsParamSetI prset = jobParams.getPreset();
129 paramset = jobParams.isServiceDefaults() ? null
131 .getJabafromJwsArgs(jobParams.getJobParams());
136 this.preset = prset; // ((JabaPreset) prset).p;
137 paramset = null; // no user supplied parameters.
146 // anonymous constructor - used for headless method calls only
150 * Jws2Instance serviceHandle; (non-Javadoc)
152 * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
153 * jalview.gui.AlignFrame)
155 * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
156 * alignFrame) { if (serviceHandle==null) { throw new
157 * Error("Implementation error: No service handle for this Jws2 service."); }
158 * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
161 * add the menu item for a particular jws2 service instance
167 abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
168 final AlignFrame alignFrame);
170 static boolean registerAAConWSInstance(final JMenu wsmenu,
171 final Jws2Instance service, final AlignFrame alignFrame)
173 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
174 // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
177 // not an instantaneous calculation GUI type service
180 // create the instaneous calculation GUI bits and update state if existing
181 // GUI elements already present
183 JCheckBoxMenuItem _aaConEnabled = null;
184 for (int i = 0; i < wsmenu.getItemCount(); i++)
186 JMenuItem item = wsmenu.getItem(i);
187 if (item instanceof JCheckBoxMenuItem
188 && item.getText().equals(aaui.getAAconToggle()))
190 _aaConEnabled = (JCheckBoxMenuItem) item;
193 // is there an aaCon worker already present - if so, set it to use the
194 // given service handle
196 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
198 .getRegisteredWorkersOfClass(aaui.getClient());
199 if (aaconClient != null && aaconClient.size() > 0)
201 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
203 if (!worker.service.getHostURL().equals(service.getHostURL()))
205 // javax.swing.SwingUtilities.invokeLater(new Runnable()
210 removeCurrentAAConWorkerFor(aaui, alignFrame);
211 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
218 // is there a service already registered ? there shouldn't be if we are
219 // being called correctly
220 if (_aaConEnabled == null)
222 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
223 aaui.getAAconToggle());
225 aaConEnabled.setToolTipText(
226 JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
227 aaConEnabled.addActionListener(new ActionListener()
230 public void actionPerformed(ActionEvent arg0)
232 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
234 .getRegisteredWorkersOfClass(aaui.getClient());
235 if (aaconClient != null && aaconClient.size() > 0)
237 removeCurrentAAConWorkerFor(aaui, alignFrame);
241 buildCurrentAAConWorkerFor(aaui, alignFrame);
247 wsmenu.add(aaConEnabled);
248 final JMenuItem modifyParams = new JMenuItem(
249 aaui.getAAeditSettings());
250 modifyParams.setToolTipText(JvSwingUtils.wrapTooltip(true,
251 aaui.getAAeditSettingsTooltip()));
252 modifyParams.addActionListener(new ActionListener()
256 public void actionPerformed(ActionEvent arg0)
258 showAAConAnnotationSettingsFor(aaui, alignFrame);
261 wsmenu.add(modifyParams);
262 wsmenu.addMenuListener(new MenuListener()
266 public void menuSelected(MenuEvent arg0)
268 // TODO: refactor to the implementing class.
269 if (alignFrame.getViewport().getAlignment().isNucleotide()
273 aaConEnabled.setEnabled(true);
274 modifyParams.setEnabled(true);
278 aaConEnabled.setEnabled(false);
279 modifyParams.setEnabled(false);
281 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
283 .getRegisteredWorkersOfClass(aaui.getClient());
284 if (aaconClient != null && aaconClient.size() > 0)
286 aaConEnabled.setSelected(true);
290 aaConEnabled.setSelected(false);
295 public void menuDeselected(MenuEvent arg0)
297 // TODO Auto-generated method stub
302 public void menuCanceled(MenuEvent arg0)
304 // TODO Auto-generated method stub
313 private static void showAAConAnnotationSettingsFor(
314 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
317 * preferred settings Whether AACon is automatically recalculated Which
318 * AACon server to use What parameters to use
320 // could actually do a class search for this too
321 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
322 .getCalcIdSettingsFor(aaui.getCalcId());
325 fave = createDefaultAAConSettings(aaui);
327 new SequenceAnnotationWSClient(fave, alignFrame, true);
331 private static void buildCurrentAAConWorkerFor(
332 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
334 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
337 private static void buildCurrentAAConWorkerFor(
338 final AlignAnalysisUIText aaui, AlignFrame alignFrame,
339 Jws2Instance service)
342 * preferred settings Whether AACon is automatically recalculated Which
343 * AACon server to use What parameters to use
345 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
346 .getCalcIdSettingsFor(aaui.getCalcId());
349 fave = createDefaultAAConSettings(aaui, service);
354 && !fave.getService().getHostURL()
355 .equals(service.getHostURL()))
357 Cache.log.debug("Changing AACon service to " + service.getHostURL()
358 + " from " + fave.getService().getHostURL());
359 fave.setService(service);
362 new SequenceAnnotationWSClient(fave, alignFrame, false);
365 private static AAConSettings createDefaultAAConSettings(
366 AlignAnalysisUIText aaui)
368 return createDefaultAAConSettings(aaui, null);
371 private static AAConSettings createDefaultAAConSettings(
372 AlignAnalysisUIText aaui, Jws2Instance service)
376 if (!service.getServiceType()
377 .equals(compbio.ws.client.Services.AAConWS.toString()))
380 "Ignoring invalid preferred service for AACon calculations (service type was "
381 + service.getServiceType() + ")");
386 // check service is actually in the list of currently avaialable
388 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
397 // get the default service for AACon
398 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
399 aaui.getServiceType());
403 // TODO raise dialog box explaining error, and/or open the JABA
406 MessageManager.getString("error.no_aacon_service_found"));
408 return new AAConSettings(true, service, null, null);
411 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
412 AlignFrame alignFrame)
414 alignFrame.getViewport().getCalcManager()
415 .removeRegisteredWorkersOfClass(aaui.getClient());