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