(JAL-974,JAL-975) new handler for JABAWS sequence and alignment annotation services
authorjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 3 Nov 2011 18:14:25 +0000 (18:14 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 3 Nov 2011 18:14:25 +0000 (18:14 +0000)
src/jalview/ws/jws2/SequenceAnnotationWSClient.java [new file with mode: 0644]

diff --git a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java
new file mode 100644 (file)
index 0000000..3e4cbe1
--- /dev/null
@@ -0,0 +1,144 @@
+/**
+ * 
+ */
+package jalview.ws.jws2;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.List;
+
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+
+import compbio.metadata.Argument;
+
+import jalview.api.AlignCalcWorkerI;
+import jalview.datamodel.AlignmentView;
+import jalview.gui.AlignFrame;
+import jalview.gui.JvSwingUtils;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.WsParamSetI;
+
+/**
+ * @author jimp
+ * 
+ */
+public class SequenceAnnotationWSClient extends Jws2Client
+{
+
+  /**
+   * initialise a client so its attachWSMenuEntry method can be called.
+   */
+  public SequenceAnnotationWSClient()
+  {
+    // TODO Auto-generated constructor stub
+  }
+
+  public SequenceAnnotationWSClient(final Jws2Instance sh,
+          AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
+  {
+    super(alignFrame, preset, null);
+    List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
+            .getCalcManager()
+            .getRegisteredWorkersOfClass(AAConsClient.class);
+    if (clnts == null || clnts.size() == 0)
+    {
+      if (!processParams(sh, editParams))
+      {
+        return;
+      }
+      alignFrame
+              .getViewport()
+              .getCalcManager()
+              .registerWorker(
+                      new AAConsClient(sh, alignFrame, preset, paramset));
+    }
+    else
+    {
+      AAConsClient worker = (AAConsClient) 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(preset, paramset);
+
+    }
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see jalview.ws.jws2.Jws2Client#attachWSMenuEntry(javax.swing.JMenu,
+   * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
+   */
+  public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
+          final AlignFrame alignFrame)
+  {
+    if (service.serviceType.toLowerCase().contains("aaconws"))
+    {
+      boolean hasparams = service.hasParameters();
+      String calcName = "AACons";
+      System.out.println("Making an aacons client!");
+      JMenuItem aacons = new JMenuItem("AACons Defaults");
+      aacons.addActionListener(new ActionListener()
+      {
+
+        @Override
+        public void actionPerformed(ActionEvent e)
+        {
+          new SequenceAnnotationWSClient(service, alignFrame, null, false);
+        }
+      });
+      wsmenu.add(aacons);
+      if (hasparams)
+      {
+        // only add these menu options if the service has user-modifiable
+        // arguments
+        aacons = new JMenuItem("Edit settings and run ...");
+        aacons.setToolTipText("View and change the parameters before alignment.");
+
+        aacons.addActionListener(new ActionListener()
+        {
+          public void actionPerformed(ActionEvent e)
+          {
+            new SequenceAnnotationWSClient(service, alignFrame, null, true);
+          }
+        });
+        wsmenu.add(aacons);
+        List<WsParamSetI> presets = service.getParamStore().getPresets();
+        if (presets != null && presets.size() > 0)
+        {
+          JMenu presetlist = new JMenu("Run " + calcName + "with preset");
+
+          for (final WsParamSetI preset : presets)
+          {
+            final JMenuItem methodR = new JMenuItem(preset.getName());
+            methodR.setToolTipText("<html><p>"
+                    + JvSwingUtils.wrapTooltip("<strong>"
+                            + (preset.isModifiable() ? "User Preset"
+                                    : "Service Preset") + "</strong><br/>"
+                            + preset.getDescription() + "</p>") + "</html>");
+            methodR.addActionListener(new ActionListener()
+            {
+              public void actionPerformed(ActionEvent e)
+              {
+                new SequenceAnnotationWSClient(service, alignFrame, preset,
+                        false);
+              }
+
+            });
+            presetlist.add(methodR);
+          }
+          wsmenu.add(presetlist);
+        }
+      }
+
+    }
+  }
+}