JAL-3878 Split web services menu entries by programs and hosts.
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Thu, 30 Sep 2021 12:23:49 +0000 (14:23 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Thu, 30 Sep 2021 12:23:49 +0000 (14:23 +0200)
src/jalview/gui/AlignFrame.java
src/jalview/ws2/operations/AlignmentOperation.java
src/jalview/ws2/operations/Operation.java

index 9781f16..9fb6ee5 100644 (file)
@@ -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
+              .<WebServiceI, String>comparing(o -> o.getHostName())
+              .<String>thenComparing(o -> o.getName()));
+      Map<String, String> 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);
         }
       }
index 9a65d01..32a5abc 100644 (file)
@@ -82,6 +82,12 @@ public class AlignmentOperation implements Operation
   }
 
   @Override
+  public String getHostName()
+  {
+    return service.getHostName();
+  }
+
+  @Override
   public int getMinSequences()
   {
     return 2;
index a7b229d..e244afa 100644 (file)
@@ -8,6 +8,8 @@ public interface Operation
 
   public String getTypeName();
 
+  public String getHostName();
+
   public int getMinSequences();
 
   public int getMaxSequences();