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