JAL-1601 Load and display JPred4 service in AlignFrame
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Thu, 5 Oct 2023 13:16:04 +0000 (15:16 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 13 Oct 2023 12:37:43 +0000 (14:37 +0200)
src/jalview/gui/AlignFrame.java
src/jalview/gui/Desktop.java
src/jalview/ws2/actions/BaseAction.java
src/jalview/ws2/gui/WebServicesMenuManager.java

index 8ae4601..2849d6b 100644 (file)
@@ -184,6 +184,7 @@ import jalview.ws.params.WsParamSetI;
 import jalview.ws.seqfetcher.DbSourceProxy;
 import jalview.ws2.client.api.WebServiceDiscovererI;
 import jalview.ws2.client.ebi.JobDispatcherWSDiscoverer;
+import jalview.ws2.client.jpred4.JPred4WSDiscoverer;
 import jalview.ws2.client.slivka.SlivkaWSDiscoverer;
 import jalview.ws2.gui.WebServicesMenuManager;
 
@@ -986,6 +987,15 @@ public class AlignFrame extends GAlignFrame
         menu.setInProgress(discoverer.isRunning());
         menu.setNoServices(services.isEmpty() && discoverer.isDone());
       };
+  
+  private WebServiceDiscovererI.ServicesChangeListener jpred4ServiceChangeListener =
+      (discoverer, services) -> {
+        // run when jpred4 services change
+        var menu = AlignFrame.this.jpred4Menu;
+        menu.setServices(discoverer);
+        menu.setInProgress(discoverer.isRunning());
+        menu.setNoServices(services.isEmpty() && discoverer.isDone());
+      };
 
   /* Set up intrinsic listeners for dynamically generated GUI bits. */
   private void addServiceListeners()
@@ -999,6 +1009,10 @@ public class AlignFrame extends GAlignFrame
     {
       JobDispatcherWSDiscoverer.getInstance().addServicesChangeListener(ebiServiceChangeListener);
     }
+    if (Cache.getDefault("SHOW_JPRED4_SERVICES", true))
+    {
+      JPred4WSDiscoverer.getInstance().addServicesChangeListener(jpred4ServiceChangeListener);
+    }
     if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
     {
       WSDiscovererI discoverer = Jws2Discoverer.getInstance();
@@ -1015,6 +1029,7 @@ public class AlignFrame extends GAlignFrame
       public void internalFrameClosed(InternalFrameEvent e) {
         System.out.println("deregistering discoverer listener");
         SlivkaWSDiscoverer.getInstance().removeServicesChangeListener(slivkaServiceChangeListener);
+        JPred4WSDiscoverer.getInstance().removeServicesChangeListener(jpred4ServiceChangeListener);
         Jws2Discoverer.getInstance().removeServiceChangeListener(AlignFrame.this);
         Desktop.getInstance().removeJalviewPropertyChangeListener("services", legacyListener);
         closeMenuItem_actionPerformed(true);
@@ -4672,6 +4687,7 @@ public class AlignFrame extends GAlignFrame
 
   private WebServicesMenuManager slivkaMenu = new WebServicesMenuManager("slivka", this);
   private WebServicesMenuManager ebiMenu = new WebServicesMenuManager("job dispatcher", this);
+  private WebServicesMenuManager jpred4Menu = new WebServicesMenuManager("jpred4", this);
 
   /**
    * Schedule the web services menu rebuild to the event dispatch thread.
@@ -4699,6 +4715,15 @@ public class AlignFrame extends GAlignFrame
         ebiMenu.setNoServices(discoverer.isDone() && !discoverer.hasServices());
         webService.add(ebiMenu.getMenu());
       }
+      if (Cache.getDefault("SHOW_JPRED4_SERVICES", true))
+      {
+        Console.info("Building web services menu for jpred4");
+        JPred4WSDiscoverer discoverer = JPred4WSDiscoverer.getInstance();
+        jpred4Menu.setServices(discoverer);
+        jpred4Menu.setInProgress(discoverer.isRunning());
+        jpred4Menu.setNoServices(discoverer.isDone() && !discoverer.hasServices());
+        webService.add(jpred4Menu.getMenu());
+      }
       if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
       {
         WSDiscovererI jws2servs = Jws2Discoverer.getInstance();
index 02643ec..b671f9c 100644 (file)
@@ -2747,6 +2747,11 @@ public class Desktop extends GDesktop
       tasks.add(jalview.ws2.client.ebi.JobDispatcherWSDiscoverer
               .getInstance().startDiscoverer());
     }
+    if (Cache.getDefault("SHOW_JPRED4_SERVICES", true))
+    {
+      tasks.add(jalview.ws2.client.jpred4.JPred4WSDiscoverer
+              .getInstance().startDiscoverer());
+    }
     if (blocking)
     {
       for (Future<?> task : tasks) {
index 6e92f4c..a46a4e7 100644 (file)
@@ -1,10 +1,17 @@
 package jalview.ws2.actions;
 
 import java.util.EnumSet;
+import java.util.List;
 import java.util.Objects;
 
+import jalview.gui.AlignViewport;
+import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.params.ArgumentI;
 import jalview.ws2.actions.api.ActionI;
+import jalview.ws2.actions.api.TaskEventListener;
+import jalview.ws2.actions.api.TaskI;
 import jalview.ws2.api.CredentialType;
+import jalview.ws2.api.Credentials;
 import jalview.ws2.api.WebService;
 
 /**
index f9b8c02..48dfbbc 100644 (file)
@@ -32,6 +32,7 @@ import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.params.ArgumentI;
 import jalview.ws.params.ParamDatastoreI;
 import jalview.ws.params.WsParamSetI;
+import jalview.ws2.actions.BaseAction;
 import jalview.ws2.actions.BaseTask;
 import jalview.ws2.actions.PollingTaskExecutor;
 import jalview.ws2.actions.alignment.AlignmentAction;
@@ -42,6 +43,7 @@ import jalview.ws2.actions.api.ActionI;
 import jalview.ws2.actions.api.TaskEventListener;
 import jalview.ws2.actions.api.TaskI;
 import jalview.ws2.actions.hmmer.PhmmerAction;
+import jalview.ws2.actions.secstructpred.SecStructPredAction;
 import jalview.ws2.api.Credentials;
 import jalview.ws2.api.WebService;
 import jalview.ws2.client.api.WebServiceProviderI;
@@ -480,14 +482,18 @@ public class WebServicesMenuManager
         calcManager.startWorker(worker);
       return;
     }
-    if (action instanceof PhmmerAction)
+    if (action instanceof PhmmerAction || action instanceof SecStructPredAction)
     {
-      var _action = (PhmmerAction) action;
+      var _action = (BaseAction<AlignmentI>) action;
       var handler = new SearchServiceGuiHandler(_action, frame);
-      TaskI<AlignmentI> task = _action.createTask(viewport, args, credentials);
+      var task = (BaseTask<?, AlignmentI>) _action  // FIXME: unsafe cast
+          .createTask(viewport, args, credentials);
       var executor = PollingTaskExecutor.fromPool(viewport.getServiceExecutor());
       task.addTaskEventListener(handler);
-      _action.perform(viewport, args, credentials, handler);
+      var future = executor.submit(task);
+      task.setCancelAction(() -> {
+        future.cancel(true);
+      });
       return;
     }
     Console.warn(String.format(