import com.google.gwt.dom.client.Element;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.user.client.DOM;
-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.RootPanel;
if (w == null) {
// We convert the element to a gwt htmlPanel
setElementImpl(e);
- GqUi.attachWidget(this, null);
+ WidgetsUtils.attachWidget(this, null);
} else {
Widget p = w.getParent();
if (p instanceof Panel) {
Element n = e.getParentElement();
n.appendChild(getElement());
getElement().appendChild(e);
- GqUi.attachWidget(this, null);
+ WidgetsUtils.attachWidget(this, null);
}
}
}
}
} else if (parent instanceof HTMLPanel) {
- GqUi.doLogicalDetachFromHtmlPanel(w);
-
+ WidgetsUtils.doLogicalDetachFromHtmlPanel(w);
} else {
// the widget will be physically detach
w.removeFromParent();
import static com.google.gwt.query.client.GQuery.$;
+import java.util.Iterator;
+
import com.google.gwt.dom.client.BodyElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.ComplexPanel;
-import com.google.gwt.user.client.ui.GqUi;
+import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Panel;
+import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.WidgetCollection;
public class WidgetsUtils {
if ($(e).widget() != null && $(e).widget().isAttached()) {
replaceWidget($(e).widget(), widget, false);
} else {
- GqUi.detachWidget(widget);
+ detachWidget(widget);
hideAndAfter(e, widget.getElement());
- GqUi.attachWidget(widget, getFirstParentWidget(widget));
+ attachWidget(widget, getFirstParentWidget(widget));
}
}
if ($(e).widget() != null && $(e).widget().isAttached()) {
replaceWidget($(e).widget(), widget, true);
} else {
- GqUi.detachWidget(widget);
+ detachWidget(widget);
replaceOrAppend(e, widget.getElement());
- GqUi.attachWidget(widget, getFirstParentWidget(widget));
+ attachWidget(widget, getFirstParentWidget(widget));
}
}
boolean removed = false;
// TODO: handle tables
if (parent instanceof HTMLPanel) {
- ((HTMLPanel) parent).addAndReplaceElement(newWidget, oldWidget.getElement());
+ ((HTMLPanel) parent).addAndReplaceElement(newWidget,
+ (com.google.gwt.dom.client.Element)oldWidget.getElement());
if (!remove) {
$(newWidget).before($(oldWidget));
}
oldWidget.setVisible(false);
}
}
+
+ /**
+ * Attach a widget to the GWT widget list.
+ *
+ * @param widget to attach
+ * @param firstParentWidget the parent widget,
+ * If it is null we just add the widget to the gwt detach list
+ */
+ public static void attachWidget(Widget widget, Widget firstParentWidget) {
+ if (widget != null && widget.getParent() == null) {
+ if (firstParentWidget == null) {
+ RootPanel.detachOnWindowClose(widget);
+ widgetOnAttach(widget);
+ } else if (firstParentWidget instanceof HTMLPanel) {
+ ((HTMLPanel) firstParentWidget).add(widget,
+ widget.getElement().getParentElement()
+ .<com.google.gwt.user.client.Element>cast());
+ } else {
+ throw new RuntimeException(
+ "No HTMLPanel available to attach the widget.");
+ }
+ }
+ }
+
+ /**
+ * Remove a widget from the detach list
+ */
+ public static void detachWidget(final Widget widget) {
+ if (widget != null) {
+ widget.removeFromParent();
+ }
+ }
+
+ /**
+ * This method detach a widget of its parent without doing a physical
+ * detach (DOM manipulation)
+ *
+ * @param w
+ */
+ public static void doLogicalDetachFromHtmlPanel(Widget w) {
+ Widget parent = w.getParent();
+
+ if (parent instanceof HTMLPanel) {
+ complexPanelGetChildren((HTMLPanel) parent).remove(w);
+ widgetSetParent(w, null);
+ } else{
+ throw new IllegalStateException(
+ "You can only use this method to detach a child from an HTMLPanel");
+ }
+ }
+
+ /**
+ * Return children of the first widget's panel
+ */
+ public static Iterator<Widget> getChildren(Widget w){
+ if(w instanceof Panel){
+ return ((Panel)w).iterator();
+ }
+ if(w instanceof Composite){
+ return getChildren(compositeGetWidget((Composite)w));
+ }
+ return null;
+ }
+
+ private static native void widgetOnAttach(Widget w) /*-{
+ w.@com.google.gwt.user.client.ui.Widget::onAttach()();
+ }-*/;
+
+ private static native void widgetSetParent(Widget w, Widget p) /*-{
+ w.@com.google.gwt.user.client.ui.Widget::setParent(Lcom/google/gwt/user/client/ui/Widget;)(p);
+ }-*/;
+
+ private static native Widget compositeGetWidget(Composite w) /*-{
+ return w.@com.google.gwt.user.client.ui.Composite::getWidget()();
+ }-*/;
+
+ private static native WidgetCollection complexPanelGetChildren(ComplexPanel w) /*-{
+ return w.@com.google.gwt.user.client.ui.ComplexPanel::getChildren()();
+ }-*/;
}
+++ /dev/null
-/*
- * Copyright 2011, The gwtquery team.
- *
- * 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 java.util.Iterator;
-
-/**
- * GQuery Utility class to access protected methods in ui package.
- */
-public class GqUi {
-
- public static void attachWidget(Widget widget, Widget firstParentWidget) {
- if (widget != null && widget.getParent() == null) {
-
- if (firstParentWidget == null) {
- RootPanel.detachOnWindowClose(widget);
- widget.onAttach();
- } else if (firstParentWidget instanceof HTMLPanel) {
- ((HTMLPanel) firstParentWidget).add(widget,
- widget.getElement().getParentElement()
- .<com.google.gwt.user.client.Element>cast());
- } else {
- throw new RuntimeException(
- "No HTMLPanel available to attach the widget.");
- }
- }
- }
-
- public static void detachWidget(final Widget widget) {
- if (widget != null) {
- widget.removeFromParent();
- }
- }
-
-
-
- /**
- * This method detach a widget of its parent without do a physical detach (DOM
- * manipulation)
- *
- * @param w
- */
- public static void doLogicalDetachFromHtmlPanel(Widget w) {
- Widget parent = w.getParent();
-
- if (parent instanceof HTMLPanel) {
- ((HTMLPanel) parent).getChildren().remove(w);
- w.setParent(null);
-
- } else{
- throw new IllegalStateException(
- "You can only use this method to detach a child from an HTMLPanel");
- }
-
-
- }
-
- public static Iterator<Widget> getChildren(Widget w){
- if(w instanceof Panel){
- return ((Panel)w).iterator();
- }
- if(w instanceof Composite){
- return getChildren(((Composite)w).getWidget());
- }
-
- return null;
- }
-}