Search in sources :

Example 16 with LayoutBoundTransferable

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable 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)

Example 17 with LayoutBoundTransferable

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.

the class DefaultFormLayoutDropHandler method handleComponentReordering.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.AbstractDefaultLayoutDropHandler
     * #handleComponentReordering(com.vaadin.event.dd.DragAndDropEvent)
     */
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    FormLayoutTargetDetails details = (FormLayoutTargetDetails) event.getTargetDetails();
    DDFormLayout layout = (DDFormLayout) details.getTarget();
    Component comp = transferable.getComponent();
    int idx = details.getOverIndex();
    int oldIdx = layout.getComponentIndex(comp);
    if (idx == oldIdx) {
        // Dropping on myself
        return;
    }
    // Detach
    layout.removeComponent(comp);
    if (idx > 0 && idx > oldIdx) {
        idx--;
    }
    // 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);
    }
}
Also used : DDFormLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout) VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) FormLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout.FormLayoutTargetDetails) Component(com.vaadin.ui.Component)

Example 18 with LayoutBoundTransferable

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.

the class DefaultFormLayoutDropHandler 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();
    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);
    }
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) 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) FormLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout.FormLayoutTargetDetails) Component(com.vaadin.ui.Component) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout)

Example 19 with LayoutBoundTransferable

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.

the class DefaultHorizontalLayoutDropHandler method handleDropFromLayout.

/**
 * Handle a drop from another layout
 *
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) 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
    HorizontalDropLocation loc = (details).getDropLocation();
    if (loc == HorizontalDropLocation.CENTER || loc == HorizontalDropLocation.RIGHT) {
        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);
    }
}
Also used : HorizontalLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalLayout.HorizontalLayoutTargetDetails) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Example 20 with LayoutBoundTransferable

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable in project cuba by cuba-platform.

the class DefaultHorizontalLayoutDropHandler method handleComponentReordering.

/**
 * Called when a component changed location within the layout
 *
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    // Component re-ordering
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    HorizontalLayoutTargetDetails details = (HorizontalLayoutTargetDetails) event.getTargetDetails();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
    Component comp = transferable.getComponent();
    int idx = details.getOverIndex();
    int oldIndex = layout.getComponentIndex(comp);
    if (idx == oldIndex) {
        // Index did not change
        return;
    }
    // Detach
    layout.removeComponent(comp);
    // Account for detachment if new index is bigger then old index
    if (idx > oldIndex) {
        idx--;
    }
    // Increase index if component is dropped after or above a previous
    // component
    HorizontalDropLocation loc = details.getDropLocation();
    if (loc == HorizontalDropLocation.CENTER || loc == HorizontalDropLocation.RIGHT) {
        idx++;
    }
    // Add component
    if (idx >= 0) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp, 0);
    }
    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(comp, dropAlignment);
    }
}
Also used : HorizontalLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalLayout.HorizontalLayoutTargetDetails) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Aggregations

LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)27 Component (com.vaadin.ui.Component)23 ComponentContainer (com.vaadin.ui.ComponentContainer)12 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)12 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)9 HorizontalDropLocation (com.vaadin.shared.ui.dd.HorizontalDropLocation)7 DDAbsoluteLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout)5 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)5 ComponentPosition (com.vaadin.ui.AbsoluteLayout.ComponentPosition)3 DDAccordion (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAccordion)2 DDCssLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout)2 CssLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout.CssLayoutTargetDetails)2 FormLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout.FormLayoutTargetDetails)2 DDGridLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout)2 GridLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails)2 HorizontalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalLayout.HorizontalLayoutTargetDetails)2 DDTabSheet (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet)2 TabSheetTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet.TabSheetTargetDetails)2 VerticalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDVerticalLayout.VerticalLayoutTargetDetails)2 AbsoluteLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AbsoluteLayoutTargetDetails)2