Merge branch 'alpha/origin_2022_JAL-3066_Jalview_212_slivka-integration' into spike...
[jalview.git] / src / jalview / ws / api / ServiceWithParameters.java
1 package jalview.ws.api;
2
3 import jalview.bin.Cache;
4 import jalview.gui.AlignFrame;
5 import jalview.ws.jws2.MsaWSClient;
6 import jalview.ws.jws2.SequenceAnnotationWSClient;
7 import jalview.ws.params.ParamManager;
8
9 import javax.swing.JMenu;
10
11 public abstract class ServiceWithParameters extends UIinfo
12 {
13
14   protected jalview.ws.uimodel.AlignAnalysisUIText aaui;
15
16   public ServiceWithParameters(String serviceType, String action,
17           String name, String description, String hosturl)
18   {
19     super(serviceType, action, name, description, hosturl);
20   }
21
22   public abstract void initParamStore(ParamManager userParameterStore);
23
24   public jalview.ws.uimodel.AlignAnalysisUIText getAlignAnalysisUI()
25   {
26     return aaui;
27   }
28
29   public void setAlignAnalysisUI(
30           jalview.ws.uimodel.AlignAnalysisUIText aaui)
31   {
32     this.aaui = aaui;
33   }
34
35   public boolean isInteractiveUpdate()
36   {
37     return aaui != null && aaui.isAA();
38   }
39   // config flags for SeqAnnotationServiceCalcWorker
40
41   public boolean isProteinService()
42   {
43     return aaui == null ? true : aaui.isPr();
44   }
45
46   public boolean isNucleotideService()
47   {
48     return aaui == null ? false : aaui.isNa();
49   }
50
51   public boolean isNeedsAlignedSequences()
52   {
53     return aaui == null ? false : aaui.isNeedsAlignedSeqs();
54   }
55
56   public boolean isAlignmentAnalysis()
57   {
58     return aaui == null ? false : aaui.isAA();
59   }
60
61   public boolean isFilterSymbols()
62   {
63     return aaui != null ? aaui.isFilterSymbols() : true;
64   }
65
66   public int getMinimumInputSequences()
67   {
68     return aaui != null ? aaui.getMinimumSequences() : 1;
69   }
70
71   public String getNameURI()
72   {
73     return "java:" + getName();
74   }
75
76   public String getUri()
77   {
78     // TODO verify that service parameter sets in projects are consistent with
79     // Jalview 2.10.4
80     // this is only valid for Jaba 1.0 - this formula might have to change!
81     return getHostURL()
82             + (getHostURL().lastIndexOf("/") == (getHostURL().length() - 1)
83                     ? ""
84                     : "/")
85             + getName();
86   }
87
88   protected enum ServiceClient
89   {
90     MSAWSCLIENT, SEQUENCEANNOTATIONWSCLIENT;
91   };
92
93   protected ServiceClient style = null;
94
95   public void attachWSMenuEntry(JMenu atpoint, AlignFrame alignFrame)
96   {
97     switch (style)
98     {
99     case MSAWSCLIENT:
100         new MsaWSClient().attachWSMenuEntry(atpoint, this, alignFrame);
101       break;
102     case SEQUENCEANNOTATIONWSCLIENT:
103         new SequenceAnnotationWSClient().attachWSMenuEntry(atpoint, this,
104                 alignFrame);
105       break;
106     default:
107       Cache.log.warn("Implementation error ? Service " + getName()
108               + " has Unknown service style " + style);
109     }
110   }
111 }