JAL-3878 Separate gui elements from operations.
[jalview.git] / src / jalview / ws2 / WebServiceInfoUpdater.java
index 8152abf..c9557c6 100644 (file)
@@ -8,12 +8,14 @@ import jalview.gui.WebserviceInfo;
 
 public class WebServiceInfoUpdater implements PropertyChangeListener
 {
+  private final WebServiceWorkerI worker;
   private final WebserviceInfo wsInfo;
 
   private String outputHeader = "";
 
-  public WebServiceInfoUpdater(WebserviceInfo wsInfo)
+  public WebServiceInfoUpdater(WebServiceWorkerI worker, WebserviceInfo wsInfo)
   {
+    this.worker = worker;
     this.wsInfo = wsInfo;
   }
 
@@ -76,6 +78,7 @@ public class WebServiceInfoUpdater implements PropertyChangeListener
       break;
     }
     wsInfo.setStatus(job.getJobNum(), wsInfoStatus);
+    updateWSInfoGlobalStatus();
   }
 
   private void logChanged(PropertyChangeEvent evt)
@@ -96,4 +99,33 @@ public class WebServiceInfoUpdater implements PropertyChangeListener
             newLog.substring(oldLog.length()));
   }
 
+
+  private void updateWSInfoGlobalStatus()
+  {
+    var jobs = worker.getJobs();
+    if (jobs.countRunning() > 0)
+    {
+      wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
+    }
+    else if (jobs.countQueuing() > 0
+            || jobs.countSubmitted() < jobs.size())
+    {
+      wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
+    }
+    else
+    {
+      if (jobs.countSuccessful() > 0)
+      {
+        wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
+      }
+      else if (jobs.countCancelled() > 0)
+      {
+        wsInfo.setStatus(WebserviceInfo.STATE_CANCELLED_OK);
+      }
+      else if (jobs.countFailed() > 0)
+      {
+        wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);
+      }
+    }
+  }
 }