Search in sources :

Example 1 with LayoutBoundTransferable

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

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

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

the class DefaultAccordionDropHandler method handleComponentReordering.

/**
 * Called when tabs are being rearranged
 *
 * @param event
 *            A drag and drop event
 */
@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    AccordionTargetDetails details = (AccordionTargetDetails) event.getTargetDetails();
    DDAccordion acc = (DDAccordion) details.getTarget();
    VerticalDropLocation location = details.getDropLocation();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component c = transferable.getComponent();
    int idx = details.getOverIndex();
    Tab tab = acc.getTab(c);
    if (location == VerticalDropLocation.TOP) {
        // Left of previous tab
        int originalIndex = acc.getTabPosition(tab);
        if (originalIndex > idx) {
            acc.setTabPosition(tab, idx);
        } else if (idx - 1 >= 0) {
            acc.setTabPosition(tab, idx - 1);
        }
    } else if (location == VerticalDropLocation.BOTTOM) {
        // Right of previous tab
        int originalIndex = acc.getTabPosition(tab);
        if (originalIndex > idx) {
            acc.setTabPosition(tab, idx + 1);
        } else {
            acc.setTabPosition(tab, idx);
        }
    }
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) Tab(com.vaadin.ui.TabSheet.Tab) DDAccordion(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAccordion) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) AccordionTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AccordionTargetDetails) Component(com.vaadin.ui.Component)

Example 4 with LayoutBoundTransferable

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

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

the class DefaultVerticalLayoutDropHandler 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();
    VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) 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
    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 : VerticalLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDVerticalLayout.VerticalLayoutTargetDetails) VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) Component(com.vaadin.ui.Component) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout)

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