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