Merge branch 'JAL-3878_ws-overhaul-3' into with_ws_overhaul-3
[jalview.git] / src / jalview / ws2 / actions / alignment / AlignmentAction.java
1 package jalview.ws2.actions.alignment;
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.AlignmentWebServiceClientI;
13
14 /**
15  * Implementation of the {@link BaseAction} that runs alignment services. This
16  * type of action requires {@link AlignmentWebServiceClientI} to retrieve
17  * alignment result from the server.
18  * 
19  * @author mmwarowny
20  *
21  */
22 public class AlignmentAction extends BaseAction<AlignmentResult>
23 {
24   /**
25    * A builder for AlignemntActions. Adds {@code client} and {@code submitGaps}
26    * parameters to the base builder.
27    * 
28    * @author mmwarowny
29    */
30   public static class Builder extends BaseAction.Builder<AlignmentAction>
31   {
32     protected AlignmentWebServiceClientI client;
33
34     protected boolean submitGaps = false;
35
36     public Builder(AlignmentWebServiceClientI client)
37     {
38       super();
39       Objects.requireNonNull(client);
40       this.client = client;
41     }
42
43     public void submitGaps(boolean val)
44     {
45       submitGaps = val;
46     }
47
48     public AlignmentAction build()
49     {
50       return new AlignmentAction(this);
51     }
52   }
53
54   public static Builder newBuilder(AlignmentWebServiceClientI client)
55   {
56     return new Builder(client);
57   }
58
59   protected final boolean submitGaps;
60
61   protected final AlignmentWebServiceClientI client;
62
63   public AlignmentAction(Builder builder)
64   {
65     super(builder);
66     submitGaps = builder.submitGaps;
67     client = builder.client;
68   }
69
70   @Override
71   public TaskI<AlignmentResult> perform(AlignmentViewport viewport,
72       List<ArgumentI> args, Credentials credentials,
73       TaskEventListener<AlignmentResult> handler)
74   {
75     var msa = viewport.getAlignmentView(true);
76     var task = new AlignmentTask(
77         client, this, args, credentials, msa, viewport, submitGaps, handler);
78     task.start(viewport.getServiceExecutor());
79     return task;
80   }
81
82   /**
83    * Returns if the action is active for the given viewport. Alignment services
84    * are non-interactive, so the action is never active.
85    */
86   @Override
87   public boolean isActive(AlignmentViewport viewport)
88   {
89     return false;
90   }
91
92 }