Search in sources :

Example 1 with HorizontalDropLocation

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

the class VDDTabSheet method emphasis.

/**
 * Emphasisizes a container element
 *
 * @param element
 */
protected void emphasis(Element element, VDragEvent event) {
    boolean internalDrag = event.getTransferable().getDragSource() == this;
    if (tabBar.getElement().isOrHasChild(element)) {
        Widget w = Util.findWidget(element, null);
        if (w == tabBar && !internalDrag) {
            // Over spacer
            Element spacerContent = spacer.getChild(0).cast();
            spacerContent.appendChild(newTab);
            currentlyEmphasised = element;
        } else if (w instanceof VCaption) {
            // Over a tab
            HorizontalDropLocation location = VDragDropUtil.getHorizontalDropLocation(DOM.asOld(element), Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()), tabLeftRightDropRatio);
            if (location == HorizontalDropLocation.LEFT) {
                int index = getTabPosition(w);
                if (index == 0) {
                    currentlyEmphasised = tabBar.getWidget(0).getElement().getFirstChildElement().cast();
                    currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_LEFT);
                } else {
                    Widget prevTab = tabBar.getWidget(index - 1);
                    currentlyEmphasised = prevTab.getElement();
                    currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_RIGHT);
                }
            } else if (location == HorizontalDropLocation.RIGHT) {
                int index = getTabPosition(w);
                currentlyEmphasised = tabBar.getWidget(index).getElement();
                currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_RIGHT);
            } else {
                int index = getTabPosition(w);
                currentlyEmphasised = tabBar.getWidget(index).getElement();
                currentlyEmphasised.addClassName(CLASSNAME_NEW_TAB_CENTER);
            }
        }
    }
}
Also used : Element(com.google.gwt.dom.client.Element) Widget(com.google.gwt.user.client.ui.Widget) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation) VCaption(com.vaadin.client.VCaption)

Example 2 with HorizontalDropLocation

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

the class VDDGridLayout method getHorizontalDropLocation.

/**
 * Returns the horizontal drop location
 *
 * @param cell
 *            The cell details
 * @param event
 *            The drag event
 * @return
 */
protected HorizontalDropLocation getHorizontalDropLocation(CellDetails cell, VDragEvent event) {
    // Get the horizontal location
    HorizontalDropLocation hdetail;
    int x = Util.getTouchOrMouseClientX(event.getCurrentGwtEvent()) - getAbsoluteLeft() - cell.x;
    assert (x >= 0 && x <= cell.width);
    if (x < cell.width * cellLeftRightDropRatio) {
        hdetail = HorizontalDropLocation.LEFT;
    } else if (x < cell.width * (1.0 - cellLeftRightDropRatio)) {
        hdetail = HorizontalDropLocation.CENTER;
    } else {
        hdetail = HorizontalDropLocation.RIGHT;
    }
    return hdetail;
}
Also used : HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

Example 3 with HorizontalDropLocation

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

use of com.vaadin.shared.ui.dd.HorizontalDropLocation 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 5 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;
    }
    setStyleName(currentlyEmphasised.getElement(), OVER, true);
    setStyleName(currentlyEmphasised.getElement(), OVER + "-" + location.toString().toLowerCase(), true);
}
Also used : HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation)

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