Search in sources :

Example 1 with VerticalDropLocation

use of com.vaadin.shared.ui.dd.VerticalDropLocation 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 2 with VerticalDropLocation

use of com.vaadin.shared.ui.dd.VerticalDropLocation 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 3 with VerticalDropLocation

use of com.vaadin.shared.ui.dd.VerticalDropLocation 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 4 with VerticalDropLocation

use of com.vaadin.shared.ui.dd.VerticalDropLocation 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)

Example 5 with VerticalDropLocation

use of com.vaadin.shared.ui.dd.VerticalDropLocation in project cuba by cuba-platform.

the class VDDCssLayout method updateDrag.

public void updateDrag(VDragEvent drag) {
    if (placeHolderElement == null) {
        /*
             * Drag image might not have been detach due to lazy attaching in
             * the DragAndDropManager. Detach it again here if it has not been
             * detached.
             */
        attachDragImageToLayout(drag);
        return;
    }
    if (drag.getElementOver().isOrHasChild(placeHolderElement)) {
        return;
    }
    if (placeHolderElement.hasParentElement()) {
        /*
             * Remove the placeholder from the DOM so we can reposition
             */
        placeHolderElement.removeFromParent();
    }
    Widget w = Util.findWidget(drag.getElementOver(), null);
    ComponentConnector draggedConnector = (ComponentConnector) drag.getTransferable().getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);
    if (draggedConnector != null && w == draggedConnector.getWidget()) {
        /*
             * Dragging drag image over the placeholder should not have any
             * effect (except placeholder should be removed)
             */
        return;
    }
    if (w != null && w != this) {
        HorizontalDropLocation hl = getHorizontalDropLocation(w, drag);
        VerticalDropLocation vl = getVerticalDropLocation(w, drag);
        if (hl == HorizontalDropLocation.LEFT || vl == VerticalDropLocation.TOP) {
            Element prev = w.getElement().getPreviousSibling().cast();
            if (draggedConnector == null || prev == null || !draggedConnector.getWidget().getElement().isOrHasChild(prev)) {
                w.getElement().getParentElement().insertBefore(placeHolderElement, w.getElement());
            }
        } else if (hl == HorizontalDropLocation.RIGHT || vl == VerticalDropLocation.BOTTOM) {
            Element next = w.getElement().getNextSibling().cast();
            if (draggedConnector == null || next == null || !draggedConnector.getWidget().getElement().isOrHasChild(next)) {
                w.getElement().getParentElement().insertAfter(placeHolderElement, w.getElement());
            }
        } else {
            Element prev = w.getElement().getPreviousSibling().cast();
            if (draggedConnector == null || prev == null || !draggedConnector.getWidget().getElement().isOrHasChild(prev)) {
                w.getElement().getParentElement().insertBefore(placeHolderElement, w.getElement());
            }
        }
    } else {
        /*
             * First child or hoovering outside of current components
             */
        getElement().appendChild(placeHolderElement);
    }
    updatePlaceHolderStyleProperties(drag);
}
Also used : ComponentConnector(com.vaadin.client.ComponentConnector) VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) Element(com.google.gwt.dom.client.Element) Widget(com.google.gwt.user.client.ui.Widget) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Aggregations

VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)25 Component (com.vaadin.ui.Component)13 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)9 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)8 HorizontalDropLocation (com.vaadin.shared.ui.dd.HorizontalDropLocation)5 ComponentContainer (com.vaadin.ui.ComponentContainer)5 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)5 DDAccordion (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAccordion)3 FormLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout.FormLayoutTargetDetails)3 VerticalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDVerticalLayout.VerticalLayoutTargetDetails)3 AccordionTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.details.AccordionTargetDetails)3 VerticalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.v7.DDVerticalLayout.VerticalLayoutTargetDetails)3 ComponentConnector (com.vaadin.client.ComponentConnector)3 MouseEventDetails (com.vaadin.shared.MouseEventDetails)3 Element (com.google.gwt.dom.client.Element)2 Widget (com.google.gwt.user.client.ui.Widget)2 DDCssLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout)2 CssLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout.CssLayoutTargetDetails)2 Style (com.google.gwt.dom.client.Style)1 Element (com.google.gwt.user.client.Element)1