JAL-3954 Create fallback for handling unknown actions
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 10 May 2023 13:20:14 +0000 (15:20 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 10 May 2023 13:20:14 +0000 (15:20 +0200)
src/jalview/ws2/actions/api/TaskEventListener.java
src/jalview/ws2/gui/WebServicesMenuManager.java

index 94de9d0..9dee10c 100644 (file)
@@ -108,4 +108,55 @@ public interface TaskEventListener<T>
    *          new log string
    */
   void subJobErrorLogChanged(TaskI<T> source, JobI job, String log);
+
+  @SuppressWarnings("rawtypes")
+  static final TaskEventListener NULL_LISTENER = new TaskEventListener()
+  {
+    @Override
+    public void taskStarted(TaskI source, List subJobs)
+    {
+    }
+
+    @Override
+    public void taskStatusChanged(TaskI source, JobStatus status)
+    {
+    }
+
+    @Override
+    public void taskCompleted(TaskI source, Object result)
+    {
+    }
+
+    @Override
+    public void taskException(TaskI source, Exception e)
+    {
+    }
+
+    @Override
+    public void taskRestarted(TaskI source)
+    {
+    }
+
+    @Override
+    public void subJobStatusChanged(TaskI source, JobI job,
+            JobStatus status)
+    {
+    }
+
+    @Override
+    public void subJobLogChanged(TaskI source, JobI job, String log)
+    {
+    }
+
+    @Override
+    public void subJobErrorLogChanged(TaskI source, JobI job, String log)
+    {
+    }
+  };
+
+  @SuppressWarnings("unchecked")
+  static <T> TaskEventListener<T> nullListener()
+  {
+    return (TaskEventListener<T>) NULL_LISTENER;
+  }
 }
index d6cf5b7..8f48690 100644 (file)
@@ -24,6 +24,7 @@ import javax.swing.JMenuItem;
 import javax.swing.ToolTipManager;
 import javax.swing.border.EmptyBorder;
 
+import jalview.bin.Console;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.gui.JvSwingUtils;
@@ -36,6 +37,7 @@ 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.TaskEventListener;
 import jalview.ws2.actions.api.TaskI;
 import jalview.ws2.api.Credentials;
 import jalview.ws2.api.WebService;
@@ -468,8 +470,11 @@ public class WebServicesMenuManager
       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()));
+    Console.warn(String.format(
+            "No known handler for action type %s. All output will be discarded.",
+            action.getClass().getName()));
+    return action.perform(viewport, args, credentials,
+            TaskEventListener.nullListener());
   }
 
   private static CompletionStage<List<ArgumentI>> openEditParamsDialog(