Changeset 4517
- Timestamp:
- Sep 9, 2013, 11:26:15 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/servlet/src/org/proteios/gui/form/Select.java
r4056 r4517 27 27 */ 28 28 package org.proteios.gui.form; 29 30 import org.apache.commons.lang3.StringEscapeUtils; 29 31 30 32 import se.lu.thep.waf.constraints.VParameter; … … 52 54 this.name = param.getName(); 53 55 this.options = new ArrayList<Option>(); 54 setLabel(param.getName()); 55 } 56 57 public Select(D param, List<Option> options) 58 { 59 this(param); 60 this.options.addAll(options); 61 } 62 63 public Select(D param, List<String> options, String selected) 56 setLabel(param.getName()); 57 } 58 59 60 public Select(D param, List<Option> options) 64 61 { 65 62 this(param); 66 for(String str : options) 67 { 68 Option o = new Option(str); 69 addOption(o); 70 } 71 selectOption(selected); 72 } 73 74 public Select(D param, List<Option> optionList, List<String> selected) 75 { 76 this(param); 77 this.options.addAll(optionList); 78 setMultiple(true); 79 if (selected != null) 80 { 81 for(String str : selected) 82 { 83 selectOption(str); 84 } 85 } 86 setMaxSize(5); 87 } 63 this.options.addAll(options); 64 } 65 66 67 public Select(D param, List<String> options, String selected) 68 { 69 this(param); 70 for (String str : options) 71 { 72 Option o = new Option(str); 73 addOption(o); 74 } 75 selectOption(selected); 76 } 77 78 79 public Select(D param, List<Option> optionList, List<String> selected) 80 { 81 this(param); 82 this.options.addAll(optionList); 83 setMultiple(true); 84 if (selected != null) 85 { 86 for (String str : selected) 87 { 88 selectOption(str); 89 } 90 } 91 setMaxSize(5); 92 } 93 88 94 89 95 public String getName() … … 92 98 } 93 99 100 94 101 public void setName(String name) 95 102 { … … 139 146 } 140 147 148 141 149 public Boolean isHidden() 142 150 { … … 150 158 } 151 159 152 /** 153 Sets number of visible options. If number of options is lower than the given size 154 size is set to the number of options. Does nothing if there are no options. 155 */ 160 161 /** 162 * Sets number of visible options. If number of options is lower than the 163 * given size size is set to the number of options. Does nothing if there 164 * are no options. 165 */ 156 166 public void setMaxSize(Integer size) 157 167 { 158 if (getOptions() != null) 159 { 160 if (getOptions().size() < size) 161 { 162 setSize(getOptions().size()); 163 } 164 else 165 { 166 setSize(size); 167 } 168 } 169 } 170 171 /** 172 Sets all options matching the given value to selected 173 */ 174 public void selectOption(String value) 175 { 168 if (getOptions() != null) 169 { 170 if (getOptions().size() < size) 171 { 172 setSize(getOptions().size()); 173 } 174 else 175 { 176 setSize(size); 177 } 178 } 179 } 180 181 182 /** 183 * Sets all options matching the given value to selected 184 */ 185 public void selectOption(String value) 186 { 176 187 // Set selected option 177 188 if (value != null) 178 189 { 190 // The option list is escaped. So the value also need to be escaped 191 // for proper string matching 192 String compValue = StringEscapeUtils.escapeHtml3(value); 179 193 if (getOptions() != null) 180 194 { 181 for (Option opt : getOptions())195 for (Option opt : getOptions()) 182 196 { 183 if (opt.getValue().equals( value))197 if (opt.getValue().equals(compValue)) 184 198 { 185 199 opt.setSelected(true); … … 190 204 } 191 205 192 193 194 195 196 197 198 199 200 201 202 for(String str : selected)203 204 205 206 207 206 207 /** 208 * Sets all options matching any value in the input list to selected. 209 * 210 * @param selected List<Sting> selected List with selected values. 211 */ 212 public void selectOptions(List<String> selected) 213 { 214 if (selected != null) 215 { 216 for (String str : selected) 217 { 218 selectOption(str); 219 } 220 } 221 } 208 222 }
Note: See TracChangeset
for help on using the changeset viewer.