JAL-2089 patch broken merge to master for Release 2.10.0b1
[jalview.git] / src / jalview / ws / jws2 / MsaWSClient.java
index fd01777..8fa118d 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -20,7 +20,7 @@
  */
 package jalview.ws.jws2;
 
-import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentView;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
@@ -58,7 +58,7 @@ public class MsaWSClient extends Jws2Client
 
   public MsaWSClient(Jws2Instance sh, String altitle,
           jalview.datamodel.AlignmentView msa, boolean submitGaps,
-          boolean preserveOrder, Alignment seqdataset,
+          boolean preserveOrder, AlignmentI seqdataset,
           AlignFrame _alignFrame)
   {
     this(sh, null, null, false, altitle, msa, submitGaps, preserveOrder,
@@ -68,7 +68,7 @@ public class MsaWSClient extends Jws2Client
 
   public MsaWSClient(Jws2Instance sh, WsParamSetI preset, String altitle,
           jalview.datamodel.AlignmentView msa, boolean submitGaps,
-          boolean preserveOrder, Alignment seqdataset,
+          boolean preserveOrder, AlignmentI seqdataset,
           AlignFrame _alignFrame)
   {
     this(sh, preset, null, false, altitle, msa, submitGaps, preserveOrder,
@@ -95,7 +95,7 @@ public class MsaWSClient extends Jws2Client
   public MsaWSClient(Jws2Instance sh, WsParamSetI preset,
           List<Argument> arguments, boolean editParams, String altitle,
           jalview.datamodel.AlignmentView msa, boolean submitGaps,
-          boolean preserveOrder, Alignment seqdataset,
+          boolean preserveOrder, AlignmentI seqdataset,
           AlignFrame _alignFrame)
   {
     super(_alignFrame, preset, arguments);
@@ -109,8 +109,7 @@ public class MsaWSClient extends Jws2Client
       // redundant at mo - but may change
       JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
               .formatMessage("label.service_called_is_not_msa_service",
-                      new String[]
-                      { sh.serviceType }), MessageManager
+                      new String[] { sh.serviceType }), MessageManager
               .getString("label.internal_jalview_error"),
               JOptionPane.WARNING_MESSAGE);
 
@@ -120,13 +119,14 @@ public class MsaWSClient extends Jws2Client
     if ((wsInfo = setWebService(sh, false)) == null)
     {
       JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
-              .formatMessage("label.msa_service_is_unknown", new String[]
-              { sh.serviceType }), MessageManager
+              .formatMessage("label.msa_service_is_unknown",
+                      new String[] { sh.serviceType }), MessageManager
               .getString("label.internal_jalview_error"),
               JOptionPane.WARNING_MESSAGE);
 
       return;
     }
+
     startMsaWSClient(altitle, msa, submitGaps, preserveOrder, seqdataset);
 
   }
@@ -138,7 +138,7 @@ public class MsaWSClient extends Jws2Client
   }
 
   private void startMsaWSClient(String altitle, AlignmentView msa,
-          boolean submitGaps, boolean preserveOrder, Alignment seqdataset)
+          boolean submitGaps, boolean preserveOrder, AlignmentI seqdataset)
   {
     // if (!locateWebService())
     // {
@@ -172,8 +172,25 @@ public class MsaWSClient extends Jws2Client
     MsaWSThread msathread = new MsaWSThread(server, preset, paramset,
             WsURL, wsInfo, alignFrame, WebServiceName, jobtitle, msa,
             submitGaps, preserveOrder, seqdataset);
-    wsInfo.setthisService(msathread);
-    msathread.start();
+    if (msathread.hasValidInput())
+    {
+      wsInfo.setthisService(msathread);
+      wsInfo.setVisible(true);
+      msathread.start();
+    }
+    else
+    {
+      JOptionPane.showMessageDialog(alignFrame,
+              MessageManager.getString("info.invalid_msa_input_mininfo"),
+              MessageManager.getString("info.invalid_msa_notenough"),
+              JOptionPane.INFORMATION_MESSAGE);
+      wsInfo.setVisible(false);
+    }
+  }
+
+  public static void main(String[] args)
+  {
+    System.out.println("A".matches("(-*[a-zA-Z]-*){1}[a-zA-Z-]*"));
   }
 
   protected String getServiceActionKey()
@@ -199,6 +216,7 @@ public class MsaWSClient extends Jws2Client
     return (WebServiceName.indexOf("lustal") > -1); // cheat!
   }
 
+  @Override
   public void attachWSMenuEntry(JMenu rmsawsmenu,
           final Jws2Instance service, final AlignFrame alignFrame)
   {
@@ -230,8 +248,7 @@ public class MsaWSClient extends Jws2Client
       {
         action = "Realign ";
         msawsmenu = new JMenu(MessageManager.formatMessage(
-                "label.realign_with_params", new String[]
-                { svcname }));
+                "label.realign_with_params", new String[] { svcname }));
         msawsmenu.setToolTipText(MessageManager
                 .getString("label.align_sequences_to_existing_alignment"));
         rmsawsmenu.add(msawsmenu);
@@ -239,20 +256,25 @@ public class MsaWSClient extends Jws2Client
       final boolean withGaps = submitGaps;
 
       JMenuItem method = new JMenuItem(MessageManager.formatMessage(
-              "label.calcname_with_default_settings", new String[]
-              { calcName }));
-      method.setToolTipText(MessageManager.formatMessage(
-              "label.action_with_default_settings", new String[]
-              { action }));
+              "label.calcname_with_default_settings",
+              new String[] { calcName }));
+      method.setToolTipText(MessageManager
+              .formatMessage("label.action_with_default_settings",
+                      new String[] { action }));
 
       method.addActionListener(new ActionListener()
       {
+        @Override
         public void actionPerformed(ActionEvent e)
         {
           AlignmentView msa = alignFrame.gatherSequencesForAlignment();
-          new MsaWSClient(service, alignFrame.getTitle(), msa, withGaps,
-                  true, alignFrame.getViewport().getAlignment()
-                          .getDataset(), alignFrame);
+
+          if (msa != null)
+          {
+            new MsaWSClient(service, alignFrame.getTitle(), msa, withGaps,
+                    true, alignFrame.getViewport().getAlignment()
+                            .getDataset(), alignFrame);
+          }
 
         }
       });
@@ -268,12 +290,17 @@ public class MsaWSClient extends Jws2Client
 
         method.addActionListener(new ActionListener()
         {
+          @Override
           public void actionPerformed(ActionEvent e)
           {
             AlignmentView msa = alignFrame.gatherSequencesForAlignment();
-            new MsaWSClient(service, null, null, true, alignFrame
-                    .getTitle(), msa, withGaps, true, alignFrame
-                    .getViewport().getAlignment().getDataset(), alignFrame);
+            if (msa != null)
+            {
+              new MsaWSClient(service, null, null, true, alignFrame
+                      .getTitle(), msa, withGaps, true, alignFrame
+                      .getViewport().getAlignment().getDataset(),
+                      alignFrame);
+            }
 
           }
         });
@@ -281,25 +308,16 @@ public class MsaWSClient extends Jws2Client
         List<WsParamSetI> presets = service.getParamStore().getPresets();
         if (presets != null && presets.size() > 0)
         {
-          JMenu presetlist = new JMenu(MessageManager.formatMessage(
-                  "label.run_with_preset_params", new String[]
-                  { calcName }));
+          JMenu presetlist = new JMenu(
+                  MessageManager.formatMessage(
+                          "label.run_with_preset_params",
+                          new String[] { calcName }));
 
           final int showToolTipFor = ToolTipManager.sharedInstance()
                   .getDismissDelay();
           for (final WsParamSetI preset : presets)
           {
-            final JMenuItem methodR = new JMenuItem(preset.getName())
-            {
-              @Override
-              protected void finalize() throws Throwable
-              {
-                // failsafe to ensure tooltip hover time is restored
-                ToolTipManager.sharedInstance().setDismissDelay(
-                        showToolTipFor);
-                super.finalize();
-              }
-            };
+            final JMenuItem methodR = new JMenuItem(preset.getName());
             final int QUICK_TOOLTIP = 1500;
             // JAL-1582 shorten tooltip display time in these menu items as
             // they can obscure other options
@@ -315,28 +333,37 @@ public class MsaWSClient extends Jws2Client
               @Override
               public void mouseExited(MouseEvent e)
               {
-                ToolTipManager.sharedInstance().setDismissDelay(showToolTipFor);
+                ToolTipManager.sharedInstance().setDismissDelay(
+                        showToolTipFor);
               }
 
             });
-            methodR.setToolTipText(JvSwingUtils.wrapTooltip(
-                    true,
-                    "<p><strong>"
-                            + (preset.isModifiable() ? MessageManager
-                                    .getString("label.user_preset")
-                                    : MessageManager
-                                            .getString("label.service_preset"))
-                            + "</strong><br/>" + preset.getDescription()
-                            + "</p>"));
+            String tooltip = JvSwingUtils
+                    .wrapTooltip(
+                            true,
+                            "<strong>"
+                                    + (preset.isModifiable() ? MessageManager
+                                            .getString("label.user_preset")
+                                            : MessageManager
+                                                    .getString("label.service_preset"))
+                                    + "</strong><br/>"
+                                    + preset.getDescription());
+            methodR.setToolTipText(tooltip);
             methodR.addActionListener(new ActionListener()
             {
+              @Override
               public void actionPerformed(ActionEvent e)
               {
                 AlignmentView msa = alignFrame
                         .gatherSequencesForAlignment();
-                new MsaWSClient(service, preset, alignFrame.getTitle(),
-                        msa, false, true, alignFrame.getViewport()
-                                .getAlignment().getDataset(), alignFrame);
+
+                if (msa != null)
+                {
+                  MsaWSClient msac = new MsaWSClient(service, preset,
+                          alignFrame.getTitle(), msa, false, true,
+                          alignFrame.getViewport().getAlignment()
+                                  .getDataset(), alignFrame);
+                }
 
               }