JAL-1432 updated copyright notices
[jalview.git] / src / jalview / ws / jws1 / WS1Client.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.ws.jws1;
20
21 import jalview.gui.AlignFrame;
22 import jalview.gui.WebserviceInfo;
23 import jalview.ws.WSClient;
24 import jalview.ws.WSMenuEntryProviderI;
25
26 import javax.swing.JMenu;
27
28 import ext.vamsas.ServiceHandle;
29
30 /**
31  * JWS1 Specific UI attributes and methods
32  * 
33  * @author JimP
34  * 
35  */
36 public abstract class WS1Client extends WSClient implements
37         WSMenuEntryProviderI
38 {
39
40   /**
41    * original service handle that this client was derived from
42    */
43   ServiceHandle serviceHandle = null;
44
45   /**
46    * default constructor
47    */
48   public WS1Client()
49   {
50     super();
51   }
52
53   /**
54    * initialise WSClient service information attributes from the service handle
55    * 
56    * @param sh
57    * @return the service instance information GUI for this client and job.
58    */
59   protected WebserviceInfo setWebService(ServiceHandle sh)
60   {
61     return setWebService(sh, false);
62   }
63
64   /**
65    * initialise WSClient service information attributes from the service handle
66    * 
67    * @param sh
68    * @param headless
69    *          true implies no GUI objects will be created.
70    * @return the service instance information GUI for this client and job.
71    */
72   protected WebserviceInfo setWebService(ServiceHandle sh, boolean headless)
73   {
74     WebServiceName = sh.getName();
75     if (ServiceActions.containsKey(sh.getAbstractName()))
76     {
77       WebServiceJobTitle = sh.getName(); // TODO: control sh.Name specification
78       // properly
79       // add this for short names. +(String)
80       // ServiceActions.get(sh.getAbstractName());
81     }
82     else
83     {
84       WebServiceJobTitle = sh.getAbstractName() + " using " + sh.getName();
85
86     }
87     WebServiceReference = sh.getDescription();
88     WsURL = sh.getEndpointURL();
89     WebserviceInfo wsInfo = null;
90     if (!headless)
91     {
92       wsInfo = new WebserviceInfo(WebServiceJobTitle, WebServiceReference);
93     }
94     return wsInfo;
95   }
96
97   /**
98    * convenience method to pass the serviceHandle reference that instantiated
99    * this service on to the menu entry constructor
100    * 
101    * @param wsmenu
102    *          the menu to which any menu entries/sub menus are to be attached
103    * @param alignFrame
104    *          the alignFrame instance that provides input data for the service
105    */
106   public void attachWSMenuEntry(JMenu wsmenu, final AlignFrame alignFrame)
107   {
108     if (serviceHandle == null)
109     {
110       throw new Error(
111               "IMPLEMENTATION ERROR: cannot attach WS Menu Entry without service handle reference!");
112     }
113     attachWSMenuEntry(wsmenu, serviceHandle, alignFrame);
114   }
115
116   /**
117    * method implemented by each concrete WS1Client implementation that creates
118    * menu entries that enact their service using data from alignFrame.
119    * 
120    * @param wsmenu
121    *          where new menu entries (and submenus) are to be attached
122    * @param serviceHandle
123    *          the serviceHandle document for the service that entries are
124    *          created for
125    * @param alignFrame
126    */
127   public abstract void attachWSMenuEntry(JMenu wsmenu,
128           final ServiceHandle serviceHandle, final AlignFrame alignFrame);
129
130 }