JAL-3809 - Fixed param edit dialog for jalviewjs.
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 3 Feb 2021 18:48:32 +0000 (19:48 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 22 Feb 2021 12:02:50 +0000 (13:02 +0100)
Edit settings dialog now works asynchronously.
Annotation services still do not add annotations to the sequences.

src/jalview/gui/AlignFrame.java
src/jalview/gui/WsJobParameters.java
src/jalview/ws/WSClient.java
src/jalview/ws/jws2/MsaWSClient.java
src/jalview/ws/jws2/SequenceAnnotationWSClient.java

index 9d8407a..db6870e 100644 (file)
@@ -1141,16 +1141,18 @@ public class AlignFrame extends GAlignFrame
     {
       WsParamSetI set = new HMMERPreset();
       WsJobParameters params = new WsJobParameters(store, set, args);
-      if (params.showRunDialog())
-      {
-        args = params.getJobParams();
-      }
-      else
-      {
-        return; // user cancelled
-      }
+      params.showRunDialog().thenAccept((startJob) -> {
+        if (startJob)
+        {
+          var args2 = params.getJobParams();
+          new Thread(new HMMBuild(this, args2)).start();
+        }
+      });
+    }
+    else
+    {
+      new Thread(new HMMBuild(this, args)).start();
     }
-    new Thread(new HMMBuild(this, args)).start();
   }
 
   @Override
@@ -1172,16 +1174,18 @@ public class AlignFrame extends GAlignFrame
     {
       WsParamSetI set = new HMMERPreset();
       WsJobParameters params = new WsJobParameters(store, set, args);
-      if (params.showRunDialog())
-      {
-        args = params.getJobParams();
-      }
-      else
-      {
-        return; // user cancelled
-      }
+      params.showRunDialog().thenAccept((startJob) -> {
+        if (startJob)
+        {
+          var args2 = params.getJobParams();
+          new Thread(new HMMAlign(this, args2)).start();
+        }
+      });
+    }
+    else
+    {
+      new Thread(new HMMAlign(this, args)).start();
     }
-    new Thread(new HMMAlign(this, args)).start();
   }
 
   @Override
@@ -1203,17 +1207,20 @@ public class AlignFrame extends GAlignFrame
     {
       WsParamSetI set = new HMMERPreset();
       WsJobParameters params = new WsJobParameters(store, set, args);
-      if (params.showRunDialog())
-      {
-        args = params.getJobParams();
-      }
-      else
-      {
-        return; // user cancelled
-      }
+      params.showRunDialog().thenAccept((startJob) -> {
+        if (startJob)
+        {
+          var args2 = params.getJobParams();
+          new Thread(new HMMSearch(this, args2)).start();
+          alignPanel.repaint();
+        }
+      });
+    }
+    else
+    {
+      new Thread(new HMMSearch(this, args)).start();
+      alignPanel.repaint();
     }
-    new Thread(new HMMSearch(this, args)).start();
-    alignPanel.repaint();
   }
 
   @Override
@@ -1232,18 +1239,20 @@ public class AlignFrame extends GAlignFrame
     {
       WsParamSetI set = new HMMERPreset();
       WsJobParameters params = new WsJobParameters(store, set, args);
-      if (params.showRunDialog())
-      {
-        args = params.getJobParams();
-      }
-      else
-      {
-        return; // user cancelled
-      }
+      params.showRunDialog().thenAccept((startJob) -> {
+        if (startJob)
+        {
+          var args2 = params.getJobParams();
+          new Thread(new JackHMMER(this, args2)).start();
+          alignPanel.repaint();
+        }
+      });
+    }
+    else
+    {
+      new Thread(new JackHMMER(this, args)).start();
+      alignPanel.repaint();
     }
-    new Thread(new JackHMMER(this, args)).start();
-    alignPanel.repaint();
-
   }
 
   /**
index 719b7d9..88819e4 100644 (file)
@@ -48,14 +48,18 @@ import java.awt.event.ItemListener;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Vector;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
 
 import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JDialog;
+import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTextArea;
+import javax.swing.WindowConstants;
 import javax.swing.border.TitledBorder;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
@@ -93,6 +97,9 @@ public class WsJobParameters extends JPanel implements ItemListener,
 
   // TODO ABSRACT FROM JABAWS CLASSES
 
+  // completion stage representing whether start was clicked
+  private final CompletableFuture<Boolean> completionStage = new CompletableFuture<>();
+  
   /**
    * manager for options and parameters.
    */
@@ -123,13 +130,22 @@ public class WsJobParameters extends JPanel implements ItemListener,
   JTextArea setDescr = new JTextArea();
 
   JScrollPane paramPane = new JScrollPane();
+  
+  JButton startjob = JvSwingUtils.makeButton(
+          MessageManager.getString("action.start_job"),
+          MessageManager.getString("label.start_job_current_settings"),
+          this::startjob_actionPerformed);
+  JButton canceljob = JvSwingUtils.makeButton(
+          MessageManager.getString("action.cancel_job"),
+          MessageManager.getString("label.cancel_job_close_dialog"),
+          this::canceljob_actionPerformed);
 
   ParamDatastoreI paramStore;
 
   // set true when 'Start Job' is clicked
   boolean startJob = false;
 
-  JDialog frame = null;
+  JFrame frame = null;
 
   UIinfo service;
 
@@ -195,10 +211,10 @@ public class WsJobParameters extends JPanel implements ItemListener,
    * 
    * @return
    */
-  public boolean showRunDialog()
+  public CompletionStage<Boolean> showRunDialog()
   {
-
-    frame = new JDialog(Desktop.getInstance(), true);
+    frame = new JFrame();
+    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
     if (service != null)
     {
       frame.setTitle(MessageManager.formatMessage("label.edit_params_for",
@@ -228,9 +244,9 @@ public class WsJobParameters extends JPanel implements ItemListener,
 
       }
     });
+    
     frame.setVisible(true);
-
-    return startJob;
+    return completionStage;
   }
 
   private void jbInit()
@@ -254,75 +270,21 @@ public class WsJobParameters extends JPanel implements ItemListener,
     updatepref = JvSwingUtils.makeButton(
             MessageManager.getString("action.update"),
             MessageManager.getString("label.update_user_parameter_set"),
-            new ActionListener()
-            {
-
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                update_actionPerformed();
-              }
-            });
+            this::update_actionPerformed);
     deletepref = JvSwingUtils.makeButton(
             MessageManager.getString("action.delete"),
             MessageManager.getString("label.delete_user_parameter_set"),
-            new ActionListener()
-            {
-
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                delete_actionPerformed();
-              }
-            });
+            this::delete_actionPerformed);
     createpref = JvSwingUtils.makeButton(
             MessageManager.getString("action.create"),
             MessageManager.getString("label.create_user_parameter_set"),
-            new ActionListener()
-            {
-
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                create_actionPerformed();
-              }
-            });
+            this::create_actionPerformed);
     revertpref = JvSwingUtils.makeButton(
             MessageManager.getString("action.revert"),
             MessageManager
                     .getString("label.revert_changes_user_parameter_set"),
-            new ActionListener()
-            {
+            this::revert_actionPerformed);
 
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                revert_actionPerformed();
-              }
-            });
-
-    JButton startjob = JvSwingUtils.makeButton(
-            MessageManager.getString("action.start_job"),
-            MessageManager.getString("label.start_job_current_settings"),
-            new ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                startjob_actionPerformed();
-              }
-            });
-    JButton canceljob = JvSwingUtils.makeButton(
-            MessageManager.getString("action.cancel_job"),
-            MessageManager.getString("label.cancel_job_close_dialog"),
-            new ActionListener()
-            {
-              @Override
-              public void actionPerformed(ActionEvent e)
-              {
-                canceljob_actionPerformed();
-              }
-            });
 
     JPanel setDetails = new JPanel();
     setDetails.setBorder(
@@ -424,13 +386,13 @@ public class WsJobParameters extends JPanel implements ItemListener,
     validate();
   }
 
-  protected void revert_actionPerformed()
+  protected void revert_actionPerformed(ActionEvent e)
   {
     reInitDialog(lastParmSet);
     updateWebServiceMenus();
   }
 
-  protected void update_actionPerformed()
+  protected void update_actionPerformed(ActionEvent e)
   {
     if (isUserPreset)
     {
@@ -448,7 +410,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
     paramStore.deletePreset(lastParmSet2);
   }
 
-  protected void delete_actionPerformed()
+  protected void delete_actionPerformed(ActionEvent e)
   {
     if (isUserPreset)
     {
@@ -459,7 +421,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
     updateWebServiceMenus();
   }
 
-  protected void create_actionPerformed()
+  protected void create_actionPerformed(ActionEvent e)
   {
     String curname = ((String) setName.getSelectedItem()).trim();
     if (curname.length() > 0)
@@ -478,22 +440,24 @@ public class WsJobParameters extends JPanel implements ItemListener,
     }
   }
 
-  protected void canceljob_actionPerformed()
+  protected void canceljob_actionPerformed(ActionEvent e)
   {
     startJob = false;
     if (frame != null)
     {
       frame.setVisible(false);
     }
+    completionStage.complete(false);
   }
 
-  protected void startjob_actionPerformed()
+  protected void startjob_actionPerformed(ActionEvent e)
   {
     startJob = true;
     if (frame != null)
     {
       frame.setVisible(false);
     }
+    completionStage.complete(true);
   }
 
   void initForService(WsParamSetI paramSet, List<ArgumentI> jobArgset)
index 33aea90..a68f3f3 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.ws;
 
+import jalview.bin.Cache;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.gui.WebserviceInfo;
@@ -32,6 +33,8 @@ import jalview.ws.params.ParamDatastoreI;
 import jalview.ws.params.WsParamSetI;
 
 import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
 
 public abstract class WSClient // implements WSMenuEntryProviderI
 {
@@ -116,7 +119,7 @@ public abstract class WSClient // implements WSMenuEntryProviderI
    * @param arguments
    */
   public WSClient(AlignFrame _alignFrame, WsParamSetI preset,
-          List<ArgumentI> arguments)
+      List<ArgumentI> arguments)
   {
     alignFrame = _alignFrame;
     this.preset = preset;
@@ -131,12 +134,12 @@ public abstract class WSClient // implements WSMenuEntryProviderI
     if (!b)
     {
       return new WebserviceInfo(WebServiceJobTitle,
-              WebServiceJobTitle + " using service hosted at "
-                      + WsURL + "\n"
-                      + (serv.getDescription() != null
-                              ? serv.getDescription()
-                              : ""),
-              false);
+          WebServiceJobTitle + " using service hosted at "
+              + WsURL + "\n"
+              + (serv.getDescription() != null
+                  ? serv.getDescription()
+                  : ""),
+          false);
     }
     return null;
   }
@@ -148,15 +151,14 @@ public abstract class WSClient // implements WSMenuEntryProviderI
    * @param editParams
    * @return
    */
-  protected boolean processParams(ServiceWithParameters sh,
-          boolean editParams)
+  protected CompletionStage<Boolean> processParams(ServiceWithParameters sh,
+      boolean editParams)
   {
     return processParams(sh, editParams, false);
   }
 
-  protected boolean processParams(ServiceWithParameters sh,
-          boolean editParams,
-          boolean adjustingExisting)
+  protected CompletionStage<Boolean> processParams(ServiceWithParameters sh,
+      boolean editParams, boolean adjustingExisting)
   {
 
     if (editParams)
@@ -165,35 +167,38 @@ public abstract class WSClient // implements WSMenuEntryProviderI
       sh.initParamStore(Desktop.getUserParameterStore());
 
       WsJobParameters jobParams = (preset == null && paramset != null
-              && paramset.size() > 0)
-                      ? new WsJobParameters((ParamDatastoreI) null, sh,
-                              (WsParamSetI) null, paramset)
-                      : new WsJobParameters((ParamDatastoreI) null, sh,
-                              preset, (List<ArgumentI>) null);
+          && paramset.size() > 0)
+              ? new WsJobParameters((ParamDatastoreI) null, sh,
+                  (WsParamSetI) null, paramset)
+              : new WsJobParameters((ParamDatastoreI) null, sh,
+                  preset, (List<ArgumentI>) null);
       if (adjustingExisting)
       {
         jobParams.setName(MessageManager
-                .getString("label.adjusting_parameters_for_calculation"));
+            .getString("label.adjusting_parameters_for_calculation"));
       }
-      if (!jobParams.showRunDialog())
-      {
-        return false; // dialog cancelled
-      }
-
-      WsParamSetI prset = jobParams.getPreset();
-      if (prset == null)
-      {
-        paramset = jobParams.isServiceDefaults() ? null
+      var stage = jobParams.showRunDialog();
+      return stage.thenApply((startJob) -> {
+        if (startJob)
+        {
+          WsParamSetI prset = jobParams.getPreset();
+          if (prset == null)
+          {
+            paramset = jobParams.isServiceDefaults() ? null
                 : jobParams.getJobParams();
-        this.preset = null;
-      }
-      else
-      {
-        this.preset = prset; // ((JabaPreset) prset).p;
-        paramset = null; // no user supplied parameters.
-      }
+            this.preset = null;
+          }
+          else
+          {
+            this.preset = prset; // ((JabaPreset) prset).p;
+            paramset = null; // no user supplied parameters.
+          }
+        }
+        return startJob;
+      });
+
     }
-    return true;
+    return CompletableFuture.completedFuture(true);
   }
 
 }
index e44381c..3123078 100644 (file)
@@ -110,42 +110,41 @@ public class MsaWSClient extends Jws2Client implements WSMenuEntryProviderI
           AlignFrame _alignFrame)
   {
     super(_alignFrame, preset, arguments);
-    if (!processParams(sh, editParams))
-    {
-      return;
-    }
-
-    if (!(sh instanceof JalviewServiceEndpointProviderI
-            && ((JalviewServiceEndpointProviderI) sh)
-                    .getEndpoint() instanceof MultipleSequenceAlignmentI))
-    {
-      // redundant at mo - but may change
-      JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
-              MessageManager.formatMessage(
-                      "label.service_called_is_not_msa_service",
-                      new String[]
-                      { sh.getName() }),
-              MessageManager.getString("label.internal_jalview_error"),
-              JvOptionPane.WARNING_MESSAGE);
-
-      return;
-    }
-    serviceHandle = sh;
-    server = (MultipleSequenceAlignmentI) ((JalviewServiceEndpointProviderI) sh)
-            .getEndpoint();
-    if ((wsInfo = setWebService(sh, false)) == null)
-    {
-      JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), MessageManager
-              .formatMessage("label.msa_service_is_unknown", new String[]
-              { sh.getName() }),
-              MessageManager.getString("label.internal_jalview_error"),
-              JvOptionPane.WARNING_MESSAGE);
-
-      return;
-    }
-
-    startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
-
+    processParams(sh, editParams).thenAccept((startJob) -> {
+      if (!startJob)
+        return;
+      
+      if (!(sh instanceof JalviewServiceEndpointProviderI
+              && ((JalviewServiceEndpointProviderI) sh)
+                      .getEndpoint() instanceof MultipleSequenceAlignmentI))
+      {
+        // redundant at mo - but may change
+        JvOptionPane.showMessageDialog(Desktop.getDesktopPane(),
+                MessageManager.formatMessage(
+                        "label.service_called_is_not_msa_service",
+                        new String[]
+                        { sh.getName() }),
+                MessageManager.getString("label.internal_jalview_error"),
+                JvOptionPane.WARNING_MESSAGE);
+  
+        return;
+      }
+      serviceHandle = sh;
+      server = (MultipleSequenceAlignmentI) ((JalviewServiceEndpointProviderI) sh)
+              .getEndpoint();
+      if ((wsInfo = setWebService(sh, false)) == null)
+      {
+        JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), MessageManager
+                .formatMessage("label.msa_service_is_unknown", new String[]
+                { sh.getName() }),
+                MessageManager.getString("label.internal_jalview_error"),
+                JvOptionPane.WARNING_MESSAGE);
+  
+        return;
+      }
+  
+      startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
+    });
   }
 
   public MsaWSClient()
index 6939db4..838ea60 100644 (file)
@@ -61,8 +61,8 @@ public class SequenceAnnotationWSClient extends Jws2Client
   // dan think. Do I need to change this method to run RNAalifold through the
   // GUI
 
-  public void initSequenceAnnotationWSClient(final ServiceWithParameters sh,
-          AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
+  private void initSequenceAnnotationWSClient(final ServiceWithParameters sh,
+      AlignFrame alignFrame, final WsParamSetI preset, boolean editParams)
   {
     // dan changed! dan test. comment out if conditional
     // if (alignFrame.getViewport().getAlignment().isNucleotide())
@@ -82,74 +82,97 @@ public class SequenceAnnotationWSClient extends Jws2Client
       // columns
 
       List<AlignCalcWorkerI> clnts = alignFrame.getViewport()
-              .getCalcManager()
-              .getWorkersOfClass(SeqAnnotationServiceCalcWorker.class);
+          .getCalcManager()
+          .getWorkersOfClass(SeqAnnotationServiceCalcWorker.class);
 
-      SeqAnnotationServiceCalcWorker worker = null;
+      SeqAnnotationServiceCalcWorker tmpworker = null;
       if (clnts != null)
       {
         for (AlignCalcWorkerI _worker : clnts)
         {
-          worker = (SeqAnnotationServiceCalcWorker) _worker;
-          if (worker.hasService()
-                  && worker.getService().getClass().equals(clientClass))
+          tmpworker = (SeqAnnotationServiceCalcWorker) _worker;
+          if (tmpworker.hasService()
+              && tmpworker.getService().getClass().equals(clientClass))
           {
             break;
           }
-          worker = null;
+          tmpworker = null;
         }
       }
+      final var worker = tmpworker;
       if (worker == null)
       {
-        if (!processParams(sh, editParams))
-        {
-          return;
-        }
-        try
-        {
-          worker = new SeqAnnotationServiceCalcWorker(sh, alignFrame, this.preset,
+        processParams(sh, editParams).thenAccept((startJob) -> {
+          if (startJob)
+          {
+            final SeqAnnotationServiceCalcWorker worker_;
+            try
+            {
+              worker_ = new SeqAnnotationServiceCalcWorker(sh, alignFrame, this.preset,
                   paramset);
-        } catch (Exception x)
-        {
-          x.printStackTrace();
-          throw new Error(
+            } catch (Exception x)
+            {
+              x.printStackTrace();
+              throw new Error(
                   MessageManager.getString("error.implementation_error"),
                   x);
-        }
-        alignFrame.getViewport().getCalcManager().registerWorker(worker); // also
-                                                                          // starts
-                                                                          // the
-                                                                          // worker
+            }
+            alignFrame.getViewport().getCalcManager().registerWorker(worker_);
+                // also starts the worker
+            startSeqAnnotationWorker(sh, alignFrame, preset, editParams);
+          }
+        });
       }
       else
       {
+        WsParamSetI preset_;
         if (editParams)
         {
           paramset = worker.getArguments();
-          preset = worker.getPreset();
+          preset_ = worker.getPreset();
+        }
+        else
+        {
+          preset_ = preset;
         }
+        processParams(sh, editParams, true).thenAccept((startJob) -> {
+          if (startJob)
+          {
+            // reinstate worker if it was blacklisted (might have happened due
+            // to
+            // invalid parameters)
+            alignFrame.getViewport().getCalcManager().enableWorker(worker);
+            worker.updateParameters(this.preset, paramset);
+            startSeqAnnotationWorker(sh, alignFrame, preset_, editParams);
+          }
+        });
 
-        if (!processParams(sh, editParams, true))
+        if (!processParams(sh, editParams, true).toCompletableFuture().join())
         {
           return;
         }
-        // reinstate worker if it was blacklisted (might have happened due to
-        // invalid parameters)
-        alignFrame.getViewport().getCalcManager().enableWorker(worker);
-        worker.updateParameters(this.preset, paramset);
       }
     }
+    else
+    {
+      startSeqAnnotationWorker(sh, alignFrame, preset, editParams);
+    }
+  }
+
+  private void startSeqAnnotationWorker(ServiceWithParameters sh,
+      AlignFrame alignFrame, WsParamSetI preset, boolean editParams)
+  {
     if (!sh.isInteractiveUpdate())
     {
       // build IUPred style client. take sequences, returns annotation per
       // sequence.
-      if (!processParams(sh, editParams))
-      {
-        return;
-      }
-
-      alignFrame.getViewport().getCalcManager().startWorker(
+      processParams(sh, editParams).thenAccept((startJob) -> {
+        if (startJob)
+        {
+          alignFrame.getViewport().getCalcManager().startWorker(
               new SeqAnnotationServiceCalcWorker(sh, alignFrame, preset, paramset));
+        }
+      });
     }
   }