Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.ws.jws2

File Jws2ClientFactory.java

 

Coverage histogram

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

Code metrics

42
71
12
1
298
232
37
0.52
5.92
12
3.08

Classes

Class Line # Actions
Jws2ClientFactory 26 71 37
0.25625.6%
 

Contributing tests

This file is covered by 134 tests. .

Source view

1    package jalview.ws.jws2;
2   
3    import jalview.api.AlignCalcManagerI2;
4    import jalview.api.AlignCalcWorkerI;
5    import jalview.bin.Cache;
6    import jalview.bin.Console;
7    import jalview.gui.AlignFrame;
8    import jalview.gui.JvSwingUtils;
9    import jalview.util.MessageManager;
10    import jalview.ws.api.ServiceWithParameters;
11    import jalview.ws.jws2.dm.AAConSettings;
12    import jalview.ws.jws2.jabaws2.Jws2Instance;
13    import jalview.ws.params.AutoCalcSetting;
14    import jalview.ws.uimodel.AlignAnalysisUIText;
15   
16    import java.awt.event.ActionEvent;
17    import java.awt.event.ActionListener;
18    import java.util.List;
19   
20    import javax.swing.JCheckBoxMenuItem;
21    import javax.swing.JMenu;
22    import javax.swing.JMenuItem;
23    import javax.swing.event.MenuEvent;
24    import javax.swing.event.MenuListener;
25   
 
26    public class Jws2ClientFactory
27    {
 
28  18167 toggle static boolean registerAAConWSInstance(final JMenu wsmenu,
29    final ServiceWithParameters service, final AlignFrame alignFrame)
30    {
31  18167 final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null
32    // ; //
33    // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
34  18167 if (aaui == null)
35    {
36    // not an instantaneous calculation GUI type service
37  16284 return false;
38    }
39    // create the instaneous calculation GUI bits and update state if existing
40    // GUI elements already present
41   
42  1883 JCheckBoxMenuItem _aaConEnabled = null;
43  4722 for (int i = 0; i < wsmenu.getItemCount(); i++)
44    {
45  2839 JMenuItem item = wsmenu.getItem(i);
46  2839 if (item instanceof JCheckBoxMenuItem
47    && item.getText().equals(aaui.getAAconToggle()))
48    {
49  0 _aaConEnabled = (JCheckBoxMenuItem) item;
50    }
51    }
52    // is there an aaCon worker already present - if so, set it to use the
53    // given service handle
54    {
55  1883 AlignCalcManagerI2 mger = alignFrame.getViewport()
56    .getCalcManager();
57  1883 if (mger != null)
58    {
59  1859 List<AlignCalcWorkerI> aaconClient = mger
60    .getWorkersOfClass(aaui.getClient());
61  1859 if (aaconClient != null && aaconClient.size() > 0)
62    {
63  0 SeqAnnotationServiceCalcWorker worker = (SeqAnnotationServiceCalcWorker) aaconClient
64    .get(0);
65  0 if (!worker.service.getHostURL().equals(service.getHostURL()))
66    {
67    // javax.swing.SwingUtilities.invokeLater(new Runnable()
68    {
69    // @Override
70    // public void run()
71    {
72  0 removeCurrentAAConWorkerFor(aaui, alignFrame);
73  0 buildCurrentAAConWorkerFor(aaui, alignFrame, service);
74    }
75    } // );
76    }
77    }
78    }
79    }
80   
81    // is there a service already registered ? there shouldn't be if we are
82    // being called correctly
83  1883 if (_aaConEnabled == null)
84    {
85  1883 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
86    aaui.getAAconToggle());
87   
88  1883 aaConEnabled.setToolTipText(
89    JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
90  1883 aaConEnabled.addActionListener(new ActionListener()
91    {
 
92  0 toggle @Override
93    public void actionPerformed(ActionEvent arg0)
94    {
95   
96  0 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
97    .getCalcManager()
98    .getWorkersOfClass(SeqAnnotationServiceCalcWorker.class);
99  0 if (aaconClient != null)
100    {
101  0 for (AlignCalcWorkerI worker : aaconClient)
102    {
103  0 if (((SeqAnnotationServiceCalcWorker) worker).getService()
104    .getClass().equals(aaui.getClient()))
105    {
106  0 removeCurrentAAConWorkerFor(aaui, alignFrame);
107  0 return;
108    }
109    }
110    }
111  0 buildCurrentAAConWorkerFor(aaui, alignFrame);
112    }
113   
114    });
115  1883 wsmenu.add(aaConEnabled);
116  1883 final JMenuItem modifyParams = new JMenuItem(
117    aaui.getAAeditSettings());
118  1883 modifyParams.setToolTipText(JvSwingUtils.wrapTooltip(true,
119    aaui.getAAeditSettingsTooltip()));
120  1883 modifyParams.addActionListener(new ActionListener()
121    {
122   
 
123  0 toggle @Override
124    public void actionPerformed(ActionEvent arg0)
125    {
126  0 showAAConAnnotationSettingsFor(aaui, alignFrame);
127    }
128    });
129  1883 wsmenu.add(modifyParams);
130  1883 wsmenu.addMenuListener(new MenuListener()
131    {
132   
 
133  0 toggle @Override
134    public void menuSelected(MenuEvent arg0)
135    {
136    // TODO: refactor to the implementing class.
137  0 if (alignFrame.getViewport().getAlignment().isNucleotide()
138    ? aaui.isNa()
139    : aaui.isPr())
140    {
141  0 aaConEnabled.setEnabled(true);
142  0 modifyParams.setEnabled(true);
143    }
144    else
145    {
146  0 aaConEnabled.setEnabled(false);
147  0 modifyParams.setEnabled(false);
148  0 return;
149    }
150  0 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
151    .getCalcManager()
152    .getWorkersOfClass(SeqAnnotationServiceCalcWorker.class);
153   
154  0 boolean serviceEnabled = false;
155  0 if (aaconClient != null)
156    {
157    // NB code duplicatino again!
158  0 for (AlignCalcWorkerI _worker : aaconClient)
159    {
160  0 SeqAnnotationServiceCalcWorker worker = (SeqAnnotationServiceCalcWorker) _worker;
161    // this could be cleaner ?
162  0 if (worker.hasService()
163    && aaui.getClient()
164    .equals(worker.getService().getClass()))
165    {
166  0 serviceEnabled = true;
167    }
168    }
169    }
170  0 aaConEnabled.setSelected(serviceEnabled);
171    }
172   
 
173  0 toggle @Override
174    public void menuDeselected(MenuEvent arg0)
175    {
176    // TODO Auto-generated method stub
177   
178    }
179   
 
180  0 toggle @Override
181    public void menuCanceled(MenuEvent arg0)
182    {
183    // TODO Auto-generated method stub
184   
185    }
186    });
187   
188    }
189  1883 return true;
190    }
191   
 
192  0 toggle private static void showAAConAnnotationSettingsFor(
193    final AlignAnalysisUIText aaui, AlignFrame alignFrame)
194    {
195    /*
196    * preferred settings Whether AACon is automatically recalculated Which
197    * AACon server to use What parameters to use
198    */
199    // could actually do a class search for this too
200  0 AutoCalcSetting fave = alignFrame.getViewport()
201    .getCalcIdSettingsFor(aaui.getCalcId());
202  0 if (fave == null)
203    {
204  0 fave = createDefaultAAConSettings(aaui);
205    }
206  0 new SequenceAnnotationWSClient(fave, alignFrame, true);
207   
208    }
209   
 
210  0 toggle private static void buildCurrentAAConWorkerFor(
211    final AlignAnalysisUIText aaui, AlignFrame alignFrame)
212    {
213  0 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
214    }
215   
 
216  0 toggle private static void buildCurrentAAConWorkerFor(
217    final AlignAnalysisUIText aaui, AlignFrame alignFrame,
218    ServiceWithParameters service)
219    {
220    /*
221    * preferred settings Whether AACon is automatically recalculated Which
222    * AACon server to use What parameters to use
223    */
224  0 AutoCalcSetting fave = alignFrame.getViewport()
225    .getCalcIdSettingsFor(aaui.getCalcId());
226  0 if (fave == null)
227    {
228  0 fave = createDefaultAAConSettings(aaui, service);
229    }
230    else
231    {
232  0 if (service != null && !fave.getService().getHostURL()
233    .equals(service.getHostURL()))
234    {
235  0 Console.debug("Changing AACon service to " + service.getHostURL()
236    + " from " + fave.getService().getHostURL());
237  0 fave.setService(service);
238    }
239    }
240  0 new SequenceAnnotationWSClient(fave, alignFrame, false);
241    }
242   
 
243  0 toggle private static AutoCalcSetting createDefaultAAConSettings(
244    AlignAnalysisUIText aaui)
245    {
246  0 return createDefaultAAConSettings(aaui, null);
247    }
248   
 
249  0 toggle private static AutoCalcSetting createDefaultAAConSettings(
250    AlignAnalysisUIText aaui, ServiceWithParameters service)
251    {
252  0 if (service != null)
253    {
254    // if (!service.getServiceType()
255    // .equals(compbio.ws.client.Services.AAConWS.toString()))
256    // {
257    // Console.warn(
258    // "Ignoring invalid preferred service for AACon calculations (service
259    // type was "
260    // + service.getServiceType() + ")");
261    // service = null;
262    // }
263    // else
264    {
265    // check service is actually in the list of currently avaialable
266    // services
267  0 if (!PreferredServiceRegistry.getRegistry().contains(service))
268    {
269    // it isn't ..
270  0 service = null;
271    }
272    }
273    }
274  0 if (service == null)
275    {
276    // get the default service for AACon
277  0 service = PreferredServiceRegistry.getRegistry().getPreferredServiceFor(null,
278    aaui.getServiceType());
279    }
280  0 if (service == null)
281    {
282    // TODO raise dialog box explaining error, and/or open the JABA
283    // preferences menu.
284  0 throw new Error(
285    MessageManager.getString("error.no_aacon_service_found"));
286    }
287  0 return service instanceof Jws2Instance
288    ? new AAConSettings(true, service, null, null)
289    : new AutoCalcSetting(service, null, null, true);
290    }
291   
 
292  0 toggle private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
293    AlignFrame alignFrame)
294    {
295  0 alignFrame.getViewport().getCalcManager()
296    .removeWorkersOfClass(aaui.getClient());
297    }
298    }