From 86548f0e8aa9f296ff246e328d25cc166e3ed4d7 Mon Sep 17 00:00:00 2001
From: Jim Procter
Date: Wed, 25 Sep 2013 16:33:41 +0100
Subject: [PATCH] JAL-1365 unified GUI building for AACon and RNAAliFold
service clients
---
.../ws/jws2/SequenceAnnotationWSClient.java | 159 ++++++++------------
1 file changed, 63 insertions(+), 96 deletions(-)
diff --git a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java
index eecefd9..cca6af3 100644
--- a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java
+++ b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java
@@ -25,6 +25,7 @@ import jalview.gui.JvSwingUtils;
import jalview.ws.jws2.dm.AAConSettings;
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;
@@ -43,9 +44,6 @@ import javax.swing.event.MenuListener;
*/
public class SequenceAnnotationWSClient extends Jws2Client
{
-
- public static final String AAConCalcId = "jabaws2.AACon";
-
/**
* initialise a client so its attachWSMenuEntry method can be called.
*/
@@ -75,33 +73,45 @@ public class SequenceAnnotationWSClient extends Jws2Client
// return;
//
// }
- if (sh.action.toLowerCase().contains("conservation"))
+ AlignAnalysisUIText aaui = sh.getAlignAnalysisUI();
+ if (aaui!=null)
{
+ Class clientClass = aaui.getClient();
+
// Build an AACon style client - take alignment, return annotation for
// columns
List clnts = alignFrame.getViewport()
.getCalcManager()
- .getRegisteredWorkersOfClass(AAConClient.class);
+ .getRegisteredWorkersOfClass(clientClass);
+ JabawsAlignCalcWorker worker;
if (clnts == null || clnts.size() == 0)
{
if (!processParams(sh, editParams))
{
return;
}
- AAConClient worker;
+ try {
+ worker = (JabawsAlignCalcWorker) (clientClass.getConstructor(
+ new Class[] { Jws2Instance.class,
+ AlignFrame.class, WsParamSetI.class,
+ List.class }).newInstance(new Object[] { sh, alignFrame, this.preset, paramset}));
+ } catch (Exception x)
+ {
+ x.printStackTrace();
+ throw new Error("Implementation error",x);
+ }
alignFrame
.getViewport()
.getCalcManager()
.registerWorker(
- worker = new AAConClient(sh, alignFrame,
- this.preset, paramset));
+ worker);
alignFrame.getViewport().getCalcManager().startWorker(worker);
}
else
{
- AAConClient worker = (AAConClient) clnts.get(0);
+ worker = (JabawsAlignCalcWorker) clnts.get(0);
if (editParams)
{
paramset = worker.getArguments();
@@ -116,7 +126,6 @@ public class SequenceAnnotationWSClient extends Jws2Client
// invalid parameters)
alignFrame.getViewport().getCalcManager().workerMayRun(worker);
worker.updateParameters(this.preset, paramset);
-
}
}
if (sh.action.toLowerCase().contains("disorder"))
@@ -134,51 +143,6 @@ public class SequenceAnnotationWSClient extends Jws2Client
.startWorker(
new AADisorderClient(sh, alignFrame, preset, paramset));
}
-
-
- // dan test dan changed!
- if (sh.action.toLowerCase().contains("rna structure prediction"))
- {
-
- List clnts = alignFrame.getViewport()
- .getCalcManager()
- .getRegisteredWorkersOfClass(RNAalifoldClient.class);
- if (clnts == null || clnts.size() == 0)
- {
- if (!processParams(sh, editParams))
- {
- return;
- }
- RNAalifoldClient worker;
- alignFrame
- .getViewport()
- .getCalcManager()
- .registerWorker(
- worker = new RNAalifoldClient(sh, alignFrame,
- this.preset, paramset));
- alignFrame.getViewport().getCalcManager().startWorker(worker);
- }
- else
- {
- RNAalifoldClient worker = (RNAalifoldClient) clnts.get(0);
- if (editParams)
- {
- paramset = worker.getArguments();
- preset = worker.getPreset();
- }
-
- if (!processParams(sh, editParams, true))
- {
- return;
- }
-
- // reinstate worker if it was blacklisted (might have happened due to
- // invalid parameters)
- alignFrame.getViewport().getCalcManager().workerMayRun(worker);
- worker.updateParameters(this.preset, paramset);
- }
-
- }
}
public SequenceAnnotationWSClient(AAConSettings fave,
@@ -198,10 +162,8 @@ public class SequenceAnnotationWSClient extends Jws2Client
public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
final AlignFrame alignFrame)
{
- if (service.serviceType.equals(compbio.ws.client.Services.AAConWS
- .toString()))
- {
- registerAAConWSInstance(wsmenu, service, alignFrame);
+ if (registerAAConWSInstance(wsmenu, service, alignFrame)) {
+ // Alignment dependent analysis calculation WS gui
return;
}
boolean hasparams = service.hasParameters();
@@ -287,21 +249,24 @@ public class SequenceAnnotationWSClient extends Jws2Client
}
}
- private final String AAconToggle = "AACon Calculations",
- AAconToggleTooltip = "When checked, AACon calculations are updated automatically.",
- AAeditSettings = "Change AACon Settings...",
- AAeditSettingsTooltip = "Modify settings for AACon calculations.";
-
- private void registerAAConWSInstance(final JMenu wsmenu,
+
+ private boolean registerAAConWSInstance(final JMenu wsmenu,
final Jws2Instance service, final AlignFrame alignFrame)
{
- // register this in the AACon settings set
+ 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(AAconToggle))
+ && item.getText().equals(aaui.getAAconToggle()))
{
_aaConEnabled = (JCheckBoxMenuItem) item;
}
@@ -311,10 +276,10 @@ public class SequenceAnnotationWSClient extends Jws2Client
{
List aaconClient = alignFrame.getViewport()
.getCalcManager()
- .getRegisteredWorkersOfClass(AAConClient.class);
+ .getRegisteredWorkersOfClass(aaui.getClient());
if (aaconClient != null && aaconClient.size() > 0)
{
- AAConClient worker = (AAConClient) aaconClient.get(0);
+ JabawsAlignCalcWorker worker = (JabawsAlignCalcWorker) aaconClient.get(0);
if (!worker.service.hosturl.equals(service.hosturl))
{
// javax.swing.SwingUtilities.invokeLater(new Runnable()
@@ -322,8 +287,8 @@ public class SequenceAnnotationWSClient extends Jws2Client
// @Override
// public void run()
{
- removeCurrentAAConWorkerFor(alignFrame);
- buildCurrentAAConWorkerFor(alignFrame, service);
+ removeCurrentAAConWorkerFor(aaui, alignFrame);
+ buildCurrentAAConWorkerFor(aaui, alignFrame, service);
}
}// );
}
@@ -335,18 +300,19 @@ public class SequenceAnnotationWSClient extends Jws2Client
if (_aaConEnabled == null)
{
final JCheckBoxMenuItem aaConEnabled = new JCheckBoxMenuItem(
- AAconToggle);
+ aaui.getAAconToggle());
wsmenu.addMenuListener(new MenuListener()
{
@Override
public void menuSelected(MenuEvent arg0)
{
- wsmenu.setEnabled(!alignFrame.getViewport().getAlignment()
- .isNucleotide());
+ // TODO: refactor to the implementing class.
+ wsmenu.setEnabled((alignFrame.getViewport().getAlignment()
+ .isNucleotide() ? aaui.isNa() : aaui.isPr()));
List aaconClient = alignFrame.getViewport()
.getCalcManager()
- .getRegisteredWorkersOfClass(AAConClient.class);
+ .getRegisteredWorkersOfClass(aaui.getClient());
if (aaconClient != null && aaconClient.size() > 0)
{
aaConEnabled.setSelected(true);
@@ -372,7 +338,7 @@ public class SequenceAnnotationWSClient extends Jws2Client
}
});
aaConEnabled.setToolTipText(""
- + JvSwingUtils.wrapTooltip(AAconToggleTooltip + "
")
+ + JvSwingUtils.wrapTooltip(aaui.getAAconToggleTooltip() + "
")
+ "");
aaConEnabled.addActionListener(new ActionListener()
{
@@ -381,23 +347,23 @@ public class SequenceAnnotationWSClient extends Jws2Client
{
List aaconClient = alignFrame.getViewport()
.getCalcManager()
- .getRegisteredWorkersOfClass(AAConClient.class);
+ .getRegisteredWorkersOfClass(aaui.getClient());
if (aaconClient != null && aaconClient.size() > 0)
{
- removeCurrentAAConWorkerFor(alignFrame);
+ removeCurrentAAConWorkerFor(aaui, alignFrame);
}
else
{
- buildCurrentAAConWorkerFor(alignFrame);
+ buildCurrentAAConWorkerFor(aaui, alignFrame);
}
}
});
wsmenu.add(aaConEnabled);
- JMenuItem modifyParams = new JMenuItem(AAeditSettings);
+ JMenuItem modifyParams = new JMenuItem(aaui.getAAeditSettings());
modifyParams.setToolTipText(""
- + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "
")
+ + JvSwingUtils.wrapTooltip(aaui.getAAeditSettingsTooltip() + "")
+ "");
modifyParams.addActionListener(new ActionListener()
{
@@ -405,15 +371,16 @@ public class SequenceAnnotationWSClient extends Jws2Client
@Override
public void actionPerformed(ActionEvent arg0)
{
- showAAConAnnotationSettingsFor(alignFrame);
+ showAAConAnnotationSettingsFor(aaui, alignFrame);
}
});
wsmenu.add(modifyParams);
}
+ return true;
}
- private static void showAAConAnnotationSettingsFor(AlignFrame alignFrame)
+ private static void showAAConAnnotationSettingsFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
{
/*
* preferred settings Whether AACon is automatically recalculated Which
@@ -421,21 +388,21 @@ public class SequenceAnnotationWSClient extends Jws2Client
*/
// could actually do a class search for this too
AAConSettings fave = (AAConSettings) alignFrame.getViewport()
- .getCalcIdSettingsFor(AAConCalcId);
+ .getCalcIdSettingsFor(aaui.getCalcId());
if (fave == null)
{
- fave = createDefaultAAConSettings();
+ fave = createDefaultAAConSettings(aaui);
}
new SequenceAnnotationWSClient(fave, alignFrame, true);
}
- private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame)
+ private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame)
{
- buildCurrentAAConWorkerFor(alignFrame, null);
+ buildCurrentAAConWorkerFor(aaui, alignFrame, null);
}
- private static void buildCurrentAAConWorkerFor(AlignFrame alignFrame,
+ private static void buildCurrentAAConWorkerFor(final AlignAnalysisUIText aaui, AlignFrame alignFrame,
Jws2Instance service)
{
/*
@@ -443,10 +410,10 @@ public class SequenceAnnotationWSClient extends Jws2Client
* AACon server to use What parameters to use
*/
AAConSettings fave = (AAConSettings) alignFrame.getViewport()
- .getCalcIdSettingsFor(AAConCalcId);
+ .getCalcIdSettingsFor(aaui.getCalcId());
if (fave == null)
{
- fave = createDefaultAAConSettings(service);
+ fave = createDefaultAAConSettings(aaui, service);
}
else
{
@@ -461,12 +428,12 @@ public class SequenceAnnotationWSClient extends Jws2Client
new SequenceAnnotationWSClient(fave, alignFrame, false);
}
- private static AAConSettings createDefaultAAConSettings()
+ private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui)
{
- return createDefaultAAConSettings(null);
+ return createDefaultAAConSettings(aaui, null);
}
- private static AAConSettings createDefaultAAConSettings(
+ private static AAConSettings createDefaultAAConSettings(AlignAnalysisUIText aaui,
Jws2Instance service)
{
if (service != null)
@@ -494,7 +461,7 @@ public class SequenceAnnotationWSClient extends Jws2Client
{
// get the default service for AACon
service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
- compbio.ws.client.Services.AAConWS.toString());
+ aaui.getServiceType());
}
if (service == null)
{
@@ -505,9 +472,9 @@ public class SequenceAnnotationWSClient extends Jws2Client
return new AAConSettings(true, service, null, null);
}
- private static void removeCurrentAAConWorkerFor(AlignFrame alignFrame)
+ private static void removeCurrentAAConWorkerFor(AlignAnalysisUIText aaui, AlignFrame alignFrame)
{
alignFrame.getViewport().getCalcManager()
- .removeRegisteredWorkersOfClass(AAConClient.class);
+ .removeRegisteredWorkersOfClass(aaui.getClient());
}
}
--
1.7.10.2