JAL-1517 fix copyright for 2.8.2
[jalview.git] / src / jalview / ws / jws1 / WS1Client.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.jws1;
22
23 import jalview.gui.AlignFrame;
24 import jalview.gui.WebserviceInfo;
25 import jalview.ws.WSClient;
26 import jalview.ws.WSMenuEntryProviderI;
27
28 import javax.swing.JMenu;
29
30 import ext.vamsas.ServiceHandle;
31
32 /**
33  * JWS1 Specific UI attributes and methods
34  * 
35  * @author JimP
36  * 
37  */
38 public abstract class WS1Client extends WSClient implements
39         WSMenuEntryProviderI
40 {
41
42   /**
43    * original service handle that this client was derived from
44    */
45   ServiceHandle serviceHandle = null;
46
47   /**
48    * default constructor
49    */
50   public WS1Client()
51   {
52     super();
53   }
54
55   /**
56    * initialise WSClient service information attributes from the service handle
57    * 
58    * @param sh
59    * @return the service instance information GUI for this client and job.
60    */
61   protected WebserviceInfo setWebService(ServiceHandle sh)
62   {
63     return setWebService(sh, false);
64   }
65
66   /**
67    * initialise WSClient service information attributes from the service handle
68    * 
69    * @param sh
70    * @param headless
71    *          true implies no GUI objects will be created.
72    * @return the service instance information GUI for this client and job.
73    */
74   protected WebserviceInfo setWebService(ServiceHandle sh, boolean headless)
75   {
76     WebServiceName = sh.getName();
77     if (ServiceActions.containsKey(sh.getAbstractName()))
78     {
79       WebServiceJobTitle = sh.getName(); // TODO: control sh.Name specification
80       // properly
81       // add this for short names. +(String)
82       // ServiceActions.get(sh.getAbstractName());
83     }
84     else
85     {
86       WebServiceJobTitle = sh.getAbstractName() + " using " + sh.getName();
87
88     }
89     WebServiceReference = sh.getDescription();
90     WsURL = sh.getEndpointURL();
91     WebserviceInfo wsInfo = null;
92     if (!headless)
93     {
94       wsInfo = new WebserviceInfo(WebServiceJobTitle, WebServiceReference);
95     }
96     return wsInfo;
97   }
98
99   /**
100    * convenience method to pass the serviceHandle reference that instantiated
101    * this service on to the menu entry constructor
102    * 
103    * @param wsmenu
104    *          the menu to which any menu entries/sub menus are to be attached
105    * @param alignFrame
106    *          the alignFrame instance that provides input data for the service
107    */
108   public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
109   {
110     if (serviceHandle == null)
111     {
112       throw new Error(
113               "IMPLEMENTATION ERROR: cannot attach WS Menu Entry without service handle reference!");
114     }
115     attachWSMenuEntry(wsmenu, serviceHandle, alignFrame);
116   }
117
118   /**
119    * method implemented by each concrete WS1Client implementation that creates
120    * menu entries that enact their service using data from alignFrame.
121    * 
122    * @param wsmenu
123    *          where new menu entries (and submenus) are to be attached
124    * @param serviceHandle
125    *          the serviceHandle document for the service that entries are
126    *          created for
127    * @param alignFrame
128    */
129   public abstract void attachWSMenuEntry(JMenu wsmenu,
130           final ServiceHandle serviceHandle, final AlignFrame alignFrame);
131
132 }