JAL-2629 combine with/without defaults in one method call
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 30 Mar 2018 14:44:04 +0000 (15:44 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 30 Mar 2018 14:44:04 +0000 (15:44 +0100)
src/jalview/gui/AlignFrame.java
src/jalview/jbgui/GAlignFrame.java

index 27d4f5e..009d946 100644 (file)
@@ -106,6 +106,7 @@ import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.params.ArgumentI;
 import jalview.ws.params.ParamDatastoreI;
 import jalview.ws.params.WsParamSetI;
+import jalview.ws.params.simple.Option;
 import jalview.ws.seqfetcher.DbSourceProxy;
 
 import java.awt.BorderLayout;
@@ -1024,96 +1025,92 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   @Override
-  public void hmmBuildSettings_actionPerformed()
+  public void hmmBuild_actionPerformed(boolean withDefaults)
   {
-    if (!(alignmentIsSufficient(1)))
+    if (!alignmentIsSufficient(1))
     {
       return;
     }
-    WsParamSetI set = new HMMERPreset();
     List<ArgumentI> args = new ArrayList<>();
-    ParamDatastoreI store = new HMMERParamStore("hmmbuild");
-    WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
-            args);
-    if (params.showRunDialog())
+    if (withDefaults)
     {
-      new Thread(new HMMBuild(this, params.getJobParams())).start();
+      // todo: construct this in HMMERPreset?
+      String argName = MessageManager.getString("label.hmmbuild_for");
+      String argValue = MessageManager.getString("label.alignment");
+      args.add(
+              new Option(argName, null, false, null, argValue, null, null));
     }
-    alignPanel.repaint();
-
+    else
+    {
+      WsParamSetI set = new HMMERPreset();
+      ParamDatastoreI store = HMMERParamStore.forBuild();
+      WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+              args);
+      if (params.showRunDialog())
+      {
+        args = params.getJobParams();
+      }
+      else
+      {
+        return; // user cancelled
+      }
+    }
+    new Thread(new HMMBuild(this, args)).start();
   }
 
   @Override
-  public void hmmAlignSettings_actionPerformed()
+  public void hmmAlign_actionPerformed(boolean withDefaults)
   {
     if (!(checkForHMM() && alignmentIsSufficient(2)))
     {
       return;
     }
-    WsParamSetI set = new HMMERPreset();
     List<ArgumentI> args = new ArrayList<>();
-    ParamDatastoreI store = new HMMERParamStore("hmmalign");
-    WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
-            args);
-    if (params.showRunDialog())
+    if (!withDefaults)
     {
-      new Thread(new HMMAlign(this, params.getJobParams()))
-            .start();
+      WsParamSetI set = new HMMERPreset();
+      ParamDatastoreI store = HMMERParamStore.forAlign();
+      WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+              args);
+      if (params.showRunDialog())
+      {
+        args = params.getJobParams();
+      }
+      else
+      {
+        return; // user cancelled
+      }
     }
-    alignPanel.repaint();
+    new Thread(new HMMAlign(this, args)).start();
   }
 
   @Override
-  public void hmmSearchSettings_actionPerformed()
+  public void hmmSearch_actionPerformed(boolean withDefaults)
   {
     if (!checkForHMM())
     {
       return;
     }
-    WsParamSetI set = new HMMERPreset();
     List<ArgumentI> args = new ArrayList<>();
-    ParamDatastoreI store = new HMMERParamStore("hmmsearch");
-    WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
-            args);
-    if (params.showRunDialog())
+    if (!withDefaults)
     {
-      new Thread(new HMMSearch(this, params.getJobParams()))
-            .start();
+      WsParamSetI set = new HMMERPreset();
+      ParamDatastoreI store = HMMERParamStore.forSearch();
+      WsJobParameters params = new WsJobParameters(new JFrame(), store, set,
+              args);
+      if (params.showRunDialog())
+      {
+        args = params.getJobParams();
+      }
+      else
+      {
+        return; // user cancelled
+      }
     }
+    new Thread(new HMMSearch(this, args)).start();
     alignPanel.repaint();
   }
 
-  @Override
-  public void hmmBuildRun_actionPerformed()
-  {
-    if (!alignmentIsSufficient(1))
-    {
-      return;
-    }
-    new Thread(new HMMBuild(this, null))
-            .start();
-  }
-
-  @Override
-  public void hmmAlignRun_actionPerformed()
-  {
-    if (!(checkForHMM() && alignmentIsSufficient(2)))
-    {
-      return;
-    }
-    new Thread(new HMMAlign(this, null)).start();
-  }
-
-  @Override
-  public void hmmSearchRun_actionPerformed()
-  {
-    if (!checkForHMM())
-    {
-      return;
-    }
-    new Thread(new HMMSearch(this, null)).start();
-  }
-
   /**
    * Checks if the frame has a selected hidden Markov model
    * 
index 507bbc8..8226cee 100755 (executable)
@@ -1764,7 +1764,7 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        hmmBuildRun_actionPerformed();
+        hmmBuild_actionPerformed(true);
       }
     });
     hmmBuildSettings.setText(
@@ -1774,7 +1774,7 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        hmmBuildSettings_actionPerformed();
+        hmmBuild_actionPerformed(false);
       }
     });
     hmmAlignRun.setText(MessageManager.formatMessage(
@@ -1784,7 +1784,7 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        hmmAlignRun_actionPerformed();
+        hmmAlign_actionPerformed(true);
       }
     });
     hmmAlignSettings.setText(
@@ -1794,7 +1794,7 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        hmmAlignSettings_actionPerformed();
+        hmmAlign_actionPerformed(false);
       }
     });
     hmmSearchRun.setText(MessageManager.formatMessage(
@@ -1804,7 +1804,17 @@ public class GAlignFrame extends JInternalFrame
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        hmmSearchRun_actionPerformed();
+        hmmSearch_actionPerformed(true);
+      }
+    });
+    hmmSearchSettings.setText(
+            MessageManager.getString("label.edit_settings_and_run"));
+    hmmSearchSettings.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        hmmSearch_actionPerformed(false);
       }
     });
     addDatabase.setText(MessageManager.getString("label.add_database"));
@@ -1822,16 +1832,6 @@ public class GAlignFrame extends JInternalFrame
         }
       }
     });
-    hmmSearchSettings.setText(
-            MessageManager.getString("label.edit_settings_and_run"));
-    hmmSearchSettings.addActionListener(new ActionListener()
-    {
-      @Override
-      public void actionPerformed(ActionEvent e)
-      {
-        hmmSearchSettings_actionPerformed();
-      }
-    });
     selectHighlighted.addActionListener(al);
     JMenu tooltipSettingsMenu = new JMenu(
             MessageManager.getString("label.sequence_id_tooltip"));
@@ -2538,11 +2538,11 @@ public class GAlignFrame extends JInternalFrame
   {
   }
 
-  protected void hmmBuildRun_actionPerformed()
+  protected void hmmBuild_actionPerformed(boolean withDefaults)
   {
   }
 
-  protected void hmmSearchRun_actionPerformed()
+  protected void hmmSearch_actionPerformed(boolean withDefaults)
   {
   }
 
@@ -2551,19 +2551,7 @@ public class GAlignFrame extends JInternalFrame
   {
   }
 
-  protected void hmmAlignRun_actionPerformed()
-  {
-  }
-
-  protected void hmmBuildSettings_actionPerformed()
-  {
-  }
-
-  protected void hmmSearchSettings_actionPerformed()
-  {
-  }
-
-  protected void hmmAlignSettings_actionPerformed()
+  protected void hmmAlign_actionPerformed(boolean withDefaults)
   {
   }