JAL-4199 Change actions to be task factories
[jalview.git] / src / jalview / ws2 / actions / annotation / AnnotationAction.java
1 package jalview.ws2.actions.annotation;
2
3 import java.util.List;
4 import java.util.Objects;
5
6 import jalview.api.AlignViewportI;
7 import jalview.viewmodel.AlignmentViewport;
8 import jalview.ws.params.ArgumentI;
9 import jalview.ws2.actions.BaseAction;
10 import jalview.ws2.actions.api.TaskEventListener;
11 import jalview.ws2.actions.api.TaskI;
12 import jalview.ws2.api.Credentials;
13 import jalview.ws2.client.api.AnnotationWebServiceClientI;
14
15 public class AnnotationAction extends BaseAction<AnnotationResult>
16 {
17   /**
18    * A builder of {@link AnnotationAction} instances.
19    */
20   public static class Builder extends BaseAction.Builder<AnnotationAction>
21   {
22     protected AnnotationWebServiceClientI client;
23     
24     protected boolean alignmentAnalysis = false;
25     
26     protected boolean requireAlignedSequences = false;
27     
28     protected boolean filterSymbols = true;
29
30     public Builder(AnnotationWebServiceClientI client)
31     {
32       super();
33       Objects.requireNonNull(client);
34       this.client = client;
35     }
36     
37     /**
38      * Set if action is an alignment analysis action.
39      */
40     public void alignmentAnalysis(boolean val)
41     {
42       alignmentAnalysis = val;
43     }
44     
45     /**
46      * Set if action require aligned sequences.
47      */
48     public void requireAlignedSequences(boolean val)
49     {
50       requireAlignedSequences = val;
51     }
52
53     /**
54      * Set if action requires non-standard residues to be filtered out 
55      */
56     public void filterSymbols(boolean val)
57     {
58       filterSymbols = val;
59     }
60
61     public AnnotationAction build()
62     {
63       return new AnnotationAction(this);
64     }
65   }
66
67   public static Builder newBuilder(AnnotationWebServiceClientI client)
68   {
69     return new Builder(client);
70   }
71
72   protected final AnnotationWebServiceClientI client;
73   
74   protected final boolean alignmentAnalysis;
75   
76   protected final boolean requireAlignedSequences;
77   
78   protected final boolean filterSymbols;
79
80   protected AnnotationAction(Builder builder)
81   {
82     super(builder);
83     client = builder.client;
84     alignmentAnalysis = builder.alignmentAnalysis;
85     requireAlignedSequences = builder.requireAlignedSequences;
86     filterSymbols = builder.filterSymbols;
87   }
88   
89   @Override
90   public AnnotationTask createTask(AlignViewportI viewport,
91       List<ArgumentI> args, Credentials credentials)
92   {
93     return new AnnotationTask(client, this, args, credentials, viewport);
94   }
95   
96   /**
97    * Return if this action is an alignment analysis service.
98    */
99   public boolean isAlignmentAnalysis()
100   {
101     return alignmentAnalysis;
102   }
103
104   /**
105    * Return if this action require sequences to be aligned.
106    */
107   public boolean getRequireAlignedSequences()
108   {
109     return requireAlignedSequences;
110   }
111   
112   /**
113    * Return if this action require non-standard symbols to be filtered out.
114    */
115   public boolean getFilterSymbols()
116   {
117     return filterSymbols;
118   }
119   
120   @Override
121   public boolean isActive(AlignmentViewport viewport)
122   {
123     return false;
124   }
125 }