Example usage for com.vaadin.ui Component getParent

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

Introduction

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

Prototype

@Override
public HasComponents getParent();

Source Link

Document

Gets the parent component of the component.

Usage

From source file:annis.libgui.IDGenerator.java

License:Apache License

public static String assignID(Component c, String fieldName) {
    String id = null;/*from   w w  w .  j ava  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.esofthead.mycollab.mobile.module.crm.view.activity.RelatedItemSelectionView.java

License:Open Source License

@Override
public void attach() {
    super.attach();
    Component parent = this.getParent();
    while (parent != null && !(parent instanceof NavigationManager)) {
        parent = parent.getParent();
    }/*from  w w w.  j  a  v  a  2 s. c  o m*/
    this.previousView = ((NavigationManager) parent).getCurrentComponent();
}

From source file:com.esofthead.mycollab.mobile.ui.AbstractMobilePageView.java

License:Open Source License

@Override
public NavigationManager getNavigationManager() {
    Component parent = this.getParent();
    while (parent != null) {
        if (parent instanceof NavigationManager)
            return (NavigationManager) parent;
        else/*from  w ww. ja v a2 s.com*/
            parent = parent.getParent();
    }
    return null;
}

From source file:com.esofthead.mycollab.vaadin.ui.UIUtils.java

License:Open Source License

public static <T> T getRoot(Component container, Class<T> type) {
    HasComponents parent = container.getParent();
    while (parent != null) {
        if (type.isAssignableFrom(parent.getClass())) {
            return (T) parent;
        } else {/* w w  w  . j a v  a  2 s  .c  o m*/
            parent = parent.getParent();
        }
    }
    return null;
}

From source file:com.esofthead.mycollab.vaadin.ui.UIUtils.java

License:Open Source License

public static boolean removeChildAssociate(Component container, Class type) {
    HasComponents parent = container.getParent();
    while (parent != null) {
        if (type.isAssignableFrom(parent.getClass()) && (parent instanceof ComponentContainer)) {
            ((ComponentContainer) parent).removeComponent(container);
            return true;
        } else {//  w w  w.  j ava  2 s  . c  om
            return removeChildAssociate(parent, type);
        }
    }
    return false;
}

From source file:com.explicatis.ext_token_field.ExtTokenField.java

License:Apache License

/**
 * copied from AbstractComponentContainer
 * //from  w ww.  ja va2  s .c o  m
 * @param c
 */
public void addComponent(Component c) {
    // Make sure we're not adding the component inside it's own content
    if (isOrHasAncestor(c)) {
        throw new IllegalArgumentException("Component cannot be added inside it's own content");
    }

    if (c.getParent() != null) {
        // If the component already has a parent, try to remove it
        AbstractSingleComponentContainer.removeFromParent(c);
    }

    c.setParent(this);
    fireComponentAttachEvent(c);
    markAsDirty();
}

From source file:com.explicatis.ext_token_field.ExtTokenField.java

License:Apache License

/**
 * copied from AbstractComponentContainer
 * /*from  ww w . ja  va2 s.  co  m*/
 */
public void removeComponent(Component c) {
    if (equals(c.getParent())) {
        c.setParent(null);
        fireComponentDetachEvent(c);
        markAsDirty();
    }
}

From source file:com.foc.vaadin.gui.components.FVImageField.java

License:Apache License

public boolean saveObjectBeforeUploadIfCreated() {
    boolean error = false;
    //If Object is created we need to insert it first
    FocObject focObject = getFocObject();
    if (focObject != null && focObject.isCreated()) {
        error = true;//from  w w w .  j a v  a 2s.com

        Component comp = this;
        while (comp != null && comp.getParent() != null) {
            comp = comp.getParent();

            if (comp instanceof FocXMLLayout) {
                FocXMLLayout xmlLay = (FocXMLLayout) comp;
                xmlLay.copyGuiToMemory();
                if (xmlLay.getValidationLayout() != null) {
                    if (!xmlLay.getValidationLayout().commit()) {
                        error = false;
                        break;
                    }
                }
            }
        }

        //If Still created we try directly saving
        if (!error && focObject.isCreated())
            focObject.validate(true);
    }
    return error;
}

From source file:com.foc.vaadin.gui.components.TableTreeDelegate.java

License:Apache License

public FocXMLLayout getFocXMLLayout() {
    FocXMLLayout xmlLayout = null;// w w w.ja  v  a 2  s  .  co m

    Component comp = (Component) getTreeOrTable();
    while (comp != null && xmlLayout == null) {
        if (comp instanceof FocXMLLayout) {
            xmlLayout = (FocXMLLayout) comp;
        }
        comp = comp.getParent();
    }
    return xmlLayout;
}

From source file:com.foc.vaadin.gui.FocXMLGuiComponentDelegate.java

License:Apache License

public FocXMLLayout getFocXMLLayout() {
    FocXMLLayout layout = null;//from w w  w  . j a  v a2 s. c  o m
    if (component != null) {
        Component cmp = (Component) component;
        while (cmp != null && layout == null) {
            cmp = cmp.getParent();
            if (cmp instanceof FocXMLLayout) {
                layout = (FocXMLLayout) cmp;
            }
        }
    }
    return layout;
}