Example usage for com.google.gwt.user.client.ui Widget getParent

List of usage examples for com.google.gwt.user.client.ui Widget getParent

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Widget getParent.

Prototype

public Widget getParent() 

Source Link

Document

Gets this widget's parent panel.

Usage

From source file:com.allen_sauer.gwt.dnd.demo.client.example.duallist.ListBoxDragController.java

License:Apache License

ArrayList<Widget> getSelectedWidgets(MouseListBox mouseListBox) {
    ArrayList<Widget> widgetList = new ArrayList<Widget>();
    for (Widget widget : context.selectedWidgets) {
        if (widget.getParent().getParent() == mouseListBox) {
            widgetList.add(widget);/*w  w w  . j  a  v a 2  s  .  co  m*/
        }
    }
    return widgetList;
}

From source file:com.allen_sauer.gwt.dnd.demo.client.example.duallist.ListBoxDropController.java

License:Apache License

@Override
public void onDrop(DragContext context) {
    MouseListBox from = (MouseListBox) context.draggable.getParent().getParent();
    for (Widget widget : context.selectedWidgets) {
        if (widget.getParent().getParent() == from) {
            HTML htmlClone = new HTML(DOM.getInnerHTML(widget.getElement()));
            mouseListBox.add(htmlClone);
        }//ww w . j  av  a2  s  .  c o  m
    }
    super.onDrop(context);
}

From source file:com.allen_sauer.gwt.dnd.demo.client.example.matryoshka.MatryoshkaSetWidgetDropController.java

License:Apache License

private static void makeLastChild(Widget child) {
    Widget parent = child.getParent();
    if (parent instanceof AbsolutePanel) {
        AbsolutePanel p = (AbsolutePanel) child.getParent();
        p.add(child, p.getWidgetLeft(child), p.getWidgetTop(child));
    }/*from   ww  w  .  ja  v  a  2s . c o m*/
}

From source file:com.bearsoft.gwt.ui.containers.AnchorsPanel.java

public void ajustDisplay(Widget child) {
    if (child.getParent() == this) {
        Element el = getWidgetContainerElement(child);
        boolean visible = !child.getElement().hasAttribute("aria-hidden");
        if (visible)
            el.getStyle().clearDisplay();
        else//  ww w  .j  a  va 2  s.  c  o  m
            el.getStyle().setDisplay(Style.Display.NONE);
    }
}

From source file:com.bearsoft.gwt.ui.containers.GridPanel.java

@Override
public boolean remove(Widget widget) {
    return super.remove(widget.getParent());
}

From source file:com.calclab.hablar.core.client.pages.accordion.AccordionPanel.java

License:Apache License

/**
 * Check if the given widget is a child of this accordion
 * //from   w w  w  .  jav a  2  s  .  c  om
 * @param widget
 *            the widget to check
 * @return true if the widget is in the accordion, false if not
 */
public boolean hasWidget(Widget widget) {
    return widget.getParent() == layoutPanel;
}

From source file:com.cgxlib.xq.client.plugins.widgets.WidgetsHtmlPanel.java

License:Apache License

public WidgetsHtmlPanel(Element e) {
    super("");
    if (e != null) {
        Widget w = $(e).widget();
        if (w == null) {
            // We convert the element to a gwt htmlPanel
            setElementImpl(e);/*from  ww w  . jav  a  2s. co  m*/
            WidgetsUtils.attachWidget(this, null);
        } else {
            Widget p = w.getParent();
            if (p instanceof Panel) {
                // Replace the widget by this panel
                this.add(w);
                ((Panel) p).add(this);
            } else {
                // Replace the element by this element
                Element n = e.getParentElement();
                n.appendChild(getElement());
                getElement().appendChild(e);
                WidgetsUtils.attachWidget(this, null);
            }
        }
    }
    adoptSubWidgets();
}

From source file:com.cgxlib.xq.client.plugins.widgets.WidgetsHtmlPanel.java

License:Apache License

/**
 * Adopt the {@link Widget widet} <code>w</code>. if the current parent of the
 * widget is an {@link HTMLPanel} or is null, the widget will not detach
 * physically in order to maintain the html structure. If the parent is an
 * other widget, it will be physically detach and reattach to this panel.
 *
 * @param w/*  ww  w  . ja va  2 s.  c  o m*/
 */
protected void doAdopt(Widget w) {
    Widget parent = w.getParent();
    boolean mustBePhysicallyReattach = false;

    if (parent == null) {
        if (RootPanel.isInDetachList(w)) {
            RootPanel.detachNow(w);
        }
    } else if (parent instanceof HTMLPanel) {
        WidgetsUtils.doLogicalDetachFromHtmlPanel(w);
    } else {
        // the widget will be physically detach
        w.removeFromParent();
        mustBePhysicallyReattach = true;
    }

    getChildren().add(w);

    if (mustBePhysicallyReattach) {
        DOM.appendChild(getElement(), w.getElement());
    }

    adopt(w);
}

From source file:com.cgxlib.xq.client.plugins.widgets.WidgetsUtils.java

License:Apache License

private static void replaceWidget(Widget oldWidget, Widget newWidget, boolean remove) {
    Widget parent = oldWidget.getParent();
    boolean removed = false;
    // TODO: handle tables
    if (parent instanceof HTMLPanel) {
        ((HTMLPanel) parent).addAndReplaceElement(newWidget, (Element) oldWidget.getElement());
        if (!remove) {
            $(newWidget).before($(oldWidget));
        }/*from   w  ww  .ja  v a 2  s.  co  m*/
        removed = true;
    } 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 && !removed && oldWidget.isAttached()) {
        oldWidget.removeFromParent();
    } else {
        oldWidget.setVisible(false);
    }
}

From source file:com.cgxlib.xq.client.plugins.widgets.WidgetsUtils.java

License:Apache License

/**
 * Attach a widget to the GWT widget list. Normally used when XQ
 * creates widgets wrapping existing dom elements.
 * It does nothing if the widget is already attached to another widget.
 *
 * @param widget            to attach//from  w ww  . j  a v a2s . c  o  m
 * @param firstParentWidget the parent widget,
 *                          If it is null and it is not inside any other widget, 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) {
            firstParentWidget = getFirstParentWidget(widget);
            if (firstParentWidget == null) {
                RootPanel.detachOnWindowClose(widget);
                widgetOnAttach(widget);
            } else {
                attachWidget(widget, firstParentWidget);
            }
        } else if (firstParentWidget instanceof HTMLPanel) {
            HTMLPanel h = (HTMLPanel) firstParentWidget;
            Element p = widget.getElement().getParentElement();
            if (p != null) {
                h.add(widget, p);
            } else {
                h.add(widget);
            }
        } else if (firstParentWidget instanceof HasOneWidget) {
            ((HasOneWidget) firstParentWidget).setWidget(widget);
        } else if (firstParentWidget instanceof HasWidgets) {
            try {
                ((HasWidgets) firstParentWidget).add(widget);
            } catch (UnsupportedOperationException e) {
                // Some widgets like 'table' has no implementation of 'add(widget)'
                widgetSetParent(widget, firstParentWidget);
            }
        } else {
            widgetSetParent(widget, firstParentWidget);
        }
    }
}