Example usage for com.vaadin.ui Component setParent

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

Introduction

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

Prototype

public void setParent(HasComponents parent);

Source Link

Document

Sets the parent connector of the component.

Usage

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

License:Apache License

/**
 * copied from AbstractComponentContainer
 * //from ww w.  j  a  v a  2s.  c om
 * @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
 * /*  ww w.  j a v  a  2  s  . c  om*/
 */
public void removeComponent(Component c) {
    if (equals(c.getParent())) {
        c.setParent(null);
        fireComponentDetachEvent(c);
        markAsDirty();
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebAbstractTable.java

License:Apache License

@Override
public void addGeneratedColumn(String columnId, ColumnGenerator<? super E> generator) {
    checkNotNullArgument(columnId, "columnId is null");
    checkNotNullArgument(generator, "generator is null for column id '%s'", columnId);

    MetaPropertyPath targetCol = getDatasource().getMetaClass().getPropertyPath(columnId);
    Object generatedColumnId = targetCol != null ? targetCol : columnId;

    Column column = getColumn(columnId);
    Column associatedRuntimeColumn = null;
    if (column == null) {
        Column newColumn = new Column(generatedColumnId);

        columns.put(newColumn.getId(), newColumn);
        columnsOrder.add(newColumn);//from  w w w .ja va2s.  c o m

        associatedRuntimeColumn = newColumn;
        newColumn.setOwner(this);
    }

    // save column order
    Object[] visibleColumns = component.getVisibleColumns();

    boolean removeOldGeneratedColumn = component.getColumnGenerator(generatedColumnId) != null;
    // replace generator for column if exist
    if (removeOldGeneratedColumn) {
        component.removeGeneratedColumn(generatedColumnId);
    }

    component.addGeneratedColumn(generatedColumnId,
            new CustomColumnGenerator(generator, associatedRuntimeColumn) {
                @SuppressWarnings("unchecked")
                @Override
                public Object generateCell(com.vaadin.ui.Table source, Object itemId, Object columnId) {
                    Entity entity = getDatasource().getItem(itemId);

                    com.haulmont.cuba.gui.components.Component component = getColumnGenerator()
                            .generateCell(entity);
                    if (component == null) {
                        return null;
                    }

                    if (component instanceof PlainTextCell) {
                        return ((PlainTextCell) component).getText();
                    }

                    if (component instanceof BelongToFrame) {
                        BelongToFrame belongToFrame = (BelongToFrame) component;
                        if (belongToFrame.getFrame() == null) {
                            belongToFrame.setFrame(getFrame());
                        }
                    }
                    component.setParent(WebAbstractTable.this);

                    com.vaadin.ui.Component vComponent = component.unwrapComposition(Component.class);

                    // wrap field for show required asterisk
                    if ((vComponent instanceof com.vaadin.ui.Field)
                            && (((com.vaadin.ui.Field) vComponent).isRequired())) {
                        VerticalLayout layout = new VerticalLayout();
                        layout.addComponent(vComponent);

                        if (vComponent.getWidth() < 0) {
                            layout.setWidthUndefined();
                        }

                        layout.addComponent(vComponent);
                        vComponent = layout;
                    }
                    return vComponent;
                }
            });

    if (removeOldGeneratedColumn) {
        // restore column order
        component.setVisibleColumns(visibleColumns);
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebTabSheet.java

License:Apache License

@Override
public TabSheet.Tab addTab(String name, Component childComponent) {
    if (childComponent.getParent() != null && childComponent.getParent() != this) {
        throw new IllegalStateException("Component already has parent");
    }/* w w w .j a  v a 2s.co  m*/

    final Tab tab = new Tab(name, childComponent);

    this.tabs.put(name, tab);

    final com.vaadin.ui.Component tabComponent = WebComponentsHelper.getComposition(childComponent);
    tabComponent.setSizeFull();

    tabMapping.put(tabComponent, new ComponentDescriptor(name, childComponent));
    com.vaadin.ui.TabSheet.Tab tabControl = this.component.addTab(tabComponent);

    if (getDebugId() != null) {
        this.component.setTestId(tabControl,
                AppUI.getCurrent().getTestIdManager().getTestId(getDebugId() + "." + name));
    }
    if (AppUI.getCurrent().isTestMode()) {
        this.component.setCubaId(tabControl, name);
    }

    if (frame != null) {
        if (childComponent instanceof BelongToFrame && ((BelongToFrame) childComponent).getFrame() == null) {
            ((BelongToFrame) childComponent).setFrame(frame);
        } else {
            frame.registerComponent(childComponent);
        }
    }

    childComponent.setParent(this);

    return tab;
}

From source file:com.haulmont.cuba.web.gui.components.WebTabSheet.java

License:Apache License

@Override
public void removeTab(String name) {
    final Tab tab = tabs.get(name);
    if (tab == null) {
        throw new IllegalStateException(String.format("Can't find tab '%s'", name));
    }/*ww w .  j a  v a2 s.  c o  m*/
    tabs.remove(name);

    Component childComponent = tab.getComponent();
    com.vaadin.ui.Component vComponent = WebComponentsHelper.unwrap(childComponent);
    this.component.removeComponent(vComponent);

    tabMapping.remove(vComponent);

    childComponent.setParent(null);
}

From source file:com.haulmont.cuba.web.gui.components.WebTabSheet.java

License:Apache License

@Override
public void removeAllTabs() {
    tabMapping.clear();/* ww  w .j a  va 2  s  .  c o m*/
    component.removeAllComponents();

    List<Tab> currentTabs = new ArrayList<>(tabs.values());
    tabs.clear();

    for (Tab tab : currentTabs) {
        Component childComponent = tab.getComponent();

        childComponent.setParent(null);
    }
}

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

License:Apache License

@Override
public void showCustomPopup(Component popupComponent) {
    if (getState().customPopup != null) {
        ((AbstractComponent) getState().customPopup).setParent(null);
    }/*ww  w  .j a v  a 2  s. c  o m*/

    getState().customPopup = popupComponent;
    getRpcProxy(CubaTableClientRpc.class).showCustomPopup();

    popupComponent.setParent(this);
}

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

License:Apache License

protected void refreshRenderedComponents() {
    detachGeneratedComponents();//from   w ww.j  a  v  a  2  s  .c o m

    nodeWidgets.clear();
    itemIds.clear();

    if (widgetBuilder != null) {
        // Iterates through hierarchical tree using a stack of iterators
        final Stack<Iterator<?>> iteratorStack = new Stack<>();
        Collection<?> ids = rootItemIds();

        if (ids != null) {
            iteratorStack.push(ids.iterator());
        }

        while (!iteratorStack.isEmpty()) {

            // Gets the iterator for current tree level
            final Iterator<?> i = iteratorStack.peek();

            // If the level is finished, back to previous tree level
            if (!i.hasNext()) {

                // Removes used iterator from the stack
                iteratorStack.pop();
            } else {
                final Object itemId = i.next();

                itemIds.add(itemId);

                Component c = widgetBuilder.buildWidget(this, itemId, areChildrenAllowed(itemId));
                c.setParent(this);
                c.markAsDirty();

                nodeWidgets.add(c);

                if (hasChildren(itemId) && areChildrenAllowed(itemId)) {
                    iteratorStack.push(getChildren(itemId).iterator());
                }
            }
        }
    }
}

From source file:de.datenhahn.vaadin.rendererpackage.ComponentRenderer.java

License:Apache License

@Override
public JsonValue encode(Component component) {
    component.setParent(getParentGrid());
    return Json.create(component.getConnectorId());
}

From source file:info.magnolia.ui.vaadin.dialog.BaseDialog.java

License:Open Source License

/**
 * Sets a Component/*from  www  .j  av a  2s  .co  m*/
 * <p>
 * The composition root must be set to non-null value before the component can be used. The composition root can only be set once.
 * </p>
 *
 * @param newContent
 * the root of the composition component tree.
 */
protected void adoptComponent(Component newContent) {
    if (newContent != null) {
        // set new component
        if (newContent.getParent() != null) {
            if (newContent.getParent() == this) {
                newContent.setParent(null);
            } else {
                // If the component already has a parent, try to remove it
                AbstractSingleComponentContainer.removeFromParent(newContent);
            }
        }
        newContent.setParent(this);
    }
    markAsDirty();

}