Clover icon

Coverage Report

  1. Project Clover database Wed Dec 3 2025 17:03:17 GMT
  2. Package jalview.ws2.actions.annotation

File AlignCalcWorkerAdapter.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
60% of files have more coverage

Code metrics

12
48
15
2
186
160
22
0.46
3.2
7.5
1.47

Classes

Class Line # Actions
AlignCalcWorkerAdapter 19 48 19
0.00%
AlignCalcWorkerAdapter.WorkerListener 160 0 3
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package jalview.ws2.actions.annotation;
2   
3    import java.util.ArrayList;
4    import java.util.Collections;
5    import java.util.List;
6   
7    import jalview.analysis.AlignmentAnnotationUtils;
8    import jalview.api.AlignViewportI;
9    import jalview.api.AlignmentViewPanel;
10    import jalview.api.PollableAlignCalcWorkerI;
11    import jalview.datamodel.AlignmentAnnotation;
12    import jalview.datamodel.AlignmentI;
13    import jalview.workers.AlignCalcWorker;
14    import jalview.ws.params.ArgumentI;
15    import jalview.ws2.actions.api.TaskEventListener;
16    import jalview.ws2.actions.api.TaskI;
17    import jalview.ws2.api.Credentials;
18   
 
19    public class AlignCalcWorkerAdapter extends AlignCalcWorker implements PollableAlignCalcWorkerI
20    {
21    private static int calcCount = 0;
22   
23    private final int calcNumber = calcCount++;
24   
25    private final AnnotationAction action;
26   
27    private final List<ArgumentI> args;
28   
29    private final Credentials credentials;
30   
31    private TaskI<AnnotationResult> currentTask = null;
32   
33    private TaskEventListener<AnnotationResult> taskListener = new TaskEventListener<>()
34    {
 
35  0 toggle @Override
36    public void taskCompleted(TaskI source, AnnotationResult result)
37    {
38  0 int graphGroup = alignViewport.getAlignment().getLastGraphGroup();
39  0 List<AlignmentAnnotation> annotations = new ArrayList<>();
40  0 for (AlignmentAnnotation ala : result.getAnnotations())
41    {
42  0 if (ala.graphGroup > 0)
43  0 ala.graphGroup += graphGroup;
44  0 var newAnnot = alignViewport.getAlignment()
45    .updateFromOrCopyAnnotation(ala);
46  0 if (newAnnot.sequenceRef != null)
47    {
48  0 newAnnot.sequenceRef.addAlignmentAnnotation(newAnnot);
49  0 newAnnot.adjustForAlignment();
50  0 AlignmentAnnotationUtils.replaceAnnotationOnAlignmentWith(
51    newAnnot, newAnnot.label, newAnnot.getCalcId());
52    }
53  0 annotations.add(newAnnot);
54    }
55  0 updateOurAnnots(annotations);
56  0 listener.workerHasResult(
57    AlignCalcWorkerAdapter.this,
58    new AnnotationResult(
59    annotations,
60    result.hasFeatures,
61    result.featureColours,
62    result.featureFilters));
63    }
64    };
65   
 
66  0 toggle public AlignCalcWorkerAdapter(AlignViewportI alignViewport, AlignmentViewPanel alignPanel, AnnotationAction action,
67    List<ArgumentI> args, Credentials credentials)
68    {
69  0 super(alignViewport, alignPanel);
70  0 this.action = action;
71  0 this.args = args;
72  0 this.credentials = credentials;
73    }
74   
 
75  0 toggle @Override
76    public String getCalcName()
77    {
78  0 return action.getWebService().getName();
79    }
80   
 
81  0 toggle @Override
82    public void updateAnnotation()
83    {
84   
85    }
86   
 
87  0 toggle private void updateOurAnnots(List<AlignmentAnnotation> newAnnots)
88    {
89  0 List<AlignmentAnnotation> oldAnnots = ourAnnots != null ? ourAnnots : List.of();
90  0 AlignmentI alignment = alignViewport.getAlignment();
91  0 for (AlignmentAnnotation annotation : oldAnnots)
92  0 if (!newAnnots.contains(annotation))
93  0 alignment.deleteAnnotation(annotation);
94  0 for (AlignmentAnnotation annotation : newAnnots)
95  0 alignment.validateAnnotation(annotation);
96  0 ourAnnots = Collections.synchronizedList(newAnnots);
97    }
98   
 
99  0 toggle @Override
100    public synchronized void startUp() throws Throwable
101    {
102  0 if (alignViewport.isClosed())
103    {
104  0 calcMan.disableWorker(this);
105  0 abortAndDestroy();
106  0 throw new IllegalStateException("Starting calculation for closed viewport");
107    }
108  0 currentTask = action.createTask(alignViewport, args, credentials);
109  0 currentTask.addTaskEventListener(taskListener);
110  0 currentTask.init();
111  0 listener.workerStarted(this);
112    }
113   
 
114  0 toggle @Override
115    public boolean poll() throws Throwable
116    {
117  0 return currentTask.poll();
118    }
119   
 
120  0 toggle @Override
121    public synchronized void cancel()
122    {
123  0 try
124    {
125  0 currentTask.cancel();
126    } finally
127    {
128  0 currentTask.removeTaskEventListener(taskListener);
129  0 listener.workerStopped(this);
130    }
131    }
132   
 
133  0 toggle @Override
134    public synchronized void done()
135    {
136  0 try
137    {
138  0 currentTask.complete();
139    } catch (Exception e)
140    {
141    } finally
142    {
143  0 currentTask.removeTaskEventListener(taskListener);
144  0 listener.workerStopped(this);
145    }
146    }
147   
 
148  0 toggle @Override
149    public boolean isDeletable()
150    {
151  0 return true;
152    }
153   
 
154  0 toggle @Override
155    public String toString()
156    {
157  0 return "AlignCalcWorkerAdapter-" + calcNumber + " for " + getCalcName();
158    }
159   
 
160    public interface WorkerListener extends java.util.EventListener
161    {
 
162  0 toggle default void workerStarted(AlignCalcWorkerAdapter source)
163    {
164    };
165   
 
166  0 toggle default void workerStopped(AlignCalcWorkerAdapter source)
167    {
168    };
169   
 
170  0 toggle default void workerHasResult(AlignCalcWorkerAdapter source, AnnotationResult result)
171    {
172    };
173   
174    static final WorkerListener NULL_LISTENER = new WorkerListener()
175    {
176    };
177    }
178   
179    private WorkerListener listener = WorkerListener.NULL_LISTENER;
180   
 
181  0 toggle public void setWorkerListener(WorkerListener listener)
182    {
183  0 if (listener == null) listener = WorkerListener.NULL_LISTENER;
184  0 this.listener = listener;
185    }
186    }