JAL-1601 Create SecStructPredTask class
[jalview.git] / src / jalview / ws2 / actions / BaseAction.java
index 37fbe39..a46a4e7 100644 (file)
@@ -1,9 +1,18 @@
 package jalview.ws2.actions;
 
 import java.util.EnumSet;
+import java.util.List;
+import java.util.Objects;
 
+import jalview.gui.AlignViewport;
+import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.params.ArgumentI;
 import jalview.ws2.actions.api.ActionI;
+import jalview.ws2.actions.api.TaskEventListener;
+import jalview.ws2.actions.api.TaskI;
 import jalview.ws2.api.CredentialType;
+import jalview.ws2.api.Credentials;
+import jalview.ws2.api.WebService;
 
 /**
  * An abstract base class storing common data and implementing their getters
@@ -12,15 +21,16 @@ import jalview.ws2.api.CredentialType;
  * {@code isActive} implementations.
  * 
  * @author mmwarowny
- *
- * @param <T>
+ * @param <R>
  *          task result type
  */
-public abstract class BaseAction<T> implements ActionI<T>
+public abstract class BaseAction<R> implements ActionI<R>
 {
-  public static class Builder
+  public static abstract class Builder<A extends BaseAction<?>>
   {
-    protected String name;
+    protected WebService<A> webService;
+
+    protected String name = null;
 
     protected String tooltip = "";
 
@@ -36,9 +46,18 @@ public abstract class BaseAction<T> implements ActionI<T>
 
     protected EnumSet<CredentialType> requiredCredentials = EnumSet.noneOf(CredentialType.class);
 
-    public Builder(String name)
+    public Builder()
+    {
+    }
+
+    public void name(String val)
+    {
+      this.name = val;
+    }
+
+    public void webService(WebService<A> val)
     {
-      this.name = name;
+      this.webService = val;
     }
 
     public void tooltip(String val)
@@ -82,6 +101,8 @@ public abstract class BaseAction<T> implements ActionI<T>
     }
   }
 
+  protected final WebService<? extends ActionI<R>> webService;
+
   protected final String name;
 
   protected final String tooltip;
@@ -98,8 +119,10 @@ public abstract class BaseAction<T> implements ActionI<T>
 
   protected final EnumSet<CredentialType> requiredCredentials;
 
-  protected BaseAction(Builder builder)
+  protected BaseAction(Builder<? extends BaseAction<R>> builder)
   {
+    Objects.requireNonNull(builder.webService);
+    this.webService = builder.webService;
     this.name = builder.name;
     this.tooltip = builder.tooltip;
     this.subcategory = builder.subcategory;
@@ -110,9 +133,10 @@ public abstract class BaseAction<T> implements ActionI<T>
     this.requiredCredentials = builder.requiredCredentials;
   }
 
-  public static Builder newBuilder(String name)
+  @Override
+  public WebService<? extends ActionI<R>> getWebService()
   {
-    return new Builder(name);
+    return webService;
   }
 
   @Override
@@ -121,6 +145,20 @@ public abstract class BaseAction<T> implements ActionI<T>
     return name;
   }
 
+  /**
+   * Returns a full name of the action which comprises of the service name and
+   * the action name if present.
+   * 
+   * @return full name of this action
+   */
+  public String getFullName()
+  {
+    if (name == null || name.isEmpty())
+      return webService.getName();
+    else
+      return webService.getName() + " " + name;
+  }
+
   @Override
   public String getTooltip()
   {