Search in sources :

Example 11 with HorizontalDropLocation

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

Example 12 with HorizontalDropLocation

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

the class VDDHorizontalSplitPanel method updateDragDetails.

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 *
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {
    Element over = event.getElementOver();
    if (over == null) {
        return;
    }
    // Resolve where the drop was made
    HorizontalDropLocation location = null;
    Widget content = null;
    if (firstContainer.isOrHasChild(over)) {
        location = HorizontalDropLocation.LEFT;
        content = Util.findWidget(firstContainer, null);
    } else if (splitter.isOrHasChild(over)) {
        location = HorizontalDropLocation.CENTER;
        content = this;
    } else if (secondContainer.isOrHasChild(over)) {
        location = HorizontalDropLocation.RIGHT;
        content = Util.findWidget(secondContainer, null);
    }
    event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, location);
    if (content != null) {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS, content.getClass().getName());
    } else {
        event.getDropDetails().put(Constants.DROP_DETAIL_OVER_CLASS, this.getClass().getName());
    }
    // Add mouse event details
    MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event.getCurrentGwtEvent(), getElement());
    event.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT, details.serialize());
}
Also used : MouseEventDetails(com.vaadin.shared.MouseEventDetails) Element(com.google.gwt.dom.client.Element) Widget(com.google.gwt.user.client.ui.Widget) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Example 13 with HorizontalDropLocation

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

the class VDDTabSheet method updateDragDetails.

/**
 * Updates the drop details while dragging. This is needed to ensure client
 * side criterias can validate the drop location.
 *
 * @param event
 *            The drag event
 */
protected void updateDragDetails(VDragEvent event) {
    Element element = event.getElementOver();
    if (element == null)
        return;
    if (tabBar.getElement().isOrHasChild(element)) {
        Widget w = Util.findWidget(element, null);
        if (w == tabBar) {
            // Ove3r the spacer
            // Add index
            event.getDropDetails().put(Constants.DROP_DETAIL_TO, tabBar.getWidgetCount() - 1);
            // Add drop location
            event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, HorizontalDropLocation.RIGHT);
        } else {
            // Add index
            event.getDropDetails().put(Constants.DROP_DETAIL_TO, getTabPosition(w));
            // Add drop location
            HorizontalDropLocation location = VDragDropUtil.getHorizontalDropLocation(DOM.asOld(element), Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), tabLeftRightDropRatio);
            event.getDropDetails().put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, location);
        }
        // Add mouse event details
        MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event.getCurrentGwtEvent(), getElement());
        event.getDropDetails().put(Constants.DROP_DETAIL_MOUSE_EVENT, details.serialize());
    }
}
Also used : MouseEventDetails(com.vaadin.shared.MouseEventDetails) Element(com.google.gwt.dom.client.Element) Widget(com.google.gwt.user.client.ui.Widget) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Example 14 with HorizontalDropLocation

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

the class VDDHorizontalLayout method emphasis.

/**
 * Empasises the drop location of the component when hovering over a
 * ĆhildComponentContainer. Passing null as the container removes any
 * previous emphasis.
 *
 * @param container
 *            The container which we are hovering over
 * @param event
 *            The drag event
 */
protected void emphasis(Widget container, VDragEvent event) {
    // Remove emphasis from previous hovers
    deEmphasis();
    // validate container
    if (container == null || !getElement().isOrHasChild(container.getElement())) {
        return;
    }
    currentlyEmphasised = container;
    HorizontalDropLocation location = null;
    // Add drop location specific style
    if (currentlyEmphasised != this) {
        location = getHorizontalDropLocation(container, event);
    } else {
        location = HorizontalDropLocation.CENTER;
    }
    UIObject.setStyleName(currentlyEmphasised.getElement(), OVER, true);
    UIObject.setStyleName(currentlyEmphasised.getElement(), OVER + "-" + location.toString().toLowerCase(), true);
}
Also used : HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Example 15 with HorizontalDropLocation

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

the class DefaultCssLayoutDropHandler method handleHTML5Drop.

@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
    CssLayoutTargetDetails details = (CssLayoutTargetDetails) event.getTargetDetails();
    Component over = details.getOverComponent();
    DDCssLayout layout = (DDCssLayout) details.getTarget();
    int idx = (details).getOverIndex();
    HorizontalDropLocation hl = details.getHorizontalDropLocation();
    VerticalDropLocation vl = details.getVerticalDropLocation();
    if (over == layout) {
        if (vl == VerticalDropLocation.TOP || hl == HorizontalDropLocation.LEFT) {
            idx = 0;
        } else if (vl == VerticalDropLocation.BOTTOM || hl == HorizontalDropLocation.RIGHT) {
            idx = -1;
        }
    } else {
        if (vl == VerticalDropLocation.BOTTOM || hl == HorizontalDropLocation.RIGHT) {
            idx++;
        }
    }
    if (idx >= 0 && idx < layout.getComponentCount()) {
        layout.addComponent(resolveComponentFromHTML5Drop(event), idx);
    } else {
        layout.addComponent(resolveComponentFromHTML5Drop(event));
    }
}
Also used : DDCssLayout(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout) CssLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout.CssLayoutTargetDetails) VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation) Component(com.vaadin.ui.Component)

Aggregations

HorizontalDropLocation (com.vaadin.shared.ui.dd.HorizontalDropLocation)20 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)7 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)5 Component (com.vaadin.ui.Component)5 Element (com.google.gwt.dom.client.Element)4 Widget (com.google.gwt.user.client.ui.Widget)4 HorizontalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDHorizontalLayout.HorizontalLayoutTargetDetails)3 DDTabSheet (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet)3 TabSheetTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet.TabSheetTargetDetails)3 HorizontalLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.v7.DDHorizontalLayout.HorizontalLayoutTargetDetails)3 ComponentConnector (com.vaadin.client.ComponentConnector)3 MouseEventDetails (com.vaadin.shared.MouseEventDetails)3 DDCssLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout)2 CssLayoutTargetDetails (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDCssLayout.CssLayoutTargetDetails)2 ComponentContainer (com.vaadin.ui.ComponentContainer)2 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)2 Style (com.google.gwt.dom.client.Style)1 UIObject (com.google.gwt.user.client.ui.UIObject)1 VCaption (com.vaadin.client.VCaption)1 Tab (com.vaadin.ui.TabSheet.Tab)1