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

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

Introduction

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

Prototype

@Override
public boolean isAttached() 

Source Link

Document

Determines whether this widget is currently attached to the browser's document (i.e., there is an unbroken chain of widgets between this widget and the underlying browser document).

Usage

From source file:org.opencms.ade.containerpage.client.ui.CmsSmallElementsHandler.java

License:Open Source License

/**
 * Checks if  a given widget counts as 'small'.<p>
 *
 * @param widget the widget to check//  ww  w .ja va  2  s .  c  o  m
 *
 * @return  true if the widget is small
 */
public static boolean isSmall(Widget widget) {

    assert widget.isAttached();
    return (CmsPositionBean.generatePositionInfo(widget.getElement()).getHeight() < NECESSARY_HEIGHT)
            && (CmsPositionBean.getBoundingClientRect(widget.getElement()).getHeight() < NECESSARY_HEIGHT);

}

From source file:org.pentaho.gwt.widgets.client.utils.ElementUtils.java

License:Open Source License

public static void removeScrollingFromSplitPane(Widget panel) {
    if (!panel.isAttached()) {
        // throw new IllegalStateException("Operation not allowed while element not on DOM");
    }// w  w w . j  a va2s  . c o  m

    if ((panel instanceof HorizontalSplitPanel || panel instanceof VerticalSplitPanel) == false) {
        throw new IllegalArgumentException("Widget not expected SplitPane type"); //$NON-NLS-1$
    }

    if (panel instanceof HorizontalSplitPanel) {
        HorizontalSplitPanel hp = (HorizontalSplitPanel) panel;
        removeScrollingFromUpTo(hp.getLeftWidget().getElement(), hp.getElement());
        removeScrollingFromUpTo(hp.getRightWidget().getElement(), hp.getElement());
    } else {
        VerticalSplitPanel vp = (VerticalSplitPanel) panel;
        removeScrollingFromUpTo(vp.getTopWidget().getElement(), vp.getElement());
        removeScrollingFromUpTo(vp.getBottomWidget().getElement(), vp.getElement());
    }

}

From source file:org.rebioma.client.SingleUploader.java

License:Apache License

/**
 * This constructor allows to use an existing form panel.
 * //from w ww. j  a v  a2 s  .c om
 * @param type
 *        file input to use
 * @param status
 *        Customized status widget to use
 * @param submitButton
 *        Customized button which submits the form
 * @param form
 *        Customized form panel
 */
public SingleUploader(FileInputType type, IUploadStatus status, Widget submitButton, FormPanel form) {
    super(type, form);

    final Uploader thisInstance = this;

    if (status == null) {
        status = new BaseUploadStatus();
        super.add(status.getWidget());
    }
    super.setStatusWidget(status);

    this.button = submitButton;
    if (submitButton != null) {
        submitButton.addStyleName("submit");
        if (submitButton instanceof HasClickHandlers) {
            ((HasClickHandlers) submitButton).addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    thisInstance.submit();
                }
            });
        }
        if (submitButton instanceof HasText) {
            ((HasText) submitButton).setText(I18N_CONSTANTS.uploaderSend());
        }
        // The user could have attached the button anywhere in the page.
        if (!submitButton.isAttached()) {
            super.add(submitButton);
        }
    }
}

From source file:org.rhq.coregui.client.util.WidgetUtility.java

License:Open Source License

private static void printWidget(Widget widget, int level) {
    String simpleClassName;//from  w w  w  .j a va2  s.  c  om
    try {
        String className = widget.getClass().getName();
        simpleClassName = className.substring(className.lastIndexOf(".") + 1);
    } catch (Exception e) {
        simpleClassName = "?";
    }
    String id;
    try {
        id = (widget.getElement() != null) ? widget.getElement().getId() : "?";
    } catch (Exception e) {
        id = "?";
    }
    String title;
    try {
        title = widget.getTitle();
    } catch (Exception e) {
        title = "?";
    }

    StringBuilder flags = new StringBuilder();

    if (widget.isAttached()) {
        if (flags.length() != 0) {
            flags.append(", ");
        }
        flags.append("attached");
    }
    if (widget.isVisible()) {
        if (flags.length() != 0) {
            flags.append(", ");
        }
        flags.append("visible");
    }

    if (widget instanceof BaseWidget) {
        BaseWidget baseWidget = (BaseWidget) widget;

        if (baseWidget.isCreated()) {
            if (flags.length() != 0) {
                flags.append(", ");
            }
            flags.append("created");
        }
        if (baseWidget.isConfigOnly()) {
            if (flags.length() != 0) {
                flags.append(", ");
            }
            flags.append("configOnly");
        }
    }

    if (widget instanceof Canvas) {
        Canvas canvas = (Canvas) widget;

        if (canvas.isDrawn()) {
            if (flags.length() != 0) {
                flags.append(", ");
            }
            flags.append("drawn");
        }
        if (canvas.isDirty()) {
            if (flags.length() != 0) {
                flags.append(", ");
            }
            flags.append("dirty");
        }
        if (canvas.isDisabled()) {
            if (flags.length() != 0) {
                flags.append(", ");
            }
            flags.append("disabled");
        }
    }

    if (widget instanceof HLayout) {
        if (flags.length() != 0) {
            flags.append(", ");
        }
        flags.append("hlayout");
    } else if (widget instanceof VLayout) {
        if (flags.length() != 0) {
            flags.append(", ");
        }
        flags.append("vlayout");
    } else if (widget instanceof Layout) {
        if (flags.length() != 0) {
            flags.append(", ");
        }
        flags.append("layout");
    }

    StringBuilder indent = new StringBuilder();
    for (int i = 0; i < level; i++) {
        indent.append("  ");
    }

    Log.info(indent + simpleClassName + "[id=" + id + ", title=" + title + ", flags=[" + flags + "]]");
}

From source file:org.rstudio.core.client.WidgetHandlerRegistration.java

License:Open Source License

public WidgetHandlerRegistration(Widget widget) {
    widget.addAttachHandler(new AttachEvent.Handler() {
        @Override//from  ww w .  ja  v a 2s  . co  m
        public void onAttachOrDetach(AttachEvent event) {
            unregister();
            if (event.isAttached())
                register();
        }
    });

    if (widget.isAttached())
        register();
}

From source file:org.vaadin.addon.gwtgraphics.client.VectorObject.java

License:Apache License

public void setParent(Widget parent) {
    Widget oldParent = this.parent;
    if (parent == null) {
        if (oldParent != null && oldParent.isAttached()) {
            onDetach();/*  ww w  .ja v a 2s .  c  om*/
            assert !isAttached() : "Failure of " + this.getClass().getName() + " to call super.onDetach()";
        }
        this.parent = null;
    } else {
        if (oldParent != null) {
            throw new IllegalStateException("Cannot set a new parent without first clearing the old parent");
        }
        this.parent = parent;
        if (parent.isAttached()) {
            onAttach();
            assert isAttached() : "Failure of " + this.getClass().getName() + " to call super.onAttach()";
        }
    }
}

From source file:org.vaadin.alump.fancylayouts.gwt.client.connect.FancyCssLayoutConnector.java

License:Apache License

@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
    // super.onConnectorHierarchyChange(event);

    // Remove old children
    for (ComponentConnector child : event.getOldChildren()) {
        if (child.getParent() != this) {
            Widget widget = child.getWidget();
            if (widget.isAttached()) {
                getWidget().remove(widget);
            }/*w ww . jav a  2  s.c om*/
        }
    }

    // Add or move children
    int index = 0;
    for (ComponentConnector child : getChildComponents()) {
        getWidget().addOrMove(child.getWidget(), index);
        ++index;
    }
}

From source file:org.vaadin.alump.fancylayouts.gwt.client.connect.FancyPanelConnector.java

License:Apache License

@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {

    // Remove old children
    for (ComponentConnector child : event.getOldChildren()) {
        if (child.getParent() != this) {
            logger.fine("Remove old child widget");
            Widget widget = child.getWidget();
            if (widget != null && widget.isAttached()) {
                getWidget().remove(widget);
            }/*from   w w w .java 2s . c  o m*/
        }
    }

    for (ComponentConnector child : getChildComponents()) {
        try {
            getWidget().add(child.getWidget());
        } catch (Exception e) {
            logger.severe("Failed to add! " + e.getMessage());
        }
    }

    ComponentConnector currentConnector = (ComponentConnector) getState().currentComponent;
    if (currentConnector != null) {
        getWidget().setContent(currentConnector.getWidget());
    }

}

From source file:org.vaadin.alump.gridstack.client.GridStackLayoutConnector.java

License:Apache License

@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
    Duration duration = new Duration();
    getWidget().batchUpdate();/*from w  w w  . ja v  a2 s.  c  o  m*/

    for (ComponentConnector child : event.getOldChildren()) {
        if (child.getParent() != this) {
            Widget widget = child.getWidget();
            if (widget.isAttached()) {
                getWidget().remove(widget);
            }
        }
    }

    for (ComponentConnector child : getChildComponents()) {
        if (child.getWidget().getParent() != getWidget()) {
            getWidget().add(child.getWidget(), getState().childOptions.get(child));
        }
    }

    getWidget().commit();
    LOGGER.info("onConnectorHierarchyChange took " + duration.elapsedMillis() + "ms");
}

From source file:org.vaadin.alump.masonry.client.MasonryLayoutConnector.java

License:Apache License

@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {

    getWidget().initialize(getState().columnWidth);

    for (ComponentConnector child : event.getOldChildren()) {
        if (child.getParent() != this) {
            Widget widget = child.getWidget();
            if (widget.isAttached()) {
                getWidget().removeItem(widget);
            }/*  w  w  w. j a  v  a2s. c  o  m*/
        }
    }

    int reconstructFrom = findFirstMismatchInChildren(getChildComponents());

    // Clean reordered widgets
    if (reconstructFrom < getWidget().getWidgetCount()) {
        Set<Widget> removeWidgets = new HashSet<Widget>();
        for (int i = reconstructFrom; i < getWidget().getWidgetCount(); ++i) {
            removeWidgets.add(getWidget().getWidget(i));
        }
        for (Widget remove : removeWidgets) {
            getWidget().removeItem(remove);
        }
    }

    // Add new or reordered children
    for (int i = reconstructFrom; i < getChildComponents().size(); ++i) {
        ComponentConnector cc = getChildComponents().get(i);
        getWidget().addItem(cc.getWidget(), getState().itemStyleNames.get(cc));
    }

    scheduleLayout();
}