Java Code Examples for com.vaadin.ui.Component#getParent()

The following examples show how to use com.vaadin.ui.Component#getParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebComponentsHelper.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the component should be visible to the client. Returns false if
 * the child should not be sent to the client, true otherwise.
 *
 * @param child The child to check
 * @return true if the child is visible to the client, false otherwise
 */
public static boolean isComponentVisibleToClient(Component child) {
    if (!child.isVisible()) {
        return false;
    }
    HasComponents parent = child.getParent();

    if (parent instanceof SelectiveRenderer) {
        if (!((SelectiveRenderer) parent).isRendered(child)) {
            return false;
        }
    }

    if (parent != null) {
        return isComponentVisibleToClient(parent);
    } else {
        if (child instanceof UI) {
            // UI has no parent and visibility was checked above
            return true;
        } else {
            // Component which is not attached to any UI
            return false;
        }
    }
}
 
Example 2
Source File: WebComponentsHelper.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Tests if component visible and its container visible.
 *
 * @param child component
 * @return component visibility
 */
public static boolean isComponentVisible(Component child) {
    if (child.getParent() instanceof TabSheet) {
        TabSheet tabSheet = (TabSheet) child.getParent();
        TabSheet.Tab tab = tabSheet.getTab(child);
        if (!tab.isVisible()) {
            return false;
        }
    }

    if (child.getParent() instanceof CubaGroupBox) {
        // ignore groupbox content container visibility
        return isComponentVisible(child.getParent());
    }

    return child.isVisible() && (child.getParent() == null || isComponentVisible(child.getParent()));
}
 
Example 3
Source File: AbstractDefaultLayoutDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
public void drop(DragAndDropEvent event) {
    // Get information about the drop
    TargetDetails details = event.getTargetDetails();
    DropTarget layout = details.getTarget();
    Component source = event.getTransferable().getSourceComponent();

    if (event.getTransferable().getData("html5Data") != null) {
        handleHTML5Drop(event);
    } else if (layout == source) {
        handleComponentReordering(event);
    } else if (event.getTransferable() instanceof LayoutBoundTransferable) {
        LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
                .getTransferable();
        Component comp = transferable.getComponent();
        if (comp == layout) {
            if (comp.getParent() instanceof DDAbsoluteLayout) {
                handleDropFromAbsoluteParentLayout(event);
            }
        } else {
            handleDropFromLayout(event);
        }
    }
}
 
Example 4
Source File: MHorizontalLayout.java    From viritin with Apache License 2.0 6 votes vote down vote up
/**
 * Expands selected components. Also sets the only sane width for expanded
 * components (100%).
 *
 * @param componentsToExpand the components that should be expanded
 * @return the object itself for further configuration
 */
public MHorizontalLayout expand(Component... componentsToExpand) {
    if (getWidth() < 0) {
        // Make full height if no other size is set
        withFullWidth();
    }

    for (Component component : componentsToExpand) {
        if (component.getParent() != this) {
            addComponent(component);
        }
        setExpandRatio(component, 1);
        component.setWidth(100, Unit.PERCENTAGE);
    }
    return this;
}
 
Example 5
Source File: WebComponentsHelper.java    From cuba with Apache License 2.0 5 votes vote down vote up
public static boolean isComponentExpanded(com.haulmont.cuba.gui.components.Component component) {
    Component vComponent = WebComponentsHelper.getComposition(component);
    if (vComponent.getParent() instanceof AbstractOrderedLayout) {
        AbstractOrderedLayout layout = (AbstractOrderedLayout) vComponent.getParent();
        return (int)layout.getExpandRatio(vComponent) == 1;
    }

    return false;
}
 
Example 6
Source File: WebComponentsHelper.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if component enabled and visible and its container enabled.
 *
 * @param child component
 * @return component enabled state
 */
public static boolean isComponentEnabled(Component child) {
    if (child.getParent() instanceof TabSheet) {
        TabSheet tabSheet = (TabSheet) child.getParent();
        TabSheet.Tab tab = tabSheet.getTab(child);
        if (!tab.isEnabled()) {
            return false;
        }
    }

    return child.isEnabled() && (child.getParent() == null || isComponentEnabled(child.getParent())) &&
            isComponentVisible(child);
}
 
Example 7
Source File: WebComponentsHelper.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * @return the direct child component of the layout which contains the component involved to event
 */
protected static Component getDirectChildComponent(Component targetComponent, Component vaadinSource) {
    while (targetComponent != null
            && targetComponent.getParent() != vaadinSource) {
        targetComponent = targetComponent.getParent();
    }

    return targetComponent;
}
 
Example 8
Source File: CubaUIUtils.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Component getWindowOrUI(Component component) {
    Component parent = component;
    while (parent != null
            && !(parent instanceof Window)
            && !(parent instanceof UI)) {
        parent = parent.getParent();
    }

    return parent;
}
 
Example 9
Source File: DefaultAbsoluteLayoutDropHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a drop from another layout
 * 
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event
            .getTargetDetails();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    Component component = transferable.getComponent();
    Component source = event.getTransferable().getSourceComponent();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();

    // Check that we are not dragging an outer layout into an
    // inner
    // layout
    Component parent = source.getParent();
    while (parent != null) {
        parent = parent.getParent();
    }

    // remove component from source
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(component);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }

    // Add component to absolute layout
    layout.addComponent(component, "left:" + leftPixelPosition + "px;top:"
            + topPixelPosition + "px");
}
 
Example 10
Source File: MVerticalLayout.java    From viritin with Apache License 2.0 5 votes vote down vote up
/**
 * Expands selected components. Also adds to layout and sets the only sane
 * height for expanded components (100%) if needed.
 *
 * @param componentsToExpand components that should be expanded
 * @return the object itself for further configuration
 */
public MVerticalLayout expand(Component... componentsToExpand) {
    if (getHeight() < 0) {
        // Make full height if no other size is set
        withFullHeight();
    }
    for (Component component : componentsToExpand) {
        if (component.getParent() != this) {
            addComponent(component);
        }
        setExpandRatio(component, 1);
        component.setHeight(100, Unit.PERCENTAGE);
    }
    return this;
}
 
Example 11
Source File: ComponentViewAdapter.java    From jdal with Apache License 2.0 5 votes vote down vote up
public ComponentViewAdapter(Component component) {
	if (component.getParent() != null) {
		component.setParent(null);
	}
	
	setCompositionRoot(component);
}
 
Example 12
Source File: VaadinUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Return the window where a component is attached
 * @param component
 * @return the window or null if none
 */
public static Window getWindow(Component component) {
	while (component.getParent() != null) {
		if (component.getParent() instanceof Window)
			return (Window) component.getParent();
		
		component = component.getParent();
	}
	
	return null;
}
 
Example 13
Source File: DefaultVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
/**
 * Handle a drop from another layout
 * 
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event
            .getTargetDetails();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details
            .getTarget();
    Component source = event.getTransferable().getSourceComponent();
    int idx = (details).getOverIndex();
    Component comp = transferable.getComponent();

    // Check that we are not dragging an outer layout into an inner
    // layout
    Component parent = layout.getParent();
    while (parent != null) {
        if (parent == comp) {
            return;
        }
        parent = parent.getParent();
    }

    // Detach from old source
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(comp);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }

    // Increase index if component is dropped after or above a
    // previous
    // component
    VerticalDropLocation loc = (details).getDropLocation();
    if (loc == VerticalDropLocation.MIDDLE
            || loc == VerticalDropLocation.BOTTOM) {
        idx++;
    }

    // Add component
    if (idx >= 0) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp);
    }

    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(comp, dropAlignment);
    }
}
 
Example 14
Source File: DefaultVerticalLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
/**
 * Handle a drop from another layout
 * 
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event
            .getTargetDetails();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details
            .getTarget();
    Component source = event.getTransferable().getSourceComponent();
    int idx = (details).getOverIndex();
    Component comp = transferable.getComponent();

    // Check that we are not dragging an outer layout into an inner
    // layout
    Component parent = layout.getParent();
    while (parent != null) {
        if (parent == comp) {
            return;
        }
        parent = parent.getParent();
    }

    // Detach from old source
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(comp);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }

    // Increase index if component is dropped after or above a
    // previous
    // component
    VerticalDropLocation loc = (details).getDropLocation();
    if (loc == VerticalDropLocation.MIDDLE
            || loc == VerticalDropLocation.BOTTOM) {
        idx++;
    }

    // Add component
    if (idx >= 0) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp);
    }

    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(comp, dropAlignment);
    }
}
 
Example 15
Source File: DefaultCssLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    CssLayoutTargetDetails details = (CssLayoutTargetDetails) event
            .getTargetDetails();
    DDCssLayout layout = (DDCssLayout) details.getTarget();
    HorizontalDropLocation hl = details.getHorizontalDropLocation();
    VerticalDropLocation vl = details.getVerticalDropLocation();
    Component source = event.getTransferable().getSourceComponent();
    int idx = (details).getOverIndex();
    Component comp = transferable.getComponent();
    Component over = details.getOverComponent();

    if (over == layout) {
        if (vl == VerticalDropLocation.TOP
                || hl == HorizontalDropLocation.LEFT) {
            idx = 0;
        } else if (vl == VerticalDropLocation.BOTTOM
                || hl == HorizontalDropLocation.RIGHT) {
            idx = -1;
        }
    } else {
        if (vl == VerticalDropLocation.BOTTOM
                || hl == HorizontalDropLocation.RIGHT) {
            idx++;
        }
    }

    // Check that we are not dragging an outer layout into an inner
    // layout
    Component parent = layout.getParent();
    while (parent != null) {
        if (parent == comp) {
            return;
        }
        parent = parent.getParent();
    }

    // If source is an instance of a component container then remove
    // it
    // from there,
    // the component cannot have two parents.
    if (source instanceof ComponentContainer) {
        ComponentContainer sourceLayout = (ComponentContainer) source;
        sourceLayout.removeComponent(comp);
    }

    // Add component
    if (idx >= 0 && idx < layout.getComponentCount()) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp);
    }
}
 
Example 16
Source File: DefaultFormLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event
            .getTransferable();
    FormLayoutTargetDetails details = (FormLayoutTargetDetails) event
            .getTargetDetails();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details
            .getTarget();
    Component source = event.getTransferable().getSourceComponent();
    int idx = details.getOverIndex();
    Component comp = transferable.getComponent();

    // Check that we are not dragging an outer layout into an inner
    // layout
    Component parent = layout.getParent();
    while (parent != null) {
        if (parent == comp) {
            return;
        }
        parent = parent.getParent();
    }

    // Detach from old source
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(comp);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }

    // Increase index if component is dropped after or above a
    // previous
    // component
    VerticalDropLocation loc = (details).getDropLocation();
    if (loc == VerticalDropLocation.MIDDLE
            || loc == VerticalDropLocation.BOTTOM) {
        idx++;
    }

    // Add component
    if (idx >= 0) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp);
    }

    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(comp, dropAlignment);
    }
}