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 org.apache.commons.lang.StringUtils;
37
38
39
40
41
42
43 public class Button extends ControlImpl {
44
45
46
47
48 private static final String HTML_PRE_DIVIDED = "<table cellpadding=0 cellspacing=0 border=0><tr><td>";
49
50 private String label;
51
52 private String iconSrc;
53
54 private String onclick;
55
56 private int state = BUTTONSTATE_NORMAL;
57
58 private int buttonType = BUTTONTYPE_PUSHBUTTON;
59
60 private String pushButtonTag = "span";
61
62 private boolean small;
63
64 public Button() {
65 }
66
67 public Button(String name, String value) {
68 super(name, value);
69 }
70
71 @Override
72 public void setLabel(String s) {
73 this.label = s;
74 }
75
76 @Override
77 public String getLabel() {
78 if (this.label != null) {
79 return this.label;
80 }
81
82 return this.getValue();
83 }
84
85
86
87
88
89 public void setIconSrc(String s) {
90 this.iconSrc = s;
91 }
92
93 public String getIconSrc() {
94 if (iconSrc == null) {
95 return StringUtils.EMPTY;
96 }
97
98
99 return "<img src=\"" + this.iconSrc + "\" />";
100 }
101
102 public void setOnclick(String s) {
103 this.onclick = s;
104 }
105
106 public String getOnclick() {
107 return this.onclick;
108 }
109
110 public void setHtmlPre() {
111 if (super.getHtmlPre(null) == null) {
112 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
113 this.setHtmlPre(StringUtils.EMPTY);
114 }
115 else {
116 this.setHtmlPre(HTML_PRE_DIVIDED);
117 }
118 }
119 }
120
121 public void setHtmlInter() {
122 if (super.getHtmlInter(null) == null) {
123 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
124 this.setHtmlInter(StringUtils.EMPTY);
125 }
126 else {
127 this.setHtmlInter("</td><td>");
128 }
129 }
130 }
131
132 public void setHtmlPost() {
133 if (super.getHtmlPost(null) == null) {
134 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
135 this.setHtmlPost(StringUtils.EMPTY);
136 }
137 else {
138 this.setHtmlPost("</td></tr></table>");
139 }
140 }
141 }
142
143 public void setSmall(boolean b) {
144 this.small = b;
145 }
146
147 public boolean getSmall() {
148 return this.small;
149 }
150
151 public void setPushButtonTag(String s) {
152 this.pushButtonTag = s;
153 }
154
155 public String getPushButtonTag() {
156 return this.pushButtonTag;
157 }
158
159 @Override
160 public String getHtml() {
161 StringBuffer html = new StringBuffer();
162 this.setHtmlPre();
163 this.setHtmlInter();
164 this.setHtmlPost();
165 html.append(this.getHtmlPre());
166 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) {
167 html.append(this.getHtmlPushbutton());
168 }
169 else {
170 html.append(this.getHtmlDividedbutton());
171 }
172 html.append(this.getHtmlPost());
173 return html.toString();
174 }
175
176 public String getHtmlDividedbutton() {
177 StringBuffer html = new StringBuffer();
178 String buttonType;
179 if (this.getButtonType() == BUTTONTYPE_RADIO) {
180 buttonType = "radio";
181 }
182 else {
183 buttonType = "checkbox";
184 }
185 html.append("<input type=\"" + buttonType + "\"");
186 html.append(" name=\"" + this.getName() + "\"");
187 html.append(" value=\"" + ControlImpl.escapeHTML(this.getValue()) + "\"");
188 html.append(" id=\"" + this.getId() + "\"");
189 if (StringUtils.isNotEmpty(this.getOnclick())) {
190 html.append(" onclick=\"" + this.getOnclick() + "\"");
191 }
192 if (this.getState() == BUTTONSTATE_PUSHED) {
193 html.append(" checked=\"checked\"");
194 }
195 html.append(this.getHtmlCssClass());
196 html.append(this.getHtmlCssStyles());
197 html.append(" />");
198 if (this.getSaveInfo()) {
199 html.append(this.getHtmlSaveInfo());
200 }
201 html.append(this.getHtmlInter());
202 html.append("<a href=\"javascript:mgnlShiftDividedButton('" + this.getId() + "');");
203 if (StringUtils.isNotEmpty(this.getOnclick())) {
204 html.append(this.getOnclick());
205 }
206 html.append("\" " + this.getHtmlCssClass() + ">");
207
208 html.append(this.getLabel());
209 html.append(this.getIconSrc());
210
211 html.append("</a>");
212 return html.toString();
213 }
214
215 public String getHtmlPushbutton() {
216 StringBuffer html = new StringBuffer();
217 html.append("<" + this.getPushButtonTag());
218 if (StringUtils.isEmpty(this.getCssClass())) {
219 if (this.getSmall()) {
220 this.setCssClass(CSSCLASS_CONTROLBUTTONSMALL);
221 }
222 else {
223 this.setCssClass(CSSCLASS_CONTROLBUTTON);
224 }
225 }
226 if (this.getState() == BUTTONSTATE_PUSHED) {
227 this.setCssClass(this.getCssClass() + "_PUSHED");
228 }
229
230 this.setEvent("onclick", "mgnlShiftPushButtonClick(this);");
231 if (StringUtils.isNotEmpty(this.getOnclick())) {
232 this.setEvent("onclick", this.getOnclick());
233 }
234 this.setEvent("onmousedown", "mgnlShiftPushButtonDown(this);");
235 this.setEvent("onmouseout", "mgnlShiftPushButtonOut(this);");
236
237 html.append(this.getHtmlEvents());
238 html.append(this.getHtmlId());
239 html.append(this.getHtmlCssClass());
240 html.append(this.getHtmlCssStyles());
241 html.append(">");
242
243 html.append(this.getIconSrc());
244 html.append(this.getLabel());
245 html.append("</" + this.getPushButtonTag() + ">");
246 return html.toString();
247 }
248
249 public void setState(int i) {
250 this.state = i;
251 }
252
253 public int getState() {
254 return this.state;
255 }
256
257 public void setButtonType(int i) {
258 this.buttonType = i;
259 }
260
261 public int getButtonType() {
262 return this.buttonType;
263 }
264
265 }