1 package jalview.ws.jws2;
3 import jalview.api.AlignCalcWorkerI;
4 import jalview.bin.Cache;
5 import jalview.gui.AlignFrame;
6 import jalview.gui.JvSwingUtils;
7 import jalview.util.MessageManager;
8 import jalview.ws.api.ServiceWithParameters;
9 import jalview.ws.jws2.dm.AAConSettings;
10 import jalview.ws.jws2.jabaws2.Jws2Instance;
11 import jalview.ws.uimodel.AlignAnalysisUIText;
13 import java.awt.event.ActionEvent;
14 import java.awt.event.ActionListener;
15 import java.util.List;
17 import javax.swing.JCheckBoxMenuItem;
18 import javax.swing.JMenu;
19 import javax.swing.JMenuItem;
20 import javax.swing.event.MenuEvent;
21 import javax.swing.event.MenuListener;
23 public class Jws2ClientFactory
25 static boolean registerAAConWSInstance(final JMenu wsmenu,
26 final ServiceWithParameters service, final AlignFrame alignFrame)
28 Jws2Instance jaba_service = (Jws2Instance) service;
29 final AlignAnalysisUIText aaui = jaba_service.getAlignAnalysisUI(); // null
31 // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
34 // not an instantaneous calculation GUI type service
37 // create the instaneous calculation GUI bits and update state if existing
38 // GUI elements already present
40 JCheckBoxMenuItem _aaConEnabled = null;
41 for (int i = 0; i < wsmenu.getItemCount(); i++)
43 JMenuItem item = wsmenu.getItem(i);
44 if (item instanceof JCheckBoxMenuItem
45 && item.getText().equals(aaui.getAAconToggle()))
47 _aaConEnabled = (JCheckBoxMenuItem) item;
50 // is there an aaCon worker already present - if so, set it to use the
51 // given service handle
53 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
55 .getRegisteredWorkersOfClass(aaui.getClient());
56 if (aaconClient != null && aaconClient.size() > 0)
58 AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
60 if (!worker.service.getHostURL().equals(service.getHostURL()))
62 // javax.swing.SwingUtilities.invokeLater(new Runnable()
67 removeCurrentAAConWorkerFor(aaui, alignFrame);
68 buildCurrentAAConWorkerFor(aaui, alignFrame, jaba_service);
75 // is there a service already registered ? there shouldn't be if we are
76 // being called correctly
77 if (_aaConEnabled == null)
79 final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
80 aaui.getAAconToggle());
82 aaConEnabled.setToolTipText(
83 JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
84 aaConEnabled.addActionListener(new ActionListener()
87 public void actionPerformed(ActionEvent arg0)
89 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
91 .getRegisteredWorkersOfClass(aaui.getClient());
92 if (aaconClient != null && aaconClient.size() > 0)
94 removeCurrentAAConWorkerFor(aaui, alignFrame);
98 buildCurrentAAConWorkerFor(aaui, alignFrame);
104 wsmenu.add(aaConEnabled);
105 final JMenuItem modifyParams = new JMenuItem(
106 aaui.getAAeditSettings());
107 modifyParams.setToolTipText(JvSwingUtils.wrapTooltip(true,
108 aaui.getAAeditSettingsTooltip()));
109 modifyParams.addActionListener(new ActionListener()
113 public void actionPerformed(ActionEvent arg0)
115 showAAConAnnotationSettingsFor(aaui, alignFrame);
118 wsmenu.add(modifyParams);
119 wsmenu.addMenuListener(new MenuListener()
123 public void menuSelected(MenuEvent arg0)
125 // TODO: refactor to the implementing class.
126 if (alignFrame.getViewport().getAlignment().isNucleotide()
130 aaConEnabled.setEnabled(true);
131 modifyParams.setEnabled(true);
135 aaConEnabled.setEnabled(false);
136 modifyParams.setEnabled(false);
138 List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
140 .getRegisteredWorkersOfClass(aaui.getClient());
141 if (aaconClient != null && aaconClient.size() > 0)
143 aaConEnabled.setSelected(true);
147 aaConEnabled.setSelected(false);
152 public void menuDeselected(MenuEvent arg0)
154 // TODO Auto-generated method stub
159 public void menuCanceled(MenuEvent arg0)
161 // TODO Auto-generated method stub
170 private static void showAAConAnnotationSettingsFor(
171 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
174 * preferred settings Whether AACon is automatically recalculated Which
175 * AACon server to use What parameters to use
177 // could actually do a class search for this too
178 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
179 .getCalcIdSettingsFor(aaui.getCalcId());
182 fave = createDefaultAAConSettings(aaui);
184 new SequenceAnnotationWSClient(fave, alignFrame, true);
188 private static void buildCurrentAAConWorkerFor(
189 final AlignAnalysisUIText aaui, AlignFrame alignFrame)
191 buildCurrentAAConWorkerFor(aaui, alignFrame, null);
194 private static void buildCurrentAAConWorkerFor(
195 final AlignAnalysisUIText aaui, AlignFrame alignFrame,
196 Jws2Instance service)
199 * preferred settings Whether AACon is automatically recalculated Which
200 * AACon server to use What parameters to use
202 AAConSettings fave = (AAConSettings) alignFrame.getViewport()
203 .getCalcIdSettingsFor(aaui.getCalcId());
206 fave = createDefaultAAConSettings(aaui, service);
210 if (service != null && !fave.getService().getHostURL()
211 .equals(service.getHostURL()))
213 Cache.log.debug("Changing AACon service to " + service.getHostURL()
214 + " from " + fave.getService().getHostURL());
215 fave.setService(service);
218 new SequenceAnnotationWSClient(fave, alignFrame, false);
221 private static AAConSettings createDefaultAAConSettings(
222 AlignAnalysisUIText aaui)
224 return createDefaultAAConSettings(aaui, null);
227 private static AAConSettings createDefaultAAConSettings(
228 AlignAnalysisUIText aaui, Jws2Instance service)
232 if (!service.getServiceType()
233 .equals(compbio.ws.client.Services.AAConWS.toString()))
236 "Ignoring invalid preferred service for AACon calculations (service type was "
237 + service.getServiceType() + ")");
242 // check service is actually in the list of currently avaialable
244 if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
253 // get the default service for AACon
254 service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
255 aaui.getServiceType());
259 // TODO raise dialog box explaining error, and/or open the JABA
262 MessageManager.getString("error.no_aacon_service_found"));
264 return new AAConSettings(true, service, null, null);
267 private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
268 AlignFrame alignFrame)
270 alignFrame.getViewport().getCalcManager()
271 .removeRegisteredWorkersOfClass(aaui.getClient());