JAL-961 JAL-975 extend api to support removal of workers no-longer required by the...
[jalview.git] / src / jalview / workers / AlignCalcWorker.java
1 /**
2  * 
3  */
4 package jalview.workers;
5
6 import java.util.List;
7
8 import jalview.api.AlignCalcManagerI;
9 import jalview.api.AlignCalcWorkerI;
10 import jalview.api.AlignViewportI;
11 import jalview.api.AlignmentViewPanel;
12 import jalview.datamodel.AlignmentAnnotation;
13 import jalview.datamodel.AlignmentI;
14
15 /**
16  * Base class for alignment calculation workers 
17  * @author jimp
18  *
19  */
20 public abstract class AlignCalcWorker implements AlignCalcWorkerI
21 {
22   /**
23    * manager and data source for calculations
24    */
25   protected AlignViewportI alignViewport;
26   protected AlignCalcManagerI calcMan;
27   protected AlignmentViewPanel ap;
28   protected List<AlignmentAnnotation> ourAnnots=null;
29   
30   public AlignCalcWorker(AlignViewportI alignViewport,
31           AlignmentViewPanel alignPanel)
32   {
33     this.alignViewport = alignViewport;
34     calcMan=alignViewport.getCalcManager();
35     ap = alignPanel;    
36   }
37   protected void abortAndDestroy()
38   {
39     if (calcMan!=null) {
40       calcMan.workerComplete(this);
41     }
42     alignViewport=null;
43     calcMan=null;
44     ap=null;
45     
46   }
47   public boolean involves(AlignmentAnnotation i)
48   {
49     return ourAnnots!=null && ourAnnots.contains(i);
50   }
51
52   /**
53    * permanently remove from the alignment all annotation rows managed by this worker
54    */
55   @Override
56   public void removeOurAnnotation()
57   {
58     if (ourAnnots!=null && alignViewport!=null)
59     {
60       AlignmentI alignment=alignViewport.getAlignment();
61       synchronized (ourAnnots) {
62         for (AlignmentAnnotation aa:ourAnnots)
63         {
64           alignment.deleteAnnotation(aa, true);
65         }
66       }
67     }
68   }
69   // TODO: allow GUI to query workers associated with annotation to add items to annotation label panel popup menu
70
71 }