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