JAL-3070 standard way of storing/recovering documentation URL for service
authorJim Procter <jprocter@issues.jalview.org>
Wed, 10 Jul 2019 16:46:23 +0000 (17:46 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 10 Jul 2019 16:46:23 +0000 (17:46 +0100)
src/jalview/ws/api/UIinfo.java
src/jalview/ws/jws2/SequenceAnnotationWSClient.java
src/jalview/ws/jws2/jabaws2/Jws2Instance.java

index 01fb809..8ef4d5b 100644 (file)
@@ -139,4 +139,26 @@ public class UIinfo
     // TODO Auto-generated method stub
     return false;
   }
+
+  private String docUrl = null;
+
+  /**
+   * set the URL that will be offered to show documentation for the service
+   * 
+   * @param url
+   */
+  public void setDocumentationUrl(String url)
+  {
+    docUrl = url;
+  }
+
+  public boolean hasDocumentationUrl()
+  {
+    return docUrl != null && docUrl.length() > 7;
+  }
+
+  public String getDocumentationUrl()
+  {
+    return docUrl;
+  }
 }
\ No newline at end of file
index eb08848..fda9ab5 100644 (file)
@@ -25,6 +25,7 @@ import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.gui.JvSwingUtils;
 import jalview.util.MessageManager;
+import jalview.ws.api.ServiceWithParameters;
 import jalview.ws.jws2.dm.AAConSettings;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.params.WsParamSetI;
@@ -157,7 +158,8 @@ public class SequenceAnnotationWSClient extends Jws2Client
    * jalview.ws.jws2.jabaws2.Jws2Instance, jalview.gui.AlignFrame)
    */
   @Override
-  public void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
+  public void attachWSMenuEntry(JMenu wsmenu,
+          final ServiceWithParameters service,
           final AlignFrame alignFrame)
   {
     if (registerAAConWSInstance(wsmenu, service, alignFrame))
@@ -179,7 +181,8 @@ public class SequenceAnnotationWSClient extends Jws2Client
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        new SequenceAnnotationWSClient(service, alignFrame, null, false);
+        new SequenceAnnotationWSClient((Jws2Instance) service, alignFrame,
+                null, false);
       }
     });
     wsmenu.add(annotservice);
@@ -197,7 +200,8 @@ public class SequenceAnnotationWSClient extends Jws2Client
         @Override
         public void actionPerformed(ActionEvent e)
         {
-          new SequenceAnnotationWSClient(service, alignFrame, null, true);
+          new SequenceAnnotationWSClient((Jws2Instance) service, alignFrame,
+                  null, true);
         }
       });
       wsmenu.add(annotservice);
@@ -222,7 +226,8 @@ public class SequenceAnnotationWSClient extends Jws2Client
             @Override
             public void actionPerformed(ActionEvent e)
             {
-              new SequenceAnnotationWSClient(service, alignFrame, preset,
+              new SequenceAnnotationWSClient((Jws2Instance) service,
+                      alignFrame, preset,
                       false);
             }
 
@@ -237,7 +242,7 @@ public class SequenceAnnotationWSClient extends Jws2Client
     {
       annotservice = new JMenuItem(
               MessageManager.getString("label.view_documentation"));
-      if (service.docUrl != null)
+      if (service != null && service.hasDocumentationUrl())
       {
         annotservice.addActionListener(new ActionListener()
         {
@@ -245,13 +250,14 @@ public class SequenceAnnotationWSClient extends Jws2Client
           @Override
           public void actionPerformed(ActionEvent arg0)
           {
-            Desktop.instance.showUrl(service.docUrl);
+            Desktop.instance.showUrl(service.getDocumentationUrl());
           }
         });
         annotservice.setToolTipText(
                 JvSwingUtils.wrapTooltip(true, MessageManager.formatMessage(
                         "label.view_service_doc_url", new String[]
-                        { service.docUrl, service.docUrl })));
+                        { service.getDocumentationUrl(),
+                            service.getDocumentationUrl() })));
         wsmenu.add(annotservice);
       }
     }
index 143bc1c..55799f0 100644 (file)
@@ -32,6 +32,7 @@ import jalview.ws.params.ParamDatastoreI;
 import jalview.ws.params.ParamManager;
 
 import java.io.Closeable;
+import java.net.URL;
 
 import javax.swing.JMenu;
 
@@ -47,8 +48,6 @@ public class Jws2Instance extends ServiceWithParameters
 
   public JABAService service;
 
-  public String docUrl;
-
   /**
    * 
    * @param hosturl
@@ -71,11 +70,26 @@ public class Jws2Instance extends ServiceWithParameters
     int p = description.indexOf("MORE INFORMATION:");
     if (p > -1)
     {
-      docUrl = description.substring(description.indexOf("http", p)).trim();
+      String docUrl = description.substring(description.indexOf("http", p))
+              .trim();
       if (docUrl.indexOf('\n') > -1)
       {
         docUrl = docUrl.substring(0, docUrl.indexOf("\n")).trim();
       }
+      if (docUrl.length() > 0)
+      {
+        try
+        {
+          URL url = new URL(docUrl);
+          if (url != null)
+          {
+            setDocumentationUrl(docUrl);
+          }
+        } catch (Exception x)
+        {
+
+        }
+      }
 
     }
   }