diff options
author | Manolo Carrasco <manolo@apache.org> | 2011-03-24 11:42:58 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2011-03-24 11:42:58 +0000 |
commit | e370d58a00d61b2193a8d19c31dfa7a9a86374c8 (patch) | |
tree | 28dfc40b9e441e8ed04e8bd65fe1934927c15bac | |
parent | ae0f39d4abe15ed9690ac51c7e8e8a22fcf4a2db (diff) | |
download | gwtquery-e370d58a00d61b2193a8d19c31dfa7a9a86374c8.tar.gz gwtquery-e370d58a00d61b2193a8d19c31dfa7a9a86374c8.zip |
Handle replacement of widgets, it needs to deal with more gwt panels
-rwxr-xr-x | gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java | 4 | ||||
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java | 55 |
2 files changed, 45 insertions, 14 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java index bc3f35e8..4e452ff5 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java @@ -446,7 +446,7 @@ public class Widgets extends QueuePlugin<Widgets> { }
protected boolean isWidgetCreationAuthorizedFrom(Element e) {
- return $(e).widget() == null && !WidgetsUtils.matchesTags(e, excludedTags);
+ return !WidgetsUtils.matchesTags(e, excludedTags);
}
/**
@@ -461,9 +461,7 @@ public class Widgets extends QueuePlugin<Widgets> { W widget = factory.create(e);
if (initializer != null) {
-
initializer.initialize(widget, e);
-
}
return widget;
}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java index ef247fac..a5b0c5e5 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetsUtils.java @@ -15,9 +15,15 @@ */ package com.google.gwt.query.client.plugins.widgets; +import static com.google.gwt.query.client.GQuery.$; + import com.google.gwt.dom.client.Element; import com.google.gwt.query.client.GQuery; +import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.GqUi; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Panel; +import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; public class WidgetsUtils { @@ -76,15 +82,35 @@ public class WidgetsUtils { } } - private static void hideAndAppend(Element oldElement, Element newElement) { + private static void hideAndAfter(Element oldElement, Element newElement) { assert oldElement != null && newElement != null; GQuery.$(oldElement).hide().after(newElement); String c = oldElement.getClassName(); if (!c.isEmpty()) { newElement.addClassName(c); } - } - + } + + private static void replaceWidget(Widget oldWidget, Widget newWidget, boolean remove) { + Widget parent = oldWidget.getParent(); + // TODO: handle tables + if (parent instanceof HTMLPanel) { + ((HTMLPanel) parent).addAndReplaceElement(newWidget, oldWidget.getElement().<com.google.gwt.dom.client.Element>cast()); + } else if (parent instanceof ComplexPanel) { + ((ComplexPanel) parent).add(newWidget); + } else if (parent instanceof SimplePanel) { + ((SimplePanel) parent).setWidget(newWidget); + } else if (parent instanceof Panel) { + ((Panel) parent).add(newWidget); + } else { + assert false : "Can not replace an attached widget whose parent is a " + parent.getClass().getName(); + } + if (remove) { + oldWidget.removeFromParent(); + } else { + oldWidget.setVisible(false); + } + } /** * Replace a dom element by a widget. @@ -92,20 +118,27 @@ public class WidgetsUtils { */ public static void replaceOrAppend(Element e, Widget widget) { assert e != null && widget != null; - GqUi.detachWidget(widget); - replaceOrAppend(e, widget.getElement()); - GqUi.attachWidget(widget); + if ($(e).widget() != null) { + replaceWidget($(e).widget(), widget, true); + } else { + GqUi.detachWidget(widget); + replaceOrAppend(e, widget.getElement()); + GqUi.attachWidget(widget); + } } /** * Append a widget to a dom element, and hide it. * Element classes will be copied to the new widget. */ - public static void hideAndAppend(Element e, Widget widget) { + public static void hideAndAfter(Element e, Widget widget) { assert e != null && widget != null; - GqUi.detachWidget(widget); - hideAndAppend(e, widget.getElement()); - GqUi.attachWidget(widget); + if ($(e).widget() != null) { + replaceWidget($(e).widget(), widget, false); + } else { + GqUi.detachWidget(widget); + hideAndAfter(e, widget.getElement()); + GqUi.attachWidget(widget); + } } - } |