import jalview.gui.WebserviceInfo;
+/**
+ * A helper class that can be attached as a listener to the {@link WSJob}
+ * object. It updates the job status in the {@link jalview.gui.WebServiceInfo}
+ * window according to the state changes of the job object.
+ *
+ * The {@link WebServiceInfoUpdater} object allows to decouple GUI updates
+ * from the web service worker logic.
+ *
+ * @author mmwarowny
+ *
+ */
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;
}
break;
}
wsInfo.setStatus(job.getJobNum(), wsInfoStatus);
+ updateWSInfoGlobalStatus();
}
private void logChanged(PropertyChangeEvent evt)
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);
+ }
+ }
+ }
}