From c6bce37c6553e40f0d3149546a8c96916cf04e21 Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Wed, 10 May 2023 15:20:14 +0200 Subject: [PATCH] JAL-3954 Create fallback for handling unknown actions --- src/jalview/ws2/actions/api/TaskEventListener.java | 51 ++++++++++++++++++++ src/jalview/ws2/gui/WebServicesMenuManager.java | 9 +++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/jalview/ws2/actions/api/TaskEventListener.java b/src/jalview/ws2/actions/api/TaskEventListener.java index 94de9d0..9dee10c 100644 --- a/src/jalview/ws2/actions/api/TaskEventListener.java +++ b/src/jalview/ws2/actions/api/TaskEventListener.java @@ -108,4 +108,55 @@ public interface TaskEventListener * new log string */ void subJobErrorLogChanged(TaskI 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 TaskEventListener nullListener() + { + return (TaskEventListener) NULL_LISTENER; + } } diff --git a/src/jalview/ws2/gui/WebServicesMenuManager.java b/src/jalview/ws2/gui/WebServicesMenuManager.java index d6cf5b7..8f48690 100644 --- a/src/jalview/ws2/gui/WebServicesMenuManager.java +++ b/src/jalview/ws2/gui/WebServicesMenuManager.java @@ -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> openEditParamsDialog( -- 1.7.10.2