JAL-2446 merged to spike branch
[jalview.git] / src / jalview / ws / jws1 / SeqSearchWSThread.java
index 7c2ea49..edc9ae8 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.
  * 
  */
 package jalview.ws.jws1;
 
-import java.util.*;
-
-import jalview.analysis.*;
-import jalview.bin.*;
-import jalview.datamodel.*;
-import jalview.gui.*;
+import jalview.analysis.AlignSeq;
+import jalview.api.FeatureColourI;
+import jalview.bin.Cache;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AlignmentView;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
+import jalview.gui.WebserviceInfo;
 import jalview.io.NewickFile;
 import jalview.util.MessageManager;
 import jalview.ws.AWsJob;
 import jalview.ws.JobStateSummary;
 import jalview.ws.WSClientI;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Vector;
+
 import vamsas.objects.simple.MsaResult;
 import vamsas.objects.simple.SeqSearchResult;
 
@@ -85,7 +95,9 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
       int nseqs = 0;
       if (minlen < 0)
       {
-          throw new Error(MessageManager.getString("error.implementation_error_minlen_must_be_greater_zero"));
+        throw new Error(
+                MessageManager
+                        .getString("error.implementation_error_minlen_must_be_greater_zero"));
       }
       for (int i = 0; i < seqs.length; i++)
       {
@@ -126,8 +138,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
                     .extractGaps(jalview.util.Comparison.GapChars,
                             seqs[i].getSequenceAsString());
           }
-          emptySeqs.add(new String[]
-          { newname, empty });
+          emptySeqs.add(new String[] { newname, empty });
         }
       }
       if (submitGaps)
@@ -143,6 +154,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
      * 
      * @return true if getAlignment will return a valid alignment result.
      */
+    @Override
     public boolean hasResults()
     {
       if (subjobComplete
@@ -161,7 +173,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
      * 
      * @return null or { Alignment(+features and annotation), NewickFile)}
      */
-    public Object[] getAlignment(Alignment dataset, Hashtable featureColours)
+    public Object[] getAlignment(AlignmentI dataset,
+            Map<String, FeatureColourI> featureColours)
     {
 
       if (result != null && result.isFinished())
@@ -196,7 +209,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
           if (inFile != null && inFile.length() > 0)
           {
             new jalview.io.AnnotationFile().readAnnotationFile(al, inFile,
-                    jalview.io.AppletFormatAdapter.PASTE);
+                    jalview.io.DataSourceType.PASTE);
           }
         } catch (Exception e)
         {
@@ -212,7 +225,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
           if (inFile != null && inFile.length() > 0)
           {
             jalview.io.FeaturesFile ff = new jalview.io.FeaturesFile(
-                    inFile, jalview.io.AppletFormatAdapter.PASTE);
+                    inFile, jalview.io.DataSourceType.PASTE);
             ff.parse(al, featureColours, false);
           }
         } catch (Exception e)
@@ -229,7 +242,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
           if (inFile != null && inFile.length() > 0)
           {
             nf = new jalview.io.NewickFile(inFile,
-                    jalview.io.AppletFormatAdapter.PASTE);
+                    jalview.io.DataSourceType.PASTE);
             if (!nf.isValid())
             {
               nf.close();
@@ -259,8 +272,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
          * trigger a 'fetchDBids' to annotate sequences with database ids...
          */
 
-        return new Object[]
-        { al, nf };
+        return new Object[] { al, nf };
       }
       return null;
     }
@@ -279,6 +291,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
      * 
      * @return boolean true if job can be submitted.
      */
+    @Override
     public boolean hasValidInput()
     {
       if (seqs.getSeqs() != null)
@@ -291,7 +304,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
 
   String alTitle; // name which will be used to form new alignment window.
 
-  Alignment dataset; // dataset to which the new alignment will be
+  AlignmentI dataset; // dataset to which the new alignment will be
 
   // associated.
 
@@ -333,7 +346,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
   SeqSearchWSThread(ext.vamsas.SeqSearchI server, String wsUrl,
           WebserviceInfo wsinfo, jalview.gui.AlignFrame alFrame,
           String wsname, String title, AlignmentView _msa, String db,
-          Alignment seqset)
+          AlignmentI seqset)
   {
     this(server, wsUrl, wsinfo, alFrame, _msa, wsname, db);
     OutputHeader = wsInfo.getProgressText();
@@ -365,11 +378,13 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public boolean isCancellable()
   {
     return true;
   }
 
+  @Override
   public void cancelJob()
   {
     if (!jobComplete && jobs != null)
@@ -436,17 +451,21 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public void pollJob(AWsJob job) throws Exception
   {
     ((SeqSearchWSJob) job).result = server.getResult(((SeqSearchWSJob) job)
             .getJobId());
   }
 
+  @Override
   public void StartJob(AWsJob job)
   {
     if (!(job instanceof SeqSearchWSJob))
     {
-        throw new Error(MessageManager.formatMessage("error.implementation_error_msawbjob_called", new String[]{job.getClass().toString()}));
+      throw new Error(MessageManager.formatMessage(
+              "error.implementation_error_msawbjob_called",
+              new String[] { job.getClass().toString() }));
     }
     SeqSearchWSJob j = (SeqSearchWSJob) job;
     if (j.isSubmitted())
@@ -464,7 +483,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
       j.setSubmitted(true);
       j.result = new MsaResult();
       j.result.setFinished(true);
-      j.result.setStatus(MessageManager.getString("label.empty_alignment_job"));
+      j.result.setStatus(MessageManager
+              .getString("label.empty_alignment_job"));
       ((MsaResult) j.result).setMsa(null);
     }
     try
@@ -483,7 +503,9 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
       {
         if (jobsubmit == null)
         {
-          throw new Exception(MessageManager.formatMessage("exception.web_service_returned_null_try_later", new String[]{WsUrl}));
+          throw new Exception(MessageManager.formatMessage(
+                  "exception.web_service_returned_null_try_later",
+                  new String[] { WsUrl }));
         }
 
         throw new Exception(jobsubmit.getJobId());
@@ -501,9 +523,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
       wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
       wsInfo.setStatus(j.getJobnum(),
               WebserviceInfo.STATE_STOPPED_SERVERERROR);
-      wsInfo.appendProgressText(
-              j.getJobnum(),
-              MessageManager.getString("info.failed_to_submit_sequences_for_alignment"));
+      wsInfo.appendProgressText(j.getJobnum(), MessageManager
+              .getString("info.failed_to_submit_sequences_for_alignment"));
 
       // e.printStackTrace(); // TODO: JBPNote DEBUG
     }
@@ -524,6 +545,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
     return msa;
   }
 
+  @Override
   public void parseResult()
   {
     int results = 0; // number of result sets received
@@ -541,8 +563,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
                   .getAlignment();
           if (valign != null)
           {
-            wsInfo.appendProgressText(jobs[j].getJobnum(),
-                    MessageManager.getString("info.alignment_object_method_notes"));
+            wsInfo.appendProgressText(jobs[j].getJobnum(), MessageManager
+                    .getString("info.alignment_object_method_notes"));
             String[] lines = valign.getMethod();
             for (int line = 0; line < lines.length; line++)
             {
@@ -567,6 +589,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
       wsInfo.showResultsNewFrame
               .addActionListener(new java.awt.event.ActionListener()
               {
+                @Override
                 public void actionPerformed(java.awt.event.ActionEvent evt)
                 {
                   displayResults(true);
@@ -575,6 +598,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
       wsInfo.mergeResults
               .addActionListener(new java.awt.event.ActionListener()
               {
+                @Override
                 public void actionPerformed(java.awt.event.ActionEvent evt)
                 {
                   displayResults(false);
@@ -600,7 +624,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
     // NewickFile nf[] = new NewickFile[jobs.length];
     for (int j = 0; j < jobs.length; j++)
     {
-      Hashtable featureColours = new Hashtable();
+      Map<String, FeatureColourI> featureColours = new HashMap<String, FeatureColourI>();
       Alignment al = null;
       NewickFile nf = null;
       if (jobs[j].hasResults())
@@ -642,7 +666,8 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
               AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
       if (nf != null)
       {
-        af.ShowNewickTree(nf, MessageManager.formatMessage("label.tree_from", new String[]{this.alTitle}));
+        af.showNewickTree(nf, MessageManager.formatMessage(
+                "label.tree_from", new String[] { this.alTitle }));
       }
       // initialise with same renderer settings as in parent alignframe.
       af.getFeatureRenderer().transferSettings(this.featureSettings);
@@ -651,6 +676,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
     }
   }
 
+  @Override
   public boolean canMergeResults()
   {
     return false;