+ static boolean registerAAConWSInstance(final JMenu wsmenu,
+ final Jws2Instance service, final AlignFrame alignFrame)
+ {
+ final AlignAnalysisUIText aaui = service.getAlignAnalysisUI(); // null ; //
+ // AlignAnalysisUIText.aaConGUI.get(service.serviceType.toString());
+ if (aaui == null)
+ {
+ // not an instantaneous calculation GUI type service
+ return false;
+ }
+ // create the instaneous calculation GUI bits and update state if existing
+ // GUI elements already present
+
+ JCheckBoxMenuItem _aaConEnabled = null;
+ for (int i = 0; i < wsmenu.getItemCount(); i++)
+ {
+ JMenuItem item = wsmenu.getItem(i);
+ if (item instanceof JCheckBoxMenuItem
+ && item.getText().equals(aaui.getAAconToggle()))
+ {
+ _aaConEnabled = (JCheckBoxMenuItem) item;
+ }
+ }
+ // is there an aaCon worker already present - if so, set it to use the
+ // given service handle
+ {
+ List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
+ .getCalcManager()
+ .getRegisteredWorkersOfClass(aaui.getClient());
+ if (aaconClient != null && aaconClient.size() > 0)
+ {
+ AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
+ .get(0);
+ if (!worker.service.getHostURL().equals(service.getHostURL()))
+ {
+ // javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ // @Override
+ // public void run()
+ {
+ removeCurrentAAConWorkerFor(aaui, alignFrame);
+ buildCurrentAAConWorkerFor(aaui, alignFrame, service);
+ }
+ } // );
+ }
+ }
+ }
+
+ // is there a service already registered ? there shouldn't be if we are
+ // being called correctly
+ if (_aaConEnabled == null)
+ {
+ final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
+ aaui.getAAconToggle());
+
+ aaConEnabled.setToolTipText(
+ JvSwingUtils.wrapTooltip(true, aaui.getAAconToggleTooltip()));
+ aaConEnabled.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent arg0)
+ {
+ List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
+ .getCalcManager()
+ .getRegisteredWorkersOfClass(aaui.getClient());
+ if (aaconClient != null && aaconClient.size() > 0)
+ {
+ removeCurrentAAConWorkerFor(aaui, alignFrame);
+ }
+ else
+ {
+ buildCurrentAAConWorkerFor(aaui, alignFrame);
+
+ }
+ }
+
+ });
+ wsmenu.add(aaConEnabled);
+ final JMenuItem modifyParams = new JMenuItem(
+ aaui.getAAeditSettings());
+ modifyParams.setToolTipText(JvSwingUtils.wrapTooltip(true,
+ aaui.getAAeditSettingsTooltip()));
+ modifyParams.addActionListener(new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent arg0)
+ {
+ showAAConAnnotationSettingsFor(aaui, alignFrame);
+ }
+ });
+ wsmenu.add(modifyParams);
+ wsmenu.addMenuListener(new MenuListener()
+ {
+
+ @Override
+ public void menuSelected(MenuEvent arg0)
+ {
+ // TODO: refactor to the implementing class.
+ if (alignFrame.getViewport().getAlignment().isNucleotide()
+ ? aaui.isNa()
+ : aaui.isPr())
+ {
+ aaConEnabled.setEnabled(true);
+ modifyParams.setEnabled(true);
+ }
+ else
+ {
+ aaConEnabled.setEnabled(false);
+ modifyParams.setEnabled(false);
+ }
+ List<AlignCalcWorkerI> aaconClient = alignFrame.getViewport()
+ .getCalcManager()
+ .getRegisteredWorkersOfClass(aaui.getClient());
+ if (aaconClient != null && aaconClient.size() > 0)
+ {
+ aaConEnabled.setSelected(true);
+ }
+ else
+ {
+ aaConEnabled.setSelected(false);
+ }
+ }
+
+ @Override
+ public void menuDeselected(MenuEvent arg0)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void menuCanceled(MenuEvent arg0)
+ {
+ // TODO Auto-generated method stub
+
+ }
+ });
+
+ }
+ return true;
+ }
+
+ private static void showAAConAnnotationSettingsFor(
+ final AlignAnalysisUIText aaui, AlignFrame alignFrame)
+ {
+ /*
+ * preferred settings Whether AACon is automatically recalculated Which
+ * AACon server to use What parameters to use
+ */
+ // could actually do a class search for this too
+ AAConSettings fave = (AAConSettings) alignFrame.getViewport()
+ .getCalcIdSettingsFor(aaui.getCalcId());
+ if (fave == null)
+ {
+ fave = createDefaultAAConSettings(aaui);
+ }
+ new SequenceAnnotationWSClient(fave, alignFrame, true);
+
+ }
+
+ private static void buildCurrentAAConWorkerFor(
+ final AlignAnalysisUIText aaui, AlignFrame alignFrame)
+ {
+ buildCurrentAAConWorkerFor(aaui, alignFrame, null);
+ }
+
+ private static void buildCurrentAAConWorkerFor(
+ final AlignAnalysisUIText aaui, AlignFrame alignFrame,
+ Jws2Instance service)
+ {
+ /*
+ * preferred settings Whether AACon is automatically recalculated Which
+ * AACon server to use What parameters to use
+ */
+ AAConSettings fave = (AAConSettings) alignFrame.getViewport()
+ .getCalcIdSettingsFor(aaui.getCalcId());
+ if (fave == null)
+ {
+ fave = createDefaultAAConSettings(aaui, service);
+ }
+ else
+ {
+ if (service != null
+ && !fave.getService().getHostURL()
+ .equals(service.getHostURL()))
+ {
+ Cache.log.debug("Changing AACon service to " + service.getHostURL()
+ + " from " + fave.getService().getHostURL());
+ fave.setService(service);
+ }
+ }
+ new SequenceAnnotationWSClient(fave, alignFrame, false);
+ }
+
+ private static AAConSettings createDefaultAAConSettings(
+ AlignAnalysisUIText aaui)
+ {
+ return createDefaultAAConSettings(aaui, null);
+ }
+
+ private static AAConSettings createDefaultAAConSettings(
+ AlignAnalysisUIText aaui, Jws2Instance service)
+ {
+ if (service != null)
+ {
+ if (!service.getServiceType()
+ .equals(compbio.ws.client.Services.AAConWS.toString()))
+ {
+ Cache.log.warn(
+ "Ignoring invalid preferred service for AACon calculations (service type was "
+ + service.getServiceType() + ")");
+ service = null;
+ }
+ else
+ {
+ // check service is actually in the list of currently avaialable
+ // services
+ if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
+ {
+ // it isn't ..
+ service = null;
+ }
+ }
+ }
+ if (service == null)
+ {
+ // get the default service for AACon
+ service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
+ aaui.getServiceType());
+ }
+ if (service == null)
+ {
+ // TODO raise dialog box explaining error, and/or open the JABA
+ // preferences menu.
+ throw new Error(
+ MessageManager.getString("error.no_aacon_service_found"));
+ }
+ return new AAConSettings(true, service, null, null);
+ }
+
+ private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui,
+ AlignFrame alignFrame)
+ {
+ alignFrame.getViewport().getCalcManager()
+ .removeRegisteredWorkersOfClass(aaui.getClient());
+ }
+