Search in sources :

Example 1 with FormLayoutTargetDetails

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

the class DefaultFormLayoutDropHandler method handleHTML5Drop.

@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    FormLayoutTargetDetails details = (FormLayoutTargetDetails) event.getTargetDetails();
    int idx = details.getOverIndex();
    AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
    // 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(resolveComponentFromHTML5Drop(event), idx);
    } else {
        layout.addComponent(resolveComponentFromHTML5Drop(event));
    }
    // Add component alignment if given
    if (dropAlignment != null) {
        layout.setComponentAlignment(resolveComponentFromHTML5Drop(event), dropAlignment);
    }
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) FormLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout.FormLayoutTargetDetails) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout)

Example 2 with FormLayoutTargetDetails

use of com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout.FormLayoutTargetDetails 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 3 with FormLayoutTargetDetails

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

Aggregations

FormLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout.FormLayoutTargetDetails)3 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)3 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)2 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)2 Component (com.vaadin.ui.Component)2 DDFormLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout)1 ComponentContainer (com.vaadin.ui.ComponentContainer)1 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)1