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