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.JvSwingUtils;
27 import jalview.util.MessageManager;
28 import jalview.ws.api.ServiceWithParameters;
29 import jalview.ws.jws2.dm.AAConSettings;
30 import jalview.ws.jws2.dm.JabaWsParamSet;
31 import jalview.ws.jws2.jabaws2.Jws2Instance;
32 import jalview.ws.params.ArgumentI;
33 import jalview.ws.params.WsParamSetI;
34 import jalview.ws.uimodel.AlignAnalysisUIText;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.util.List;
40 import javax.swing.JCheckBoxMenuItem;
41 import javax.swing.JMenu;
42 import javax.swing.JMenuItem;
43 import javax.swing.event.MenuEvent;
44 import javax.swing.event.MenuListener;
47 * provides metadata for a jabaws2 service instance - resolves names, etc.
52 public abstract class Jws2Client extends jalview.ws.WSClient
54 public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset,
55 List<ArgumentI> arguments)
57 super(_alignFrame, preset, arguments);
60 if (!((preset instanceof JabaPreset)
61 || preset instanceof JabaWsParamSet))
64 * { this.preset = ((JabaPreset) preset).p; } else if (preset instanceof
65 * JabaWsParamSet) { List<Argument> newargs = new ArrayList<Argument>();
66 * JabaWsParamSet pset = ((JabaWsParamSet) preset); for (Option opt :
67 * pset.getjabaArguments()) { newargs.add(opt); } if (arguments != null
68 * && arguments.size() > 0) { // merge arguments with preset's own
69 * arguments. for (Argument opt : arguments) { newargs.add(opt); } }
70 * paramset = newargs; } else {
72 throw new Error(MessageManager.getString(
73 "error.implementation_error_can_only_instantiate_jaba_param_sets"));
78 // TODO: verify that paramset is compatible with the service being
85 // anonymous constructor - used for headless method calls only
89 * Jws2Instance serviceHandle; (non-Javadoc)
91 * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
92 * jalview.gui.AlignFrame)
94 * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
95 * alignFrame) { if (serviceHandle==null) { throw new
96 * Error("Implementation error: No service handle for this Jws2 service."); }
97 * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
100 * add the menu item for a particular jws2 service instance
106 abstract void attachWSMenuEntry(JMenu wsmenu,
107 final ServiceWithParameters service,
108 final AlignFrame alignFrame);
110 static boolean registerAAConWSInstance(final JMenu wsmenu,
111 final ServiceWithParameters service, final AlignFrame alignFrame)
113 Jws2Instance jaba_service = (Jws2Instance) service;
114 final AlignAnalysisUIText aaui = jaba_service.getAlignAnalysisUI(); // null ; //
115 // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
118 // not an instantaneous calculation GUI type service
121 // create the instaneous calculation GUI bits and update state if existing
122 // GUI elements already present
124 JCheckBoxMenuItem _aaConEnabled = null;
125 for (int i = 0; i < wsmenu.getItemCount(); i++)
127 JMenuItem item = wsmenu.getItem(i);
128 if (item instanceof JCheckBoxMenuItem
129 && item.getText().equals(aaui.getAAconToggle()))
131 _aaConEnabled = (JCheckBoxMenuItem) item;
134 // is there an aaCon worker already present - if so, set it to use the
135 // given service handle
137 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
139 .getRegisteredWorkersOfClass(aaui.getClient());
140 if (aaconClient != null && aaconClient.size() > 0)
142 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
144 if (!worker.service.getHostURL().equals(service.getHostURL()))
146 // javax.swing.SwingUtilities.invokeLater(new Runnable()
151 removeCurrentAAConWorkerFor(aaui, alignFrame);
152 buildCurrentAAConWorkerFor(aaui, alignFrame, jaba_service);
159 // is there a service already registered ? there shouldn't be if we are
160 // being called correctly
161 if (_aaConEnabled == null)
163 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
164 aaui.getAAconToggle());
166 aaConEnabled.setToolTipText(
167 JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
168 aaConEnabled.addActionListener(new ActionListener()
171 public void actionPerformed(ActionEvent arg0)
173 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
175 .getRegisteredWorkersOfClass(aaui.getClient());
176 if (aaconClient != null && aaconClient.size() > 0)
178 removeCurrentAAConWorkerFor(aaui, alignFrame);
182 buildCurrentAAConWorkerFor(aaui, alignFrame);
188 wsmenu.add(aaConEnabled);
189 final JMenuItem modifyParams = new JMenuItem(
190 aaui.getAAeditSettings());
191 modifyParams.setToolTipText(JvSwingUtils.wrapTooltip(true,
192 aaui.getAAeditSettingsTooltip()));
193 modifyParams.addActionListener(new ActionListener()
197 public void actionPerformed(ActionEvent arg0)
199 showAAConAnnotationSettingsFor(aaui, alignFrame);
202 wsmenu.add(modifyParams);
203 wsmenu.addMenuListener(new MenuListener()
207 public void menuSelected(MenuEvent arg0)
209 // TODO: refactor to the implementing class.
210 if (alignFrame.getViewport().getAlignment().isNucleotide()
214 aaConEnabled.setEnabled(true);
215 modifyParams.setEnabled(true);
219 aaConEnabled.setEnabled(false);
220 modifyParams.setEnabled(false);
222 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
224 .getRegisteredWorkersOfClass(aaui.getClient());
225 if (aaconClient != null && aaconClient.size() > 0)
227 aaConEnabled.setSelected(true);
231 aaConEnabled.setSelected(false);
236 public void menuDeselected(MenuEvent arg0)
238 // TODO Auto-generated method stub
243 public void menuCanceled(MenuEvent arg0)
245 // TODO Auto-generated method stub
254 private static void showAAConAnnotationSettingsFor(
255 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
258 * preferred settings Whether AACon is automatically recalculated Which
259 * AACon server to use What parameters to use
261 // could actually do a class search for this too
262 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
263 .getCalcIdSettingsFor(aaui.getCalcId());
266 fave = createDefaultAAConSettings(aaui);
268 new SequenceAnnotationWSClient(fave, alignFrame, true);
272 private static void buildCurrentAAConWorkerFor(
273 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
275 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
278 private static void buildCurrentAAConWorkerFor(
279 final AlignAnalysisUIText aaui, AlignFrame alignFrame,
280 Jws2Instance service)
283 * preferred settings Whether AACon is automatically recalculated Which
284 * AACon server to use What parameters to use
286 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
287 .getCalcIdSettingsFor(aaui.getCalcId());
290 fave = createDefaultAAConSettings(aaui, service);
295 && !fave.getService().getHostURL()
296 .equals(service.getHostURL()))
298 Cache.log.debug("Changing AACon service to " + service.getHostURL()
299 + " from " + fave.getService().getHostURL());
300 fave.setService(service);
303 new SequenceAnnotationWSClient(fave, alignFrame, false);
306 private static AAConSettings createDefaultAAConSettings(
307 AlignAnalysisUIText aaui)
309 return createDefaultAAConSettings(aaui, null);
312 private static AAConSettings createDefaultAAConSettings(
313 AlignAnalysisUIText aaui, Jws2Instance service)
317 if (!service.getServiceType()
318 .equals(compbio.ws.client.Services.AAConWS.toString()))
321 "Ignoring invalid preferred service for AACon calculations (service type was "
322 + service.getServiceType() + ")");
327 // check service is actually in the list of currently avaialable
329 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
338 // get the default service for AACon
339 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
340 aaui.getServiceType());
344 // TODO raise dialog box explaining error, and/or open the JABA
347 MessageManager.getString("error.no_aacon_service_found"));
349 return new AAConSettings(true, service, null, null);
352 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
353 AlignFrame alignFrame)
355 alignFrame.getViewport().getCalcManager()
356 .removeRegisteredWorkersOfClass(aaui.getClient());