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:cc.alcina.framework.gwt.client.util.WidgetUtils.java

License:Apache License

public static void resizeUsingInfo(int containerHeight, int containerWidth, Iterator<Widget> widgets,
        int parentAdjustHeight, int parentAdjustWidth) {
    while (widgets.hasNext()) {
        Widget widget = widgets.next();
        if (widget == null || !widget.isVisible()) {
            continue;
        }/*w  w w.j  a v a 2s.co m*/
        int availableHeight = containerHeight;
        int availableWidth = containerWidth;
        if (widget instanceof HasLayoutInfo) {
            String name = widget.getClass().getName();
            if (debug) {
                GWT.log(CommonUtils.formatJ("%s: ", CommonUtils.simpleClassName(widget.getClass())), null);
            }
            LayoutInfo info = ((HasLayoutInfo) widget).getLayoutInfo();
            info.beforeLayout();
            if (info.to100percentOfAvailableHeight() || info.to100percentOfAvailableWidth()) {
                int usedHeight = 0;
                int usedWidth = 0;
                Widget parent = widget.getParent();
                Iterator<Widget> childIterator = null;
                availableHeight = info.useBestOffsetForParentHeight()
                        ? getBestOffsetHeight(parent.getElement(), true)
                        : containerHeight;
                availableHeight = Math.min(availableHeight, containerHeight);
                availableWidth = info.useBestOffsetForParentWidth()
                        ? getBestOffsetWidth(parent.getElement(), true)
                        : containerWidth;
                availableWidth = Math.min(availableWidth, containerWidth);
                if (parent instanceof HasLayoutInfo) {
                    childIterator = ((HasLayoutInfo) parent).getLayoutInfo().getLayoutWidgets();
                } else if (parent instanceof HasWidgets) {
                    childIterator = ((HasWidgets) parent).iterator();
                }
                boolean ignoreChildrenForHeight = info.to100percentOfAvailableHeight()
                        && (isDirectionalLayoutPanel(parent, true) || info.ignoreSiblingsForHeight());
                boolean ignoreChildrenForWidth = info.to100percentOfAvailableWidth()
                        && (isDirectionalLayoutPanel(parent, false) || info.ignoreSiblingsForWidth());
                if (childIterator != null) {
                    while (childIterator.hasNext()) {
                        Widget cw = childIterator.next();
                        if (cw != widget && WidgetUtils.isVisibleWithOffsetParent(cw.getElement())
                                && cw.isAttached()) {
                            if (!ignoreChildrenForHeight) {
                                usedHeight += getBestOffsetHeight(cw.getElement(), true, false);
                            }
                            if (!ignoreChildrenForWidth) {
                                usedWidth += getBestOffsetWidth(cw.getElement());
                            }
                        }
                    }
                }
                if (info.to100percentOfAvailableHeight()) {
                    availableHeight = availableHeight - usedHeight - parentAdjustHeight
                            - info.getAdjustHeight();
                    if (debug) {
                        GWT.log(CommonUtils.formatJ("%s: %s - comp %s",
                                CommonUtils.simpleClassName(widget.getClass()), availableHeight,
                                containerHeight), null);
                    }
                    if (availableHeight >= 0) {
                        widget.setHeight((availableHeight) + "px");
                    }
                }
                if (info.to100percentOfAvailableWidth()) {
                    availableWidth = availableWidth - usedWidth - parentAdjustWidth - info.getAdjustWidth();
                    if (availableWidth >= 0) {
                        widget.setWidth((availableWidth) + "px");
                    }
                }
            }
            Iterator<Widget> toResize = info.getWidgetsToResize();
            while (toResize.hasNext()) {
                toResize.next().setHeight(containerHeight + "px");
            }
            resizeUsingInfo(availableHeight, availableWidth, info.getLayoutWidgets(),
                    info.getClientAdjustHeight(), info.getClientAdjustWidth());
            info.afterLayout();
        } // haslayoutinfo
        else if (widget instanceof HasWidgets) {
            resizeUsingInfo(availableHeight, availableWidth, ((HasWidgets) widget).iterator(), 0, 0);
        }
    } // while
}

From source file:cc.kune.common.client.ui.DottedTabPanel.java

License:GNU Affero Public License

/**
 * Blink current tab.//from  w w  w  .ja v a2 s.c  om
 */
public void blinkCurrentTab() {
    final Widget tab = tabPanel.getTabWidget(tabPanel.getSelectedIndex());
    new BlinkAnimation(tab.getParent(), 350).animate(5);
}

From source file:ch.unifr.pai.twice.layout.client.eclipseLayout.MiceLayout.java

License:Apache License

/**
 * Show the component widget in fullscreen mode
 * //w w w.  j a  v a2  s . co  m
 * @param w
 */
public void setFullscreen(Widget w) {
    originOfFullScreenWidget = (SimplePanel) w.getParent();
    super.setWidget(w);
}

From source file:ch.unifr.pai.twice.layout.client.eclipseLayout.MiceSplitLayoutPanel.java

License:Apache License

/**
 * Removes a widget from the split layout panel. If the widget is not the center tab panel, it can be removed directly. Otherwise, it is checked if there
 * are other widgets in the split panel which can be used as the new center widget (because a layout panel always has to contain a center widget),
 * afterwards the tab panel can be removed. If no other tab panels are around which can be made the new center widget, the whole split layout panel is
 * removed from its parent unless it is the root split layout panel (what results in a warning)
 * /*from w ww.  jav  a  2s.  co m*/
 * @see com.google.gwt.user.client.ui.SplitLayoutPanel#remove(com.google.gwt.user.client.ui.Widget)
 */
@Override
public boolean remove(Widget child) {
    if (getWidgetDirection(child.getParent()) != Direction.CENTER) {
        setWidgetMinSize(child.getParent(), 0);
        setWidgetSize(child.getParent(), 0);
        return super.remove(child.getParent());
    } else {
        Widget lastNonCenterWidget = getLastNonCenterWidget();
        if (lastNonCenterWidget instanceof MiceLayoutTabPanel
                || lastNonCenterWidget instanceof MiceSplitLayoutPanel) {
            Widget originParent = lastNonCenterWidget.getParent();
            ((ResizeLayoutPanel) getCenter()).setWidget(lastNonCenterWidget);
            setWidgetSize(originParent, 0);
            setWidgetMinSize(originParent, 0);
            return super.remove(originParent);

        } else if (getParentMiceSplitLayoutPanel() != null) {
            return getParentMiceSplitLayoutPanel().remove(this);
        } else {
            Window.alert("You've tried to remove the last element - this is not allowed");
            return false;
        }

    }
}

From source file:co.fxl.gui.gwt.GWTElement.java

License:Open Source License

private IShell find(Widget widget) {
    if (widget instanceof PopupPanel)
        return new GWTPopUp((PopupPanel) widget);
    else if (widget instanceof RootPanel)
        return StatusDisplay.instance();
    else {//from   w  w  w.java2  s.  co  m
        Widget parent = widget.getParent();
        if (parent == null)
            return StatusDisplay.instance();
        return find(parent);
    }
}

From source file:com.ait.toolkit.sencha.touch.client.core.ComplexContainer.java

License:Open Source License

@Override
public boolean remove(final Widget w) {
    if (getChildren().contains(w)) {
        try {//from w  ww.java2s  . co m
            if (w instanceof Component) {
                try {
                    // Orphan.
                    orphan(w);
                } finally {
                    // Physical detach.
                    remove((Component) w, true);
                    // Logical detach.
                }
            } else if (w.getParent() != this && w.getParent() != null) {
                // In presence of a GWT component that has been added using
                // a WidgetComponent,
                // use a finally scheduled command to cleanup removal.
                Scheduler.get().scheduleFinally(new RemoveFromParentHelperCommand(w, w.getParent()));
            }
        } finally {
            getChildren().remove(w);
        }
        return true;

    }
    return false;

}

From source file:com.ait.toolkit.sencha.touch.client.core.ComplexContainer.java

License:Open Source License

/**
 * Finalize the attachment of a Widget to this Panel. This method is the
 * <b>last</b> step in adding or inserting a Widget into a Panel, and should
 * be called after physical attachment in the DOM is complete. This Panel
 * becomes the parent of the child Widget, and the child will now fire its
 * {@link Widget#onAttach()} event if this Panel is currently attached.
 * //from  ww w. j  a  v  a  2  s. c  o  m
 * @param child
 *            the widget to be adopted
 * @see #add(Widget)
 */
protected final void adopt(Widget child) {
    assert (child.getParent() == null);
    adopt(child, this);
}

From source file:com.ait.toolkit.sencha.touch.client.core.ComplexContainer.java

License:Open Source License

/**
 * <p>//w w w  .  j ava2 s . c  o  m
 * This method must be called as part of the remove method of any Panel. It
 * ensures that the Widget's parent is cleared. This method should be called
 * after verifying that the child Widget is an existing child of the Panel,
 * but before physically removing the child Widget from the DOM. The child
 * will now fire its {@link Widget#onDetach()} event if this Panel is
 * currently attached.
 * </p>
 * <p>
 * Calls to {@link #orphan(Widget)} should be wrapped in a try/finally block
 * to ensure that the widget is physically detached even if orphan throws an
 * exception.
 * </p>
 * 
 * @param child
 *            the widget to be disowned
 * @see #add(Widget)
 */
protected final void orphan(Widget child) {
    assert (child.getParent() == this);
    setParent(child, null);
}

From source file:com.ait.toolkit.sencha.touch.client.core.ComplexContainer.java

License:Open Source License

/**
 * Adjusts beforeIndex to account for the possibility that the given widget
 * is already a child of this panel./*  w w w .  j  av  a2s  .co  m*/
 * 
 * @param child
 *            the widget that might be an existing child
 * @param beforeIndex
 *            the index at which it will be added to this panel
 * @return the modified index
 */
protected int adjustIndex(Widget child, int beforeIndex) {
    checkIndexBoundsForInsertion(beforeIndex);

    // Check to see if this widget is already a direct child.
    if (child.getParent() == this) {
        // If the Widget's previous position was left of the desired new
        // position
        // shift the desired position left to reflect the removal
        int idx = getWidgetIndex(child);
        if (idx < beforeIndex) {
            beforeIndex--;
        }
    }

    return beforeIndex;
}

From source file:com.alkacon.acacia.client.AttributeHandler.java

License:Open Source License

/**
 * Clears the error styles on the given tabbed panel.<p>
 * /*  w  ww. j a  v  a2s  . com*/
 * @param tabbedPanel the tabbed panel
 */
public static void clearErrorStyles(TabbedPanel<?> tabbedPanel) {

    for (int i = 0; i < tabbedPanel.getTabCount(); i++) {
        Widget tab = tabbedPanel.getTabWidget(i);
        tab.setTitle(null);
        tab.getParent().removeStyleName(I_LayoutBundle.INSTANCE.form().hasError());
        tab.getParent().removeStyleName(I_LayoutBundle.INSTANCE.form().hasWarning());
    }
}