Revision: 10460
Author:   rdcas...@google.com
Date:     Fri Jul 15 09:31:20 2011
Log:      Replace SafeHtmlTemplates with ElementBuilder in RenderablePanel

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

Modified:
 /trunk/user/src/com/google/gwt/user/client/ui/Composite.java
 /trunk/user/src/com/google/gwt/user/client/ui/RenderablePanel.java
 /trunk/user/src/com/google/gwt/user/client/ui/RenderableStamper.java

=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/Composite.java Wed Jul 6 10:57:13 2011 +++ /trunk/user/src/com/google/gwt/user/client/ui/Composite.java Fri Jul 15 09:31:20 2011
@@ -15,12 +15,12 @@
  */
 package com.google.gwt.user.client.ui;

-import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.builder.shared.HtmlBuilderFactory;
+import com.google.gwt.dom.builder.shared.HtmlSpanBuilder;
 import com.google.gwt.dom.client.Element;
-import com.google.gwt.safehtml.client.SafeHtmlTemplates;
+import com.google.gwt.event.logical.shared.AttachEvent;
 import com.google.gwt.safehtml.shared.SafeHtml;
 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
-import com.google.gwt.event.logical.shared.AttachEvent;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Event;

@@ -43,13 +43,6 @@
  */
 public abstract class Composite extends Widget implements IsRenderable {

-  interface HTMLTemplates extends SafeHtmlTemplates {
-    @Template("<span id=\"{0}\"></span>")
-     SafeHtml renderWithId(String id);
-  }
-  private static final HTMLTemplates TEMPLATE =
-      GWT.create(HTMLTemplates.class);
-
   private Widget widget;

   private IsRenderable renderable;
@@ -104,14 +97,14 @@
   }

   @Override
-  @SuppressWarnings("deprecation")
public final void render(RenderableStamper stamper, SafeHtmlBuilder builder) {
     if (renderable != null) {
       renderable.render(stamper, builder);
     } else {
- // TODO(rdcastro): Investigate whether SafeHtml or ElementBuilder stamping should be used
-      // to avoid any performance regressions.
-      builder.append(TEMPLATE.renderWithId(stamper.getToken()));
+      HtmlSpanBuilder spanBuilder = HtmlBuilderFactory.get()
+          .createSpanBuilder();
+      stamper.stamp(spanBuilder).end();
+      builder.append(spanBuilder.asSafeHtml());
     }
   }

=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/RenderablePanel.java Wed Jul 6 10:57:13 2011 +++ /trunk/user/src/com/google/gwt/user/client/ui/RenderablePanel.java Fri Jul 15 09:31:20 2011
@@ -15,10 +15,10 @@
  */
 package com.google.gwt.user.client.ui;

-import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.builder.shared.HtmlDivBuilder;
+import com.google.gwt.dom.builder.shared.HtmlBuilderFactory;
 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;
@@ -38,16 +38,6 @@

   private static String TAG_NAME = "div";

-  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) {
@@ -193,19 +183,19 @@
   }

   @Override
-  @SuppressWarnings("deprecation")
   public void render(RenderableStamper stamper, SafeHtmlBuilder builder) {
     String styleName = getStyleName();

- // TODO(rdcastro): Investigate whether SafeHtml or ElementBuilder stamping should be used here
-    // to avoid any performance regressions.
-    String id = stamper.getToken();
+    HtmlDivBuilder divBuilder = HtmlBuilderFactory.get()
+        .createDivBuilder();
     if (styleName != null) {
- builder.append(TEMPLATE.renderWithIdAndClass(id, styleName, getInnerHtml()));
+      divBuilder.className(styleName);
       styleName = null;
-    } else {
-      builder.append(TEMPLATE.renderWithId(id, getInnerHtml()));
-    }
+    }
+    stamper.stamp(divBuilder);
+    divBuilder.html(getInnerHtml()).end();
+
+    builder.append(divBuilder.asSafeHtml());
   }

   @Override
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/RenderableStamper.java Wed Jul 6 10:57:13 2011 +++ /trunk/user/src/com/google/gwt/user/client/ui/RenderableStamper.java Fri Jul 15 09:31:20 2011
@@ -15,7 +15,7 @@
  */
 package com.google.gwt.user.client.ui;

-import com.google.gwt.dom.builder.shared.ElementBuilderBase;
+import com.google.gwt.dom.builder.shared.HtmlElementBuilderBase;
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.safehtml.shared.SafeHtml;
@@ -53,15 +53,6 @@
// TODO(rdcastro): Add a DEV-only check to make sure the element is attached.
     return Document.get().getElementById(token);
   }
-
-  /**
-   * Exposes the token used for stamping {@link IsRenderable} objects.
- * @deprecated This method is born deprecated, and should not be used in new code.
-   */
-  @Deprecated
-  public String getToken() {
-    return token;
-  }

   /**
* Stamps an HTML element in such a way that it can be later found in the DOM tree.
@@ -94,7 +85,12 @@
* To be used by {@link IsRenderable} objects built using ElementBuilder, this assumes * the given elementBuilder is for the root element that should later be claimed.
    */
-  public void stamp(ElementBuilderBase<?> elementBuilder) {
+  public <T extends HtmlElementBuilderBase<?>> T stamp(T elementBuilder) {
     elementBuilder.id(token);
+    return elementBuilder;
+  }
+
+  private String getToken() {
+    return token;
   }
 }

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

Reply via email to