From 4fc20cbfb109c5333892bf39a36c50b370cfef5d Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Fri, 25 Mar 2022 19:04:38 +0100 Subject: [PATCH] JAL-3878 Add slivka discoverer and menu to AlignFrame --- src/jalview/gui/AlignFrame.java | 30 +++++++++++++++++++++++------- src/jalview/gui/Desktop.java | 3 ++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 6f3a7e3..94d6b6b 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -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); }); } diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 88c94f6..0fa74d6 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -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) { -- 1.7.10.2