Example usage for com.vaadin.ui Component isAttached

List of usage examples for com.vaadin.ui Component isAttached

Introduction

In this page you can find the example usage for com.vaadin.ui Component isAttached.

Prototype

public boolean isAttached();

Source Link

Document

Checks if the connector is attached to a VaadinSession.

Usage

From source file:annis.libgui.IDGenerator.java

License:Apache License

public static String assignID(Component c, String fieldName) {
    String id = null;//from  www.j a  va  2  s.c o  m
    if (c != null && fieldName != null && !fieldName.isEmpty()) {
        Preconditions.checkArgument(c.isAttached(),
                "Component " + c.getConnectorId() + " must be attached before it can get an automatic ID.");
        id = c.getId();
        if (id == null) {
            // try to get the parent ID
            HasComponents parent = c.getParent();
            if (parent == null || parent instanceof UI) {
                // use class name as ID
                id = fieldName;
            } else {
                String parentID = parent.getId();
                if (parentID == null) {
                    parentID = assignID(parent);
                }
                String idBase = parentID + ":" + fieldName;
                // check that no other child has the same ID
                int counter = 1;
                id = idBase;
                while (childHasID(parent, id)) {
                    id = idBase + "." + counter++;
                }
            }
            c.setId(id);
        }
    }
    return id;
}

From source file:com.haulmont.cuba.web.toolkit.ui.CubaWidgetsTree.java

License:Apache License

protected void detachGeneratedComponents() {
    for (Component c : nodeWidgets) {
        if (c.isAttached()) {
            c.detach();/*from  w w w. j  a  v a 2  s .co m*/
        }
    }
}