KickJava   Java API By Example, From Geeks To Geeks.

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


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-2006 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 ButtonSet extends ControlImpl {
29
30     // default values for divided button (checkbox, radio)
31
private static final String JavaDoc HTML_PRE_DIVIDED = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"; //$NON-NLS-1$
32

33     private static final String JavaDoc HTML_POST_DIVIDED = "</table>"; //$NON-NLS-1$
34

35     private static final String JavaDoc BUTTONHTML_PRE_DIVIDED = "<tr><td>"; //$NON-NLS-1$
36

37     private static final String JavaDoc BUTTONHTML_INTER_DIVIDED = "</td><td>"; //$NON-NLS-1$
38

39     private static final String JavaDoc BUTTONHTML_POST_DIVIDED = "</td></tr>"; //$NON-NLS-1$
40

41     // default values for push button
42

43     private static final String JavaDoc HTML_INTER_PUSH = " "; //$NON-NLS-1$
44

45     private List JavaDoc buttons = new ArrayList JavaDoc();
46
47     private int buttonType = BUTTONTYPE_RADIO;
48
49     private String JavaDoc buttonHtmlPre; // html before each button
50

51     private String JavaDoc buttonHtmlInter; // html between each button and label (not available for push button)
52

53     private String JavaDoc buttonHtmlPost; // html after each label
54

55     public ButtonSet() {
56     }
57
58     public ButtonSet(String JavaDoc name, String JavaDoc value) {
59         super(name, value);
60     }
61
62     public ButtonSet(String JavaDoc name, List JavaDoc values) {
63         super(name, values);
64     }
65
66     public ButtonSet(String JavaDoc name, Content websiteNode) {
67         super(name, websiteNode);
68     }
69
70     public void setButtons(List JavaDoc buttons) {
71         this.buttons = buttons;
72     }
73
74     public void setButtons(Button button) {
75         this.getButtons().add(button);
76     }
77
78     public List JavaDoc getButtons() {
79         return this.buttons;
80     }
81
82     public void setButtonHtmlPre(String JavaDoc s) {
83         this.buttonHtmlPre = s;
84     }
85
86     public String JavaDoc getButtonHtmlPre() {
87         if (this.buttonHtmlPre == null) {
88             if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
89                 return StringUtils.EMPTY;
90             }
91             return BUTTONHTML_PRE_DIVIDED;
92         }
93         return this.buttonHtmlPre;
94     }
95
96     public void setButtonHtmlInter(String JavaDoc s) {
97         this.buttonHtmlInter = s;
98     }
99
100     public String JavaDoc getButtonHtmlInter() {
101         if (this.buttonHtmlInter == null) {
102             if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
103                 return StringUtils.EMPTY;
104             }
105             return BUTTONHTML_INTER_DIVIDED;
106         }
107         return this.buttonHtmlInter;
108     }
109
110     public void setButtonHtmlPost(String JavaDoc s) {
111         this.buttonHtmlPost = s;
112     }
113
114     public String JavaDoc getButtonHtmlPost() {
115         if (this.buttonHtmlPost == null) {
116             if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
117                 return StringUtils.EMPTY;
118             }
119             return BUTTONHTML_POST_DIVIDED;
120         }
121         return buttonHtmlPost;
122
123     }
124
125     public String JavaDoc getHtmlPre() {
126         if (super.getHtmlPre(null) == null) {
127             if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
128                 return StringUtils.EMPTY;
129             }
130             return HTML_PRE_DIVIDED;
131         }
132         return super.getHtmlPre();
133     }
134
135     public String JavaDoc getHtmlInter() {
136         if (super.getHtmlInter(null) == null) {
137             if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
138                 return HTML_INTER_PUSH;
139             }
140             return StringUtils.EMPTY;
141         }
142         return super.getHtmlInter();
143     }
144
145     public String JavaDoc getHtmlPost() {
146         if (super.getHtmlPost(null) == null) {
147             if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
148                 return StringUtils.EMPTY;
149             }
150             return HTML_POST_DIVIDED;
151         }
152         return super.getHtmlPost();
153
154     }
155
156     public void setButtonType(int i) {
157         this.buttonType = i;
158     }
159
160     public int getButtonType() {
161         return this.buttonType;
162     }
163
164     public String JavaDoc getHtml() {
165         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
166         html.append(this.getHtmlPre());
167         Iterator JavaDoc it = this.getButtons().iterator();
168         int i = 0;
169         while (it.hasNext()) {
170             Button b = (Button) it.next();
171             if (b.getName() == null) {
172                 b.setName(this.getName());
173             }
174             b.setButtonType(this.getButtonType());
175             b.setSaveInfo(false);
176             if (b.getHtmlPre(null) == null) {
177                 b.setHtmlPre(this.getButtonHtmlPre());
178             }
179             if (b.getHtmlInter(null) == null) {
180                 b.setHtmlInter(this.getButtonHtmlInter());
181             }
182             if (b.getHtmlPost(null) == null) {
183                 b.setHtmlPost(this.getButtonHtmlPost());
184             }
185             if (StringUtils.isEmpty(b.getCssClass())) {
186                 b.setCssClass(this.getCssClass());
187             }
188             b.setId(this.getName() + "_SETBUTTON_" + i); //$NON-NLS-1$
189
if (this.getValueType() == ControlImpl.VALUETYPE_MULTIPLE) {
190                 if (this.getValues().size() != 0) {
191                     if (this.getValues().contains(b.getValue())) {
192                         b.setState(BUTTONSTATE_PUSHED);
193                     }
194                     else {
195                         b.setState(BUTTONSTATE_NORMAL);
196                     }
197                 }
198             }
199             else {
200                 if (StringUtils.isNotEmpty(this.getValue())) {
201                     if (this.getValue().equals(b.getValue())) {
202                         b.setState(BUTTONSTATE_PUSHED);
203                     }
204                     else {
205                         b.setState(BUTTONSTATE_NORMAL);
206                     }
207                 }
208             }
209             html.append(b.getHtml());
210             if (it.hasNext()) {
211                 html.append(this.getHtmlInter());
212             }
213             i++;
214         }
215         html.append(this.getHtmlPost());
216         html.append(this.getHtmlSaveInfo());
217         return html.toString();
218     }
219 }
220
Popular Tags