JAL-1517 source formatting
[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     {
58       return new URL(opt.getBasicURL().toExternalForm() + "/"
59               + opt.getFurtherDetails());
60     } catch (NullPointerException q)
61     {
62     } catch (MalformedURLException q)
63     {
64
65     }
66     return null;
67   }
68
69   @Override
70   public boolean isRequired()
71   {
72     return opt.isRequired();
73   }
74
75   @Override
76   public String getDescription()
77   {
78     return opt.getDescription();
79   }
80
81   @Override
82   public List<String> getPossibleValues()
83   {
84     // TODO: assert typesafety
85     return opt.getPossibleValues();
86   }
87
88   @Override
89   public void setValue(String selectedItem)
90   {
91     try
92     {
93       opt.setDefaultValue(selectedItem);
94     } catch (Exception e)
95     {
96       e.printStackTrace();
97       throw new Error(
98               "Implementation error: cannot set Jaba Option to a value outside its allowed value range!");
99     }
100   }
101
102   @Override
103   public OptionI copy()
104   {
105     return new JabaOption(ParameterUtils.copyOption(opt));
106   }
107
108   /**
109    * get the underlying Jaba option or parameter object. Note - use copy first
110    * if you want to modify the value of the option.
111    * 
112    * @return
113    */
114   public Option getOption()
115   {
116     return opt;
117   }
118
119 }