JAL-3878 Implement gui elements for annotation servicces
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 11 Apr 2022 16:19:38 +0000 (18:19 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Mon, 11 Apr 2022 16:19:38 +0000 (18:19 +0200)
src/jalview/ws2/gui/AnnotationServiceGuiHandler.java [new file with mode: 0644]
src/jalview/ws2/gui/WebServicesMenuManager.java

diff --git a/src/jalview/ws2/gui/AnnotationServiceGuiHandler.java b/src/jalview/ws2/gui/AnnotationServiceGuiHandler.java
new file mode 100644 (file)
index 0000000..43e2680
--- /dev/null
@@ -0,0 +1,120 @@
+package jalview.ws2.gui;
+
+import java.util.List;
+
+import jalview.gui.AlignFrame;
+import jalview.gui.AlignmentPanel;
+import jalview.gui.IProgressIndicator;
+import jalview.gui.IProgressIndicatorHandler;
+import jalview.ws2.actions.annotation.AnnotationAction;
+import jalview.ws2.actions.annotation.AnnotationResult;
+import jalview.ws2.actions.api.JobI;
+import jalview.ws2.actions.api.TaskEventListener;
+import jalview.ws2.actions.api.TaskI;
+import jalview.ws2.api.JobStatus;
+
+public class AnnotationServiceGuiHandler
+    implements TaskEventListener<AnnotationResult>
+{
+  private final AlignFrame alignFrame;
+
+  private final AlignmentPanel alignPanel;
+
+  private final IProgressIndicator progressIndicator;
+
+  private final AnnotationAction action;
+
+  public AnnotationServiceGuiHandler(AnnotationAction action, AlignFrame frame)
+  {
+    this.alignFrame = frame;
+    this.alignPanel = frame.alignPanel;
+    this.progressIndicator = frame;
+    this.action = action;
+  }
+
+  @Override
+  public void taskStarted(TaskI<AnnotationResult> source, List<? extends JobI> subJobs)
+  {
+    progressIndicator.registerHandler(source.getUid(),
+        new IProgressIndicatorHandler()
+        {
+          @Override
+          public boolean cancelActivity(long id)
+          {
+            source.cancel();
+            return true;
+          }
+
+          @Override
+          public boolean canCancel()
+          {
+            return true;
+          }
+        });
+  }
+
+  @Override
+  public void taskStatusChanged(TaskI<AnnotationResult> source, JobStatus status)
+  {
+    switch (status)
+    {
+    case INVALID:
+    case COMPLETED:
+    case CANCELLED:
+    case FAILED:
+    case SERVER_ERROR:
+      progressIndicator.removeProgressBar(source.getUid());
+      break;
+    case READY:
+    case SUBMITTED:
+    case QUEUED:
+    case RUNNING:
+    case UNKNOWN:
+      progressIndicator.addProgressBar(source.getUid(), action.getFullName());
+      break;
+    }
+  }
+
+  @Override
+  public void taskCompleted(TaskI<AnnotationResult> source, AnnotationResult result)
+  {
+    if (result == null)
+      return;
+    if (result.getTransferFeatures() && alignFrame.alignPanel == alignPanel)
+    {
+      alignFrame.getViewport().setShowSequenceFeatures(true);
+      alignFrame.setMenusForViewport();
+    }
+    alignPanel.adjustAnnotationHeight();
+  }
+
+  @Override
+  public void taskException(TaskI<AnnotationResult> source, Exception e)
+  {
+
+  }
+
+  @Override
+  public void taskRestarted(TaskI<AnnotationResult> source)
+  {
+
+  }
+
+  @Override
+  public void subJobStatusChanged(TaskI<AnnotationResult> source, JobI job, JobStatus status)
+  {
+
+  }
+
+  @Override
+  public void subJobLogChanged(TaskI<AnnotationResult> source, JobI job, String log)
+  {
+
+  }
+
+  @Override
+  public void subJobErrorLogChanged(TaskI<AnnotationResult> source, JobI job, String log)
+  {
+
+  }
+}
index 188f587..c75c483 100644 (file)
@@ -30,6 +30,7 @@ import jalview.ws.params.ArgumentI;
 import jalview.ws.params.ParamDatastoreI;
 import jalview.ws.params.WsParamSetI;
 import jalview.ws2.actions.alignment.AlignmentAction;
+import jalview.ws2.actions.annotation.AnnotationAction;
 import jalview.ws2.actions.api.ActionI;
 import jalview.ws2.actions.api.TaskI;
 import jalview.ws2.api.Credentials;
@@ -249,6 +250,12 @@ public class WebServicesMenuManager
       var handler = new AlignmentServiceGuiHandler(_action, frame);
       return _action.perform(viewport, args, credentials, handler);
     }
+    if (action instanceof AnnotationAction)
+    {
+      var _action = (AnnotationAction) action;
+      var handler = new AnnotationServiceGuiHandler(_action, frame);
+      return _action.perform(viewport, args, credentials, handler);
+    }
     throw new IllegalArgumentException(
         String.format("Illegal action type %s", action.getClass().getName()));
   }