]> source.dussan.org Git - gwtquery.git/commitdiff
Adding a panel() method to widgets plugin so as gquery is able to convert any element...
authorManolo Carrasco <manolo@apache.org>
Fri, 19 Oct 2012 07:34:02 +0000 (09:34 +0200)
committerManolo Carrasco <manolo@apache.org>
Fri, 19 Oct 2012 07:34:02 +0000 (09:34 +0200)
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/HtmlPanelWidgetFactory.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsHtmlPanel.java

index 804c42ed39fdf42d2dd56a3a9af39002c70d095b..657e72f94d04e4a392a22a176af71bac3897d854 100755 (executable)
@@ -21,6 +21,7 @@ import java.util.List;
 import com.google.gwt.dom.client.Element;\r
 import com.google.gwt.query.client.GQuery;\r
 import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory;\r
+import com.google.gwt.query.client.plugins.widgets.HtmlPanelWidgetFactory;\r
 import com.google.gwt.query.client.plugins.widgets.LabelWidgetFactory;\r
 import com.google.gwt.query.client.plugins.widgets.PasswordTextBoxWidgetFactory;\r
 import com.google.gwt.query.client.plugins.widgets.TextAreaWidgetFactory;\r
@@ -128,10 +129,10 @@ public class Widgets extends QueuePlugin<Widgets> {
     return widgets(new ButtonWidgetFactory(), initializers);\r
   }\r
 \r
-  public Widgets label() {\r
-    return widgets(new LabelWidgetFactory(), null);\r
+  public Widgets panel() {\r
+    return widgets(new HtmlPanelWidgetFactory(), null);\r
   }\r
-\r
+  \r
   public Widgets label(WidgetInitializer<Label> initializers) {\r
     return widgets(new LabelWidgetFactory(), initializers);\r
   }\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/HtmlPanelWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/HtmlPanelWidgetFactory.java
new file mode 100644 (file)
index 0000000..cda3611
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2012, The gwtquery team.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client.plugins.widgets;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.user.client.ui.HTMLPanel;
+
+public class HtmlPanelWidgetFactory implements WidgetFactory<HTMLPanel> {
+  
+  public HTMLPanel create(Element e) {
+    return new WidgetsHtmlPanel(e);
+  }
+  
+}
\ No newline at end of file
index 14a192b7f472511187b3ffc62c948bedcb3e3ef1..0742e4a9525399619ba06ccf6287b7100fb93143 100644 (file)
@@ -22,24 +22,50 @@ import com.google.gwt.query.client.GQuery;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.ui.GqUi;
 import com.google.gwt.user.client.ui.HTMLPanel;
+import com.google.gwt.user.client.ui.Panel;
 import com.google.gwt.user.client.ui.RootPanel;
 import com.google.gwt.user.client.ui.Widget;
 
 /**
- * This {@link HTMLPanel} takes as content the outer html of an element already
+ * This {@link HTMLPanel} takes as content an element already
  * attached to the DOM. If {@link Widget widgets} are present in the children of
  * the element to attach, they will be automatically adopted by the panel in
  * order to keep a consistent widgets hierarchy.
- * 
  */
 public class WidgetsHtmlPanel extends HTMLPanel {
 
   public WidgetsHtmlPanel(Element e) {
     super("");
-    e.removeFromParent();
-    getElement().appendChild(e);
+    if (e != null) {
+      Widget w = $(e).widget();
+      if (w == null) {
+        // We convert the element to a gwt htmlPanel 
+        setElementImpl(e);
+        GqUi.attachWidget(this, null);
+      } else {
+        Widget p = w.getParent();
+        if (p instanceof Panel) {
+          // Replace the widget by this panel
+          this.add(w);
+          ((Panel) p).add(this);
+        } else {
+          // Replace the element by this element
+          Element n = e.getParentElement();
+          n.appendChild(getElement());
+          getElement().appendChild(e);
+          GqUi.attachWidget(this, null);
+        }
+      }
+    }
     adoptSubWidgets();
   }
+  
+  /**
+   * use jsni to access private attribute 
+   */
+  private native void setElementImpl(Element e)/*-{
+    this.@com.google.gwt.user.client.ui.UIObject::element = e;
+  }-*/;
 
   /**
    * Iterate over the children of this widget's element to find widget. If