apply jalview code style
[jalview.git] / src / jalview / ws / jws2 / Jws2Discoverer.java
index dda8c4e..e56a5e5 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
+ * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * 
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ */
 package jalview.ws.jws2;
 
 import java.awt.Color;
@@ -162,10 +179,13 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     }
     System.out.println("Discovered service: " + jwsservers + " "
             + srv.toString());
-    Jws2Instance service = new Jws2Instance(jwsservers, srv.toString(), service2);
+    Jws2Instance service = new Jws2Instance(jwsservers, srv.toString(),
+            service2);
 
     services.add(service);
-    service.getParamStore();
+    // retrieve the presets and parameter set and cache now
+    service.getParamStore().getPresets();
+    service.hasParameters();
   }
 
   public class Jws2Instance
@@ -280,7 +300,27 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     public String getUri()
     {
       // this is only valid for Jaba 1.0 - this formula might have to change!
-      return hosturl+"/"+serviceType;
+      return hosturl
+              + (hosturl.lastIndexOf("/") == (hosturl.length() - 1) ? "/"
+                      : "") + serviceType;
+    }
+
+    private boolean hasParams = false, lookedForParams = false;
+
+    public boolean hasParameters()
+    {
+      if (!lookedForParams)
+      {
+        lookedForParams = true;
+        try
+        {
+          hasParams = (getRunnerConfig().getArguments().size() > 0);
+        } catch (Exception e)
+        {
+
+        }
+      }
+      return hasParams;
     }
   };
 
@@ -320,7 +360,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
   public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
   {
     // dynamically regenerate service list.
-    final JMenu jws2al = new JMenu("JABA Alignment");
+    final JMenu jws2al = new JMenu("JABAWS Alignment");
     jws2al.addMenuListener(new MenuListener()
     {
       // TODO: future: add menu listener to parent menu - so submenus are
@@ -347,7 +387,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
 
     });
     wsmenu.add(jws2al);
-    
+
   }
 
   private void populateWSMenuEntry(JMenu jws2al, final AlignFrame alignFrame)
@@ -366,6 +406,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
     MsaWSClient msacl = new MsaWSClient();
     Vector hostLabels = new Vector();
     jws2al.removeAll();
+    String lasthost = null;
     for (final Jws2Instance service : services)
     {
       atpoint = jws2al;
@@ -387,16 +428,27 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
           atpoint.setToolTipText(service.getActionText());
         }
       }
-      if (!byhost && !hostLabels.contains(host + service.getActionText()))
+      if (!byhost
+              && !hostLabels.contains(host + service.serviceType
+                      + service.getActionText()))
+      // !hostLabels.contains(host + (bytype ?
+      // service.serviceType+service.getActionText() : "")))
       {
         // add a marker indicating where this service is hosted
         // relies on services from the same host being listed in a contiguous
         // group
         JMenuItem hitm;
         atpoint.addSeparator();
-        atpoint.add(hitm = new JMenuItem(host));
-        hitm.setForeground(Color.blue);
-        hostLabels.addElement(host);
+        if (lasthost == null || !lasthost.equals(host))
+        {
+          atpoint.add(hitm = new JMenuItem(host));
+          hitm.setForeground(Color.blue);
+          lasthost = host;
+        }
+        hostLabels.addElement(host + service.serviceType
+                + service.getActionText());
+        // hostLabels.addElement(host + (bytype ?
+        // service.serviceType+service.getActionText() : ""));
       }
       msacl.attachWSMenuEntry(atpoint, service, alignFrame);
       /*