X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fws%2Fjws2%2FJws2Client.java;h=0f1a25e6fc1e8907c51e3093346d026483a5d894;hb=b19bd11f40441f651012d161f2e61ee7d45a5208;hp=4166d3eb07b427a79b9254293b62b4c5082fb8bd;hpb=59d682209891099d46b960509907c79e3fb276fe;p=jalview.git
diff --git a/src/jalview/ws/jws2/Jws2Client.java b/src/jalview/ws/jws2/Jws2Client.java
index 4166d3e..0f1a25e 100644
--- a/src/jalview/ws/jws2/Jws2Client.java
+++ b/src/jalview/ws/jws2/Jws2Client.java
@@ -1,35 +1,50 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.ws.jws2;
-import java.util.List;
-
-import javax.swing.JMenu;
-
-import compbio.metadata.Argument;
-
+import jalview.api.AlignCalcWorkerI;
+import jalview.bin.Cache;
import jalview.gui.AlignFrame;
import jalview.gui.Desktop;
+import jalview.gui.JvSwingUtils;
import jalview.gui.WebserviceInfo;
import jalview.gui.WsJobParameters;
+import jalview.util.MessageManager;
+import jalview.ws.jws2.dm.AAConSettings;
import jalview.ws.jws2.dm.JabaWsParamSet;
import jalview.ws.jws2.jabaws2.Jws2Instance;
import jalview.ws.params.WsParamSetI;
+import jalview.ws.uimodel.AlignAnalysisUIText;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.List;
+
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.event.MenuEvent;
+import javax.swing.event.MenuListener;
+
+import compbio.metadata.Argument;
/**
* provides metadata for a jabaws2 service instance - resolves names, etc.
@@ -52,7 +67,8 @@ public abstract class Jws2Client extends jalview.ws.WSClient
this.preset = preset;
if (preset != null)
{
- if (!((preset instanceof JabaPreset) || preset instanceof JabaWsParamSet))
+ if (!((preset instanceof JabaPreset)
+ || preset instanceof JabaWsParamSet))
{
/*
* { this.preset = ((JabaPreset) preset).p; } else if (preset instanceof
@@ -63,8 +79,8 @@ public abstract class Jws2Client extends jalview.ws.WSClient
* arguments. for (Argument opt : arguments) { newargs.add(opt); } }
* paramset = newargs; } else {
*/
- throw new Error(
- "Implementation error: Can only instantiate Jaba parameter sets.");
+ throw new Error(MessageManager.getString(
+ "error.implementation_error_can_only_instantiate_jaba_param_sets"));
}
}
else
@@ -90,12 +106,14 @@ public abstract class Jws2Client extends jalview.ws.WSClient
sh.paramStore = new JabaParamStore(sh,
Desktop.getUserParameterStore());
}
- WsJobParameters jobParams = (preset == null && paramset != null && paramset
- .size() > 0) ? new WsJobParameters(null, sh, null, paramset)
- : new WsJobParameters(sh, preset);
+ WsJobParameters jobParams = (preset == null && paramset != null
+ && paramset.size() > 0)
+ ? new WsJobParameters(null, sh, null, paramset)
+ : new WsJobParameters(sh, preset);
if (adjustingExisting)
{
- jobParams.setName("Adjusting parameters for existing Calculation");
+ jobParams.setName(MessageManager
+ .getString("label.adjusting_parameters_for_calculation"));
}
if (!jobParams.showRunDialog())
{
@@ -104,8 +122,9 @@ public abstract class Jws2Client extends jalview.ws.WSClient
WsParamSetI prset = jobParams.getPreset();
if (prset == null)
{
- paramset = jobParams.isServiceDefaults() ? null : JabaParamStore
- .getJabafromJwsArgs(jobParams.getJobParams());
+ paramset = jobParams.isServiceDefaults() ? null
+ : JabaParamStore
+ .getJabafromJwsArgs(jobParams.getJobParams());
this.preset = null;
}
else
@@ -132,9 +151,11 @@ public abstract class Jws2Client extends jalview.ws.WSClient
WsURL = serv.hosturl;
if (!b)
{
- return new WebserviceInfo(WebServiceJobTitle, WebServiceJobTitle
- + " using service hosted at " + serv.hosturl + "\n"
- + (serv.description != null ? serv.description : ""));
+ return new WebserviceInfo(WebServiceJobTitle,
+ WebServiceJobTitle + " using service hosted at "
+ + serv.hosturl + "\n"
+ + (serv.description != null ? serv.description : ""),
+ false);
}
return null;
}
@@ -160,4 +181,251 @@ public abstract class Jws2Client extends jalview.ws.WSClient
abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
final AlignFrame alignFrame);
+ protected 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 aaconClient = alignFrame.getViewport()
+ .getCalcManager()
+ .getRegisteredWorkersOfClass(aaui.getClient());
+ if (aaconClient != null && aaconClient.size() > 0)
+ {
+ AbstractJabaCalcWorker worker = (AbstractJabaCalcWorker) aaconClient
+ .get(0);
+ if (!worker.service.hosturl.equals(service.hosturl))
+ {
+ // 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 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 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().hosturl.equals(service.hosturl))
+ {
+ Cache.log.debug("Changing AACon service to " + service.hosturl
+ + " from " + fave.getService().hosturl);
+ 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.serviceType.toString()
+ .equals(compbio.ws.client.Services.AAConWS.toString()))
+ {
+ Cache.log.warn(
+ "Ignoring invalid preferred service for AACon calculations (service type was "
+ + service.serviceType + ")");
+ 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());
+ }
+
}