KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > controlx > search > SelectSearchControlDefinition


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.controlx.search;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
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 /**
25  * @author Philipp Bracher
26  * @version $Revision: 6341 $ ($Author: philipp $)
27  */

28 public class SelectSearchControlDefinition extends SearchControlDefinition {
29
30     /**
31      * @param name
32      * @param label
33      */

34     public SelectSearchControlDefinition(String JavaDoc name, String JavaDoc label) {
35         super(name, label, "select");
36     }
37
38     // array
39
public OrderedMap options = new ListOrderedMap();
40
41     public String JavaDoc getJsField() {
42
43         List JavaDoc pairs = new ArrayList JavaDoc();
44         for (MapIterator iter = this.getOptions().orderedMapIterator(); iter.hasNext();) {
45             iter.next();
46             String JavaDoc key = (String JavaDoc) iter.getKey();
47             String JavaDoc value = (String JavaDoc) iter.getValue();
48             pairs.add("'" + key + "': '" + value + "'");
49         }
50
51         String JavaDoc 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     /**
60      * @return Returns the options.
61      */

62     public OrderedMap getOptions() {
63         return this.options;
64     }
65
66     public void addOption(String JavaDoc value, String JavaDoc label) {
67         this.getOptions().put(value, label);
68     }
69 }
70
Popular Tags