Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.ws.jws2

File Jws2Client.java

 

Coverage histogram

../../../img/srcFileCovDistChart3.png
52% of files have more coverage

Code metrics

56
93
17
1
431
309
53
0.57
5.47
17
3.12

Classes

Class Line # Actions
Jws2Client 54 93 53
0.2228915722.3%
 

Contributing tests

This file is covered by 166 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.ws.jws2;
22   
23    import java.awt.event.ActionEvent;
24    import java.awt.event.ActionListener;
25    import java.util.List;
26   
27    import javax.swing.JCheckBoxMenuItem;
28    import javax.swing.JMenu;
29    import javax.swing.JMenuItem;
30    import javax.swing.event.MenuEvent;
31    import javax.swing.event.MenuListener;
32   
33    import compbio.metadata.Argument;
34    import jalview.api.AlignCalcWorkerI;
35    import jalview.bin.Console;
36    import jalview.gui.AlignFrame;
37    import jalview.gui.Desktop;
38    import jalview.gui.JvSwingUtils;
39    import jalview.gui.WebserviceInfo;
40    import jalview.gui.WsJobParameters;
41    import jalview.util.MessageManager;
42    import jalview.ws.jws2.dm.AAConSettings;
43    import jalview.ws.jws2.dm.JabaWsParamSet;
44    import jalview.ws.jws2.jabaws2.Jws2Instance;
45    import jalview.ws.params.WsParamSetI;
46    import jalview.ws.uimodel.AlignAnalysisUIText;
47   
48    /**
49    * provides metadata for a jabaws2 service instance - resolves names, etc.
50    *
51    * @author JimP
52    *
53    */
 
54    public abstract class Jws2Client extends jalview.ws.WSClient
55    {
56    protected AlignFrame alignFrame;
57   
58    protected WsParamSetI preset;
59   
60    protected List<Argument> paramset;
61   
 
62  0 toggle public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset,
63    List<Argument> arguments)
64    {
65  0 alignFrame = _alignFrame;
66  0 this.preset = preset;
67  0 if (preset != null)
68    {
69  0 if (!((preset instanceof JabaPreset)
70    || preset instanceof JabaWsParamSet))
71    {
72    /*
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 {
80    */
81  0 throw new Error(MessageManager.getString(
82    "error.implementation_error_can_only_instantiate_jaba_param_sets"));
83    }
84    }
85    else
86    {
87    // just provided with a bunch of arguments
88  0 this.paramset = arguments;
89    }
90    }
91   
 
92  0 toggle boolean processParams(Jws2Instance sh, boolean editParams)
93    {
94  0 return processParams(sh, editParams, false);
95    }
96   
 
97  0 toggle protected boolean processParams(Jws2Instance sh, boolean editParams,
98    boolean adjustingExisting)
99    {
100   
101  0 if (editParams)
102    {
103  0 if (sh.paramStore == null)
104    {
105  0 sh.paramStore = new JabaParamStore(sh,
106    Desktop.getUserParameterStore());
107    }
108  0 WsJobParameters jobParams = (preset == null && paramset != null
109    && paramset.size() > 0)
110    ? new WsJobParameters(null, sh, null, paramset)
111    : new WsJobParameters(sh, preset);
112  0 if (adjustingExisting)
113    {
114  0 jobParams.setName(MessageManager
115    .getString("label.adjusting_parameters_for_calculation"));
116    }
117  0 if (!jobParams.showRunDialog())
118    {
119  0 return false;
120    }
121  0 WsParamSetI prset = jobParams.getPreset();
122  0 if (prset == null)
123    {
124  0 paramset =
125    /* JAL-3739 always take values from input form */
126    /* jobParams.isServiceDefaults() ? null : */
127    JabaParamStore.getJabafromJwsArgs(jobParams.getJobParams());
128  0 this.preset = null;
129    }
130    else
131    {
132  0 this.preset = prset; // ((JabaPreset) prset).p;
133  0 paramset = null; // no user supplied parameters.
134    }
135    }
136  0 return true;
137   
138    }
139   
 
140  4629 toggle public Jws2Client()
141    {
142    // anonymous constructor - used for headless method calls only
143    }
144   
 
145  4389 toggle protected WebserviceInfo setWebService(Jws2Instance serv, boolean b)
146    {
147    // serviceHandle = serv;
148  4389 String serviceInstance = serv.action; // serv.service.getClass().getName();
149  4389 WebServiceName = serv.serviceType;
150  4389 WebServiceJobTitle = serv.getActionText();
151  4389 WsURL = serv.hosturl;
152  4389 if (!b)
153    {
154  0 return new WebserviceInfo(WebServiceJobTitle,
155    WebServiceJobTitle + " using service hosted at "
156    + serv.hosturl + "\n"
157  0 + (serv.description != null ? serv.description : ""),
158    false);
159    }
160  4389 return null;
161    }
162   
163    /*
164    * Jws2Instance serviceHandle; (non-Javadoc)
165    *
166    * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
167    * jalview.gui.AlignFrame)
168    *
169    * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
170    * alignFrame) { if (serviceHandle==null) { throw new
171    * Error("Implementation error: No service handle for this Jws2 service."); }
172    * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
173    */
174    /**
175    * add the menu item for a particular jws2 service instance
176    *
177    * @param wsmenu
178    * @param service
179    * @param alignFrame
180    */
181    abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
182    final AlignFrame alignFrame);
183   
 
184  4629 toggle protected boolean registerAAConWSInstance(final JMenu wsmenu,
185    final Jws2Instance service, final AlignFrame alignFrame)
186    {
187  4629 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
188    // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
189  4629 if (aaui == null)
190    {
191    // not an instantaneous calculation GUI type service
192  4542 return false;
193    }
194    // create the instaneous calculation GUI bits and update state if existing
195    // GUI elements already present
196   
197  87 JCheckBoxMenuItem _aaConEnabled = null;
198  261 for (int i = 0; i < wsmenu.getItemCount(); i++)
199    {
200  174 JMenuItem item = wsmenu.getItem(i);
201  174 if (item instanceof JCheckBoxMenuItem
202    && item.getText().equals(aaui.getAAconToggle()))
203    {
204  0 _aaConEnabled = (JCheckBoxMenuItem) item;
205    }
206    }
207    // is there an aaCon worker already present - if so, set it to use the
208    // given service handle
209    {
210  87 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
211    .getCalcManager()
212    .getRegisteredWorkersOfClass(aaui.getClient());
213  81 if (aaconClient != null && aaconClient.size() > 0)
214    {
215  0 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
216    .get(0);
217  0 if (!worker.service.hosturl.equals(service.hosturl))
218    {
219    // javax.swing.SwingUtilities.invokeLater(new Runnable()
220    {
221    // @Override
222    // public void run()
223    {
224  0 removeCurrentAAConWorkerFor(aaui, alignFrame);
225  0 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
226    }
227    } // );
228    }
229    }
230    }
231   
232    // is there a service already registered ? there shouldn't be if we are
233    // being called correctly
234  81 if (_aaConEnabled == null)
235    {
236  81 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
237    aaui.getAAconToggle());
238   
239  81 aaConEnabled.setToolTipText(
240    JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
241  81 aaConEnabled.addActionListener(new ActionListener()
242    {
 
243  0 toggle @Override
244    public void actionPerformed(ActionEvent arg0)
245    {
246  0 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
247    .getCalcManager()
248    .getRegisteredWorkersOfClass(aaui.getClient());
249  0 if (aaconClient != null && aaconClient.size() > 0)
250    {
251  0 removeCurrentAAConWorkerFor(aaui, alignFrame);
252    }
253    else
254    {
255  0 buildCurrentAAConWorkerFor(aaui, alignFrame);
256   
257    }
258    }
259   
260    });
261  81 wsmenu.add(aaConEnabled);
262  81 final JMenuItem modifyParams = new JMenuItem(
263    aaui.getAAeditSettings());
264  81 modifyParams.setToolTipText(JvSwingUtils.wrapTooltip(true,
265    aaui.getAAeditSettingsTooltip()));
266  81 modifyParams.addActionListener(new ActionListener()
267    {
268   
 
269  0 toggle @Override
270    public void actionPerformed(ActionEvent arg0)
271    {
272  0 showAAConAnnotationSettingsFor(aaui, alignFrame);
273    }
274    });
275  81 wsmenu.add(modifyParams);
276  81 wsmenu.addMenuListener(new MenuListener()
277    {
278   
 
279  0 toggle @Override
280    public void menuSelected(MenuEvent arg0)
281    {
282    // TODO: refactor to the implementing class.
283  0 if (alignFrame.getViewport().getAlignment().isNucleotide()
284    ? aaui.isNa()
285    : aaui.isPr())
286    {
287  0 aaConEnabled.setEnabled(true);
288  0 modifyParams.setEnabled(true);
289    }
290    else
291    {
292  0 aaConEnabled.setEnabled(false);
293  0 modifyParams.setEnabled(false);
294    }
295  0 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
296    .getCalcManager()
297    .getRegisteredWorkersOfClass(aaui.getClient());
298  0 if (aaconClient != null && aaconClient.size() > 0)
299    {
300  0 aaConEnabled.setSelected(true);
301    }
302    else
303    {
304  0 aaConEnabled.setSelected(false);
305    }
306    }
307   
 
308  0 toggle @Override
309    public void menuDeselected(MenuEvent arg0)
310    {
311    // TODO Auto-generated method stub
312   
313    }
314   
 
315  0 toggle @Override
316    public void menuCanceled(MenuEvent arg0)
317    {
318    // TODO Auto-generated method stub
319   
320    }
321    });
322   
323    }
324  81 return true;
325    }
326   
 
327  0 toggle private static void showAAConAnnotationSettingsFor(
328    final AlignAnalysisUIText aaui, AlignFrame alignFrame)
329    {
330    /*
331    * preferred settings Whether AACon is automatically recalculated Which
332    * AACon server to use What parameters to use
333    */
334    // could actually do a class search for this too
335  0 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
336    .getCalcIdSettingsFor(aaui.getCalcId());
337  0 if (fave == null)
338    {
339  0 fave = createDefaultAAConSettings(aaui);
340    }
341  0 new SequenceAnnotationWSClient(fave, alignFrame, true);
342   
343    }
344   
 
345  0 toggle private static void buildCurrentAAConWorkerFor(
346    final AlignAnalysisUIText aaui, AlignFrame alignFrame)
347    {
348  0 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
349    }
350   
 
351  0 toggle private static void buildCurrentAAConWorkerFor(
352    final AlignAnalysisUIText aaui, AlignFrame alignFrame,
353    Jws2Instance service)
354    {
355    /*
356    * preferred settings Whether AACon is automatically recalculated Which
357    * AACon server to use What parameters to use
358    */
359  0 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
360    .getCalcIdSettingsFor(aaui.getCalcId());
361  0 if (fave == null)
362    {
363  0 fave = createDefaultAAConSettings(aaui, service);
364    }
365    else
366    {
367  0 if (service != null
368    && !fave.getService().hosturl.equals(service.hosturl))
369    {
370  0 Console.debug("Changing AACon service to " + service.hosturl
371    + " from " + fave.getService().hosturl);
372  0 fave.setService(service);
373    }
374    }
375  0 new SequenceAnnotationWSClient(fave, alignFrame, false);
376    }
377   
 
378  0 toggle private static AAConSettings createDefaultAAConSettings(
379    AlignAnalysisUIText aaui)
380    {
381  0 return createDefaultAAConSettings(aaui, null);
382    }
383   
 
384  0 toggle private static AAConSettings createDefaultAAConSettings(
385    AlignAnalysisUIText aaui, Jws2Instance service)
386    {
387  0 if (service != null)
388    {
389  0 if (!service.serviceType.toString()
390    .equals(compbio.ws.client.Services.AAConWS.toString()))
391    {
392  0 Console.warn(
393    "Ignoring invalid preferred service for AACon calculations (service type was "
394    + service.serviceType + ")");
395  0 service = null;
396    }
397    else
398    {
399    // check service is actually in the list of currently avaialable
400    // services
401  0 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
402    {
403    // it isn't ..
404  0 service = null;
405    }
406    }
407    }
408  0 if (service == null)
409    {
410    // get the default service for AACon
411  0 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
412    aaui.getServiceType());
413    }
414  0 if (service == null)
415    {
416    // TODO raise dialog box explaining error, and/or open the JABA
417    // preferences menu.
418  0 throw new Error(
419    MessageManager.getString("error.no_aacon_service_found"));
420    }
421  0 return new AAConSettings(true, service, null, null);
422    }
423   
 
424  0 toggle private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
425    AlignFrame alignFrame)
426    {
427  0 alignFrame.getViewport().getCalcManager()
428    .removeRegisteredWorkersOfClass(aaui.getClient());
429    }
430   
431    }