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 @Override
147 public String getHtmlPre() {
148 if (super.getHtmlPre(null) == null) {
149 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
150 return StringUtils.EMPTY;
151 }
152 return HTML_PRE_DIVIDED;
153 }
154 return super.getHtmlPre();
155 }
156
157 @Override
158 public String getHtmlInter() {
159 if (super.getHtmlInter(null) == null) {
160 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
161 return HTML_INTER_PUSH;
162 }
163 return StringUtils.EMPTY;
164 }
165 return super.getHtmlInter();
166 }
167
168 @Override
169 public String getHtmlPost() {
170 if (super.getHtmlPost(null) == null) {
171 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
172 return StringUtils.EMPTY;
173 }
174 return HTML_POST_DIVIDED;
175 }
176 return super.getHtmlPost();
177
178 }
179
180 public void setButtonType(int i) {
181 this.buttonType = i;
182 }
183
184 public int getButtonType() {
185 return this.buttonType;
186 }
187
188 @Override
189 public String getHtml() {
190 StringBuffer html = new StringBuffer();
191 html.append(this.getHtmlPre());
192 Iterator it = this.getButtons().iterator();
193 int i = 0;
194 while (it.hasNext()) {
195 Button b = (Button) it.next();
196 if (b.getName() == null) {
197 b.setName(this.getName());
198 }
199 b.setButtonType(this.getButtonType());
200 b.setSaveInfo(false);
201 if (b.getHtmlPre(null) == null) {
202 b.setHtmlPre(this.getButtonHtmlPre());
203 }
204 if (b.getHtmlInter(null) == null) {
205 b.setHtmlInter(this.getButtonHtmlInter());
206 }
207 if (b.getHtmlPost(null) == null) {
208 b.setHtmlPost(this.getButtonHtmlPost());
209 }
210 if (StringUtils.isEmpty(b.getCssClass())) {
211 b.setCssClass(this.getCssClass());
212 }
213 b.setId(this.getName() + "_SETBUTTON_" + i);
214 if (this.getValueType() == ControlImpl.VALUETYPE_MULTIPLE) {
215 if (this.getValues().size() != 0) {
216 if (this.getValues().contains(b.getValue())) {
217 b.setState(BUTTONSTATE_PUSHED);
218 }
219 else {
220 b.setState(BUTTONSTATE_NORMAL);
221 }
222 }
223 }
224 else {
225 if (StringUtils.isNotEmpty(this.getValue())) {
226 if (this.getValue().equals(b.getValue())) {
227 b.setState(BUTTONSTATE_PUSHED);
228 }
229 else {
230 b.setState(BUTTONSTATE_NORMAL);
231 }
232 }
233 }
234 html.append(b.getHtml());
235 if (it.hasNext()) {
236 html.append(this.getHtmlInter());
237 }
238 i++;
239 }
240 html.append(this.getHtmlPost());
241 html.append(this.getHtmlSaveInfo());
242 return html.toString();
243 }
244 }