JAL-1517 fix copyright for 2.8.2
[jalview.git] / src / jalview / ws / jws2 / Jws2Client.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3  * Copyright (C) 2014 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.ws.jws2;
22
23 import java.util.List;
24
25 import javax.swing.JMenu;
26
27 import compbio.metadata.Argument;
28
29 import jalview.gui.AlignFrame;
30 import jalview.gui.Desktop;
31 import jalview.gui.WebserviceInfo;
32 import jalview.gui.WsJobParameters;
33 import jalview.util.MessageManager;
34 import jalview.ws.jws2.dm.JabaWsParamSet;
35 import jalview.ws.jws2.jabaws2.Jws2Instance;
36 import jalview.ws.params.WsParamSetI;
37
38 /**
39  * provides metadata for a jabaws2 service instance - resolves names, etc.
40  * 
41  * @author JimP
42  * 
43  */
44 public abstract class Jws2Client extends jalview.ws.WSClient
45 {
46   protected AlignFrame alignFrame;
47
48   protected WsParamSetI preset;
49
50   protected List<Argument> paramset;
51
52   public Jws2Client(AlignFrame _alignFrame, WsParamSetI preset,
53           List<Argument> arguments)
54   {
55     alignFrame = _alignFrame;
56     this.preset = preset;
57     if (preset != null)
58     {
59       if (!((preset instanceof JabaPreset) || preset instanceof JabaWsParamSet))
60       {
61         /*
62          * { this.preset = ((JabaPreset) preset).p; } else if (preset instanceof
63          * JabaWsParamSet) { List<Argument> newargs = new ArrayList<Argument>();
64          * JabaWsParamSet pset = ((JabaWsParamSet) preset); for (Option opt :
65          * pset.getjabaArguments()) { newargs.add(opt); } if (arguments != null
66          * && arguments.size() > 0) { // merge arguments with preset's own
67          * arguments. for (Argument opt : arguments) { newargs.add(opt); } }
68          * paramset = newargs; } else {
69          */
70         throw new Error(
71                 "Implementation error: Can only instantiate Jaba parameter sets.");
72       }
73     }
74     else
75     {
76       // just provided with a bunch of arguments
77       this.paramset = arguments;
78     }
79   }
80
81   boolean processParams(Jws2Instance sh, boolean editParams)
82   {
83     return processParams(sh, editParams, false);
84   }
85
86   protected boolean processParams(Jws2Instance sh, boolean editParams,
87           boolean adjustingExisting)
88   {
89
90     if (editParams)
91     {
92       if (sh.paramStore == null)
93       {
94         sh.paramStore = new JabaParamStore(sh,
95                 Desktop.getUserParameterStore());
96       }
97       WsJobParameters jobParams = (preset == null && paramset != null && paramset
98               .size() > 0) ? new WsJobParameters(null, sh, null, paramset)
99               : new WsJobParameters(sh, preset);
100       if (adjustingExisting)
101       {
102         jobParams.setName(MessageManager.getString("label.adjusting_parameters_for_calculation"));
103       }
104       if (!jobParams.showRunDialog())
105       {
106         return false;
107       }
108       WsParamSetI prset = jobParams.getPreset();
109       if (prset == null)
110       {
111         paramset = jobParams.isServiceDefaults() ? null : JabaParamStore
112                 .getJabafromJwsArgs(jobParams.getJobParams());
113         this.preset = null;
114       }
115       else
116       {
117         this.preset = prset; // ((JabaPreset) prset).p;
118         paramset = null; // no user supplied parameters.
119       }
120     }
121     return true;
122
123   }
124
125   public Jws2Client()
126   {
127     // anonymous constructor - used for headless method calls only
128   }
129
130   protected WebserviceInfo setWebService(Jws2Instance serv, boolean b)
131   {
132     // serviceHandle = serv;
133     String serviceInstance = serv.action; // serv.service.getClass().getName();
134     WebServiceName = serv.serviceType;
135     WebServiceJobTitle = serv.getActionText();
136     WsURL = serv.hosturl;
137     if (!b)
138     {
139       return new WebserviceInfo(WebServiceJobTitle, WebServiceJobTitle
140               + " using service hosted at " + serv.hosturl + "\n"
141               + (serv.description != null ? serv.description : ""));
142     }
143     return null;
144   }
145
146   /*
147    * Jws2Instance serviceHandle; (non-Javadoc)
148    * 
149    * @see jalview.ws.WSMenuEntryProviderI#attachWSMenuEntry(javax.swing.JMenu,
150    * jalview.gui.AlignFrame)
151    * 
152    * @Override public void attachWSMenuEntry(JMenu wsmenu, AlignFrame
153    * alignFrame) { if (serviceHandle==null) { throw new
154    * Error("Implementation error: No service handle for this Jws2 service."); }
155    * attachWSMenuEntry(wsmenu, serviceHandle, alignFrame); }
156    */
157   /**
158    * add the menu item for a particular jws2 service instance
159    * 
160    * @param wsmenu
161    * @param service
162    * @param alignFrame
163    */
164   abstract void attachWSMenuEntry(JMenu wsmenu, final Jws2Instance service,
165           final AlignFrame alignFrame);
166
167 }