formatting
[jalview.git] / src / jalview / ws / jws2 / MsaWSClient.java
index 820dfb4..e481780 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
  * 
@@ -19,6 +19,7 @@ package jalview.ws.jws2;
 
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.swing.*;
@@ -27,9 +28,12 @@ import jalview.datamodel.*;
 import jalview.gui.*;
 import compbio.data.msa.MsaWS;
 import compbio.metadata.Argument;
+import compbio.metadata.Option;
 import compbio.metadata.Preset;
 import compbio.metadata.PresetManager;
-import jalview.ws.jws2.Jws2Discoverer.Jws2Instance;
+import jalview.ws.jws2.dm.JabaWsParamSet;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.WsParamSetI;
 
 /**
  * DOCUMENT ME!
@@ -44,13 +48,7 @@ public class MsaWSClient extends Jws2Client
    */
   MsaWS server;
 
-  AlignFrame alignFrame;
-
-  private Preset preset;
-
-  private List<Argument> paramset;
-
-  public MsaWSClient(Jws2Discoverer.Jws2Instance sh, String altitle,
+  public MsaWSClient(Jws2Instance sh, String altitle,
           jalview.datamodel.AlignmentView msa, boolean submitGaps,
           boolean preserveOrder, Alignment seqdataset,
           AlignFrame _alignFrame)
@@ -60,9 +58,9 @@ public class MsaWSClient extends Jws2Client
     // TODO Auto-generated constructor stub
   }
 
-  public MsaWSClient(Jws2Discoverer.Jws2Instance sh, Preset preset,
-          String altitle, jalview.datamodel.AlignmentView msa,
-          boolean submitGaps, boolean preserveOrder, Alignment seqdataset,
+  public MsaWSClient(Jws2Instance sh, WsParamSetI preset, String altitle,
+          jalview.datamodel.AlignmentView msa, boolean submitGaps,
+          boolean preserveOrder, Alignment seqdataset,
           AlignFrame _alignFrame)
   {
     this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder,
@@ -86,14 +84,18 @@ public class MsaWSClient extends Jws2Client
    *          DOCUMENT ME!
    */
 
-  public MsaWSClient(Jws2Discoverer.Jws2Instance sh, Preset preset,
+  public MsaWSClient(Jws2Instance sh, WsParamSetI preset,
           List<Argument> arguments, boolean editParams, String altitle,
           jalview.datamodel.AlignmentView msa, boolean submitGaps,
           boolean preserveOrder, Alignment seqdataset,
           AlignFrame _alignFrame)
   {
-    super();
-    alignFrame = _alignFrame;
+    super(_alignFrame, preset, arguments);
+    if (!processParams(sh, editParams))
+    {
+      return;
+    }
+
     if (!(sh.service instanceof MsaWS))
     {
       // redundant at mo - but may change
@@ -107,24 +109,7 @@ public class MsaWSClient extends Jws2Client
 
       return;
     }
-    server = sh.service;
-    this.preset = preset;
-    this.paramset = arguments;
-    if (editParams)
-    {
-      WsJobParameters jobParams = new WsJobParameters(sh, preset);
-      if (!jobParams.showRunDialog())
-      {
-        return;
-      }
-      if ((this.preset = jobParams.getPreset())==null)
-      {
-        paramset = jobParams.getJobParams();
-      } else {
-        paramset = null; // no user supplied parameters.
-      }
-    }
-
+    server = (MsaWS) sh.service;
     if ((wsInfo = setWebService(sh, false)) == null)
     {
       JOptionPane.showMessageDialog(Desktop.desktop,
@@ -215,7 +200,7 @@ public class MsaWSClient extends Jws2Client
     String svcname = WebServiceName;
     if (svcname.endsWith("WS"))
     {
-      svcname = svcname.substring(0,svcname.length()-2);
+      svcname = svcname.substring(0, svcname.length() - 2);
     }
     String calcName = svcname + " ";
     if (canSubmitGaps())
@@ -224,17 +209,22 @@ public class MsaWSClient extends Jws2Client
       rmsawsmenu.add(msawsmenu);
       calcName = "";
     }
-
+    boolean hasparams = service.hasParameters();
     do
     {
+      String action = "Align ";
       if (submitGaps == true)
       {
-        msawsmenu = new JMenu("profile " + svcname);
+        action = "Realign ";
+        msawsmenu = new JMenu("Realign with " + svcname);
+        msawsmenu
+                .setToolTipText("Align sequences to an existing alignment");
         rmsawsmenu.add(msawsmenu);
       }
       final boolean withGaps = submitGaps;
-      JMenuItem method = new JMenuItem(calcName + "Defaults");
-      method.setToolTipText("Align with default settings");
+
+      JMenuItem method = new JMenuItem(calcName + "with Defaults");
+      method.setToolTipText(action + "with default settings");
 
       method.addActionListener(new ActionListener()
       {
@@ -248,45 +238,55 @@ public class MsaWSClient extends Jws2Client
         }
       });
       msawsmenu.add(method);
-      method = new JMenuItem(calcName + "Edit and run ...");
-      method.setToolTipText("View and change the parameters before alignment.");
-
-      method.addActionListener(new ActionListener()
+      if (hasparams)
       {
-        public void actionPerformed(ActionEvent e)
-        {
-          AlignmentView msa = alignFrame.gatherSequencesForAlignment();
-          new MsaWSClient(service, null, null, true, alignFrame.getTitle(),
-                  msa, withGaps, true, alignFrame.getViewport()
-                          .getAlignment().getDataset(), alignFrame);
+        // only add these menu options if the service has user-modifiable
+        // arguments
+        method = new JMenuItem("Edit settings and run ...");
+        method.setToolTipText("View and change the parameters before alignment.");
 
-        }
-      });
-      msawsmenu.add(method);
-      PresetManager presets = service.getPresets();
-      if (presets != null && presets.getPresets().size() > 0)
-      {
-        JMenu presetlist = new JMenu(calcName + "Presets");
+        method.addActionListener(new ActionListener()
+        {
+          public void actionPerformed(ActionEvent e)
+          {
+            AlignmentView msa = alignFrame.gatherSequencesForAlignment();
+            new MsaWSClient(service, null, null, true, alignFrame
+                    .getTitle(), msa, withGaps, true, alignFrame
+                    .getViewport().getAlignment().getDataset(), alignFrame);
 
-        for (final Preset preset : (List<Preset>) presets.getPresets())
+          }
+        });
+        msawsmenu.add(method);
+        List<WsParamSetI> presets = service.getParamStore().getPresets();
+        if (presets != null && presets.size() > 0)
         {
-          final JMenuItem methodR = new JMenuItem(preset.getName());
-          methodR.setToolTipText("<html><p>"+preset.getDescription()+"</p></html>");
-          methodR.addActionListener(new ActionListener()
+          JMenu presetlist = new JMenu("Run " + calcName + "with preset");
+
+          for (final WsParamSetI preset : presets)
           {
-            public void actionPerformed(ActionEvent e)
+            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()
             {
-              AlignmentView msa = alignFrame.gatherSequencesForAlignment();
-              new MsaWSClient(service, preset, alignFrame.getTitle(), msa,
-                      false, true, alignFrame.getViewport().getAlignment()
-                              .getDataset(), alignFrame);
+              public void actionPerformed(ActionEvent e)
+              {
+                AlignmentView msa = alignFrame
+                        .gatherSequencesForAlignment();
+                new MsaWSClient(service, preset, alignFrame.getTitle(),
+                        msa, false, true, alignFrame.getViewport()
+                                .getAlignment().getDataset(), alignFrame);
 
-            }
+              }
 
-          });
-          presetlist.add(methodR);
+            });
+            presetlist.add(methodR);
+          }
+          msawsmenu.add(presetlist);
         }
-        msawsmenu.add(presetlist);
       }
       if (!submitGaps && canSubmitGaps())
       {