Revision: 10352
Author:   [email protected]
Date:     Mon Jun 20 08:50:41 2011
Log: Finalizing IsRenderable API step 1: renaming wrapElement() and performDetachedInitialization().

Review at http://gwt-code-reviews.appspot.com/1463804

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=10352

Modified:
/trunk/user/src/com/google/gwt/uibinder/elementparsers/IsRenderableInterpreter.java
 /trunk/user/src/com/google/gwt/user/client/ui/Composite.java
 /trunk/user/src/com/google/gwt/user/client/ui/IsRenderable.java
 /trunk/user/src/com/google/gwt/user/client/ui/RenderablePanel.java

=======================================
--- /trunk/user/src/com/google/gwt/uibinder/elementparsers/IsRenderableInterpreter.java Tue May 24 10:37:15 2011 +++ /trunk/user/src/com/google/gwt/uibinder/elementparsers/IsRenderableInterpreter.java Mon Jun 20 08:50:41 2011
@@ -56,14 +56,14 @@
         "com.google.gwt.dom.client.Document.get().getElementById(%s).cast();",
         elementPointer, fieldManager.convertFieldToGetter(idHolder));
     fieldWriter.addAttachStatement(
-        "%s.wrapElement(%s);",
+        "%s.claimElement(%s);",
         fieldManager.convertFieldToGetter(childFieldWriter.getName()),
         elementPointer);

     // Some operations are more efficient when the Widget isn't attached to
     // the document. Perform them here.
     fieldWriter.addDetachStatement(
-        "%s.performDetachedInitialization();",
+        "%s.initializeClaimedElement();",
         fieldManager.convertFieldToGetter(childFieldWriter.getName()));

     fieldWriter.addDetachStatement(
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/Composite.java Wed Jun 8 04:46:32 2011 +++ /trunk/user/src/com/google/gwt/user/client/ui/Composite.java Mon Jun 20 08:50:41 2011
@@ -55,6 +55,25 @@
   private IsRenderable renderable;

   private Element elementToWrap;
+
+  @Override
+  public final void claimElement(Element element) {
+    if (renderable != null) {
+      renderable.claimElement(element);
+      setElement(widget.getElement());
+    } else {
+      this.elementToWrap = element;
+    }
+  }
+
+  @Override
+  public final void initializeClaimedElement() {
+    if (renderable != null) {
+      renderable.initializeClaimedElement();
+    } else {
+ elementToWrap.getParentNode().replaceChild(widget.getElement(), elementToWrap);
+    }
+  }

   @Override
   public boolean isAttached() {
@@ -72,15 +91,6 @@
     // Delegate events to the widget.
     widget.onBrowserEvent(event);
   }
-
-  @Override
-  public final void performDetachedInitialization() {
-    if (renderable != null) {
-      renderable.performDetachedInitialization();
-    } else {
- elementToWrap.getParentNode().replaceChild(widget.getElement(), elementToWrap);
-    }
-  }

   @Override
   public final SafeHtml render(String id) {
@@ -101,16 +111,6 @@
       builder.append(TEMPLATE.renderWithId(id));
     }
   }
-
-  @Override
-  public final void wrapElement(Element element) {
-    if (renderable != null) {
-      renderable.wrapElement(element);
-      setElement(widget.getElement());
-    } else {
-      this.elementToWrap = element;
-    }
-  }

   /**
    * Provides subclasses access to the topmost widget that defines this
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/IsRenderable.java Tue May 31 07:26:19 2011 +++ /trunk/user/src/com/google/gwt/user/client/ui/IsRenderable.java Mon Jun 20 08:50:41 2011
@@ -29,11 +29,17 @@
  */
 public interface IsRenderable {

+  /**
+   * Replace the previous contents of the receiver with the given element,
+   * presumed to have been created via a previous call to {@link #render}.
+   */
+  void claimElement(Element element);
+
   /**
    * Perform any initialization needed when the widget is not attached to
-   * the document. Assumed to be called after {@link #wrapElement}.
+   * the document. Assumed to be called after {@link #claimElement}.
    */
-  void performDetachedInitialization();
+  void initializeClaimedElement();

   /**
    * @see #render(String, SafeHtmlBuilder)
@@ -46,11 +52,4 @@
    * The root element of the HTML must be identifies by the given id.
    */
   void render(String id, SafeHtmlBuilder builder);
-
-  /**
-   * Replace the previous contents of the receiver with the given element,
-   * presumed to have been created via a previous call to {@link #render}.
-   * Assumes the element is attached to the document.
-   */
-  void wrapElement(Element element);
-}
+}
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/RenderablePanel.java Mon Jun 13 03:14:47 2011 +++ /trunk/user/src/com/google/gwt/user/client/ui/RenderablePanel.java Mon Jun 20 05:24:26 2011
@@ -138,6 +138,35 @@
       com.google.gwt.user.client.Element toReplace) {
     this.addAndReplaceElement(widget.asWidget(), toReplace);
   }
+
+  @Override
+  public void claimElement(Element element) {
+    if (isFullyInitialized()) {
+      /*
+ * If claimElement is being called after the widget is fully initialized, + * that's probably a programming error, as it's much more efficient to
+       * build the whole tree at once.
+       */
+      throw new IllegalStateException(
+ "claimElement() cannot be called twice, or after forcing the widget to"
+          + " render itself (e.g. after adding it to a panel)");
+    }
+
+    setElement(element);
+    html = null;
+    if (wrapInitializationCallback != null) {
+      wrapInitializationCallback.execute();
+      wrapInitializationCallback = null;
+    }
+  }
+
+  @Override
+  public void initializeClaimedElement() {
+    if (detachedInitializationCallback != null) {
+      detachedInitializationCallback.execute();
+      detachedInitializationCallback = null;
+    }
+  }

   /**
    * Adopts the given, but doesn't change anything about its DOM element.
@@ -155,14 +184,6 @@
     getChildren().add(widget);
     adopt(widget);
   }
-
-  @Override
-  public void performDetachedInitialization() {
-    if (detachedInitializationCallback != null) {
-      detachedInitializationCallback.execute();
-      detachedInitializationCallback = null;
-    }
-  }

   @Override
   public SafeHtml render(String id) {
@@ -188,27 +209,6 @@
     html = null;
     return getElement();
   }
-
-  @Override
-  public void wrapElement(Element element) {
-    if (isFullyInitialized()) {
-      /*
- * If wrapElement is being called after the widget is fully initialized, - * that's probably a programming error, as it's much more efficient to
-       * build the whole tree at once.
-       */
-      throw new IllegalStateException(
- "wrapElement() cannot be called twice, or after forcing the widget to"
-          + " render itself (e.g. after adding it to a panel)");
-    }
-
-    setElement(element);
-    html = null;
-    if (wrapInitializationCallback != null) {
-      wrapInitializationCallback.execute();
-      wrapInitializationCallback = null;
-    }
-  }

   /**
    * Returns the HTML to be set as the innerHTML of the container.

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to