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