JAL-3878 Wire web services logic to UI elements.
[jalview.git] / src / jalview / ws2 / operations / AlignmentOperation.java
index 6a1baf2..d71e839 100644 (file)
@@ -33,6 +33,7 @@ import jalview.datamodel.SequenceI;
 import jalview.datamodel.Sequence;
 import jalview.gui.AlignFrame;
 import jalview.gui.AlignViewport;
+import jalview.gui.Desktop;
 import jalview.gui.JvSwingUtils;
 import jalview.gui.WebserviceInfo;
 import jalview.gui.WsJobParameters;
@@ -518,8 +519,9 @@ public class AlignmentOperation implements Operation
       updateWSInfoGlobalStatus();
       if (results.size() > 0)
       {
-        wsInfo.showResultsNewFrame
-                .addActionListener(evt -> displayResults(results));
+        OutputWrapper out = prepareOutput(results);
+        wsInfo.showResultsNewFrame.addActionListener(evt -> displayNewFrame(
+                new Alignment(out.aln), out.alorders, out.hidden));
         wsInfo.setResultsReady();
       }
       else
@@ -529,7 +531,24 @@ public class AlignmentOperation implements Operation
       wsInfo.removeProgressBar(progbarId);
     }
 
-    private void displayResults(Map<Long, AlignmentI> alignments)
+    private class OutputWrapper
+    {
+      AlignmentI aln;
+
+      List<AlignmentOrder> alorders;
+
+      HiddenColumns hidden;
+
+      OutputWrapper(AlignmentI aln, List<AlignmentOrder> alorders,
+              HiddenColumns hidden)
+      {
+        this.aln = aln;
+        this.alorders = alorders;
+        this.hidden = hidden;
+      }
+    }
+
+    private OutputWrapper prepareOutput(Map<Long, AlignmentI> alignments)
     {
       List<AlignmentOrder> alorders = new ArrayList<>();
       SequenceI[][] results = new SequenceI[jobs.size()][];
@@ -538,8 +557,8 @@ public class AlignmentOperation implements Operation
       {
         WSJob job = jobs.get(i);
         AlignmentI aln = alignments.get(job.getUid());
-        if (aln != null)
-        { // equivalent of job.hasResults()
+        if (aln != null) // equivalent of job.hasResults()
+        {
           /* Get the alignment including any empty sequences in the original
            * order with original ids. */
           JobInput input = inputs.get(job.getUid());
@@ -571,6 +590,7 @@ public class AlignmentOperation implements Operation
           // temporary workaround for deuniquify
           @SuppressWarnings({ "rawtypes", "unchecked" })
           Hashtable names = new Hashtable(input.sequenceNames);
+          // FIXME first call to deuniquify alters original alignment
           SeqsetUtils.deuniquify(names, result);
           alorders.add(msaOrder);
           results[i] = result;
@@ -597,8 +617,8 @@ public class AlignmentOperation implements Operation
         aln.setDataset(dataset);
 
       propagateDatasetMappings(aln);
-
-      displayNewFrame(aln, alorders, hidden);
+      return new OutputWrapper(aln, alorders, hidden);
+      // displayNewFrame(aln, alorders, hidden);
     }
 
     /*
@@ -654,6 +674,9 @@ public class AlignmentOperation implements Operation
        * If alignment was requested from one half of a SplitFrame, show in a
        * SplitFrame with the other pane similarly aligned.
        */
+
+      Desktop.addInternalFrame(frame, alnTitle, AlignFrame.DEFAULT_WIDTH,
+              AlignFrame.DEFAULT_HEIGHT);
     }
 
     private List<List<Integer>> sortOrders(List<?> alorders)