Revision: 10315
Author: jul...@google.com
Date: Fri Jun 10 09:32:40 2011
Log: Resolve PotentialElement children before inserting them into a
container.
Before this patch, if someone tried to insertChild or insertBefore a
renderable child into a renderable container, a DOM exception was thrown, as
the element could not be found in the document. This patch follows the same
pattern as appendChild: it first tries to resolve the child being inserted
to
get the real element.
While in the neighborhood, fixed some Javadoc tags related to
PotentialElement.
Review at http://gwt-code-reviews.appspot.com/1454810
http://code.google.com/p/google-web-toolkit/source/detail?r=10315
Modified:
/trunk/user/src/com/google/gwt/user/client/DOM.java
=======================================
--- /trunk/user/src/com/google/gwt/user/client/DOM.java Mon Jun 6 04:09:34
2011
+++ /trunk/user/src/com/google/gwt/user/client/DOM.java Fri Jun 10 09:32:40
2011
@@ -53,11 +53,14 @@
/**
* Appends one element to another's list of children.
- * If the child element is a {@link PotentialElement}, it is first
resolved
- * {@see PotentialElement#resolve(Element)}.
+ * <p>
+ * If the child element is a {@link
com.google.gwt.user.client.ui.PotentialElement}, it is first
+ * resolved.
+ * </p>
*
* @param parent the parent element
* @param child its new child
+ * @see com.google.gwt.user.client.ui.PotentialElement#resolve(Element)
*/
public static void appendChild(Element parent, Element child) {
assert !PotentialElement.isPotential(parent) : "Cannot append to a
PotentialElement";
@@ -914,27 +917,45 @@
/**
* Inserts an element as a child of the given parent element, before
another
* child of that parent.
+ * <p>
+ * If the child element is a {@link
com.google.gwt.user.client.ui.PotentialElement}, it is first
+ * resolved.
+ * </p>
*
* @param parent the parent element
* @param child the child element to add to <code>parent</code>
* @param before an existing child element of <code>parent</code> before
which
* <code>child</code> will be inserted
+ * @see com.google.gwt.user.client.ui.PotentialElement#resolve(Element)
*/
public static void insertBefore(Element parent, Element child, Element
before) {
- parent.insertBefore(child, before);
+ assert !PotentialElement.isPotential(parent) : "Cannot insert into a
PotentialElement";
+
+ // If child isn't a PotentialElement, resolve() returns
+ // the Element itself.
+ parent.insertBefore(PotentialElement.resolve(child).<Element> cast(),
before);
}
/**
* Inserts an element as a child of the given parent element.
+ * <p>
+ * If the child element is a {@link
com.google.gwt.user.client.ui.PotentialElement}, it is first
+ * resolved.
+ * </p>
*
* @param parent the parent element
* @param child the child element to add to <code>parent</code>
* @param index the index before which the child will be inserted (any
value
* greater than the number of existing children will cause the
child
* to be appended)
+ * @see com.google.gwt.user.client.ui.PotentialElement#resolve(Element)
*/
public static void insertChild(Element parent, Element child, int index)
{
- impl.insertChild(parent, child, index);
+ assert !PotentialElement.isPotential(parent) : "Cannot insert into a
PotentialElement";
+
+ // If child isn't a PotentialElement, resolve() returns
+ // the Element itself.
+ impl.insertChild(parent, PotentialElement.resolve(child).<Element>
cast(), index);
}
/**
@@ -951,6 +972,8 @@
*/
public static void insertListItem(Element selectElem, String item,
String value, int index) {
+ assert !PotentialElement.isPotential(selectElem) : "Cannot insert into
a PotentialElement";
+
SelectElement select = selectElem.<SelectElement> cast();
OptionElement option = Document.get().createOptionElement();
option.setText(item);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors