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.jws2.dm.AAConSettings;
29 import jalview.ws.jws2.dm.JabaWsParamSet;
30 import jalview.ws.jws2.jabaws2.Jws2Instance;
31 import jalview.ws.params.ArgumentI;
32 import jalview.ws.params.WsParamSetI;
33 import jalview.ws.uimodel.AlignAnalysisUIText;
35 import java.awt.event.ActionEvent;
36 import java.awt.event.ActionListener;
37 import java.util.List;
39 import javax.swing.JCheckBoxMenuItem;
40 import javax.swing.JMenu;
41 import javax.swing.JMenuItem;
42 import javax.swing.event.MenuEvent;
43 import javax.swing.event.MenuListener;
46 * provides metadata for a jabaws2 service instance - resolves names, etc.
51 public abstract class Jws2Client extends jalview.ws.WSClient
53 public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset,
54 List<ArgumentI> arguments)
56 super(_alignFrame, preset, arguments);
59 if (!((preset instanceof JabaPreset)
60 || preset instanceof JabaWsParamSet))
63 * { this.preset = ((JabaPreset) preset).p; } else if (preset instanceof
64 * JabaWsParamSet) { List<Argument> newargs = new ArrayList<Argument>();
65 * JabaWsParamSet pset = ((JabaWsParamSet) preset); for (Option opt :
66 * pset.getjabaArguments()) { newargs.add(opt); } if (arguments != null
67 * && arguments.size() > 0) { // merge arguments with preset's own
68 * arguments. for (Argument opt : arguments) { newargs.add(opt); } }
69 * paramset = newargs; } else {
71 throw new Error(MessageManager.getString(
72 "error.implementation_error_can_only_instantiate_jaba_param_sets"));
77 // TODO: verify that paramset is compatible with the service being
84 // anonymous constructor - used for headless method calls only
88 * Jws2Instance serviceHandle; (non-Javadoc)
90 * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
91 * jalview.gui.AlignFrame)
93 * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
94 * alignFrame) { if (serviceHandle==null) { throw new
95 * Error("Implementation error: No service handle for this Jws2 service."); }
96 * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
99 * add the menu item for a particular jws2 service instance
105 abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
106 final AlignFrame alignFrame);
108 static boolean registerAAConWSInstance(final JMenu wsmenu,
109 final Jws2Instance service, final AlignFrame alignFrame)
111 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
112 // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
115 // not an instantaneous calculation GUI type service
118 // create the instaneous calculation GUI bits and update state if existing
119 // GUI elements already present
121 JCheckBoxMenuItem _aaConEnabled = null;
122 for (int i = 0; i < wsmenu.getItemCount(); i++)
124 JMenuItem item = wsmenu.getItem(i);
125 if (item instanceof JCheckBoxMenuItem
126 && item.getText().equals(aaui.getAAconToggle()))
128 _aaConEnabled = (JCheckBoxMenuItem) item;
131 // is there an aaCon worker already present - if so, set it to use the
132 // given service handle
134 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
136 .getRegisteredWorkersOfClass(aaui.getClient());
137 if (aaconClient != null && aaconClient.size() > 0)
139 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
141 if (!worker.service.getHostURL().equals(service.getHostURL()))
143 // javax.swing.SwingUtilities.invokeLater(new Runnable()
148 removeCurrentAAConWorkerFor(aaui, alignFrame);
149 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
156 // is there a service already registered ? there shouldn't be if we are
157 // being called correctly
158 if (_aaConEnabled == null)
160 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
161 aaui.getAAconToggle());
163 aaConEnabled.setToolTipText(
164 JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
165 aaConEnabled.addActionListener(new ActionListener()
168 public void actionPerformed(ActionEvent arg0)
170 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
172 .getRegisteredWorkersOfClass(aaui.getClient());
173 if (aaconClient != null && aaconClient.size() > 0)
175 removeCurrentAAConWorkerFor(aaui, alignFrame);
179 buildCurrentAAConWorkerFor(aaui, alignFrame);
185 wsmenu.add(aaConEnabled);
186 final JMenuItem modifyParams = new JMenuItem(
187 aaui.getAAeditSettings());
188 modifyParams.setToolTipText(JvSwingUtils.wrapTooltip(true,
189 aaui.getAAeditSettingsTooltip()));
190 modifyParams.addActionListener(new ActionListener()
194 public void actionPerformed(ActionEvent arg0)
196 showAAConAnnotationSettingsFor(aaui, alignFrame);
199 wsmenu.add(modifyParams);
200 wsmenu.addMenuListener(new MenuListener()
204 public void menuSelected(MenuEvent arg0)
206 // TODO: refactor to the implementing class.
207 if (alignFrame.getViewport().getAlignment().isNucleotide()
211 aaConEnabled.setEnabled(true);
212 modifyParams.setEnabled(true);
216 aaConEnabled.setEnabled(false);
217 modifyParams.setEnabled(false);
219 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
221 .getRegisteredWorkersOfClass(aaui.getClient());
222 if (aaconClient != null && aaconClient.size() > 0)
224 aaConEnabled.setSelected(true);
228 aaConEnabled.setSelected(false);
233 public void menuDeselected(MenuEvent arg0)
235 // TODO Auto-generated method stub
240 public void menuCanceled(MenuEvent arg0)
242 // TODO Auto-generated method stub
251 private static void showAAConAnnotationSettingsFor(
252 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
255 * preferred settings Whether AACon is automatically recalculated Which
256 * AACon server to use What parameters to use
258 // could actually do a class search for this too
259 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
260 .getCalcIdSettingsFor(aaui.getCalcId());
263 fave = createDefaultAAConSettings(aaui);
265 new SequenceAnnotationWSClient(fave, alignFrame, true);
269 private static void buildCurrentAAConWorkerFor(
270 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
272 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
275 private static void buildCurrentAAConWorkerFor(
276 final AlignAnalysisUIText aaui, AlignFrame alignFrame,
277 Jws2Instance service)
280 * preferred settings Whether AACon is automatically recalculated Which
281 * AACon server to use What parameters to use
283 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
284 .getCalcIdSettingsFor(aaui.getCalcId());
287 fave = createDefaultAAConSettings(aaui, service);
292 && !fave.getService().getHostURL()
293 .equals(service.getHostURL()))
295 Cache.log.debug("Changing AACon service to " + service.getHostURL()
296 + " from " + fave.getService().getHostURL());
297 fave.setService(service);
300 new SequenceAnnotationWSClient(fave, alignFrame, false);
303 private static AAConSettings createDefaultAAConSettings(
304 AlignAnalysisUIText aaui)
306 return createDefaultAAConSettings(aaui, null);
309 private static AAConSettings createDefaultAAConSettings(
310 AlignAnalysisUIText aaui, Jws2Instance service)
314 if (!service.getServiceType()
315 .equals(compbio.ws.client.Services.AAConWS.toString()))
318 "Ignoring invalid preferred service for AACon calculations (service type was "
319 + service.getServiceType() + ")");
324 // check service is actually in the list of currently avaialable
326 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
335 // get the default service for AACon
336 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
337 aaui.getServiceType());
341 // TODO raise dialog box explaining error, and/or open the JABA
344 MessageManager.getString("error.no_aacon_service_found"));
346 return new AAConSettings(true, service, null, null);
349 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
350 AlignFrame alignFrame)
352 alignFrame.getViewport().getCalcManager()
353 .removeRegisteredWorkersOfClass(aaui.getClient());