JAL-3878 Add slivka discoverer and menu to AlignFrame
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 25 Mar 2022 18:04:38 +0000 (19:04 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 25 Mar 2022 18:04:38 +0000 (19:04 +0100)
src/jalview/gui/AlignFrame.java
src/jalview/gui/Desktop.java

index 6f3a7e3..94d6b6b 100644 (file)
@@ -115,7 +115,10 @@ import jalview.ws.params.ArgumentI;
 import jalview.ws.params.ParamDatastoreI;
 import jalview.ws.params.WsParamSetI;
 import jalview.ws.seqfetcher.DbSourceProxy;
-import jalview.ws.slivkaws.SlivkaWSDiscoverer;
+import jalview.ws2.client.api.WebServiceDiscovererI;
+import jalview.ws2.client.slivka.SlivkaWSDiscoverer;
+import jalview.ws2.gui.WebServicesMenuManager;
+
 import java.io.IOException;
 import java.util.HashSet;
 import java.util.Set;
@@ -909,13 +912,22 @@ public class AlignFrame extends GAlignFrame
     buildWebServicesMenu();
   }
 
+  private WebServiceDiscovererI.ServicesChangeListener slivkaServiceChangeListener =
+      (discoverer, services) -> {
+        // run when slivka services change
+        var menu = AlignFrame.this.slivkaMenu;
+        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()
   {
     if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
     {
-      WSDiscovererI discoverer = SlivkaWSDiscoverer.getInstance();
-      discoverer.addServiceChangeListener(this);
+      WebServiceDiscovererI discoverer = SlivkaWSDiscoverer.getInstance();
+      discoverer.addServicesChangeListener(slivkaServiceChangeListener);
     }
     if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
     {
@@ -932,7 +944,7 @@ public class AlignFrame extends GAlignFrame
       @Override
       public void internalFrameClosed(InternalFrameEvent e) {
         System.out.println("deregistering discoverer listener");
-        SlivkaWSDiscoverer.getInstance().removeServiceChangeListener(AlignFrame.this);
+        SlivkaWSDiscoverer.getInstance().removeServicesChangeListener(slivkaServiceChangeListener);
         Jws2Discoverer.getInstance().removeServiceChangeListener(AlignFrame.this);
         Desktop.getInstance().removeJalviewPropertyChangeListener("services", legacyListener);
         closeMenuItem_actionPerformed(true);
@@ -4634,6 +4646,8 @@ public class AlignFrame extends GAlignFrame
     return tp;
   }
 
+  private WebServicesMenuManager slivkaMenu = new WebServicesMenuManager("slivka", this);
+
   /**
    * Schedule the web services menu rebuild to the event dispatch thread.
    */
@@ -4646,9 +4660,10 @@ public class AlignFrame extends GAlignFrame
       {
         Cache.log.info("Building web service menu for slivka");
         SlivkaWSDiscoverer discoverer = SlivkaWSDiscoverer.getInstance();
-        JMenu submenu = new JMenu("Slivka");
-        buildWebServicesMenu(discoverer, submenu);
-        webService.add(submenu);
+        slivkaMenu.setServices(discoverer);
+        slivkaMenu.setInProgress(discoverer.isRunning());
+        slivkaMenu.setNoServices(discoverer.isDone() && !discoverer.hasServices());
+        webService.add(slivkaMenu.getMenu());
       }
       if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
       {
@@ -4658,6 +4673,7 @@ public class AlignFrame extends GAlignFrame
         buildWebServicesMenu(jws2servs, submenu);
         webService.add(submenu);
       }
+      build_urlServiceMenu(webService);
       build_fetchdbmenu(webService);
     });
   }
index 88c94f6..0fa74d6 100644 (file)
@@ -2736,7 +2736,8 @@ public class Desktop extends GDesktop
     }
     if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
     {
-      tasks.add(jalview.ws.slivkaws.SlivkaWSDiscoverer.getInstance().startDiscoverer());
+      tasks.add(jalview.ws2.client.slivka.SlivkaWSDiscoverer
+          .getInstance().startDiscoverer());
     }
     if (blocking)
     {