JAL-4131 Replace usages of requireNonNullElse
[jalview.git] / src / jalview / ws2 / gui / AlignmentServiceGuiHandler.java
index 2540dd1..fd1d0ad 100644 (file)
@@ -1,7 +1,5 @@
 package jalview.ws2.gui;
 
-import static java.util.Objects.requireNonNullElse;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.BitSet;
@@ -11,8 +9,10 @@ import java.util.LinkedList;
 import java.util.List;
 
 import javax.swing.JInternalFrame;
+import javax.swing.SwingUtilities;
 
 import jalview.bin.Cache;
+import jalview.bin.Console;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentOrder;
@@ -60,7 +60,7 @@ class AlignmentServiceGuiHandler
     String panelInfo = String.format("%s using service hosted at %s%n%s",
         service.getName(), service.getUrl(), service.getDescription());
     infoPanel = new WebserviceInfo(service.getName(), panelInfo, false);
-    String actionName = requireNonNullElse(action.getName(), "Alignment");
+    String actionName = action.getName() != null ? action.getName() : "Alignment";
     alnTitle = String.format("%s %s of %s", service.getName(), actionName,
         frame.getTitle());
   }
@@ -134,9 +134,10 @@ class AlignmentServiceGuiHandler
   @Override
   public void taskCompleted(TaskI<AlignmentResult> source, AlignmentResult result)
   {
+    SwingUtilities.invokeLater(() -> infoPanel.removeProgressBar(jobs[0].getInternalId()));
     if (result == null)
     {
-      infoPanel.setFinishedNoResults();
+      SwingUtilities.invokeLater(infoPanel::setFinishedNoResults);
       return;
     }
     infoPanel.showResultsNewFrame.addActionListener(evt -> {
@@ -148,7 +149,7 @@ class AlignmentServiceGuiHandler
       displayResultsNewFrame(alnCpy, result.getAlignmentOrders(),
           result.getHiddenColumns());
     });
-    infoPanel.setResultsReady();
+    SwingUtilities.invokeLater(infoPanel::setResultsReady);
   }
 
   private void displayResultsNewFrame(Alignment aln,
@@ -188,7 +189,7 @@ class AlignmentServiceGuiHandler
       }
     }
     // no split frame or failed to create complementary alignment
-    Desktop.addInternalFrame(frame, alnTitle, AlignFrame.DEFAULT_WIDTH,
+    Desktop.addInternalFrame(newFrame, alnTitle, AlignFrame.DEFAULT_WIDTH,
         AlignFrame.DEFAULT_HEIGHT);
   }
   
@@ -224,7 +225,7 @@ class AlignmentServiceGuiHandler
   @Override
   public void taskException(TaskI<AlignmentResult> source, Exception e)
   {
-    Cache.log.error(String.format("Service %s raised an exception.", service.getName()), e);
+    Console.error(String.format("Service %s raised an exception.", service.getName()), e);
     infoPanel.appendProgressText(e.getMessage());
   }