Merge branch 'JAL-368_dragabovedesktop' into develop
[jalview.git] / src / jalview / ws / jws2 / Jws2Discoverer.java
index 8907b58..1c912d8 100644 (file)
@@ -205,17 +205,16 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
    * @param srv
    * @param service2
    */
-  synchronized void addService(String jwsservers, Services srv,
-          MsaWS service2)
+  synchronized void addService(String jwsservers, Jws2Instance service)
   {
     if (services == null)
     {
       services = new Vector<Jws2Instance>();
     }
     System.out.println("Discovered service: " + jwsservers + " "
-            + srv.toString());
-    Jws2Instance service = new Jws2Instance(jwsservers, srv.toString(),
-            service2);
+            + service.toString());
+//    Jws2Instance service = new Jws2Instance(jwsservers, srv.toString(),
+//            service2);
 
     services.add(service);
     // retrieve the presets and parameter set and cache now
@@ -227,41 +226,16 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
    * holds list of services.
    */
   protected Vector<Jws2Instance> services;
-
+  /**
+   * attach all available web services to the appropriate submenu in the given JMenu
+   */
   public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
   {
     // dynamically regenerate service list.
-    final JMenu jws2al = wsmenu; // new JMenu("JABAWS Alignment");
-    jws2al.addMenuListener(new MenuListener()
-    {
-      // TODO: future: add menu listener to parent menu - so submenus are
-      // populated *before* they are selected.
-      @Override
-      public void menuSelected(MenuEvent e)
-      {
-        populateWSMenuEntry(jws2al, alignFrame);
-      }
-
-      @Override
-      public void menuDeselected(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
-
-      }
-
-      @Override
-      public void menuCanceled(MenuEvent e)
-      {
-        // TODO Auto-generated method stub
-
-      }
-
-    });
-    wsmenu.add(jws2al);
-
+    populateWSMenuEntry(wsmenu, alignFrame, null);
   }
 
-  private void populateWSMenuEntry(JMenu jws2al, final AlignFrame alignFrame)
+  private void populateWSMenuEntry(JMenu jws2al, final AlignFrame alignFrame, String typeFilter)
   {
     if (running || services == null || services.size() == 0)
     {
@@ -305,7 +279,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
       jalview.util.QuickSort.sort(sortbytype, orderedsvcs);
       for (final Jws2Instance service : orderedsvcs)
       {
-        atpoint = jws2al;
+        atpoint = JvSwingUtils.findOrCreateMenu(jws2al,service.action);
         String type = service.serviceType;
         if (byhost)
         {
@@ -357,7 +331,8 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
           // hostLabels.addElement(host + (bytype ?
           // service.serviceType+service.getActionText() : ""));
         }
-        msacl.attachWSMenuEntry(atpoint, service, alignFrame);
+        
+        service.attachWSMenuEntry(atpoint, alignFrame);
         /*
          * JMenuItem sitem = new JMenuItem(service.serviceType);
          * sitem.setToolTipText("Hosted at " + service.hosturl);
@@ -377,6 +352,14 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
 
   public static void main(String[] args)
   {
+    if (args.length>0)
+    {
+      testUrls = new Vector<String>();
+      for (String url:args)
+      {
+        testUrls.add(url);
+      };
+    }
     Thread runner = getDiscoverer().startDiscoverer(
             new PropertyChangeListener()
             {
@@ -450,8 +433,14 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     }
   }
 
+  private static Vector<String> testUrls=null;
   public static Vector<String> getServiceUrls()
   {
+    if (testUrls!=null)
+    {
+      // return test urls, if there are any, instead of touching cache
+      return testUrls;
+    }
     String surls = Cache.getDefault(JWS2HOSTURLS,
             "http://www.compbio.dundee.ac.uk/jabaws");
     Vector<String> urls = new Vector<String>();
@@ -660,5 +649,4 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     }
     return null;
   }
-
 }