JAL-1645 Version-Rel Version 2.9 Year-Rel 2015 Licensing glob
[jalview.git] / src / jalview / ws / jws2 / dm / JabaOption.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3  * Copyright (C) 2015 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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.ws.jws2.dm;
22
23 import jalview.util.MessageManager;
24 import jalview.ws.jws2.ParameterUtils;
25 import jalview.ws.params.OptionI;
26
27 import java.net.MalformedURLException;
28 import java.net.URL;
29 import java.util.List;
30
31 import compbio.metadata.Option;
32
33 public class JabaOption implements jalview.ws.params.OptionI
34 {
35   public JabaOption(Option rg)
36   {
37     opt = rg;
38   }
39
40   Option opt;
41
42   @Override
43   public String getValue()
44   {
45     return opt.getDefaultValue();
46   }
47
48   @Override
49   public String getName()
50   {
51     return opt.getName();
52   }
53
54   @Override
55   public URL getFurtherDetails()
56   {
57     try
58     {
59       return new URL(opt.getBasicURL().toExternalForm() + "/"
60               + opt.getFurtherDetails());
61     } catch (NullPointerException q)
62     {
63     } catch (MalformedURLException q)
64     {
65
66     }
67     return null;
68   }
69
70   @Override
71   public boolean isRequired()
72   {
73     return opt.isRequired();
74   }
75
76   @Override
77   public String getDescription()
78   {
79     return opt.getDescription();
80   }
81
82   @Override
83   public List<String> getPossibleValues()
84   {
85     // TODO: assert typesafety
86     return opt.getPossibleValues();
87   }
88
89   @Override
90   public void setValue(String selectedItem)
91   {
92     try
93     {
94       opt.setDefaultValue(selectedItem);
95     } catch (Exception e)
96     {
97       e.printStackTrace();
98       throw new Error(
99               MessageManager
100                       .getString("error.implementation_error_cannot_set_jaba_option"));
101     }
102   }
103
104   @Override
105   public OptionI copy()
106   {
107     return new JabaOption(ParameterUtils.copyOption(opt));
108   }
109
110   /**
111    * get the underlying Jaba option or parameter object. Note - use copy first
112    * if you want to modify the value of the option.
113    * 
114    * @return
115    */
116   public Option getOption()
117   {
118     return opt;
119   }
120
121 }