Revision: 9077
Author: gwt.mirror...@gmail.com
Date: Fri Oct 15 04:43:56 2010
Log: Adding SafeHtml versions of addItem/insertItem to Tree and TreeItem.

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

Review by: p...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=9077

Modified:
 /trunk/user/src/com/google/gwt/user/client/ui/Tree.java
 /trunk/user/src/com/google/gwt/user/client/ui/TreeItem.java
 /trunk/user/test/com/google/gwt/user/client/ui/TreeItemTest.java
 /trunk/user/test/com/google/gwt/user/client/ui/TreeTest.java

=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/Tree.java Fri Jul 2 05:43:30 2010 +++ /trunk/user/src/com/google/gwt/user/client/ui/Tree.java Fri Oct 15 04:43:56 2010
@@ -55,6 +55,7 @@
 import com.google.gwt.i18n.client.LocaleInfo;
 import com.google.gwt.resources.client.ClientBundle;
 import com.google.gwt.resources.client.ImageResource;
+import com.google.gwt.safehtml.shared.SafeHtml;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
@@ -329,6 +330,16 @@

     return ret;
   }
+
+  /**
+   * Adds a simple tree item containing the specified html.
+   *
+   * @param itemHtml the html of the item to be added
+   * @return the item that was added
+   */
+  public TreeItem addItem(SafeHtml itemHtml) {
+    return root.addItem(itemHtml);
+  }

   /**
    * Adds an item to the root level of this tree.
@@ -492,6 +503,19 @@
   public TreeItem insertItem(int beforeIndex, String itemText) {
     return root.insertItem(beforeIndex, itemText);
   }
+
+  /**
+ * Inserts a child tree item at the specified index containing the specified
+   * html.
+   *
+   * @param beforeIndex the index where the item will be inserted
+   * @param itemHtml the html of the item to be added
+   * @return the item that was added
+   * @throws IndexOutOfBoundsException if the index is out of range
+   */
+  public TreeItem insertItem(int beforeIndex, SafeHtml itemHtml) {
+    return root.insertItem(beforeIndex, itemHtml);
+  }

   /**
    * Inserts an item into the root level of this tree.
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/TreeItem.java Tue Sep 21 07:53:19 2010 +++ /trunk/user/src/com/google/gwt/user/client/ui/TreeItem.java Fri Oct 15 04:43:56 2010
@@ -336,6 +336,18 @@
     addItem(ret);
     return ret;
   }
+
+  /**
+   * Adds a child tree item containing the specified html.
+   *
+   * @param itemHtml the item's HTML
+   * @return the item that was added
+   */
+  public TreeItem addItem(SafeHtml itemHtml) {
+    TreeItem ret = new TreeItem(itemHtml);
+    addItem(ret);
+    return ret;
+  }

   /**
    * Adds another item as a child to this one.
@@ -471,6 +483,22 @@
     insertItem(beforeIndex, ret);
     return ret;
   }
+
+  /**
+ * Inserts a child tree item at the specified index containing the specified
+   * text.
+   *
+   * @param beforeIndex the index where the item will be inserted
+   * @param itemHtml the item's HTML
+   * @return the item that was added
+   * @throws IndexOutOfBoundsException if the index is out of range
+   */
+  public TreeItem insertItem(int beforeIndex, SafeHtml itemHtml)
+      throws IndexOutOfBoundsException {
+    TreeItem ret = new TreeItem(itemHtml);
+    insertItem(beforeIndex, ret);
+    return ret;
+  }

   /**
    * Inserts an item as a child to this one.
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/TreeItemTest.java Tue Sep 21 07:53:19 2010 +++ /trunk/user/test/com/google/gwt/user/client/ui/TreeItemTest.java Fri Oct 15 04:43:56 2010
@@ -46,6 +46,12 @@
     assertEquals(b, item.getChild(0));
     assertEquals(a, item.getChild(1));
   }
+
+  public void testAddItemSafeHtml() {
+    TreeItem item = new TreeItem("foo");
+    TreeItem child = item.addItem(SafeHtmlUtils.fromSafeConstant(html));
+    assertEquals(html, child.getHTML().toLowerCase());
+  }

   public void testInsert() {
     TreeItem item = new TreeItem();
@@ -123,6 +129,12 @@
       // Expected.
     }
   }
+
+  public void testInsertItemSafeHtml() {
+    TreeItem item = new TreeItem("foo");
+ TreeItem child = item.insertItem(0, SafeHtmlUtils.fromSafeConstant(html));
+    assertEquals(html, child.getHTML().toLowerCase());
+  }

   public void testSafeHtmlConstructor() {
     TreeItem item = new TreeItem(SafeHtmlUtils.fromSafeConstant(html));
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/TreeTest.java Fri Jul 2 05:43:30 2010 +++ /trunk/user/test/com/google/gwt/user/client/ui/TreeTest.java Fri Oct 15 04:43:56 2010
@@ -16,6 +16,7 @@
 package com.google.gwt.user.client.ui;

 import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.safehtml.shared.SafeHtmlUtils;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;

@@ -26,6 +27,8 @@
  */
 public class TreeTest extends GWTTestCase {

+  private static final String html = "<b>hello</b><i>world</i>";
+
   static class Adder implements HasWidgetsTester.WidgetAdder {
     public void addChild(HasWidgets container, Widget child) {
       ((Tree) container).addItem(child);
@@ -36,6 +39,12 @@
   public String getModuleName() {
     return "com.google.gwt.user.DebugTest";
   }
+
+  public void testAddItemSafeHtml() {
+    Tree t = new Tree();
+    TreeItem item = t.addItem(SafeHtmlUtils.fromSafeConstant(html));
+    assertEquals(html, item.getHTML().toLowerCase());
+  }

   public void testAttachDetachOrder() {
     HasWidgetsTester.testAll(new Tree(), new Adder(), true);
@@ -110,6 +119,12 @@
     assertEquals(ti, t.getItem(0));
     assertEquals(wti, t.getItem(1));
   }
+
+  public void testInsertItemSafeHtml() {
+    Tree t = new Tree();
+    TreeItem item = t.insertItem(0, SafeHtmlUtils.fromSafeConstant(html));
+    assertEquals(html, item.getHTML().toLowerCase());
+  }

   public void testIterator() {
     Tree tree = new Tree();

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

Reply via email to