From 3f2a842c9e234959bd4093bd5b51765258ea5a37 Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Thu, 30 Sep 2021 14:23:49 +0200 Subject: [PATCH] JAL-3878 Split web services menu entries by programs and hosts. --- src/jalview/gui/AlignFrame.java | 22 +++++++++++++++++++- src/jalview/ws2/operations/AlignmentOperation.java | 6 ++++++ src/jalview/ws2/operations/Operation.java | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 9781f16..9fb6ee5 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -162,10 +162,13 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Comparator; import java.util.Deque; import java.util.Enumeration; +import java.util.HashMap; import java.util.Hashtable; import java.util.List; +import java.util.Map; import java.util.Vector; import javax.swing.ButtonGroup; @@ -4727,11 +4730,28 @@ public class AlignFrame extends GAlignFrame { if (discoverer.hasServices()) { - for (WebServiceI service : discoverer.getServices()) + var services = new ArrayList<>(discoverer.getServices()); + services.sort(Comparator + .comparing(o -> o.getHostName()) + .thenComparing(o -> o.getName())); + Map lastHostForOperation = new HashMap<>(); + for (final WebServiceI service : services) { + var host = service.getHostName(); for (Operation op : service.getOperations()) { JMenu atpoint = JvSwingUtils.findOrCreateMenu(menu, op.getTypeName()); + String lastHost = lastHostForOperation.get(op.getTypeName()); + if (lastHost != host) { + if (lastHost != null) + atpoint.addSeparator(); + var menuItem = new JMenuItem(host); + menuItem.setForeground(Color.blue); + menuItem.addActionListener(e -> Desktop.showUrl(host)); + atpoint.add(menuItem); + lastHostForOperation.put(op.getTypeName(), host); + } + atpoint.addSeparator(); op.getMenuBuilder().buildMenu(atpoint, this); } } diff --git a/src/jalview/ws2/operations/AlignmentOperation.java b/src/jalview/ws2/operations/AlignmentOperation.java index 9a65d01..32a5abc 100644 --- a/src/jalview/ws2/operations/AlignmentOperation.java +++ b/src/jalview/ws2/operations/AlignmentOperation.java @@ -82,6 +82,12 @@ public class AlignmentOperation implements Operation } @Override + public String getHostName() + { + return service.getHostName(); + } + + @Override public int getMinSequences() { return 2; diff --git a/src/jalview/ws2/operations/Operation.java b/src/jalview/ws2/operations/Operation.java index a7b229d..e244afa 100644 --- a/src/jalview/ws2/operations/Operation.java +++ b/src/jalview/ws2/operations/Operation.java @@ -8,6 +8,8 @@ public interface Operation public String getTypeName(); + public String getHostName(); + public int getMinSequences(); public int getMaxSequences(); -- 1.7.10.2