01: /*
02: * GWT-Ext Widget Library
03: * Copyright(c) 2007-2008, GWT-Ext.
04: * licensing@gwt-ext.com
05: *
06: * http://www.gwt-ext.com/license
07: */
08: package com.gwtext.client.widgets;
09:
10: import com.google.gwt.core.client.JavaScriptObject;
11: import com.google.gwt.user.client.ui.RootPanel;
12: import com.google.gwt.user.client.ui.Widget;
13: import com.gwtext.client.core.DomConfig;
14: import com.gwtext.client.core.DomHelper;
15: import com.gwtext.client.core.Ext;
16: import com.gwtext.client.core.ExtElement;
17: import com.gwtext.client.util.DOMUtil;
18: import com.gwtext.client.util.JavaScriptObjectHelper;
19:
20: /**
21: * Adapter between GWT {@link com.google.gwt.user.client.ui.Widget}'s and {@link com.gwtext.client.widgets.Component}'s.
22: */
23: public class WidgetComponent extends BoxComponent {
24:
25: private static final String hiddenDivID = "__gwtext_hidden";
26:
27: static {
28: init();
29: }
30:
31: private static native void init()/*-{
32:
33: $wnd.Ext.ux.WidgetComponent = function(config){
34: $wnd.Ext.ux.WidgetComponent.superclass.constructor.call(this, config);
35: };
36:
37: $wnd.Ext.ux.WidgetComponent = $wnd.Ext.extend($wnd.Ext.BoxComponent, {
38: widget : null,
39: onRender : function(container, position){
40:
41: //a GWT widget must be attached to a GWT Panel for its events to fire.
42: var attached = this.widget.@com.google.gwt.user.client.ui.Widget::isAttached()();
43: if(!attached) {
44: var rp = @com.google.gwt.user.client.ui.RootPanel::get(Ljava/lang/String;)('__gwtext_hidden');
45: rp.@com.google.gwt.user.client.ui.HasWidgets::add(Lcom/google/gwt/user/client/ui/Widget;)(this.widget);
46: }
47: var widgetEl = this.widget.@com.google.gwt.user.client.ui.UIObject::getElement()();
48: this.el = $wnd.Ext.get(widgetEl);
49: this.el.setVisible(true);
50: container.dom.insertBefore(widgetEl, position);
51: delete this.widget;
52: }
53:
54: });
55: $wnd.Ext.reg('gwtwidget', $wnd.Ext.ux.WidgetComponent);
56: }-*/;
57:
58: public WidgetComponent(Widget widget) {
59: ExtElement hiddenDiv = Ext.get(hiddenDivID);
60: if (hiddenDiv == null) {
61: DomConfig domConfig = new DomConfig("div", hiddenDivID,
62: null);
63: domConfig.setStyle("display:none;");
64: DomHelper.append(RootPanel.getBodyElement(), domConfig);
65: }
66: setWidget(widget);
67: setId(DOMUtil.getID(widget));
68: }
69:
70: public WidgetComponent(JavaScriptObject jsObj) {
71: super (jsObj);
72: }
73:
74: public void setWidget(Widget widget) {
75: JavaScriptObjectHelper.setAttribute(config, "widget", widget);
76: }
77:
78: protected native JavaScriptObject create(JavaScriptObject config) /*-{
79: return new $wnd.Ext.ux.WidgetComponent(config);
80: }-*/;
81:
82: public String getXType() {
83: return "gwtwidget";
84: }
85: }
|