Search in sources :

Example 1 with SingleComponentContainer

use of com.vaadin.ui.SingleComponentContainer in project cuba by cuba-platform.

the class DefaultAccordionDropHandler method handleDropFromLayout.

/**
 * Adds a new tab from the drop
 *
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    // Get the target details
    AccordionTargetDetails details = (AccordionTargetDetails) event.getTargetDetails();
    DDAccordion acc = (DDAccordion) details.getTarget();
    Component c = transferable.getComponent();
    int idx = details.getOverIndex();
    VerticalDropLocation location = details.getDropLocation();
    // Detach from old source
    Component source = transferable.getSourceComponent();
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(c);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }
    if (location == VerticalDropLocation.TOP) {
        acc.addTab(c, idx);
    } else if (location == VerticalDropLocation.BOTTOM) {
        acc.addTab(c, idx + 1);
    } else {
        acc.addTab(c);
    }
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) DDAccordion(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAccordion) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) ComponentContainer(com.vaadin.ui.ComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) AccordionTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AccordionTargetDetails) Component(com.vaadin.ui.Component)

Example 2 with SingleComponentContainer

use of com.vaadin.ui.SingleComponentContainer in project cuba by cuba-platform.

the class DefaultHorizontalSplitPanelDropHandler method handleDropFromLayout.

@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    ComponentContainer source = (ComponentContainer) transferable.getSourceComponent();
    HorizontalSplitPanelTargetDetails details = (HorizontalSplitPanelTargetDetails) event.getTargetDetails();
    Component component = transferable.getComponent();
    DDHorizontalSplitPanel panel = (DDHorizontalSplitPanel) details.getTarget();
    // Detach from old source
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(component);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }
    if (details.getDropLocation() == HorizontalDropLocation.LEFT) {
        // Dropped in the left area
        panel.setFirstComponent(component);
    } else if (details.getDropLocation() == HorizontalDropLocation.RIGHT) {
        // Dropped in the right area
        panel.setSecondComponent(component);
    }
}
Also used : LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) ComponentContainer(com.vaadin.ui.ComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) HorizontalSplitPanelTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalSplitPanel.HorizontalSplitPanelTargetDetails) Component(com.vaadin.ui.Component) DDHorizontalSplitPanel(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalSplitPanel)

Example 3 with SingleComponentContainer

use of com.vaadin.ui.SingleComponentContainer in project cuba by cuba-platform.

the class DefaultAbsoluteLayoutDropHandler method handleDropFromLayout.

/**
 * 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");
}
Also used : AbsoluteLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AbsoluteLayoutTargetDetails) DDAbsoluteLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) ComponentContainer(com.vaadin.ui.ComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) Component(com.vaadin.ui.Component)

Example 4 with SingleComponentContainer

use of com.vaadin.ui.SingleComponentContainer in project cuba by cuba-platform.

the class DefaultCssLayoutDropHandler method handleComponentReordering.

@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    // Component re-ordering
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    CssLayoutTargetDetails details = (CssLayoutTargetDetails) event.getTargetDetails();
    DDCssLayout layout = (DDCssLayout) details.getTarget();
    Component comp = transferable.getComponent();
    int idx = details.getOverIndex();
    // Detach from old source
    Component source = transferable.getSourceComponent();
    if (source instanceof ComponentContainer) {
        ((ComponentContainer) source).removeComponent(comp);
    } else if (source instanceof SingleComponentContainer) {
        ((SingleComponentContainer) source).setContent(null);
    }
    // Add component
    if (idx >= 0 && idx < layout.getComponentCount()) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp);
    }
}
Also used : DDCssLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout) CssLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout.CssLayoutTargetDetails) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) ComponentContainer(com.vaadin.ui.ComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) Component(com.vaadin.ui.Component)

Example 5 with SingleComponentContainer

use of com.vaadin.ui.SingleComponentContainer in project cuba by cuba-platform.

the class DefaultGridLayoutDropHandler method handleDropFromLayout.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.AbstractDefaultLayoutDropHandler
     * #handleDropFromLayout(com.vaadin.event.dd.DragAndDropEvent)
     */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails();
    DDGridLayout layout = (DDGridLayout) details.getTarget();
    Component source = event.getTransferable().getSourceComponent();
    Component comp = transferable.getComponent();
    if (comp == layout) {
        // move
        if (comp.getParent() instanceof DDAbsoluteLayout) {
            MouseEventDetails mouseDown = transferable.getMouseDownEvent();
            MouseEventDetails mouseUp = details.getMouseEvent();
            int movex = mouseUp.getClientX() - mouseDown.getClientX();
            int movey = mouseUp.getClientY() - mouseDown.getClientY();
            DDAbsoluteLayout parent = (DDAbsoluteLayout) comp.getParent();
            ComponentPosition position = parent.getPosition(comp);
            float x = position.getLeftValue() + movex;
            float y = position.getTopValue() + movey;
            position.setLeft(x, Sizeable.UNITS_PIXELS);
            position.setTop(y, Sizeable.UNITS_PIXELS);
            return;
        }
    } else {
        // 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);
        }
    }
    int row = details.getOverRow();
    int column = details.getOverColumn();
    addComponent(event, comp, column, row);
}
Also used : ComponentPosition(com.vaadin.ui.AbsoluteLayout.ComponentPosition) DDGridLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout) MouseEventDetails(com.vaadin.shared.MouseEventDetails) DDAbsoluteLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) ComponentContainer(com.vaadin.ui.ComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) GridLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails) Component(com.vaadin.ui.Component)

Aggregations

LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)11 Component (com.vaadin.ui.Component)11 ComponentContainer (com.vaadin.ui.ComponentContainer)11 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)11 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)4 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)3 DDAbsoluteLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout)2 DDAccordion (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAccordion)1 DDCssLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout)1 CssLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout.CssLayoutTargetDetails)1 FormLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout.FormLayoutTargetDetails)1 DDGridLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout)1 GridLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails)1 DDHorizontalSplitPanel (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalSplitPanel)1 HorizontalSplitPanelTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalSplitPanel.HorizontalSplitPanelTargetDetails)1 DDPanel (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDPanel)1 PanelTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDPanel.PanelTargetDetails)1 DDTabSheet (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet)1 TabSheetTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet.TabSheetTargetDetails)1 VerticalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDVerticalLayout.VerticalLayoutTargetDetails)1