1 13 package info.magnolia.cms.gui.controlx.search; 14 15 import java.util.ArrayList ; 16 import java.util.List ; 17 18 import org.apache.commons.collections.MapIterator; 19 import org.apache.commons.collections.OrderedMap; 20 import org.apache.commons.collections.map.ListOrderedMap; 21 import org.apache.commons.lang.StringUtils; 22 23 24 28 public class SelectSearchControlDefinition extends SearchControlDefinition { 29 30 34 public SelectSearchControlDefinition(String name, String label) { 35 super(name, label, "select"); 36 } 37 38 public OrderedMap options = new ListOrderedMap(); 40 41 public String getJsField() { 42 43 List pairs = new ArrayList (); 44 for (MapIterator iter = this.getOptions().orderedMapIterator(); iter.hasNext();) { 45 iter.next(); 46 String key = (String ) iter.getKey(); 47 String value = (String ) iter.getValue(); 48 pairs.add("'" + key + "': '" + value + "'"); 49 } 50 51 String str = super.getJsField(); 52 str = StringUtils.removeEnd(str, "}"); 53 str += ",options: {"; 54 str += StringUtils.join(pairs.iterator(), ","); 55 str += "}}"; 56 return str; 57 } 58 59 62 public OrderedMap getOptions() { 63 return this.options; 64 } 65 66 public void addOption(String value, String label) { 67 this.getOptions().put(value, label); 68 } 69 } 70 | Popular Tags |