1 15 package org.apache.tapestry.form; 16 17 25 public class LabeledPropertySelectionModel implements IPropertySelectionModel 26 { 27 private IPropertySelectionModel _model; 28 private String _label = ""; 29 private Object _option = null; 30 private String _value = ""; 31 32 37 public LabeledPropertySelectionModel() 38 { 39 this(EMPTY_MODEL); 40 } 41 42 47 public LabeledPropertySelectionModel(IPropertySelectionModel model) 48 { 49 _model = model; 50 } 51 52 58 public LabeledPropertySelectionModel(IPropertySelectionModel model, 59 String label) 60 { 61 this(model); 62 63 _label = label; 64 } 65 66 73 public LabeledPropertySelectionModel(IPropertySelectionModel model, 74 String label, Object option) 75 { 76 this(model, label); 77 78 _option = option; 79 } 80 81 89 public LabeledPropertySelectionModel(IPropertySelectionModel model, 90 String label, Object option, String value) 91 { 92 this(model, label, option); 93 94 _value = value; 95 } 96 97 101 public IPropertySelectionModel getModel() 102 { 103 return _model; 104 } 105 106 110 public void setModel(IPropertySelectionModel model) 111 { 112 _model = model; 113 } 114 115 118 public int getOptionCount() 119 { 120 return _model.getOptionCount() + 1; 121 } 122 123 126 public Object getOption(int index) 127 { 128 return (index == 0) ? _option : _model.getOption(index - 1); 129 } 130 131 134 public String getLabel(int index) 135 { 136 return (index == 0) ? _label : _model.getLabel(index - 1); 137 } 138 139 142 public String getValue(int index) 143 { 144 return (index == 0) ? _value : _model.getValue(index - 1); 145 } 146 147 150 public Object translateValue(String value) 151 { 152 return value.equals(_value) ? _option : _model.translateValue(value); 153 } 154 155 159 public String getLabel() 160 { 161 return _label; 162 } 163 164 168 public void setLabel(String label) 169 { 170 _label = label; 171 } 172 173 177 public String getValue() 178 { 179 return _value; 180 } 181 182 186 public void setValue(String value) 187 { 188 _value = value; 189 } 190 191 195 public Object getOption() 196 { 197 return _option; 198 } 199 200 204 public void setOption(Object option) 205 { 206 _option = option; 207 } 208 209 213 private static final IPropertySelectionModel EMPTY_MODEL = new IPropertySelectionModel() 214 { 215 218 public int getOptionCount() 219 { 220 return 0; 221 } 222 223 226 public Object getOption(int index) 227 { 228 return null; 229 } 230 231 234 public String getLabel(int index) 235 { 236 return null; 237 } 238 239 242 public String getValue(int index) 243 { 244 return null; 245 } 246 247 250 public Object translateValue(String value) 251 { 252 return null; 253 } 254 }; 255 } 256 | Popular Tags |