Search in sources :

Example 6 with VerticalDropLocation

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

the class VDDAccordion 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) {
    if (event.getElementOver() == null) {
        return;
    }
    StackItem tab = WidgetUtil.findWidget(event.getElementOver(), StackItem.class);
    if (tab != null && getElement().isOrHasChild(tab.getElement())) {
        Map<String, Object> dropDetails = event.getDropDetails();
        int index = getTabPosition(tab);
        dropDetails.put(Constants.DROP_DETAIL_TO, index);
        VerticalDropLocation location = getDropLocation(tab, event);
        dropDetails.put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION, location);
        MouseEventDetails details = MouseEventDetailsBuilder.buildMouseEventDetails(event.getCurrentGwtEvent(), getElement());
        dropDetails.put(Constants.DROP_DETAIL_MOUSE_EVENT, details.serialize());
    }
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) MouseEventDetails(com.vaadin.shared.MouseEventDetails)

Example 7 with VerticalDropLocation

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

the class VDDAccordion method emphasis.

/**
 * Emphasisizes a container element
 *
 * @param element
 */
protected void emphasis(Element element, VDragEvent event) {
    // Find the tab
    StackItem tab = WidgetUtil.findWidget(element, StackItem.class);
    if (tab != null && getElement().isOrHasChild(tab.getElement()) && currentlyEmphasised != tab) {
        VerticalDropLocation location = getDropLocation(tab, event);
        if (location == VerticalDropLocation.MIDDLE) {
            if (tab.isOpen()) {
                tab.addStyleName(CLASSNAME_OVER);
            } else {
                tab.getWidget(0).addStyleName(CLASSNAME_OVER);
            }
        } else if (!spacer.isAttached()) {
            if (location == VerticalDropLocation.TOP) {
                insertSpacer(spacer, getElement(), getWidgetIndex(tab));
                tab.setHeight((tab.getOffsetHeight() - spacer.getOffsetHeight()) + "px");
            } else if (location == VerticalDropLocation.BOTTOM) {
                insertSpacer(spacer, getElement(), getWidgetIndex(tab) + 1);
                int newHeight = tab.getOffsetHeight() - spacer.getOffsetHeight();
                if (getWidgetIndex(spacer) == getWidgetCount() - 1) {
                    newHeight -= spacer.getOffsetHeight();
                }
                if (newHeight >= 0) {
                    tab.setHeight(newHeight + "px");
                }
            }
        }
        currentlyEmphasised = tab;
    }
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation)

Example 8 with VerticalDropLocation

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

the class VDDGridLayout method emphasis.

/**
 * Emphasizes a component container when user is hovering a dragged
 * component over the container.
 *
 * @param cell
 *            The container
 * @param event
 */
protected void emphasis(CellDetails cell, VDragEvent event) {
    Style shadowStyle = dragShadow.getElement().getStyle();
    shadowStyle.setPosition(Position.ABSOLUTE);
    shadowStyle.setWidth(cell.width, Unit.PX);
    shadowStyle.setHeight(cell.height, Unit.PX);
    shadowStyle.setLeft(cell.x, Unit.PX);
    shadowStyle.setTop(cell.y, Unit.PX);
    // Remove any existing empasis
    deEmphasis();
    // Ensure we are not dragging ourself into ourself
    ComponentConnector draggedConnector = (ComponentConnector) event.getTransferable().getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);
    if (draggedConnector != null && draggedConnector.getWidget() == VDDGridLayout.this) {
        return;
    }
    HorizontalDropLocation hl = getHorizontalDropLocation(cell, event);
    VerticalDropLocation vl = getVerticalDropLocation(cell, event);
    // Apply over style
    setStyleName(dragShadow.getElement(), OVER, true);
    // Add vertical location dependent style
    setStyleName(dragShadow.getElement(), OVER + "-" + vl.toString().toLowerCase(), true);
    // Add horizontal location dependent style
    setStyleName(dragShadow.getElement(), OVER + "-" + hl.toString().toLowerCase(), true);
}
Also used : ComponentConnector(com.vaadin.client.ComponentConnector) VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) Style(com.google.gwt.dom.client.Style) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Example 9 with VerticalDropLocation

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

the class VDDGridLayout method updateDragDetails.

/**
 * Updates the drop details while dragging
 *
 * @param event
 *            The drag event
 */
public void updateDragDetails(VDragEvent event) {
    CellDetails cd = getCellDetails(event);
    if (cd != null) {
        Map<String, Object> ddetails = event.getDropDetails();
        // Add row
        ddetails.put(Constants.DROP_DETAIL_ROW, Integer.valueOf(cd.row));
        // Add column
        ddetails.put(Constants.DROP_DETAIL_COLUMN, Integer.valueOf(cd.column));
        // Add horizontal position
        HorizontalDropLocation hl = getHorizontalDropLocation(cd, event);
        ddetails.put(Constants.DROP_DETAIL_HORIZONTAL_DROP_LOCATION, hl);
        // Add vertical position
        VerticalDropLocation vl = getVerticalDropLocation(cd, event);
        ddetails.put(Constants.DROP_DETAIL_VERTICAL_DROP_LOCATION, vl);
        // Check if the cell we are hovering over has content
        Cell cell = getCell(cd.row, cd.column);
        ddetails.put(Constants.DROP_DETAIL_EMPTY_CELL, cell != null);
        // Get class information from child
        if (cell != null && cell.slot != null) {
            ComponentConnector child = cell.slot.getChild();
            if (child != null) {
                String className = child.getWidget().getClass().getName();
                ddetails.put(Constants.DROP_DETAIL_OVER_CLASS, className);
            } else {
                ddetails.put(Constants.DROP_DETAIL_OVER_CLASS, VDDGridLayout.this.getClass().getName());
            }
        } else {
            ddetails.put(Constants.DROP_DETAIL_OVER_CLASS, VDDGridLayout.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 : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) ComponentConnector(com.vaadin.client.ComponentConnector) MouseEventDetails(com.vaadin.shared.MouseEventDetails) UIObject(com.google.gwt.user.client.ui.UIObject) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Example 10 with VerticalDropLocation

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

the class DefaultCssLayoutDropHandler method handleDropFromLayout.

@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    CssLayoutTargetDetails details = (CssLayoutTargetDetails) event.getTargetDetails();
    DDCssLayout layout = (DDCssLayout) details.getTarget();
    HorizontalDropLocation hl = details.getHorizontalDropLocation();
    VerticalDropLocation vl = details.getVerticalDropLocation();
    Component source = event.getTransferable().getSourceComponent();
    int idx = (details).getOverIndex();
    Component comp = transferable.getComponent();
    Component over = details.getOverComponent();
    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++;
        }
    }
    // 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();
    }
    // the component cannot have two parents.
    if (source instanceof ComponentContainer) {
        ComponentContainer sourceLayout = (ComponentContainer) source;
        sourceLayout.removeComponent(comp);
    }
    // Add component
    if (idx >= 0 && idx < layout.getComponentCount()) {
        layout.addComponent(comp, idx);
    } else {
        layout.addComponent(comp);
    }
}
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) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) ComponentContainer(com.vaadin.ui.ComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation) Component(com.vaadin.ui.Component)

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