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:com.vaadin.terminal.gwt.client.ui.VTabsheetBase.java

License:Open Source License

public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    this.client = client;

    // Ensure correct implementation
    cachedUpdate = client.updateComponent(this, uidl, true);
    if (cachedUpdate) {
        return;//ww w  .  ja va  2s  .  c o m
    }

    // Update member references
    id = uidl.getId();
    disabled = uidl.hasAttribute("disabled");

    // Render content
    final UIDL tabs = uidl.getChildUIDL(0);

    // Paintables in the TabSheet before update
    ArrayList<Object> oldPaintables = new ArrayList<Object>();
    for (Iterator<Object> iterator = getPaintableIterator(); iterator.hasNext();) {
        oldPaintables.add(iterator.next());
    }

    // Clear previous values
    tabKeys.clear();
    disabledTabKeys.clear();

    int index = 0;
    for (final Iterator<Object> it = tabs.getChildIterator(); it.hasNext();) {
        final UIDL tab = (UIDL) it.next();
        final String key = tab.getStringAttribute("key");
        final boolean selected = tab.getBooleanAttribute("selected");
        final boolean hidden = tab.getBooleanAttribute("hidden");

        if (tab.getBooleanAttribute("disabled")) {
            disabledTabKeys.add(key);
        }

        tabKeys.add(key);

        if (selected) {
            activeTabIndex = index;
        }
        renderTab(tab, index, selected, hidden);
        index++;
    }

    int tabCount = getTabCount();
    while (tabCount-- > index) {
        removeTab(index);
    }

    for (int i = 0; i < getTabCount(); i++) {
        Paintable p = getTab(i);
        oldPaintables.remove(p);
    }

    // Perform unregister for any paintables removed during update
    for (Iterator<Object> iterator = oldPaintables.iterator(); iterator.hasNext();) {
        Object oldPaintable = iterator.next();
        if (oldPaintable instanceof Paintable) {
            Widget w = (Widget) oldPaintable;
            if (w.isAttached()) {
                w.removeFromParent();
            }
            client.unregisterPaintable((Paintable) oldPaintable);
        }
    }

}

From source file:com.vaadin.terminal.gwt.client.Util.java

License:Open Source License

/**
 * Called when the size of one or more widgets have changed during
 * rendering. Finds parent container and notifies them of the size change.
 * /* w  w w  . jav a  2  s . c  o  m*/
 * @param paintables
 */
public static void componentSizeUpdated(Set<Paintable> paintables) {
    if (paintables.isEmpty()) {
        return;
    }

    Map<Container, Set<Paintable>> childWidgets = new HashMap<Container, Set<Paintable>>();

    for (Paintable paintable : paintables) {
        Widget widget = (Widget) paintable;
        if (!widget.isAttached()) {
            continue;
        }

        // ApplicationConnection.getConsole().log(
        // "Widget " + Util.getSimpleName(widget) + " size updated");
        Widget parent = widget.getParent();
        while (parent != null && !(parent instanceof Container)) {
            parent = parent.getParent();
        }
        if (parent != null) {
            Set<Paintable> set = childWidgets.get(parent);
            if (set == null) {
                set = new HashSet<Paintable>();
                childWidgets.put((Container) parent, set);
            }
            set.add(paintable);
        }
    }

    Set<Paintable> parentChanges = new HashSet<Paintable>();
    for (Container parent : childWidgets.keySet()) {
        if (!parent.requestLayout(childWidgets.get(parent))) {
            parentChanges.add(parent);
        }
    }

    componentSizeUpdated(parentChanges);
}

From source file:de.bonprix.gridstacklayout.client.GridStackLayoutConnector.java

License:Open Source License

@Override
public void onConnectorHierarchyChange(final ConnectorHierarchyChangeEvent event) {

    // Attach all new children
    for (final ComponentConnector connector : getChildComponents()) {

        if (this.attachedChildren.contains(connector)) {
            continue;
        }/* ww w . j  ava 2s .c o  m*/

        final GridStackWidget gridstackWidget = getState().getWidgetByConnector(connector);
        getWidget().addWidget(gridstackWidget, connector.getWidget());

        this.attachedChildren.add(connector);
    }

    // Remove no longer attached children
    for (final ComponentConnector oldConnector : event.getOldChildren()) {

        if (oldConnector.getParent() == this) {
            continue;
        }

        final Widget oldChildWidget = oldConnector.getWidget();
        if (oldChildWidget.isAttached()) {
            getWidget().remove(oldChildWidget);
            this.attachedChildren.remove(oldConnector);
        }
    }
}

From source file:fr.putnami.pwt.core.widget.client.Modal.java

License:Open Source License

public void show() {
    this.ensureDismissButton();
    this.redraw();
    this.visible = true;

    Widget modal = getContainerWidget();

    if (modal.isAttached()) {
        modal.removeFromParent();//  w  ww  .  j  av  a  2 s  .  c  o m
    }

    Modal.MODAL_BACKDROP.show();
    this.getElement().getStyle().setDisplay(Display.BLOCK);
    RootPanel rootPanel = RootPanel.get();
    rootPanel.add(modal);
    StyleUtils.addStyle(rootPanel, Modal.STYLE_MODAL_OPEN);

    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
        @Override
        public boolean execute() {
            StyleUtils.addStyle(Modal.this, Modal.STYLE_VISIBLE);
            return false;
        }
    }, 150);
}

From source file:gwt.material.design.addins.client.ui.MaterialDnd.java

License:Apache License

@Override
public void setTarget(final Widget target) {
    this.target = target;
    if (!target.isAttached()) {
        target.addAttachHandler(new AttachEvent.Handler() {
            @Override//ww  w.  jav a 2  s  .  c  o m
            public void onAttachOrDetach(AttachEvent event) {
                if (event.isAttached()) {
                    initDraggable(target.getElement(), isInertia(), restriction.getRestriction().getValue(),
                            restriction.isEndOnly(), restriction.getTop(), restriction.getLeft(),
                            restriction.getBottom(), restriction.getRight());
                }
            }
        });
    } else {
        initDraggable(target.getElement(), isInertia(), restriction.getRestriction().getValue(),
                restriction.isEndOnly(), restriction.getTop(), restriction.getLeft(), restriction.getBottom(),
                restriction.getRight());
    }
}

From source file:gwt.material.design.addins.client.ui.MaterialDnd.java

License:Apache License

@Override
public void setIgnoreFrom(final Widget ignoreFrom) {
    this.ignoreFrom = ignoreFrom;
    if (!target.isAttached() && !ignoreFrom.isAttached()) {
        ignoreFrom.addAttachHandler(new AttachEvent.Handler() {
            @Override// ww  w .j  ava  2 s. c o  m
            public void onAttachOrDetach(AttachEvent event) {
                if (event.isAttached()) {
                    initIgnoreFrom(target.getElement(), ignoreFrom.getElement());
                }
            }
        });
    } else {
        initIgnoreFrom(target.getElement(), ignoreFrom.getElement());
    }
}

From source file:gwt.material.design.client.base.Waves.java

License:Apache License

/**
 * Detect and apply waves, now or when the widget is attached.
 * @param widget target widget to ensure is attached first
 *///from   www.j  av a  2s  .c  om
public static void detectAndApply(Widget widget) {
    if (!widget.isAttached()) {
        widget.addAttachHandler(new AttachEvent.Handler() {
            @Override
            public void onAttachOrDetach(AttachEvent event) {
                if (event.isAttached()) {
                    detectAndApply();
                }
            }
        });
    } else {
        detectAndApply();
    }
}

From source file:gwt.material.design.client.data.AbstractDataView.java

License:Apache License

@Override
public void render(Components<Component<?>> components) {
    // Clear the current row components
    // This does not clear the rows DOM elements
    this.rows.clearComponents();

    // Render the new components
    for (Component<?> component : components) {
        renderComponent(component);//from   ww w .ja va  2s  . c o  m
    }

    redraw = false;
    prepareRows();

    // Reset category indexes and row counts
    if (isUseCategories()) {
        for (CategoryComponent category : categories) {
            category.setCurrentIndex(-1);
            category.setRowCount(0);
        }
    }

    if (!components.isEmpty()) {
        // Remove the last attach handler
        if (attachHandler != null) {
            attachHandler.removeHandler();
        }
        // When the last component has been rendered we
        // will set the rendering flag to false.
        // This can be improved later.
        Component<?> component = components.get(components.size() - 1);
        Widget componentWidget = component.getWidget();
        AttachEvent.Handler handler = event -> {
            if (attachHandler != null) {
                attachHandler.removeHandler();
            }

            // Recheck the row height to ensure
            // the calculated row height is accurate.
            getCalculatedRowHeight();

            // Fixes an issue with heights updating too early.
            // Also ensure the cell widths are updated.
            subheaderLib.recalculate(true);

            // Fixes an issue with heights updating too early.
            subheaderLib.updateHeights();

            rendering = false;

            if (attachHandler != null) {
                attachHandler.removeHandler();
            }

            ComponentsRenderedEvent.fire(this);

            if (pendingRenderEvent) {
                RenderedEvent.fire(this);
                pendingRenderEvent = false;
            }
        };
        if (componentWidget == null || componentWidget.isAttached()) {
            handler.onAttachOrDetach(null);
        } else {
            attachHandler = componentWidget.addAttachHandler(handler);
        }
    } else {
        rendering = false;
    }
}

From source file:gwt.material.design.client.data.component.CategoryComponent.java

License:Apache License

public void setHeight(String height) {
    this.height = height;

    Widget widget = getWidget();
    if (widget != null && widget.isAttached()) {
        widget.setHeight(height);//ww  w . java  2s  .co  m
    }
}

From source file:gwtupload.client.ResumableUploader.java

License:Apache License

/**
 * This constructor allows to use an existing form panel.
 * /*ww w .  j a  v  a  2s. co  m*/
 * @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 ResumableUploader(FileInputType type, IUploadStatus status, Widget submitButton, FormPanel form) {
    super(type, form);

    final Uploader thisInstance = this;

    if (status == null) {
        status = new BaseUploadStatus();
    }
    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);
        }
    }
}