1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.gui.control;
35
36 import info.magnolia.cms.core.Content;
37
38 import java.util.ArrayList;
39 import java.util.Iterator;
40 import java.util.List;
41
42 import org.apache.commons.lang.StringUtils;
43
44
45
46
47
48
49 public class ButtonSet extends ControlImpl {
50
51
52 private static final String HTML_PRE_DIVIDED = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
53
54 private static final String HTML_POST_DIVIDED = "</table>";
55
56 private static final String BUTTONHTML_PRE_DIVIDED = "<tr><td>";
57
58 private static final String BUTTONHTML_INTER_DIVIDED = "</td><td>";
59
60 private static final String BUTTONHTML_POST_DIVIDED = "</td></tr>";
61
62
63
64 private static final String HTML_INTER_PUSH = " ";
65
66 private List buttons = new ArrayList();
67
68 private int buttonType = BUTTONTYPE_RADIO;
69
70 private String buttonHtmlPre;
71
72 private String buttonHtmlInter;
73
74 private String buttonHtmlPost;
75
76 public ButtonSet() {
77 }
78
79 public ButtonSet(String name, String value) {
80 super(name, value);
81 }
82
83 public ButtonSet(String name, List values) {
84 super(name, values);
85 }
86
87 public ButtonSet(String name, Content websiteNode) {
88 super(name, websiteNode);
89 }
90
91 public void setButtons(List buttons) {
92 this.buttons = buttons;
93 }
94
95 public void setButtons(Button button) {
96 this.getButtons().add(button);
97 }
98
99 public List getButtons() {
100 return this.buttons;
101 }
102
103 public void setButtonHtmlPre(String s) {
104 this.buttonHtmlPre = s;
105 }
106
107 public String getButtonHtmlPre() {
108 if (this.buttonHtmlPre == null) {
109 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
110 return StringUtils.EMPTY;
111 }
112 return BUTTONHTML_PRE_DIVIDED;
113 }
114 return this.buttonHtmlPre;
115 }
116
117 public void setButtonHtmlInter(String s) {
118 this.buttonHtmlInter = s;
119 }
120
121 public String getButtonHtmlInter() {
122 if (this.buttonHtmlInter == null) {
123 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
124 return StringUtils.EMPTY;
125 }
126 return BUTTONHTML_INTER_DIVIDED;
127 }
128 return this.buttonHtmlInter;
129 }
130
131 public void setButtonHtmlPost(String s) {
132 this.buttonHtmlPost = s;
133 }
134
135 public String getButtonHtmlPost() {
136 if (this.buttonHtmlPost == null) {
137 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
138 return StringUtils.EMPTY;
139 }
140 return BUTTONHTML_POST_DIVIDED;
141 }
142 return buttonHtmlPost;
143
144 }
145
146 public String getHtmlPre() {
147 if (super.getHtmlPre(null) == null) {
148 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
149 return StringUtils.EMPTY;
150 }
151 return HTML_PRE_DIVIDED;
152 }
153 return super.getHtmlPre();
154 }
155
156 public String getHtmlInter() {
157 if (super.getHtmlInter(null) == null) {
158 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
159 return HTML_INTER_PUSH;
160 }
161 return StringUtils.EMPTY;
162 }
163 return super.getHtmlInter();
164 }
165
166 public String getHtmlPost() {
167 if (super.getHtmlPost(null) == null) {
168 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
169 return StringUtils.EMPTY;
170 }
171 return HTML_POST_DIVIDED;
172 }
173 return super.getHtmlPost();
174
175 }
176
177 public void setButtonType(int i) {
178 this.buttonType = i;
179 }
180
181 public int getButtonType() {
182 return this.buttonType;
183 }
184
185 public String getHtml() {
186 StringBuffer html = new StringBuffer();
187 html.append(this.getHtmlPre());
188 Iterator it = this.getButtons().iterator();
189 int i = 0;
190 while (it.hasNext()) {
191 Button b = (Button) it.next();
192 if (b.getName() == null) {
193 b.setName(this.getName());
194 }
195 b.setButtonType(this.getButtonType());
196 b.setSaveInfo(false);
197 if (b.getHtmlPre(null) == null) {
198 b.setHtmlPre(this.getButtonHtmlPre());
199 }
200 if (b.getHtmlInter(null) == null) {
201 b.setHtmlInter(this.getButtonHtmlInter());
202 }
203 if (b.getHtmlPost(null) == null) {
204 b.setHtmlPost(this.getButtonHtmlPost());
205 }
206 if (StringUtils.isEmpty(b.getCssClass())) {
207 b.setCssClass(this.getCssClass());
208 }
209 b.setId(this.getName() + "_SETBUTTON_" + i);
210 if (this.getValueType() == ControlImpl.VALUETYPE_MULTIPLE) {
211 if (this.getValues().size() != 0) {
212 if (this.getValues().contains(b.getValue())) {
213 b.setState(BUTTONSTATE_PUSHED);
214 }
215 else {
216 b.setState(BUTTONSTATE_NORMAL);
217 }
218 }
219 }
220 else {
221 if (StringUtils.isNotEmpty(this.getValue())) {
222 if (this.getValue().equals(b.getValue())) {
223 b.setState(BUTTONSTATE_PUSHED);
224 }
225 else {
226 b.setState(BUTTONSTATE_NORMAL);
227 }
228 }
229 }
230 html.append(b.getHtml());
231 if (it.hasNext()) {
232 html.append(this.getHtmlInter());
233 }
234 i++;
235 }
236 html.append(this.getHtmlPost());
237 html.append(this.getHtmlSaveInfo());
238 return html.toString();
239 }
240 }