Search in sources :

Example 1 with GridLayoutTargetDetails

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails in project cuba by cuba-platform.

the class DefaultGridLayoutDropHandler 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) {
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails();
    DDGridLayout layout = (DDGridLayout) details.getTarget();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component comp = transferable.getComponent();
    int row = details.getOverRow();
    int column = details.getOverColumn();
    if (layout.getComponent(column, row) == null) {
        layout.removeComponent(comp);
        addComponent(event, comp, column, row);
    }
}
Also used : DDGridLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) GridLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails) Component(com.vaadin.ui.Component)

Example 2 with GridLayoutTargetDetails

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails in project cuba by cuba-platform.

the class DefaultGridLayoutDropHandler method handleHTML5Drop.

@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails();
    int row = details.getOverRow();
    int column = details.getOverColumn();
    addComponent(event, resolveComponentFromHTML5Drop(event), column, row);
}
Also used : GridLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails)

Example 3 with GridLayoutTargetDetails

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails in project cuba by cuba-platform.

the class DefaultGridLayoutDropHandler method addComponent.

protected void addComponent(DragAndDropEvent event, Component component, int column, int row) {
    GridLayoutTargetDetails details = (GridLayoutTargetDetails) event.getTargetDetails();
    DDGridLayout layout = (DDGridLayout) details.getTarget();
    // component
    if (!layout.getComponentIterator().hasNext()) {
        layout.addComponent(component, column, row);
        return;
    }
    // If component was dropped on top of another component, abort
    if (layout.getComponent(column, row) != null) {
        return;
    }
    // Add the component
    layout.addComponent(component, column, row);
    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(component, dropAlignment);
    }
}
Also used : DDGridLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout) GridLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails)

Example 4 with GridLayoutTargetDetails

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails 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

GridLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails)4 DDGridLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout)3 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)2 Component (com.vaadin.ui.Component)2 DDAbsoluteLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout)1 MouseEventDetails (com.vaadin.shared.MouseEventDetails)1 ComponentPosition (com.vaadin.ui.AbsoluteLayout.ComponentPosition)1 ComponentContainer (com.vaadin.ui.ComponentContainer)1 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)1