From ff20e75c28408c09803b8f9f15c02e7420e709e9 Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Fri, 15 Mar 2024 17:34:32 +0100 Subject: [PATCH] JAL-4389 Adjust preferences menu to work with any WSDiscoverer --- src/jalview/gui/Preferences.java | 27 ++++++++++++++++---- ...kaPreferences.java => WS2PreferencesPanel.java} | 11 ++++---- src/jalview/jbgui/GPreferences.java | 8 ++---- .../client/api/AbstractWebServiceDiscoverer.java | 2 +- .../ws2/client/api/WebServiceDiscovererI.java | 7 +++++ .../ws2/client/ebi/JobDispatcherWSDiscoverer.java | 5 ++++ .../ws2/client/jpred4/JPred4WSDiscoverer.java | 5 ++++ .../ws2/client/slivka/SlivkaWSDiscoverer.java | 5 ++++ 8 files changed, 52 insertions(+), 18 deletions(-) rename src/jalview/gui/{SlivkaPreferences.java => WS2PreferencesPanel.java} (98%) diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 19d929e..67b45e3 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -40,6 +40,7 @@ import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JInternalFrame; import javax.swing.JPanel; +import javax.swing.JTabbedPane; import javax.swing.JTextField; import javax.swing.ListSelectionModel; import javax.swing.RowFilter; @@ -58,7 +59,6 @@ import jalview.hmmer.HmmerCommand; import jalview.util.FileUtils; import ext.edu.ucsf.rbvi.strucviz2.StructureManager; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; -import jalview.bin.ApplicationSingletonProvider; import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.bin.Cache; import jalview.bin.Console; @@ -84,6 +84,10 @@ import jalview.util.MessageManager; import jalview.util.Platform; import jalview.util.UrlConstants; import jalview.ws.sifts.SiftsSettings; +import jalview.ws2.client.api.WebServiceDiscovererI; +import jalview.ws2.client.ebi.JobDispatcherWSDiscoverer; +import jalview.ws2.client.jpred4.JPred4WSDiscoverer; +import jalview.ws2.client.slivka.SlivkaWSDiscoverer; /** * DOCUMENT ME! @@ -297,7 +301,6 @@ public class Preferences extends GPreferences implements ApplicationSingletonI private WsPreferences wsPrefs; - private SlivkaPreferences slivkaPrefs; private OptionsParam promptEachTimeOpt = new OptionsParam( MessageManager.getString("label.prompt_each_time"), "Prompt each time"); @@ -373,9 +376,13 @@ public class Preferences extends GPreferences implements ApplicationSingletonI wsTab.add(wsPrefs, BorderLayout.CENTER); } - slivkaPrefs = new SlivkaPreferences(); - slivkaTab.add(slivkaPrefs, BorderLayout.CENTER); - + if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true)) + addWebServiceTab(tabbedPane, SlivkaWSDiscoverer.getInstance()); + if (Cache.getDefault("SHOW_EBI_SERVICES", true)) + addWebServiceTab(tabbedPane, JobDispatcherWSDiscoverer.getInstance()); + if (Cache.getDefault("SHOW_JPRED4_SERVICES", true)) + addWebServiceTab(tabbedPane, JPred4WSDiscoverer.getInstance()); + int width = 500, height = 450; if (Platform.isAMacAndNotJS()) { @@ -870,6 +877,16 @@ public class Preferences extends GPreferences implements ApplicationSingletonI loadLastSavedBackupsOptions(); } + + private void addWebServiceTab(JTabbedPane tabs, WebServiceDiscovererI discoverer) + { + String name = discoverer.getName(); + JPanel tab = new JPanel(); + tab.setLayout(new BorderLayout()); + tab.add(new WS2PreferencesPanel(discoverer), BorderLayout.CENTER); + tabs.add(tab, name + " services"); + } + /** * A helper method that sets the items and initial selection in a character * rendering option list (Prompt each time/Lineart/Text) diff --git a/src/jalview/gui/SlivkaPreferences.java b/src/jalview/gui/WS2PreferencesPanel.java similarity index 98% rename from src/jalview/gui/SlivkaPreferences.java rename to src/jalview/gui/WS2PreferencesPanel.java index 5f2e106..d5dc39e 100644 --- a/src/jalview/gui/SlivkaPreferences.java +++ b/src/jalview/gui/WS2PreferencesPanel.java @@ -39,7 +39,7 @@ import jalview.ws2.client.api.WebServiceDiscovererI; import jalview.ws2.client.slivka.SlivkaWSDiscoverer; @SuppressWarnings("serial") -public class SlivkaPreferences extends JPanel +public class WS2PreferencesPanel extends JPanel { { setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); @@ -202,8 +202,8 @@ public class SlivkaPreferences extends JPanel final int i = urlListTable.getSelectedRow(); if (i >= 0) { - urls.remove(i); - statuses.remove(i); + URL url = urls.remove(i); + statuses.remove(url); urlTableModel.fireTableRowsDeleted(i, i); discoverer.setUrls(urls); } @@ -286,7 +286,6 @@ public class SlivkaPreferences extends JPanel private void moveTableRow(int fromIndex, int toIndex) { URL url = urls.get(fromIndex); - int status = statuses.get(fromIndex); urls.set(fromIndex, urls.get(toIndex)); urls.set(toIndex, url); if (urlListTable.getSelectedRow() == fromIndex) @@ -360,10 +359,10 @@ public class SlivkaPreferences extends JPanel add(progressBar); } - SlivkaPreferences() + WS2PreferencesPanel(WebServiceDiscovererI discoverer) { // Initial URLs loading - discoverer = SlivkaWSDiscoverer.getInstance(); + this.discoverer = discoverer; urls.addAll(discoverer.getUrls()); for (URL url : urls) { diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index dfe08ed..099f75c 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -358,7 +358,6 @@ public class GPreferences extends JPanel */ protected JPanel wsTab = new JPanel(); - protected JPanel slivkaTab = new JPanel(); /* * Backups tab components * a lot of these are member variables instead of local variables only so that they @@ -405,7 +404,7 @@ public class GPreferences extends JPanel protected JTextArea backupfilesExampleLabel = new JTextArea(); - private final JTabbedPane tabbedPane = new JTabbedPane(); + protected final JTabbedPane tabbedPane = new JTabbedPane(); private JLabel messageLabel = new JLabel("", JLabel.CENTER); @@ -502,11 +501,8 @@ public class GPreferences extends JPanel tabbedPane.add(initStartupTab(), MessageManager.getString("label.startup")); wsTab.setLayout(new BorderLayout()); - tabbedPane.add(wsTab, MessageManager.getString("label.web_services")); + tabbedPane.add(wsTab, "JABAWS " + MessageManager.getString("label.web_services")); } - - slivkaTab.setLayout(new BorderLayout()); - tabbedPane.add(slivkaTab, "Slivka Services"); /* * Handler to validate a tab before leaving it - currently only for diff --git a/src/jalview/ws2/client/api/AbstractWebServiceDiscoverer.java b/src/jalview/ws2/client/api/AbstractWebServiceDiscoverer.java index c2c7db1..6e32d48 100644 --- a/src/jalview/ws2/client/api/AbstractWebServiceDiscoverer.java +++ b/src/jalview/ws2/client/api/AbstractWebServiceDiscoverer.java @@ -16,7 +16,7 @@ import jalview.ws2.actions.api.ActionI; import jalview.ws2.api.WebService; public abstract class AbstractWebServiceDiscoverer implements WebServiceDiscovererI -{ +{ // TODO: we can use linked hash map to group and retrieve services by type. protected List> services = List.of(); diff --git a/src/jalview/ws2/client/api/WebServiceDiscovererI.java b/src/jalview/ws2/client/api/WebServiceDiscovererI.java index 4a09ef7..f5a73c0 100644 --- a/src/jalview/ws2/client/api/WebServiceDiscovererI.java +++ b/src/jalview/ws2/client/api/WebServiceDiscovererI.java @@ -25,6 +25,13 @@ public interface WebServiceDiscovererI extends WebServiceProviderI public static final int STATUS_UNKNOWN = -2; /** + * Get the short name of the discoverer. + * + * @return discoverer name + */ + String getName(); + + /** * List the urls used by this discoverer. */ List getUrls(); diff --git a/src/jalview/ws2/client/ebi/JobDispatcherWSDiscoverer.java b/src/jalview/ws2/client/ebi/JobDispatcherWSDiscoverer.java index 48d0ba5..e357479 100644 --- a/src/jalview/ws2/client/ebi/JobDispatcherWSDiscoverer.java +++ b/src/jalview/ws2/client/ebi/JobDispatcherWSDiscoverer.java @@ -41,6 +41,11 @@ public final class JobDispatcherWSDiscoverer extends AbstractWebServiceDiscovere return instance; } + public String getName() + { + return "Job Dispatcher"; + } + public static void setParamManager(ParamManager manager) { paramManager = manager; diff --git a/src/jalview/ws2/client/jpred4/JPred4WSDiscoverer.java b/src/jalview/ws2/client/jpred4/JPred4WSDiscoverer.java index ada0d2f..8daa3b6 100644 --- a/src/jalview/ws2/client/jpred4/JPred4WSDiscoverer.java +++ b/src/jalview/ws2/client/jpred4/JPred4WSDiscoverer.java @@ -44,6 +44,11 @@ public class JPred4WSDiscoverer extends AbstractWebServiceDiscoverer return instance; } + public String getName() + { + return "JPred4"; + } + public static void setParamManager(ParamManager manager) { paramManager = manager; diff --git a/src/jalview/ws2/client/slivka/SlivkaWSDiscoverer.java b/src/jalview/ws2/client/slivka/SlivkaWSDiscoverer.java index 51e27ad..165226f 100644 --- a/src/jalview/ws2/client/slivka/SlivkaWSDiscoverer.java +++ b/src/jalview/ws2/client/slivka/SlivkaWSDiscoverer.java @@ -53,6 +53,11 @@ public class SlivkaWSDiscoverer extends AbstractWebServiceDiscoverer return instance; } + public String getName() + { + return "Slivka"; + } + public static void setParamManager(ParamManager manager) { paramManager = manager; -- 1.7.10.2