1 package jalview.ws2.actions;
3 import java.util.EnumSet;
5 import java.util.Objects;
7 import jalview.gui.AlignViewport;
8 import jalview.viewmodel.AlignmentViewport;
9 import jalview.ws.params.ArgumentI;
10 import jalview.ws2.actions.api.ActionI;
11 import jalview.ws2.actions.api.TaskEventListener;
12 import jalview.ws2.actions.api.TaskI;
13 import jalview.ws2.api.CredentialType;
14 import jalview.ws2.api.Credentials;
15 import jalview.ws2.api.WebService;
18 * An abstract base class storing common data and implementing their getters
19 * defined in {@link ActionI} interface. The concrete action implementations are
20 * encouraged to extend this class and provide their own {@code perform} and
21 * {@code isActive} implementations.
27 public abstract class BaseAction<R> implements ActionI<R>
29 public static abstract class Builder<A extends BaseAction<?>>
31 protected WebService<A> webService;
33 protected String name = null;
35 protected String tooltip = "";
37 protected String subcategory = null;
39 protected int minSequences = -1;
41 protected int maxSequences = -1;
43 protected boolean allowProtein = true;
45 protected boolean allowNucleotide = true;
47 protected EnumSet<CredentialType> requiredCredentials = EnumSet.noneOf(CredentialType.class);
53 public void name(String val)
58 public void webService(WebService<A> val)
60 this.webService = val;
63 public void tooltip(String val)
68 public void subcategory(String val)
73 public void minSequences(int val)
78 public void maxSequecnes(int val)
83 public void allowProtein(boolean val)
88 public void allowNucleotide(boolean val)
90 allowNucleotide = val;
93 public void addRequiredCredential(CredentialType val)
95 requiredCredentials.add(val);
98 public void requiredCredentials(EnumSet<CredentialType> val)
100 requiredCredentials = val;
104 protected final WebService<? extends ActionI<R>> webService;
106 protected final String name;
108 protected final String tooltip;
110 protected final String subcategory;
112 protected final int minSequences;
114 protected final int maxSequences;
116 protected final boolean allowProtein;
118 protected final boolean allowNucleotide;
120 protected final EnumSet<CredentialType> requiredCredentials;
122 protected BaseAction(Builder<? extends BaseAction<R>> builder)
124 Objects.requireNonNull(builder.webService);
125 this.webService = builder.webService;
126 this.name = builder.name;
127 this.tooltip = builder.tooltip;
128 this.subcategory = builder.subcategory;
129 this.minSequences = builder.minSequences;
130 this.maxSequences = builder.maxSequences;
131 this.allowProtein = builder.allowProtein;
132 this.allowNucleotide = builder.allowNucleotide;
133 this.requiredCredentials = builder.requiredCredentials;
137 public WebService<? extends ActionI<R>> getWebService()
143 public String getName()
149 * Returns a full name of the action which comprises of the service name and
150 * the action name if present.
152 * @return full name of this action
154 public String getFullName()
156 if (name == null || name.isEmpty())
157 return webService.getName();
159 return webService.getName() + " " + name;
163 public String getTooltip()
169 public String getSubcategory()
175 public int getMinSequences()
181 public int getMaxSequences()
187 public boolean doAllowProtein()
193 public boolean doAllowNucleotide()
195 return allowNucleotide;
199 public EnumSet<CredentialType> getRequiredCredentials()
201 return requiredCredentials;