Search in sources :

Example 1 with DDAbsoluteLayout

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

the class AbstractDefaultLayoutDropHandler method handleDropFromAbsoluteParentLayout.

/**
 * Handles a drop by a component which has an absolute layout as parent. In
 * this case the component is moved.
 *
 * @param event
 *            The drag and drop event
 */
protected void handleDropFromAbsoluteParentLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    TargetDetails details = event.getTargetDetails();
    MouseEventDetails mouseDown = transferable.getMouseDownEvent();
    MouseEventDetails mouseUp = MouseEventDetails.deSerialize((String) details.getData(Constants.DROP_DETAIL_MOUSE_EVENT));
    int movex = mouseUp.getClientX() - mouseDown.getClientX();
    int movey = mouseUp.getClientY() - mouseDown.getClientY();
    Component comp = transferable.getComponent();
    DDAbsoluteLayout parent = (DDAbsoluteLayout) comp.getParent();
    ComponentPosition position = parent.getPosition(comp);
    if (position.getLeftValue() != null) {
        float x = position.getLeftValue() + movex;
        position.setLeft(x, Sizeable.UNITS_PIXELS);
    }
    if (position.getRightValue() != null) {
        float x = position.getRightValue() - movex;
        position.setRight(x, Sizeable.UNITS_PIXELS);
    }
    if (position.getTopValue() != null) {
        float y = position.getTopValue() + movey;
        position.setTop(y, Sizeable.UNITS_PIXELS);
    }
    if (position.getBottomValue() != null) {
        float y = position.getBottomValue() - movey;
        position.setBottom(y, Sizeable.UNITS_PIXELS);
    }
}
Also used : ComponentPosition(com.vaadin.ui.AbsoluteLayout.ComponentPosition) MouseEventDetails(com.vaadin.shared.MouseEventDetails) DDAbsoluteLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) TargetDetails(com.vaadin.event.dd.TargetDetails) Component(com.vaadin.ui.Component)

Example 2 with DDAbsoluteLayout

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

the class AbstractDefaultLayoutDropHandler method drop.

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);
        }
    }
}
Also used : DDAbsoluteLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) TargetDetails(com.vaadin.event.dd.TargetDetails) DropTarget(com.vaadin.event.dd.DropTarget) Component(com.vaadin.ui.Component)

Example 3 with DDAbsoluteLayout

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

the class DefaultAbsoluteLayoutDropHandler method handleComponentReordering.

/**
 * Called when a component changed location within the layout
 *
 * @param event
 *            The drag and drop event
 */
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component component = transferable.getComponent();
    // Get top-left pixel position
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();
    ComponentPosition position = layout.getPosition(component);
    position.setLeft((float) leftPixelPosition, Sizeable.UNITS_PIXELS);
    position.setTop((float) topPixelPosition, Sizeable.UNITS_PIXELS);
}
Also used : ComponentPosition(com.vaadin.ui.AbsoluteLayout.ComponentPosition) 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) Component(com.vaadin.ui.Component)

Example 4 with DDAbsoluteLayout

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

the class DefaultAbsoluteLayoutDropHandler method handleHTML5Drop.

@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();
    layout.addComponent(resolveComponentFromHTML5Drop(event), "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)

Example 5 with DDAbsoluteLayout

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

Aggregations

DDAbsoluteLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout)6 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)5 Component (com.vaadin.ui.Component)5 AbsoluteLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AbsoluteLayoutTargetDetails)3 ComponentPosition (com.vaadin.ui.AbsoluteLayout.ComponentPosition)3 TargetDetails (com.vaadin.event.dd.TargetDetails)2 MouseEventDetails (com.vaadin.shared.MouseEventDetails)2 ComponentContainer (com.vaadin.ui.ComponentContainer)2 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)2 DDGridLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout)1 GridLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDGridLayout.GridLayoutTargetDetails)1 DropTarget (com.vaadin.event.dd.DropTarget)1