3 import java.beans.PropertyChangeEvent;
4 import java.beans.PropertyChangeListener;
5 import java.util.Objects;
7 import jalview.gui.WebserviceInfo;
10 * A helper class that can be attached as a listener to the {@link WSJob}
11 * object. It updates the job status in the {@link jalview.gui.WebServiceInfo}
12 * window according to the state changes of the job object.
14 * The {@link WebServiceInfoUpdater} object allows to decouple GUI updates
15 * from the web service worker logic.
20 public class WebServiceInfoUpdater implements PropertyChangeListener
22 private final WebServiceWorkerI worker;
23 private final WebserviceInfo wsInfo;
25 private String outputHeader = "";
27 public WebServiceInfoUpdater(WebServiceWorkerI worker, WebserviceInfo wsInfo)
33 public String getOutputHeader()
38 public void setOutputHeader(String header)
40 this.outputHeader = header;
44 public void propertyChange(PropertyChangeEvent evt)
46 switch (evt.getPropertyName())
60 private void statusChanged(PropertyChangeEvent evt)
62 WSJob job = (WSJob) evt.getSource();
63 WSJobStatus status = (WSJobStatus) evt.getNewValue();
70 wsInfoStatus = WebserviceInfo.STATE_QUEUING;
73 wsInfoStatus = WebserviceInfo.STATE_RUNNING;
76 wsInfoStatus = WebserviceInfo.STATE_STOPPED_OK;
79 wsInfoStatus = WebserviceInfo.STATE_CANCELLED_OK;
85 wsInfoStatus = WebserviceInfo.STATE_STOPPED_ERROR;
88 wsInfoStatus = WebserviceInfo.STATE_STOPPED_SERVERERROR;
91 wsInfo.setStatus(job.getJobNum(), wsInfoStatus);
92 updateWSInfoGlobalStatus();
95 private void logChanged(PropertyChangeEvent evt)
97 WSJob job = (WSJob) evt.getSource();
98 String oldLog = (String) evt.getOldValue();
99 String newLog = (String) evt.getNewValue();
100 wsInfo.appendProgressText(job.getJobNum(),
101 newLog.substring(oldLog.length()));
104 private void errorLogChanged(PropertyChangeEvent evt)
106 WSJob job = (WSJob) evt.getSource();
107 String oldLog = (String) evt.getOldValue();
108 String newLog = (String) evt.getNewValue();
109 wsInfo.appendProgressText(job.getJobNum(),
110 newLog.substring(oldLog.length()));
114 private void updateWSInfoGlobalStatus()
116 var jobs = worker.getJobs();
117 if (jobs.countRunning() > 0)
119 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
121 else if (jobs.countQueuing() > 0
122 || jobs.countSubmitted() < jobs.size())
124 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
128 if (jobs.countSuccessful() > 0)
130 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
132 else if (jobs.countCancelled() > 0)
134 wsInfo.setStatus(WebserviceInfo.STATE_CANCELLED_OK);
136 else if (jobs.countFailed() > 0)
138 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);