KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > control > Select


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.control;
14
15 import info.magnolia.cms.core.Content;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.apache.commons.lang.StringUtils;
22
23
24 /**
25  * @author Vinzenz Wyser
26  * @version 2.0
27  */

28 public class Select extends ControlSuper {
29
30     private List JavaDoc options = new ArrayList JavaDoc();
31
32     public Select() {
33     }
34
35     public Select(String JavaDoc name, String JavaDoc value) {
36         super(name, value);
37     }
38
39     public Select(String JavaDoc name, Content websiteNode) {
40         super(name, websiteNode);
41     }
42
43     public void setOptions(List JavaDoc l) {
44         this.options = l;
45     }
46
47     public void setOptions(SelectOption option) {
48         this.getOptions().add(option);
49     }
50
51     public void setOptions(String JavaDoc label, String JavaDoc value) {
52         this.getOptions().add(new SelectOption(label, value));
53     }
54
55     public List JavaDoc getOptions() {
56         return this.options;
57     }
58
59     public String JavaDoc getHtml() {
60         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
61         html.append("<select"); //$NON-NLS-1$
62
html.append(" name=\"" + this.getName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
63
html.append(" id=\"" + this.getName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
64
html.append(this.getHtmlCssClass());
65         html.append(this.getHtmlCssStyles());
66         html.append(this.getHtmlEvents());
67         html.append(">"); //$NON-NLS-1$
68
Iterator JavaDoc it = this.getOptions().iterator();
69         while (it.hasNext()) {
70             SelectOption o = (SelectOption) it.next();
71             if (StringUtils.isNotEmpty(this.getValue())) {
72                 if (this.getValue().equals(o.getValue())) {
73                     o.setSelected(true);
74                 }
75                 else {
76                     o.setSelected(false);
77                 }
78             }
79             html.append(o.getHtml());
80         }
81         html.append("</select>"); //$NON-NLS-1$
82
if (this.getSaveInfo()) {
83             html.append(this.getHtmlSaveInfo());
84         }
85         return html.toString();
86     }
87 }
Popular Tags