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