JAL-1378 JWS-71 update to from-source build of JABA v2.1 client for use with JABA...
[jalview.git] / src / jalview / ws / jws2 / dm / JabaOption.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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.jws2.dm;
19
20 import jalview.ws.jws2.ParameterUtils;
21 import jalview.ws.params.OptionI;
22
23 import java.net.MalformedURLException;
24 import java.net.URL;
25 import java.util.List;
26
27 import compbio.metadata.Option;
28
29 public class JabaOption implements jalview.ws.params.OptionI
30 {
31   public JabaOption(Option rg)
32   {
33     opt = rg;
34   }
35
36   Option opt;
37
38   @Override
39   public String getValue()
40   {
41     return opt.getDefaultValue();
42   }
43
44   @Override
45   public String getName()
46   {
47     return opt.getName();
48   }
49
50   @Override
51   public URL getFurtherDetails()
52   {
53     try {
54     return new URL(opt.getBasicURL().toExternalForm()+"/"+opt.getFurtherDetails());
55     }
56     catch (NullPointerException q) {}
57     catch (MalformedURLException q)
58     {
59       
60     }
61     return null;
62   }
63
64   @Override
65   public boolean isRequired()
66   {
67     return opt.isRequired();
68   }
69
70   @Override
71   public String getDescription()
72   {
73     return opt.getDescription();
74   }
75
76   @Override
77   public List<String> getPossibleValues()
78   {
79     // TODO: assert typesafety
80     return opt.getPossibleValues();
81   }
82
83   @Override
84   public void setValue(String selectedItem)
85   {
86     try
87     {
88       opt.setDefaultValue(selectedItem);
89     } catch (Exception e)
90     {
91       e.printStackTrace();
92       throw new Error(
93               "Implementation error: cannot set Jaba Option to a value outside its allowed value range!");
94     }
95   }
96
97   @Override
98   public OptionI copy()
99   {
100     return new JabaOption(ParameterUtils.copyOption(opt));
101   }
102
103   /**
104    * get the underlying Jaba option or parameter object. Note - use copy first
105    * if you want to modify the value of the option.
106    * 
107    * @return
108    */
109   public Option getOption()
110   {
111     return opt;
112   }
113
114 }