01: /*
02: * Copyright (C) 2004 TiongHiang Lee
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Email: thlee@onemindsoft.org
19: */
20:
21: package org.onemind.swingweb.client.gwt.ui;
22:
23: import org.onemind.swingweb.client.core.AbstractClient;
24: import org.onemind.swingweb.client.dom.DomNode;
25: import com.google.gwt.user.client.ui.*;
26:
27: public class ButtonUIHandler extends ComponentUIHandler implements
28: ClickListener {
29:
30: public void onClick(Widget sender) {
31: handleEvent(sender, null);
32: }
33:
34: public ButtonUIHandler(AbstractClient client) {
35: super (client);
36: }
37:
38: /**
39: * {@inheritDoc}
40: */
41: protected Object createComponentInstance(Object parent,
42: DomNode element) {
43: Button btn = new Button();
44: return btn;
45: }
46:
47: /**
48: * {@inheritDoc}
49: */
50: protected Object updateUI(Object com, DomNode element) {
51: Button btn = (Button) com;
52:
53: StringBuffer text = new StringBuffer();
54: String str = element.getAttribute("label");
55: String icon = element.getAttribute("icon");
56: if (icon != null && icon.length() > 0 && !icon.equals("#")) {
57: text.append("<img src=\"" + getClient().getUrl() + icon
58: + "\">");
59: }
60: if (str != null && str.length() > 0) {
61: text.append(str);
62: }
63: btn.setHTML(text.toString());
64: return super .updateUI(com, element);
65: }
66:
67: protected void postEvent(Object sender, Object data) {
68: postEvent(sender, "true", true);
69: }
70:
71: /**
72: * {@inheritDoc}
73: */
74: protected void registerListeners(Object com) {
75: Button btn = (Button) com;
76: btn.addClickListener(this );
77: super .registerListeners(com);
78: }
79:
80: protected boolean isTrue(DomNode element, String attr) {
81: String attrValue = element.getAttribute(attr);
82: if (attrValue != null && attrValue.equalsIgnoreCase("true")) {
83: return true;
84: } else {
85: return false;
86: }
87: }
88: }
|