Revision: 10219
Author:   [email protected]
Date:     Tue May 24 10:37:15 2011
Log: Attachable -> IsRenderable step 3: Renaming AttachableHTMLPanel to RenderablePanel. This guys has its days counted, as it will eventually be merged into HTMLPanel.

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

http://code.google.com/p/google-web-toolkit/source/detail?r=10219

Added:
/trunk/user/src/com/google/gwt/uibinder/elementparsers/RenderablePanelParser.java
 /trunk/user/src/com/google/gwt/user/client/ui/RenderablePanel.java
Deleted:
/trunk/user/src/com/google/gwt/uibinder/elementparsers/AttachableHTMLPanelParser.java
 /trunk/user/src/com/google/gwt/user/client/ui/AttachableHTMLPanel.java
Modified:
/trunk/user/src/com/google/gwt/uibinder/elementparsers/IsRenderableInterpreter.java
 /trunk/user/src/com/google/gwt/uibinder/rebind/AbstractFieldWriter.java
 /trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
 /trunk/user/src/com/google/gwt/user/client/ui/RenderableComposite.java

=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/uibinder/elementparsers/RenderablePanelParser.java Tue May 24 10:37:15 2011
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * 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.uibinder.elementparsers;
+
+import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.uibinder.elementparsers.HtmlMessageInterpreter.PlaceholderInterpreterProvider;
+import com.google.gwt.uibinder.rebind.UiBinderWriter;
+import com.google.gwt.uibinder.rebind.XMLElement;
+import com.google.gwt.uibinder.rebind.messages.MessageWriter;
+import com.google.gwt.uibinder.rebind.messages.PlaceholderInterpreter;
+
+/**
+ * Parses {@link com.google.gwt.user.client.ui.RenderablePanel} widgets.
+ */
+public class RenderablePanelParser implements ElementParser {
+
+  public void parse(XMLElement elem, String fieldName, JClassType type,
+      final UiBinderWriter writer) throws UnableToCompleteException {
+
+    assert writer.useLazyWidgetBuilders();
+
+    /*
+     * Gathers up elements that indicate nested IsRenderable objects.
+     */
+    IsRenderableInterpreter isRenderableInterpreter = null;
+    isRenderableInterpreter = new IsRenderableInterpreter(
+        fieldName, writer);
+
+    /*
+ * Gathers up elements that indicate nested widgets (but only those that are
+     * not inside msg elements).
+     */
+    WidgetInterpreter widgetInterpreter = new WidgetInterpreter(fieldName,
+        writer);
+
+    /*
+     * Handles non-widget elements like msg, and dom elements with ui:field
+     * attributes. There may be widgets inside a msg, which is why the
+     * construction in makeHtmlInterpreter is so complicated.
+     */
+ HtmlInterpreter htmlInterpreter = makeHtmlInterpreter(fieldName, writer);
+
+    writer.beginAttachedSection(fieldName);
+
+    final InterpreterPipe interpreters;
+    interpreters = InterpreterPipe.newPipe(
+        isRenderableInterpreter, widgetInterpreter, htmlInterpreter);
+    String html = elem.consumeInnerHtml(interpreters);
+
+    writer.endAttachedSection();
+
+    /*
+ * RenderablePanel has no no-arg ctor, so we have to generate our own, using the + * element's innerHTML and perhaps its tag attribute. Do this in a way that + * will not break subclasses if they happen to have the same constructor
+     * signature (by passing in type).
+     */
+    String customTag = elem.consumeStringAttribute("tag", null);
+
+    // TODO(rdcastro): Add support for custom tags in RenderablePanel.
+    if (customTag != null) {
+      writer.getLogger().die(
+          "RenderablePanel does not support custom root elements yet.");
+    }
+
+ writer.setFieldInitializerAsConstructor(fieldName, type, writer.declareTemplateCall(html));
+  }
+
+  /**
+ * Creates an HtmlInterpreter with our specialized placeholder interpreter, + * which will allow widget instances to be declared inside of ui:msg elements.
+   */
+  private HtmlInterpreter makeHtmlInterpreter(final String fieldName,
+      final UiBinderWriter uiWriter) {
+    final String ancestorExpression = fieldName;
+
+    PlaceholderInterpreterProvider placeholderInterpreterProvider =
+        new PlaceholderInterpreterProvider() {
+      public PlaceholderInterpreter get(MessageWriter message) {
+ return new WidgetPlaceholderInterpreter(fieldName, uiWriter, message,
+            ancestorExpression);
+      }
+    };
+
+    HtmlInterpreter htmlInterpreter = new HtmlInterpreter(uiWriter,
+        ancestorExpression, new HtmlMessageInterpreter(uiWriter,
+            placeholderInterpreterProvider));
+
+    return htmlInterpreter;
+  }
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/user/client/ui/RenderablePanel.java Tue May 24 10:37:15 2011
@@ -0,0 +1,271 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * 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.user.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.safehtml.client.SafeHtmlTemplates;
+import com.google.gwt.safehtml.shared.SafeHtml;
+import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
+import com.google.gwt.user.client.Command;
+
+/**
+ * EXPERIMENTAL and subject to change. Do not use this in production code.
+ * <p>
+ * An {@link IsRenderable} version of {@link HTMLPanel}. This class is a stepping + * in our transition to the Renderable strategy. Eventually this functionality
+ * should be merged into {@link HTMLPanel}.
+ * The only reason this class doesn't extend {@link HTMLPanel} is because it + * doesn't provide any way to build the panel lazily (which is needed here).
+ */
+public class RenderablePanel extends ComplexPanel implements IsRenderable {
+
+  private static Element hiddenDiv;
+
+  interface HTMLTemplates extends SafeHtmlTemplates {
+    @Template("<div id=\"{0}\">{1}</div>")
+    SafeHtml renderWithId(String id, SafeHtml innerHtml);
+
+    @Template("<div id=\"{0}\" class=\"{1}\">{2}</div>")
+ SafeHtml renderWithIdAndClass(String id, String styleName, SafeHtml innerHtml);
+  }
+  private static final HTMLTemplates TEMPLATE =
+      GWT.create(HTMLTemplates.class);
+
+  private static void ensureHiddenDiv() {
+    // If it's already been created, don't do anything.
+    if (hiddenDiv != null) {
+      return;
+    }
+
+    hiddenDiv = Document.get().createDivElement();
+    UIObject.setVisible(hiddenDiv, false);
+    RootPanel.getBodyElement().appendChild(hiddenDiv);
+  }
+
+ // TODO(rdcastro): Add setters for these, or maybe have a list instead of a
+  // single callback.
+  public Command wrapInitializationCallback = null;
+  public Command detachedInitializationCallback = null;
+
+  protected SafeHtml html = null;
+  private String styleName = null;
+
+  /**
+   * Creates an HTML panel with the specified HTML contents inside a DIV
+ * element. Any element within this HTML that has a specified id can contain a
+   * child widget.
+ * The actual element that will hold this HTML isn't initialized until it is
+   * needed.
+   *
+   * @param html the panel's HTML
+   */
+  public RenderablePanel(String html) {
+    this(new SafeHtmlBuilder().appendHtmlConstant(html).toSafeHtml());
+  }
+
+  /**
+   * Initializes the panel's HTML from a given {@link SafeHtml} object.
+   *
+   * Similar to {@link #HTMLPanel(String)}
+   *
+   * @param safeHtml the html to set.
+   */
+  public RenderablePanel(SafeHtml safeHtml) {
+    this.html = safeHtml;
+  }
+
+  /**
+   * Adds a child widget to the panel.
+   *
+   * @param widget the widget to be added
+   */
+  @Override
+  public void add(Widget widget) {
+    add(widget, getElement());
+  }
+
+  /**
+   * Adds a child widget to the panel, replacing the HTML element.
+   *
+   * @param widget the widget to be added
+   * @param toReplace the element to be replaced by the widget
+   */
+ public final void addAndReplaceElement(Widget widget, Element toReplace) {
+    com.google.gwt.user.client.Element clientElem = toReplace.cast();
+    addAndReplaceElement(widget, clientElem);
+  }
+
+  /**
+   * Adds a child widget to the panel, replacing the HTML element.
+   *
+   * @param widget the widget to be added
+   * @param toReplace the element to be replaced by the widget
+   * @deprecated use {@link #addAndReplaceElement(Widget, Element)}
+   */
+  @Deprecated
+  public void addAndReplaceElement(Widget widget,
+      com.google.gwt.user.client.Element toReplace) {
+ // Logic pulled from super.add(), replacing the element rather than adding.
+    widget.removeFromParent();
+    getChildren().add(widget);
+    toReplace.getParentNode().replaceChild(widget.getElement(), toReplace);
+    adopt(widget);
+  }
+
+  /**
+   * Overloaded version for IsWidget.
+   *
+   * @see #addAndReplaceElement(Widget,Element)
+   */
+  public void addAndReplaceElement(IsWidget widget,
+      com.google.gwt.user.client.Element toReplace) {
+    this.addAndReplaceElement(widget.asWidget(), toReplace);
+  }
+
+  @Override
+  public com.google.gwt.user.client.Element getElement() {
+    if (!isFullyInitialized()) {
+      // In case we haven't finished initialization yet, finish it now.
+      buildAndInitDivContainer();
+      html = null;
+
+      // We might have to add a style that has been previously set.
+      if (styleName != null) {
+        super.setStyleName(styleName);
+        styleName = null;
+      }
+    }
+    return super.getElement();
+  }
+
+  /**
+   * Adopts the given, but doesn't change anything about its DOM element.
+ * Should only be used for widgets with elements that are children of this
+   * panel's element.
+   * No-op if called with an {@link IsRenderable} that isn't also IsWidget,
+   * but safe to call with such as a convenience.
+   */
+  public void logicalAdd(IsRenderable renderable) {
+    if (!(renderable instanceof IsWidget)) {
+      // Nothing to do if not a Widget.
+      return;
+    }
+    Widget widget = ((IsWidget) renderable).asWidget();
+    getChildren().add(widget);
+    adopt(widget);
+  }
+
+  @Override
+  public void performDetachedInitialization() {
+    if (detachedInitializationCallback != null) {
+      detachedInitializationCallback.execute();
+      detachedInitializationCallback = null;
+    }
+  }
+
+  @Override
+  public SafeHtml render(String id) {
+    SafeHtmlBuilder builder = new SafeHtmlBuilder();
+    render(id, builder);
+    return builder.toSafeHtml();
+  }
+
+  @Override
+  public void render(String id, SafeHtmlBuilder builder) {
+    if (styleName != null) {
+ builder.append(TEMPLATE.renderWithIdAndClass(id, styleName, getInnerHtml()));
+      styleName = null;
+    } else {
+      builder.append(TEMPLATE.renderWithId(id, getInnerHtml()));
+    }
+  }
+
+  @Override
+  public void setStyleName(String styleName) {
+    if (!isFullyInitialized()) {
+      // If we haven't built the actual HTML element yet, we save the style
+      // to apply later on.
+      this.styleName = styleName;
+    } else {
+      super.setStyleName(styleName);
+    }
+  }
+
+  @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 a call to getElement()" + + "has forced 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.
+   */
+  protected SafeHtml getInnerHtml() {
+    return html;
+  }
+
+  /**
+ * Whether the initilization of the panel is finished (i.e., the corresponding
+   * DOM element has been built).
+   */
+  protected boolean isFullyInitialized() {
+    return html == null;
+  }
+
+  /**
+ * Method that finishes the initialization of HTMLPanel instances built from + * HTML. This will create a div to wrap the given HTML and call any callbacks
+   * that may have been added to the panel.
+   */
+  private void buildAndInitDivContainer() {
+    // Build the div that'll container the panel's HTML.
+    Element element = Document.get().createDivElement();
+    element.setInnerHTML(getInnerHtml().asString());
+    setElement(element);
+
+ // If there's any wrap callback to call, we have to attach the div before
+    // calling it, and then detach again.
+    if (wrapInitializationCallback != null) {
+      ensureHiddenDiv();
+      hiddenDiv.appendChild(element);
+      wrapInitializationCallback.execute();
+      element.getParentNode().removeChild(element);
+    }
+
+    // Call any detached init callbacks we might have.
+    if (detachedInitializationCallback != null) {
+      detachedInitializationCallback.execute();
+    }
+  }
+}
=======================================
--- /trunk/user/src/com/google/gwt/uibinder/elementparsers/AttachableHTMLPanelParser.java Tue May 24 07:34:42 2011
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * 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.uibinder.elementparsers;
-
-import com.google.gwt.core.ext.UnableToCompleteException;
-import com.google.gwt.core.ext.typeinfo.JClassType;
-import com.google.gwt.uibinder.elementparsers.HtmlMessageInterpreter.PlaceholderInterpreterProvider;
-import com.google.gwt.uibinder.rebind.UiBinderWriter;
-import com.google.gwt.uibinder.rebind.XMLElement;
-import com.google.gwt.uibinder.rebind.messages.MessageWriter;
-import com.google.gwt.uibinder.rebind.messages.PlaceholderInterpreter;
-
-/**
- * Parses {@link com.google.gwt.user.client.ui.AttachableHTMLPanel} widgets.
- */
-public class AttachableHTMLPanelParser implements ElementParser {
-
-  public void parse(XMLElement elem, String fieldName, JClassType type,
-      final UiBinderWriter writer) throws UnableToCompleteException {
-
-    assert writer.useLazyWidgetBuilders();
-
-    /*
-     * Gathers up elements that indicate nested IsRenderable objects.
-     */
-    IsRenderableInterpreter isRenderableInterpreter = null;
-    isRenderableInterpreter = new IsRenderableInterpreter(
-        fieldName, writer);
-
-    /*
- * Gathers up elements that indicate nested widgets (but only those that are
-     * not inside msg elements).
-     */
-    WidgetInterpreter widgetInterpreter = new WidgetInterpreter(fieldName,
-        writer);
-
-    /*
-     * Handles non-widget elements like msg, and dom elements with ui:field
-     * attributes. There may be widgets inside a msg, which is why the
-     * construction in makeHtmlInterpreter is so complicated.
-     */
- HtmlInterpreter htmlInterpreter = makeHtmlInterpreter(fieldName, writer);
-
-    writer.beginAttachedSection(fieldName);
-
-    final InterpreterPipe interpreters;
-    interpreters = InterpreterPipe.newPipe(
-        isRenderableInterpreter, widgetInterpreter, htmlInterpreter);
-    String html = elem.consumeInnerHtml(interpreters);
-
-    writer.endAttachedSection();
-
-    /*
- * AttachableHTMLPanel has no no-arg ctor, so we have to generate our own, using the - * element's innerHTML and perhaps its tag attribute. Do this in a way that - * will not break subclasses if they happen to have the same constructor
-     * signature (by passing in type).
-     */
-    String customTag = elem.consumeStringAttribute("tag", null);
-
-    // TODO(rdcastro): Add support for custom tags in AttachableHTMLPanel.
-    if (customTag != null) {
-      writer.getLogger().die(
- "AttachableHTMLPanel does not support custom root elements yet.");
-    }
-
- writer.setFieldInitializerAsConstructor(fieldName, type, writer.declareTemplateCall(html));
-  }
-
-  /**
- * Creates an HtmlInterpreter with our specialized placeholder interpreter, - * which will allow widget instances to be declared inside of ui:msg elements.
-   */
-  private HtmlInterpreter makeHtmlInterpreter(final String fieldName,
-      final UiBinderWriter uiWriter) {
-    final String ancestorExpression = fieldName;
-
-    PlaceholderInterpreterProvider placeholderInterpreterProvider =
-        new PlaceholderInterpreterProvider() {
-      public PlaceholderInterpreter get(MessageWriter message) {
- return new WidgetPlaceholderInterpreter(fieldName, uiWriter, message,
-            ancestorExpression);
-      }
-    };
-
-    HtmlInterpreter htmlInterpreter = new HtmlInterpreter(uiWriter,
-        ancestorExpression, new HtmlMessageInterpreter(uiWriter,
-            placeholderInterpreterProvider));
-
-    return htmlInterpreter;
-  }
-}
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/AttachableHTMLPanel.java Mon May 23 17:23:56 2011
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * 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.user.client.ui;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.dom.client.Document;
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.safehtml.client.SafeHtmlTemplates;
-import com.google.gwt.safehtml.shared.SafeHtml;
-import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
-import com.google.gwt.user.client.Command;
-
-/**
- * EXPERIMENTAL and subject to change. Do not use this in production code.
- * <p>
- * An {@link Attachable} version of {@link HTMLPanel}. This class is a stepping - * in our transition to the Attachable strategy. Eventually this functionality
- * should be merged into {@link HTMLPanel}.
- * The only reason this class doesn't extend {@link HTMLPanel} is because it - * doesn't provide any way to build the panel lazily (which is needed here).
- *
- * TODO(rdcastro): Rename this RenderablePanel.
- */
-public class AttachableHTMLPanel extends ComplexPanel implements IsRenderable {
-
-  private static Element hiddenDiv;
-
-  interface HTMLTemplates extends SafeHtmlTemplates {
-    @Template("<div id=\"{0}\">{1}</div>")
-    SafeHtml renderWithId(String id, SafeHtml innerHtml);
-
-    @Template("<div id=\"{0}\" class=\"{1}\">{2}</div>")
- SafeHtml renderWithIdAndClass(String id, String styleName, SafeHtml innerHtml);
-  }
-  private static final HTMLTemplates TEMPLATE =
-      GWT.create(HTMLTemplates.class);
-
-  private static void ensureHiddenDiv() {
-    // If it's already been created, don't do anything.
-    if (hiddenDiv != null) {
-      return;
-    }
-
-    hiddenDiv = Document.get().createDivElement();
-    UIObject.setVisible(hiddenDiv, false);
-    RootPanel.getBodyElement().appendChild(hiddenDiv);
-  }
-
- // TODO(rdcastro): Add setters for these, or maybe have a list instead of a
-  // single callback.
-  public Command wrapInitializationCallback = null;
-  public Command detachedInitializationCallback = null;
-
-  protected SafeHtml html = null;
-  private String styleName = null;
-
-  /**
-   * Creates an HTML panel with the specified HTML contents inside a DIV
- * element. Any element within this HTML that has a specified id can contain a
-   * child widget.
- * The actual element that will hold this HTML isn't initialized until it is
-   * needed.
-   *
-   * @param html the panel's HTML
-   */
-  public AttachableHTMLPanel(String html) {
-    this(new SafeHtmlBuilder().appendHtmlConstant(html).toSafeHtml());
-  }
-
-  /**
-   * Initializes the panel's HTML from a given {@link SafeHtml} object.
-   *
-   * Similar to {@link #HTMLPanel(String)}
-   *
-   * @param safeHtml the html to set.
-   */
-  public AttachableHTMLPanel(SafeHtml safeHtml) {
-    this.html = safeHtml;
-  }
-
-  /**
-   * Adds a child widget to the panel.
-   *
-   * @param widget the widget to be added
-   */
-  @Override
-  public void add(Widget widget) {
-    add(widget, getElement());
-  }
-
-  /**
-   * Adds a child widget to the panel, replacing the HTML element.
-   *
-   * @param widget the widget to be added
-   * @param toReplace the element to be replaced by the widget
-   */
- public final void addAndReplaceElement(Widget widget, Element toReplace) {
-    com.google.gwt.user.client.Element clientElem = toReplace.cast();
-    addAndReplaceElement(widget, clientElem);
-  }
-
-  /**
-   * Adds a child widget to the panel, replacing the HTML element.
-   *
-   * @param widget the widget to be added
-   * @param toReplace the element to be replaced by the widget
-   * @deprecated use {@link #addAndReplaceElement(Widget, Element)}
-   */
-  @Deprecated
-  public void addAndReplaceElement(Widget widget,
-      com.google.gwt.user.client.Element toReplace) {
- // Logic pulled from super.add(), replacing the element rather than adding.
-    widget.removeFromParent();
-    getChildren().add(widget);
-    toReplace.getParentNode().replaceChild(widget.getElement(), toReplace);
-    adopt(widget);
-  }
-
-  /**
-   * Overloaded version for IsWidget.
-   *
-   * @see #addAndReplaceElement(Widget,Element)
-   */
-  public void addAndReplaceElement(IsWidget widget,
-      com.google.gwt.user.client.Element toReplace) {
-    this.addAndReplaceElement(widget.asWidget(), toReplace);
-  }
-
-  @Override
-  public com.google.gwt.user.client.Element getElement() {
-    if (!isFullyInitialized()) {
-      // In case we haven't finished initialization yet, finish it now.
-      buildAndInitDivContainer();
-      html = null;
-
-      // We might have to add a style that has been previously set.
-      if (styleName != null) {
-        super.setStyleName(styleName);
-        styleName = null;
-      }
-    }
-    return super.getElement();
-  }
-
-  /**
-   * Adopts the given, but doesn't change anything about its DOM element.
- * Should only be used for widgets with elements that are children of this
-   * panel's element.
-   * No-op if called with an Attachable that isn't also IsWidget,
-   * but safe to call with such as a convenience.
-   */
-  public void logicalAdd(IsRenderable attachable) {
-    if (!(attachable instanceof IsWidget)) {
-      // Nothing to do if not a Widget.
-      return;
-    }
-    Widget widget = ((IsWidget) attachable).asWidget();
-    getChildren().add(widget);
-    adopt(widget);
-  }
-
-  @Override
-  public void performDetachedInitialization() {
-    if (detachedInitializationCallback != null) {
-      detachedInitializationCallback.execute();
-      detachedInitializationCallback = null;
-    }
-  }
-
-  @Override
-  public SafeHtml render(String id) {
-    SafeHtmlBuilder builder = new SafeHtmlBuilder();
-    render(id, builder);
-    return builder.toSafeHtml();
-  }
-
-  @Override
-  public void render(String id, SafeHtmlBuilder builder) {
-    if (styleName != null) {
- builder.append(TEMPLATE.renderWithIdAndClass(id, styleName, getInnerHtml()));
-      styleName = null;
-    } else {
-      builder.append(TEMPLATE.renderWithId(id, getInnerHtml()));
-    }
-  }
-
-  @Override
-  public void setStyleName(String styleName) {
-    if (!isFullyInitialized()) {
-      // If we haven't built the actual HTML element yet, we save the style
-      // to apply later on.
-      this.styleName = styleName;
-    } else {
-      super.setStyleName(styleName);
-    }
-  }
-
-  @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 a call to getElement()" - + "has forced 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.
-   */
-  protected SafeHtml getInnerHtml() {
-    return html;
-  }
-
-  /**
- * Whether the initilization of the panel is finished (i.e., the corresponding
-   * DOM element has been built).
-   */
-  protected boolean isFullyInitialized() {
-    return html == null;
-  }
-
-  /**
- * Method that finishes the initialization of HTMLPanel instances built from - * HTML. This will create a div to wrap the given HTML and call any callbacks
-   * that may have been added to the panel.
-   */
-  private void buildAndInitDivContainer() {
-    // Build the div that'll container the panel's HTML.
-    Element element = Document.get().createDivElement();
-    element.setInnerHTML(getInnerHtml().asString());
-    setElement(element);
-
- // If there's any wrap callback to call, we have to attach the div before
-    // calling it, and then detach again.
-    if (wrapInitializationCallback != null) {
-      ensureHiddenDiv();
-      hiddenDiv.appendChild(element);
-      wrapInitializationCallback.execute();
-      element.getParentNode().removeChild(element);
-    }
-
-    // Call any detached init callbacks we might have.
-    if (detachedInitializationCallback != null) {
-      detachedInitializationCallback.execute();
-    }
-  }
-}
=======================================
--- /trunk/user/src/com/google/gwt/uibinder/elementparsers/IsRenderableInterpreter.java Mon May 23 17:23:56 2011 +++ /trunk/user/src/com/google/gwt/uibinder/elementparsers/IsRenderableInterpreter.java Tue May 24 10:37:15 2011
@@ -22,9 +22,9 @@
 import com.google.gwt.uibinder.rebind.XMLElement;

 /**
- * Used by {@link AttachableHTMLPanelParser} to interpret renderable elements.
+ * Used by {@link RenderablePanelParser} to interpret renderable elements.
* Declares the appropriate {@link IsRenderable}, and returns the correct HTML
- * to be inlined in the AttachableHTMLPanel.
+ * to be inlined in the {@link RenderablePanel}.
  */
 class IsRenderableInterpreter implements XMLElement.Interpreter<String> {

=======================================
--- /trunk/user/src/com/google/gwt/uibinder/rebind/AbstractFieldWriter.java Tue May 24 07:34:42 2011 +++ /trunk/user/src/com/google/gwt/uibinder/rebind/AbstractFieldWriter.java Tue May 24 10:37:15 2011
@@ -23,7 +23,7 @@
 import com.google.gwt.core.ext.typeinfo.TypeOracle;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.uibinder.rebind.model.OwnerField;
-import com.google.gwt.user.client.ui.AttachableHTMLPanel;
+import com.google.gwt.user.client.ui.RenderablePanel;

 import java.util.ArrayList;
 import java.util.Arrays;
@@ -190,11 +190,11 @@
       boolean useLazyWidgetBuilders)
       throws UnableToCompleteException {

-    JClassType attachableHTMLPanelType = typeOracle.findType(
-        AttachableHTMLPanel.class.getName());
+    JClassType renderablePanelType = typeOracle.findType(
+        RenderablePanel.class.getName());
     boolean outputAttachDetachCallbacks = useLazyWidgetBuilders
         && getAssignableType() != null
-        && getAssignableType().isAssignableTo(attachableHTMLPanelType);
+        && getAssignableType().isAssignableTo(renderablePanelType);

     // Check initializer.
     if (initializer == null) {
@@ -250,7 +250,7 @@
       w.newline();
       w.write("// Attach section.");
       if (outputAttachDetachCallbacks) {
-        // TODO(rdcastro): This is too coupled with AttachableHTMLPanel.
+        // TODO(rdcastro): This is too coupled with RenderablePanel.
         // Make this nicer.
         w.write("%s.wrapInitializationCallback = ", getName());
         w.indent();
=======================================
--- /trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java Tue May 24 10:01:44 2011 +++ /trunk/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java Tue May 24 10:37:15 2011
@@ -1187,7 +1187,7 @@
         FieldWriter cssField = fieldManager.require(fieldName);
         cssField.addStatement("%s.ensureInjected();", fieldName);
       }
-      writeBinderForAttachableStrategy(niceWriter, rootField);
+      writeBinderForRenderableStrategy(niceWriter, rootField);
     } else {
       writeBinder(niceWriter, rootField);
     }
@@ -1253,7 +1253,7 @@
     addWidgetParser("NumberLabel");
     if (useLazyWidgetBuilders) {
       addWidgetParser("LazyPanel");
-      addWidgetParser("AttachableHTMLPanel");
+      addWidgetParser("RenderablePanel");
     }
   }

@@ -1319,10 +1319,10 @@
   }

   /**
-   * Writes a different optimized UiBinder's source for the attachable
+   * Writes a different optimized UiBinder's source for the renderable
    * strategy.
    */
-  private void writeBinderForAttachableStrategy(
+  private void writeBinderForRenderableStrategy(
IndentedWriter w, String rootField) throws UnableToCompleteException {
     writePackage(w);

=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/RenderableComposite.java Tue May 24 09:02:46 2011 +++ /trunk/user/src/com/google/gwt/user/client/ui/RenderableComposite.java Tue May 24 10:37:15 2011
@@ -32,8 +32,6 @@
  * itself, but is still under active development.
* The only reason why this isn't a subclass of {@link Composite} is to avoid
  * messing up it's API, since {@link Composite} is very often subclassed.
- *
- * TODO(rdcastro): Rename this RenderableComposite.
  */
public abstract class RenderableComposite extends Widget implements IsRenderable {

@@ -46,7 +44,7 @@

   private Widget widget;

-  private IsRenderable attachable;
+  private IsRenderable renderable;

   private Element elementToWrap;

@@ -81,9 +79,9 @@

   @Override
   public void performDetachedInitialization() {
-    if (attachable != null) {
+    if (renderable != null) {
       assert (initFinished == false);
-      attachable.performDetachedInitialization();
+      renderable.performDetachedInitialization();
       initWidgetInternal();
     } else {
elementToWrap.getParentNode().replaceChild(widget.getElement(), elementToWrap);
@@ -92,8 +90,8 @@

   @Override
   public SafeHtml render(String id) {
-    if (attachable != null) {
-      return attachable.render(id);
+    if (renderable != null) {
+      return renderable.render(id);
     } else {
       SafeHtmlBuilder builder = new SafeHtmlBuilder();
       render(id, builder);
@@ -103,8 +101,8 @@

   @Override
   public void render(String id, SafeHtmlBuilder builder) {
-    if (attachable != null) {
-      attachable.render(id, builder);
+    if (renderable != null) {
+      renderable.render(id, builder);
     } else {
       builder.append(TEMPLATE.renderWithId(id));
     }
@@ -120,9 +118,9 @@

   @Override
   public void wrapElement(Element element) {
-    if (attachable != null) {
+    if (renderable != null) {
       assert (initFinished == false);
-      attachable.wrapElement(element);
+      renderable.wrapElement(element);
     } else {
       this.elementToWrap = element;
     }
@@ -161,7 +159,7 @@
     if (widget instanceof IsRenderable) {
// In case the Widget being wrapped is an IsRenderable, we delay finishing // the initialization until the performDetachedInitialization() is called.
-      this.attachable = (IsRenderable) widget;
+      this.renderable = (IsRenderable) widget;
       return;
     }

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

Reply via email to