1 package jalview.ws2.gui;
3 import java.beans.PropertyChangeEvent;
4 import java.beans.PropertyChangeListener;
5 import java.util.Objects;
7 import jalview.gui.WebserviceInfo;
8 import jalview.ws2.WSJob;
9 import jalview.ws2.WSJobStatus;
10 import jalview.ws2.operations.WebServiceWorkerI;
13 * A helper class that can be attached as a listener to the {@link WSJob}
14 * object. It updates the job status in the {@link jalview.gui.WebServiceInfo}
15 * window according to the state changes of the job object.
17 * The {@link WebServiceInfoUpdater} object allows to decouple GUI updates
18 * from the web service worker logic.
23 public class WebServiceInfoUpdater implements PropertyChangeListener
25 private final WebServiceWorkerI worker;
26 private final WebserviceInfo wsInfo;
28 private String outputHeader = "";
30 public WebServiceInfoUpdater(WebServiceWorkerI worker, WebserviceInfo wsInfo)
36 public String getOutputHeader()
41 public void setOutputHeader(String header)
43 this.outputHeader = header;
47 public void propertyChange(PropertyChangeEvent evt)
49 switch (evt.getPropertyName())
63 private void statusChanged(PropertyChangeEvent evt)
65 WSJob job = (WSJob) evt.getSource();
66 WSJobStatus status = (WSJobStatus) evt.getNewValue();
73 wsInfoStatus = WebserviceInfo.STATE_QUEUING;
76 wsInfoStatus = WebserviceInfo.STATE_RUNNING;
79 wsInfoStatus = WebserviceInfo.STATE_STOPPED_OK;
82 wsInfoStatus = WebserviceInfo.STATE_CANCELLED_OK;
88 wsInfoStatus = WebserviceInfo.STATE_STOPPED_ERROR;
91 wsInfoStatus = WebserviceInfo.STATE_STOPPED_SERVERERROR;
94 wsInfo.setStatus(job.getJobNum(), wsInfoStatus);
95 updateWSInfoGlobalStatus();
98 private void logChanged(PropertyChangeEvent evt)
100 WSJob job = (WSJob) evt.getSource();
101 String oldLog = (String) evt.getOldValue();
102 String newLog = (String) evt.getNewValue();
103 wsInfo.appendProgressText(job.getJobNum(),
104 newLog.substring(oldLog.length()));
107 private void errorLogChanged(PropertyChangeEvent evt)
109 WSJob job = (WSJob) evt.getSource();
110 String oldLog = (String) evt.getOldValue();
111 String newLog = (String) evt.getNewValue();
112 wsInfo.appendProgressText(job.getJobNum(),
113 newLog.substring(oldLog.length()));
117 private void updateWSInfoGlobalStatus()
119 var jobs = worker.getJobs();
120 if (jobs.countRunning() > 0)
122 wsInfo.setStatus(WebserviceInfo.STATE_RUNNING);
124 else if (jobs.countQueuing() > 0
125 || jobs.countSubmitted() < jobs.size())
127 wsInfo.setStatus(WebserviceInfo.STATE_QUEUING);
131 if (jobs.countSuccessful() > 0)
133 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_OK);
135 else if (jobs.countCancelled() > 0)
137 wsInfo.setStatus(WebserviceInfo.STATE_CANCELLED_OK);
139 else if (jobs.countFailed() > 0)
141 wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_ERROR);