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